| 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 |
|
| 4891 |
varun.gupt |
13 |
import javax.mail.internet.AddressException;
|
|
|
14 |
import javax.mail.internet.InternetAddress;
|
|
|
15 |
|
| 3209 |
vikas |
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 |
|
| 4892 |
varun.gupt |
22 |
public static final String EXPORT_ENTITIES_PATH = getExportPath();
|
| 5084 |
phani.kuma |
23 |
public static final String EXPORT_JAVASCRIPT_CONTENT_PATH = "/var/lib/tomcat6/webapps/export/javascripts/";
|
| 2306 |
vikas |
24 |
public static final long ROOT_CATEGORY = 10000;
|
|
|
25 |
public static final long MOBILE_PHONES_CATEGORY = 10001;
|
|
|
26 |
public static final long MOBILE_ACCESSORIES_CATEGORY = 10011;
|
| 3656 |
mandeep.dh |
27 |
public static final long TABLETS_CATEGORY = 10010;
|
|
|
28 |
public static final long LAPTOPS_CATEGORY = 10050;
|
| 5873 |
amit.gupta |
29 |
public static final long CAMERAS_CATEGORY = 11001;
|
| 3656 |
mandeep.dh |
30 |
|
| 4137 |
varun.gupt |
31 |
public static String[] facetDefIDs = new String[] {
|
| 5941 |
amit.gupta |
32 |
"F_50010","F_50011","F_50002","F_50001", "F_50006", "F_50007", "F_50012", "F_50013", "F_50014", "F_50015", "F_50017", "F_50018", "F_50019", "F_50020", "F_50021", "F_50022", "F_50023", "F_50024", "F_50025", "F_50026", "F_50027" };
|
| 4272 |
varun.gupt |
33 |
public static String[] facetLabels = new String[] {"Category","Sub Category","Price", "Brand", "Data Connectivity",
|
| 5439 |
phani.kuma |
34 |
"Camera Resolution", "Display", "Operating System", "RAM", "Storage Capacity", "Processor",
|
| 5941 |
amit.gupta |
35 |
"Capacity", "Class", "Capacity", "Capacity", "Type", "Interface", "Resolution", "Optical Zoom", "Display Size", "Effective Resolution" };
|
| 5525 |
phani.kuma |
36 |
public static String[] rootfacetDefIDs = new String[] {"F_50010","F_50011","F_50002","F_50001"};
|
|
|
37 |
public static String[] rootfacetLabels = new String[] {"Category","Sub Category","Price", "Brand"};
|
| 1453 |
chandransh |
38 |
private static String getExportPath(){
|
| 1457 |
chandransh |
39 |
String exportPath=null;
|
| 1453 |
chandransh |
40 |
ConfigClient client = ConfigClient.getClient();
|
|
|
41 |
try{
|
|
|
42 |
exportPath = client.get("export_entities_path");
|
|
|
43 |
}catch(ConfigException ce){
|
| 2942 |
chandransh |
44 |
logger.error("Unable to read export path from the config client: ", ce);
|
|
|
45 |
logger.warn("Setting the default export path");
|
| 1475 |
chandransh |
46 |
exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
|
| 1453 |
chandransh |
47 |
}
|
|
|
48 |
return exportPath;
|
|
|
49 |
}
|
|
|
50 |
|
| 822 |
vikas |
51 |
public static boolean validatePin(String pincode) {
|
|
|
52 |
int pin;
|
|
|
53 |
try {
|
|
|
54 |
pin = Integer.parseInt(pincode);
|
|
|
55 |
}
|
|
|
56 |
catch (NumberFormatException e) {
|
|
|
57 |
return false;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
if (pin < 100000 || pin > 999999) {
|
|
|
61 |
return false;
|
|
|
62 |
}
|
|
|
63 |
return true;
|
|
|
64 |
}
|
| 4891 |
varun.gupt |
65 |
|
|
|
66 |
public static boolean isValidEmail(String emailAddress) {
|
|
|
67 |
|
|
|
68 |
if(emailAddress == null || emailAddress.isEmpty()) {
|
|
|
69 |
return false;
|
|
|
70 |
}
|
|
|
71 |
try {
|
|
|
72 |
InternetAddress address = new InternetAddress(emailAddress, true);
|
|
|
73 |
address.validate();
|
|
|
74 |
return true;
|
|
|
75 |
|
|
|
76 |
} catch (AddressException e) {
|
|
|
77 |
logger.error(emailAddress + " is not valid email address ", e);
|
|
|
78 |
return false;
|
|
|
79 |
}
|
|
|
80 |
}
|
| 822 |
vikas |
81 |
|
|
|
82 |
public static boolean validatePhone(String phone) {
|
| 839 |
vikas |
83 |
long iPhone;
|
| 822 |
vikas |
84 |
try {
|
| 839 |
vikas |
85 |
iPhone = Long.parseLong(phone);
|
| 822 |
vikas |
86 |
}
|
|
|
87 |
catch (NumberFormatException e) {
|
|
|
88 |
return false;
|
|
|
89 |
}
|
| 839 |
vikas |
90 |
|
|
|
91 |
if (iPhone < 1000000000l || iPhone > 9999999999l) {
|
|
|
92 |
return false;
|
|
|
93 |
}
|
| 822 |
vikas |
94 |
return true;
|
|
|
95 |
}
|
| 3209 |
vikas |
96 |
|
|
|
97 |
public static String getItemIdStringInCart(Cart cart) {
|
|
|
98 |
List<String> itemIds = new ArrayList<String>();
|
|
|
99 |
for (Line line : cart.getLines()) {
|
|
|
100 |
itemIds.add(Long.toString(line.getItemId()));
|
|
|
101 |
}
|
|
|
102 |
return StringUtils.join(itemIds, '_');
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
public static String getItemIdStringFromOrders(List<Order> orders) {
|
|
|
106 |
List<String> itemIds = new ArrayList<String>();
|
|
|
107 |
if (orders != null) {
|
|
|
108 |
for (Order order : orders) {
|
|
|
109 |
for (LineItem lItem : order.getLineitems()) {
|
|
|
110 |
itemIds.add(Long.toString(lItem.getItem_id()));
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
return StringUtils.join(itemIds, '_');
|
| 4892 |
varun.gupt |
115 |
}
|
| 4891 |
varun.gupt |
116 |
}
|