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