Subversion Repositories SmartDukaan

Rev

Rev 1971 | Rev 2306 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
419 rajveer 1
package in.shop2020.serving.utils;
2
 
1453 chandransh 3
import in.shop2020.config.ConfigException;
424 rajveer 4
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.model.v1.catalog.InventoryService.Client;
421 rajveer 6
import in.shop2020.thrift.clients.CatalogServiceClient;
1453 chandransh 7
import in.shop2020.thrift.clients.config.ConfigClient;
419 rajveer 8
 
9
public class Utils {
1453 chandransh 10
	public static final String EXPORT_ENTITIES_PATH = getExportPath();
424 rajveer 11
 
1453 chandransh 12
	private static String getExportPath(){
1457 chandransh 13
		String exportPath=null;
1453 chandransh 14
		ConfigClient client = ConfigClient.getClient();
15
		try{
16
			exportPath = client.get("export_entities_path");
17
		}catch(ConfigException ce){
1455 chandransh 18
			ce.printStackTrace();
1475 chandransh 19
			exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
1453 chandransh 20
		}
21
		return exportPath;
22
	}
23
 
637 rajveer 24
	public static double getItemPrice(long itemId){
424 rajveer 25
		CatalogServiceClient catalogServiceClient = null;
26
		Client client = null;
27
		Double itemPrice = 0.0;
28
		try {
29
			catalogServiceClient = new CatalogServiceClient();
30
			client = catalogServiceClient.getClient();
637 rajveer 31
			Item item = client.getItem(itemId);
517 rajveer 32
			itemPrice = item.getSellingPrice();
536 rajveer 33
 
424 rajveer 34
		}
35
		catch(Exception e){
36
			e.printStackTrace();
37
		}
38
		return itemPrice;
39
	}
40
 
449 rajveer 41
 
1971 rajveer 42
/*	
637 rajveer 43
	public static void storeCategories(Object obj) throws Exception {
44
 
45
		ByteArrayOutputStream bStream = new ByteArrayOutputStream();
46
		ObjectOutputStream oStream = new ObjectOutputStream( bStream );
47
		oStream.writeObject ( obj );
48
 
49
		byte[] byteVal = bStream. toByteArray();
50
 
51
		CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
52
		Client client = catalogServiceClient.getClient();
53
 
54
		client.putCategoryObject(byteVal);
55
	}
1971 rajveer 56
	*/
57
	/*
637 rajveer 58
	public static Object getCategories() throws Exception {
59
		CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
60
		Client client = catalogServiceClient.getClient();
61
 
62
		byte[] byteVal  = client.getCategoryObject();
63
 
64
		Object obj = null;
65
		ObjectInputStream in = null;
66
		try {
67
			ByteArrayInputStream bStream = new ByteArrayInputStream(byteVal);
68
			in = new ObjectInputStream(bStream);
69
			obj = in.readObject();
70
		}
71
		finally {
72
			if(in != null) {
73
				in.close();
74
			}
75
		}
76
		return obj;
77
	}
1971 rajveer 78
	*/
822 vikas 79
	public static boolean validatePin(String pincode) {
80
		int pin;
81
		try {
82
			pin = Integer.parseInt(pincode);
83
		}
84
		catch (NumberFormatException e) {
85
			return false;
86
		}
87
 
88
		if (pin < 100000 || pin > 999999) {
89
			return false;
90
		}
91
		return true;
92
	}
93
 
94
	public static boolean validatePhone(String phone) {
839 vikas 95
		long iPhone;
822 vikas 96
		try {
839 vikas 97
    		iPhone = Long.parseLong(phone);
822 vikas 98
		}
99
		catch (NumberFormatException e) {
100
			return false;
101
		}
839 vikas 102
 
103
		if (iPhone < 1000000000l || iPhone > 9999999999l) {
104
			return false;
105
		}
822 vikas 106
		return true;
107
	}
108
 
109
 
649 chandransh 110
//	public static void main(String args[]) throws Exception{
111
//		// to store categories
112
//		Map<Long, Category> categories = new HashMap<Long, Category>();
113
//		Map<Long, in.shop2020.metamodel.definitions.Category> cmsCategories = Catalog.getInstance().getDefinitionsContainer().getCategories();
114
//		for(in.shop2020.metamodel.definitions.Category cmsCategory: cmsCategories.values()){
115
//			Category category = new Category(cmsCategory.getID());
116
//			category.setLabel(cmsCategory.getLabel());
117
//			if(cmsCategory.getParentCategory()!=null){
118
//				category.setParentCategoryId(cmsCategory.getParentCategory().getID());
119
//			}
120
//			if(cmsCategory.getChildrenCategory()!=null){
121
//				for(in.shop2020.metamodel.definitions.Category childCategory: cmsCategory.getChildrenCategory()){
122
//					category.addChild(childCategory.getID());
123
//				}
124
//			}
125
//			categories.put(cmsCategory.getID(), category);
126
//		}
127
//		Utils.storeCategories(categories);
128
//		// to get categories
129
//		//Map<Long, Category> 
130
//		categories = (Map<Long, Category>)Utils.getCategories();
131
//		System.out.println("hello");
132
//	}
133
 
419 rajveer 134
}
745 chandransh 135