| 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;
|
| 6178 |
anupam.sin |
6 |
import in.shop2020.model.v1.order.RechargePlan;
|
| 6135 |
anupam.sin |
7 |
import in.shop2020.model.v1.order.RechargeType;
|
| 3209 |
vikas |
8 |
import in.shop2020.model.v1.user.Cart;
|
|
|
9 |
import in.shop2020.model.v1.user.Line;
|
| 6135 |
anupam.sin |
10 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 1453 |
chandransh |
11 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 419 |
rajveer |
12 |
|
| 3209 |
vikas |
13 |
import java.util.ArrayList;
|
| 6178 |
anupam.sin |
14 |
import java.util.HashMap;
|
| 3209 |
vikas |
15 |
import java.util.List;
|
| 6135 |
anupam.sin |
16 |
import java.util.Map;
|
| 6178 |
anupam.sin |
17 |
import java.util.Map.Entry;
|
| 3209 |
vikas |
18 |
|
| 4891 |
varun.gupt |
19 |
import javax.mail.internet.AddressException;
|
|
|
20 |
import javax.mail.internet.InternetAddress;
|
|
|
21 |
|
| 3209 |
vikas |
22 |
import org.apache.commons.lang.StringUtils;
|
|
|
23 |
import org.apache.log4j.Logger;
|
| 6135 |
anupam.sin |
24 |
import org.apache.thrift.transport.TTransportException;
|
| 3209 |
vikas |
25 |
|
| 419 |
rajveer |
26 |
public class Utils {
|
| 2942 |
chandransh |
27 |
private static Logger logger = Logger.getLogger(Utils.class);
|
|
|
28 |
|
| 4892 |
varun.gupt |
29 |
public static final String EXPORT_ENTITIES_PATH = getExportPath();
|
| 5084 |
phani.kuma |
30 |
public static final String EXPORT_JAVASCRIPT_CONTENT_PATH = "/var/lib/tomcat6/webapps/export/javascripts/";
|
| 2306 |
vikas |
31 |
public static final long ROOT_CATEGORY = 10000;
|
|
|
32 |
public static final long MOBILE_PHONES_CATEGORY = 10001;
|
|
|
33 |
public static final long MOBILE_ACCESSORIES_CATEGORY = 10011;
|
| 3656 |
mandeep.dh |
34 |
public static final long TABLETS_CATEGORY = 10010;
|
|
|
35 |
public static final long LAPTOPS_CATEGORY = 10050;
|
| 5873 |
amit.gupta |
36 |
public static final long CAMERAS_CATEGORY = 11001;
|
| 6135 |
anupam.sin |
37 |
|
|
|
38 |
static Map<Long, String> providersMap;
|
| 6178 |
anupam.sin |
39 |
static Map<Long, String> mobileProvidersMap;
|
|
|
40 |
static Map<Long, String> dthProvidersMap;
|
|
|
41 |
static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<Long, List<RechargePlan>>();
|
| 3656 |
mandeep.dh |
42 |
|
| 4137 |
varun.gupt |
43 |
public static String[] facetDefIDs = new String[] {
|
| 5941 |
amit.gupta |
44 |
"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 |
45 |
public static String[] facetLabels = new String[] {"Category","Sub Category","Price", "Brand", "Data Connectivity",
|
| 5439 |
phani.kuma |
46 |
"Camera Resolution", "Display", "Operating System", "RAM", "Storage Capacity", "Processor",
|
| 5941 |
amit.gupta |
47 |
"Capacity", "Class", "Capacity", "Capacity", "Type", "Interface", "Resolution", "Optical Zoom", "Display Size", "Effective Resolution" };
|
| 5525 |
phani.kuma |
48 |
public static String[] rootfacetDefIDs = new String[] {"F_50010","F_50011","F_50002","F_50001"};
|
|
|
49 |
public static String[] rootfacetLabels = new String[] {"Category","Sub Category","Price", "Brand"};
|
| 6135 |
anupam.sin |
50 |
|
|
|
51 |
static {
|
|
|
52 |
TransactionClient tcl;
|
|
|
53 |
try {
|
|
|
54 |
tcl = new TransactionClient();
|
| 6178 |
anupam.sin |
55 |
mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE);
|
|
|
56 |
dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH);
|
|
|
57 |
// providersMap.putAll(mobileProvidersMap);
|
|
|
58 |
// providersMap.putAll(dthProvidersMap);
|
|
|
59 |
for (Long operatorId : mobileProvidersMap.keySet()) {
|
|
|
60 |
List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);
|
|
|
61 |
if (!plans.isEmpty()) {
|
|
|
62 |
operatorPlanMap.put(operatorId, plans);
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
// providersMap.putAll(tcl.getClient().getServiceProviders(RechargeType.DTH));
|
| 6135 |
anupam.sin |
66 |
} catch (Exception e) {
|
|
|
67 |
logger.error("Could not get providers", e);
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
| 1453 |
chandransh |
73 |
private static String getExportPath(){
|
| 1457 |
chandransh |
74 |
String exportPath=null;
|
| 1453 |
chandransh |
75 |
ConfigClient client = ConfigClient.getClient();
|
|
|
76 |
try{
|
|
|
77 |
exportPath = client.get("export_entities_path");
|
|
|
78 |
}catch(ConfigException ce){
|
| 2942 |
chandransh |
79 |
logger.error("Unable to read export path from the config client: ", ce);
|
|
|
80 |
logger.warn("Setting the default export path");
|
| 1475 |
chandransh |
81 |
exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
|
| 1453 |
chandransh |
82 |
}
|
|
|
83 |
return exportPath;
|
|
|
84 |
}
|
|
|
85 |
|
| 822 |
vikas |
86 |
public static boolean validatePin(String pincode) {
|
|
|
87 |
int pin;
|
|
|
88 |
try {
|
|
|
89 |
pin = Integer.parseInt(pincode);
|
|
|
90 |
}
|
|
|
91 |
catch (NumberFormatException e) {
|
|
|
92 |
return false;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
if (pin < 100000 || pin > 999999) {
|
|
|
96 |
return false;
|
|
|
97 |
}
|
|
|
98 |
return true;
|
|
|
99 |
}
|
| 4891 |
varun.gupt |
100 |
|
|
|
101 |
public static boolean isValidEmail(String emailAddress) {
|
|
|
102 |
|
|
|
103 |
if(emailAddress == null || emailAddress.isEmpty()) {
|
|
|
104 |
return false;
|
|
|
105 |
}
|
|
|
106 |
try {
|
|
|
107 |
InternetAddress address = new InternetAddress(emailAddress, true);
|
|
|
108 |
address.validate();
|
|
|
109 |
return true;
|
|
|
110 |
|
|
|
111 |
} catch (AddressException e) {
|
|
|
112 |
logger.error(emailAddress + " is not valid email address ", e);
|
|
|
113 |
return false;
|
|
|
114 |
}
|
|
|
115 |
}
|
| 822 |
vikas |
116 |
|
|
|
117 |
public static boolean validatePhone(String phone) {
|
| 839 |
vikas |
118 |
long iPhone;
|
| 822 |
vikas |
119 |
try {
|
| 839 |
vikas |
120 |
iPhone = Long.parseLong(phone);
|
| 822 |
vikas |
121 |
}
|
|
|
122 |
catch (NumberFormatException e) {
|
|
|
123 |
return false;
|
|
|
124 |
}
|
| 839 |
vikas |
125 |
|
|
|
126 |
if (iPhone < 1000000000l || iPhone > 9999999999l) {
|
|
|
127 |
return false;
|
|
|
128 |
}
|
| 822 |
vikas |
129 |
return true;
|
|
|
130 |
}
|
| 3209 |
vikas |
131 |
|
|
|
132 |
public static String getItemIdStringInCart(Cart cart) {
|
|
|
133 |
List<String> itemIds = new ArrayList<String>();
|
|
|
134 |
for (Line line : cart.getLines()) {
|
|
|
135 |
itemIds.add(Long.toString(line.getItemId()));
|
|
|
136 |
}
|
|
|
137 |
return StringUtils.join(itemIds, '_');
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
public static String getItemIdStringFromOrders(List<Order> orders) {
|
|
|
141 |
List<String> itemIds = new ArrayList<String>();
|
|
|
142 |
if (orders != null) {
|
|
|
143 |
for (Order order : orders) {
|
|
|
144 |
for (LineItem lItem : order.getLineitems()) {
|
|
|
145 |
itemIds.add(Long.toString(lItem.getItem_id()));
|
|
|
146 |
}
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
return StringUtils.join(itemIds, '_');
|
| 6135 |
anupam.sin |
150 |
}
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
public static String getRechargeProviderName(long providerId) {
|
|
|
155 |
return providersMap.get(providerId);
|
|
|
156 |
}
|
| 6178 |
anupam.sin |
157 |
|
|
|
158 |
public static Map<Long, String> getMobileProvidersMap() {
|
|
|
159 |
return mobileProvidersMap;
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
public static Map<Long, String> getDthProvidersMap() {
|
|
|
163 |
return dthProvidersMap;
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
public static Map<Long, List<RechargePlan>> getOperatorPlanMap() {
|
|
|
167 |
return operatorPlanMap;
|
|
|
168 |
}
|
| 4891 |
varun.gupt |
169 |
}
|