Subversion Repositories SmartDukaan

Rev

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