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