| 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;
|
| 2505 |
rajveer |
14 |
public static final long TABLETS_CATEGORY = 10010;
|
| 2306 |
vikas |
15 |
|
| 1453 |
chandransh |
16 |
private static String getExportPath(){
|
| 1457 |
chandransh |
17 |
String exportPath=null;
|
| 1453 |
chandransh |
18 |
ConfigClient client = ConfigClient.getClient();
|
|
|
19 |
try{
|
|
|
20 |
exportPath = client.get("export_entities_path");
|
|
|
21 |
}catch(ConfigException ce){
|
| 1455 |
chandransh |
22 |
ce.printStackTrace();
|
| 1475 |
chandransh |
23 |
exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
|
| 1453 |
chandransh |
24 |
}
|
|
|
25 |
return exportPath;
|
|
|
26 |
}
|
|
|
27 |
|
| 637 |
rajveer |
28 |
public static double getItemPrice(long itemId){
|
| 424 |
rajveer |
29 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
30 |
Client client = null;
|
|
|
31 |
Double itemPrice = 0.0;
|
|
|
32 |
try {
|
|
|
33 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
34 |
client = catalogServiceClient.getClient();
|
| 637 |
rajveer |
35 |
Item item = client.getItem(itemId);
|
| 517 |
rajveer |
36 |
itemPrice = item.getSellingPrice();
|
| 536 |
rajveer |
37 |
|
| 424 |
rajveer |
38 |
}
|
|
|
39 |
catch(Exception e){
|
|
|
40 |
e.printStackTrace();
|
|
|
41 |
}
|
|
|
42 |
return itemPrice;
|
|
|
43 |
}
|
|
|
44 |
|
| 449 |
rajveer |
45 |
|
| 1971 |
rajveer |
46 |
/*
|
| 637 |
rajveer |
47 |
public static void storeCategories(Object obj) throws Exception {
|
|
|
48 |
|
|
|
49 |
ByteArrayOutputStream bStream = new ByteArrayOutputStream();
|
|
|
50 |
ObjectOutputStream oStream = new ObjectOutputStream( bStream );
|
|
|
51 |
oStream.writeObject ( obj );
|
|
|
52 |
|
|
|
53 |
byte[] byteVal = bStream. toByteArray();
|
|
|
54 |
|
|
|
55 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
56 |
Client client = catalogServiceClient.getClient();
|
|
|
57 |
|
|
|
58 |
client.putCategoryObject(byteVal);
|
|
|
59 |
}
|
| 1971 |
rajveer |
60 |
*/
|
|
|
61 |
/*
|
| 637 |
rajveer |
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 |
}
|
| 1971 |
rajveer |
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 |
|