Subversion Repositories SmartDukaan

Rev

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