Subversion Repositories SmartDukaan

Rev

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