| 419 |
rajveer |
1 |
package in.shop2020.serving.utils;
|
|
|
2 |
|
| 1453 |
chandransh |
3 |
import in.shop2020.config.ConfigException;
|
| 3209 |
vikas |
4 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
5 |
import in.shop2020.model.v1.order.Order;
|
|
|
6 |
import in.shop2020.model.v1.user.Cart;
|
|
|
7 |
import in.shop2020.model.v1.user.Line;
|
| 1453 |
chandransh |
8 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 419 |
rajveer |
9 |
|
| 3209 |
vikas |
10 |
import java.util.ArrayList;
|
|
|
11 |
import java.util.List;
|
|
|
12 |
|
|
|
13 |
import org.apache.commons.lang.StringUtils;
|
|
|
14 |
import org.apache.log4j.Logger;
|
|
|
15 |
|
| 419 |
rajveer |
16 |
public class Utils {
|
| 2942 |
chandransh |
17 |
private static Logger logger = Logger.getLogger(Utils.class);
|
|
|
18 |
|
| 1453 |
chandransh |
19 |
public static final String EXPORT_ENTITIES_PATH = getExportPath();
|
| 2306 |
vikas |
20 |
public static final long ROOT_CATEGORY = 10000;
|
|
|
21 |
public static final long MOBILE_PHONES_CATEGORY = 10001;
|
|
|
22 |
public static final long MOBILE_ACCESSORIES_CATEGORY = 10011;
|
| 3656 |
mandeep.dh |
23 |
public static final long TABLETS_CATEGORY = 10010;
|
|
|
24 |
public static final long LAPTOPS_CATEGORY = 10050;
|
|
|
25 |
|
| 4137 |
varun.gupt |
26 |
public static String[] facetDefIDs = new String[] {
|
|
|
27 |
"F_50010","F_50011","F_50002","F_50001", "F_50006", "F_50007", "F_500012", "F_500013", "F_500014", "F_500015" };
|
|
|
28 |
public static String[] facetLabels = new String[] {"Category","Sub Category","Price",
|
|
|
29 |
"Brand", "Data Connectivity", "Camera Resolution", "Display", "Operating System", "RAM", "Storage Capacity"
|
|
|
30 |
};
|
| 1453 |
chandransh |
31 |
private static String getExportPath(){
|
| 1457 |
chandransh |
32 |
String exportPath=null;
|
| 1453 |
chandransh |
33 |
ConfigClient client = ConfigClient.getClient();
|
|
|
34 |
try{
|
|
|
35 |
exportPath = client.get("export_entities_path");
|
|
|
36 |
}catch(ConfigException ce){
|
| 2942 |
chandransh |
37 |
logger.error("Unable to read export path from the config client: ", ce);
|
|
|
38 |
logger.warn("Setting the default export path");
|
| 1475 |
chandransh |
39 |
exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
|
| 1453 |
chandransh |
40 |
}
|
|
|
41 |
return exportPath;
|
|
|
42 |
}
|
|
|
43 |
|
| 822 |
vikas |
44 |
public static boolean validatePin(String pincode) {
|
|
|
45 |
int pin;
|
|
|
46 |
try {
|
|
|
47 |
pin = Integer.parseInt(pincode);
|
|
|
48 |
}
|
|
|
49 |
catch (NumberFormatException e) {
|
|
|
50 |
return false;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
if (pin < 100000 || pin > 999999) {
|
|
|
54 |
return false;
|
|
|
55 |
}
|
|
|
56 |
return true;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
public static boolean validatePhone(String phone) {
|
| 839 |
vikas |
60 |
long iPhone;
|
| 822 |
vikas |
61 |
try {
|
| 839 |
vikas |
62 |
iPhone = Long.parseLong(phone);
|
| 822 |
vikas |
63 |
}
|
|
|
64 |
catch (NumberFormatException e) {
|
|
|
65 |
return false;
|
|
|
66 |
}
|
| 839 |
vikas |
67 |
|
|
|
68 |
if (iPhone < 1000000000l || iPhone > 9999999999l) {
|
|
|
69 |
return false;
|
|
|
70 |
}
|
| 822 |
vikas |
71 |
return true;
|
|
|
72 |
}
|
| 3209 |
vikas |
73 |
|
|
|
74 |
public static String getItemIdStringInCart(Cart cart) {
|
|
|
75 |
List<String> itemIds = new ArrayList<String>();
|
|
|
76 |
for (Line line : cart.getLines()) {
|
|
|
77 |
itemIds.add(Long.toString(line.getItemId()));
|
|
|
78 |
}
|
|
|
79 |
return StringUtils.join(itemIds, '_');
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
public static String getItemIdStringFromOrders(List<Order> orders) {
|
|
|
83 |
List<String> itemIds = new ArrayList<String>();
|
|
|
84 |
if (orders != null) {
|
|
|
85 |
for (Order order : orders) {
|
|
|
86 |
for (LineItem lItem : order.getLineitems()) {
|
|
|
87 |
itemIds.add(Long.toString(lItem.getItem_id()));
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
return StringUtils.join(itemIds, '_');
|
|
|
92 |
}
|
| 822 |
vikas |
93 |
|
|
|
94 |
|
| 419 |
rajveer |
95 |
}
|
| 745 |
chandransh |
96 |
|