| 419 |
rajveer |
1 |
package in.shop2020.serving.utils;
|
|
|
2 |
|
| 1453 |
chandransh |
3 |
import in.shop2020.config.ConfigException;
|
| 12620 |
amit.gupta |
4 |
import in.shop2020.model.v1.catalog.ExclusiveAffiliateItemInfo;
|
| 3209 |
vikas |
5 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
6 |
import in.shop2020.model.v1.order.Order;
|
| 6603 |
anupam.sin |
7 |
import in.shop2020.model.v1.order.RechargeOrderStatus;
|
| 6178 |
anupam.sin |
8 |
import in.shop2020.model.v1.order.RechargePlan;
|
| 6135 |
anupam.sin |
9 |
import in.shop2020.model.v1.order.RechargeType;
|
| 3209 |
vikas |
10 |
import in.shop2020.model.v1.user.Cart;
|
|
|
11 |
import in.shop2020.model.v1.user.Line;
|
| 12620 |
amit.gupta |
12 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 6135 |
anupam.sin |
13 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 1453 |
chandransh |
14 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 419 |
rajveer |
15 |
|
| 17646 |
amit.gupta |
16 |
import java.io.BufferedReader;
|
|
|
17 |
import java.io.InputStreamReader;
|
| 3209 |
vikas |
18 |
import java.util.ArrayList;
|
| 6603 |
anupam.sin |
19 |
import java.util.Arrays;
|
| 6998 |
amit.gupta |
20 |
import java.util.Collections;
|
| 12620 |
amit.gupta |
21 |
import java.util.Date;
|
| 6178 |
anupam.sin |
22 |
import java.util.HashMap;
|
| 3209 |
vikas |
23 |
import java.util.List;
|
| 6135 |
anupam.sin |
24 |
import java.util.Map;
|
| 3209 |
vikas |
25 |
|
| 4891 |
varun.gupt |
26 |
import javax.mail.internet.AddressException;
|
|
|
27 |
import javax.mail.internet.InternetAddress;
|
|
|
28 |
|
| 3209 |
vikas |
29 |
import org.apache.commons.lang.StringUtils;
|
| 17646 |
amit.gupta |
30 |
import org.apache.http.HttpResponse;
|
|
|
31 |
import org.apache.http.client.HttpClient;
|
|
|
32 |
import org.apache.http.client.methods.HttpGet;
|
|
|
33 |
import org.apache.http.impl.client.DefaultHttpClient;
|
| 3209 |
vikas |
34 |
import org.apache.log4j.Logger;
|
|
|
35 |
|
| 419 |
rajveer |
36 |
public class Utils {
|
| 2942 |
chandransh |
37 |
private static Logger logger = Logger.getLogger(Utils.class);
|
|
|
38 |
|
| 4892 |
varun.gupt |
39 |
public static final String EXPORT_ENTITIES_PATH = getExportPath();
|
| 5084 |
phani.kuma |
40 |
public static final String EXPORT_JAVASCRIPT_CONTENT_PATH = "/var/lib/tomcat6/webapps/export/javascripts/";
|
| 2306 |
vikas |
41 |
public static final long ROOT_CATEGORY = 10000;
|
|
|
42 |
public static final long MOBILE_PHONES_CATEGORY = 10001;
|
|
|
43 |
public static final long MOBILE_ACCESSORIES_CATEGORY = 10011;
|
| 3656 |
mandeep.dh |
44 |
public static final long TABLETS_CATEGORY = 10010;
|
|
|
45 |
public static final long LAPTOPS_CATEGORY = 10050;
|
| 5873 |
amit.gupta |
46 |
public static final long CAMERAS_CATEGORY = 11001;
|
| 6135 |
anupam.sin |
47 |
|
|
|
48 |
static Map<Long, String> providersMap;
|
| 6178 |
anupam.sin |
49 |
static Map<Long, String> mobileProvidersMap;
|
|
|
50 |
static Map<Long, String> dthProvidersMap;
|
| 12620 |
amit.gupta |
51 |
static Map<Long, ExclusiveAffiliateItemInfo> exclusiveAffiliateItems = null;
|
| 6178 |
anupam.sin |
52 |
static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<Long, List<RechargePlan>>();
|
| 6204 |
rajveer |
53 |
private static Map<String, Map<String, String>> uriOperatorMap = new HashMap<String, Map<String,String>>();
|
| 12620 |
amit.gupta |
54 |
static long fifteenMinsCounter = 0l;
|
| 6204 |
rajveer |
55 |
|
| 6603 |
anupam.sin |
56 |
public static final List<RechargeOrderStatus> refundableRechargeStatusList = new ArrayList<RechargeOrderStatus>(Arrays.asList(new RechargeOrderStatus[]
|
|
|
57 |
{RechargeOrderStatus.RECHARGE_FAILED,
|
| 8932 |
anupam.sin |
58 |
RechargeOrderStatus.RECHARGE_FAILED_REFUNDED}));
|
| 6603 |
anupam.sin |
59 |
|
|
|
60 |
public static Map<RechargeOrderStatus, String> statusMap = new HashMap<RechargeOrderStatus, String>();
|
|
|
61 |
|
| 6998 |
amit.gupta |
62 |
//public static final List<String> multiValuedFacet = Arrays.asList("F_50006");
|
| 6887 |
amit.gupta |
63 |
|
| 6998 |
amit.gupta |
64 |
public static final List<String>rootfacetDefIDs = Arrays.asList("F_50010","F_50011","F_50002", "F_50001", "F_50028");
|
| 8878 |
amit.gupta |
65 |
public static final String availabilityFacet = "F_50028";
|
| 13425 |
amit.gupta |
66 |
@SuppressWarnings("serial")
|
|
|
67 |
public static final Map<String, String> NET_BANKING_CODES_MAP = Collections.unmodifiableMap(
|
|
|
68 |
new HashMap<String, String>(){
|
|
|
69 |
{
|
|
|
70 |
put("1004","AXIB");
|
|
|
71 |
put("1135","CRPB");
|
|
|
72 |
put("1029","FEDB");
|
|
|
73 |
put("1007","HDFB");
|
|
|
74 |
put("1016","ICIB");
|
| 13432 |
amit.gupta |
75 |
put("1032","SBIB");
|
|
|
76 |
put("1034","SBHB");
|
|
|
77 |
put("1038","SBMB");
|
| 17646 |
amit.gupta |
78 |
put("1035","SBMB");
|
| 13432 |
amit.gupta |
79 |
put("1039","SBTB");
|
| 17646 |
amit.gupta |
80 |
put("1127","CITNB");
|
| 13460 |
amit.gupta |
81 |
put("1033","SBBJB");
|
| 13432 |
amit.gupta |
82 |
//Oriental Bank of Commerce
|
|
|
83 |
//put("1154","");
|
| 13425 |
amit.gupta |
84 |
put("1147","CBIB");
|
|
|
85 |
put("1146","YESB");
|
|
|
86 |
put("1214","BOIB");
|
|
|
87 |
put("1215","CUBB");
|
| 13436 |
amit.gupta |
88 |
put("1212","UNIB");
|
| 13425 |
amit.gupta |
89 |
put("1224","CABB");
|
| 13432 |
amit.gupta |
90 |
put("1210","INGB");
|
|
|
91 |
put("1148","162B");
|
|
|
92 |
put("1273","DLSB");
|
| 13425 |
amit.gupta |
93 |
put("1015","JAKB");
|
|
|
94 |
put("1133","KRKB");
|
|
|
95 |
put("1143","INDB");
|
| 13436 |
amit.gupta |
96 |
put("1216","UBIB");
|
| 13425 |
amit.gupta |
97 |
put("1213","INOB");
|
|
|
98 |
put("1229","BOMB");
|
| 13432 |
amit.gupta |
99 |
put("1601","CSBN");
|
|
|
100 |
put("1602","DCBB");
|
|
|
101 |
put("1603","DSHB");
|
|
|
102 |
put("1604","IDBB");
|
|
|
103 |
put("1605","INIB");
|
|
|
104 |
put("1606","KRVB");
|
|
|
105 |
put("1607","PNBB");
|
|
|
106 |
put("1608","SOIB");
|
|
|
107 |
put("1609","SRSWT");
|
|
|
108 |
put("1610","VJYB");
|
| 17646 |
amit.gupta |
109 |
put("1611","DCBCORP");
|
|
|
110 |
put("1612","UBIBC");
|
|
|
111 |
put("1613","CPNB");
|
| 13425 |
amit.gupta |
112 |
}
|
|
|
113 |
});
|
| 6998 |
amit.gupta |
114 |
public static final Map<String, String> FACET_LABEL_MAP = Collections.unmodifiableMap(
|
|
|
115 |
new HashMap<String, String>(){
|
|
|
116 |
/**
|
|
|
117 |
*
|
|
|
118 |
*/
|
|
|
119 |
private static final long serialVersionUID = 1L;
|
|
|
120 |
|
|
|
121 |
{
|
|
|
122 |
put("F_50010","Category");
|
|
|
123 |
put("F_50011","Sub Category");
|
|
|
124 |
put("F_50002","Price");
|
|
|
125 |
put("F_50001","Brand");
|
|
|
126 |
put("F_50006","Data Connectivity");
|
|
|
127 |
put("F_50007","Camera Resolution");
|
| 12111 |
amit.gupta |
128 |
put("F_50039","");
|
| 6998 |
amit.gupta |
129 |
put("F_50012","Display");
|
|
|
130 |
put("F_50013","Operating System");
|
|
|
131 |
put("F_50014","RAM");
|
|
|
132 |
put("F_50015","Storage Capacity");
|
|
|
133 |
put("F_50017","Processor");
|
|
|
134 |
put("F_50018","Capacity");
|
|
|
135 |
put("F_50019","Class");
|
|
|
136 |
put("F_50020","Capacity");
|
|
|
137 |
put("F_50021","Capacity");
|
|
|
138 |
put("F_50022","Type");
|
|
|
139 |
put("F_50023","Interface");
|
|
|
140 |
//Resolution for Composite
|
|
|
141 |
put("F_50024","Resolution");
|
|
|
142 |
put("F_50025","Optical Zoom");
|
|
|
143 |
put("F_50026","Display Size");
|
|
|
144 |
//Resolution for DSLR
|
|
|
145 |
put("F_50027","Resolution");
|
|
|
146 |
put("F_50028","Availability");
|
|
|
147 |
put("F_50031","Operating System");
|
|
|
148 |
put("F_50032","Screen Size"); //Screen size for mobiles
|
|
|
149 |
put("F_50033","Screen Size"); //Screen size for laptop
|
|
|
150 |
put("F_50034","Screen Size"); //Screen size for tablets
|
| 7132 |
amit.gupta |
151 |
put("F_50035","Operating System"); //Screen size for tablets
|
|
|
152 |
put("F_50036","Camera Resolution"); //Screen size for tablets
|
| 8880 |
amit.gupta |
153 |
put("F_50037","Voice Call Facility"); //Screen size for tablets
|
| 9472 |
amit.gupta |
154 |
put("F_50038","Mobile Type"); //Mobile Type
|
| 8880 |
amit.gupta |
155 |
put("F_50028","Availability");
|
| 6998 |
amit.gupta |
156 |
}
|
|
|
157 |
});
|
| 6135 |
anupam.sin |
158 |
|
|
|
159 |
static {
|
| 6603 |
anupam.sin |
160 |
statusMap.put(RechargeOrderStatus.PAYMENT_FAILED, "Payment Unsuccessful");
|
|
|
161 |
statusMap.put(RechargeOrderStatus.PAYMENT_SUCCESSFUL, "Processing Recharge");
|
|
|
162 |
statusMap.put(RechargeOrderStatus.RECHARGE_FAILED, "Recharge Failed");
|
|
|
163 |
statusMap.put(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED, "Recharge Failed");
|
|
|
164 |
statusMap.put(RechargeOrderStatus.RECHARGE_SUCCESSFUL, "Recharge Successful");
|
|
|
165 |
statusMap.put(RechargeOrderStatus.REFUNDED, "Amount Refunded");
|
|
|
166 |
statusMap.put(RechargeOrderStatus.PARTIALLY_REFUNDED, "Amount Refunded");
|
|
|
167 |
|
| 6135 |
anupam.sin |
168 |
TransactionClient tcl;
|
|
|
169 |
try {
|
|
|
170 |
tcl = new TransactionClient();
|
| 6206 |
rajveer |
171 |
mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
|
|
|
172 |
dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
|
| 6178 |
anupam.sin |
173 |
// providersMap.putAll(mobileProvidersMap);
|
|
|
174 |
// providersMap.putAll(dthProvidersMap);
|
|
|
175 |
for (Long operatorId : mobileProvidersMap.keySet()) {
|
|
|
176 |
List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);
|
|
|
177 |
if (!plans.isEmpty()) {
|
|
|
178 |
operatorPlanMap.put(operatorId, plans);
|
|
|
179 |
}
|
|
|
180 |
}
|
| 6204 |
rajveer |
181 |
for (Long operatorId : mobileProvidersMap.keySet()) {
|
|
|
182 |
Map<String,String> valueMap = new HashMap<String,String>();
|
|
|
183 |
valueMap.put("Id", operatorId+"");
|
|
|
184 |
valueMap.put("Name", mobileProvidersMap.get(operatorId)+"");
|
|
|
185 |
valueMap.put("ServiceType", "1");
|
|
|
186 |
valueMap.put("ServiceName", "Prepaid Mobile");
|
|
|
187 |
uriOperatorMap.put(mobileProvidersMap.get(operatorId).toLowerCase().trim().replace(" ", "-")+"-online-recharge", valueMap);
|
|
|
188 |
}
|
|
|
189 |
for (Long operatorId : dthProvidersMap.keySet()) {
|
|
|
190 |
Map<String,String> valueMap = new HashMap<String,String>();
|
|
|
191 |
valueMap.put("Id", operatorId+"");
|
|
|
192 |
valueMap.put("Name", dthProvidersMap.get(operatorId)+"");
|
|
|
193 |
valueMap.put("ServiceType", "2");
|
|
|
194 |
valueMap.put("ServiceName", "DTH TV");
|
|
|
195 |
uriOperatorMap.put(dthProvidersMap.get(operatorId).toLowerCase().trim().replace(" ", "-")+"-online-recharge", valueMap);
|
|
|
196 |
}
|
| 6603 |
anupam.sin |
197 |
|
| 6204 |
rajveer |
198 |
Map<String,String> valueMap = new HashMap<String,String>();
|
|
|
199 |
valueMap.put("Id", "0");
|
|
|
200 |
valueMap.put("Name", "Mobile and DTH");
|
|
|
201 |
valueMap.put("ServiceType", "1");
|
|
|
202 |
valueMap.put("ServiceName", "");
|
|
|
203 |
uriOperatorMap.put("recharge", valueMap);
|
| 6178 |
anupam.sin |
204 |
// providersMap.putAll(tcl.getClient().getServiceProviders(RechargeType.DTH));
|
| 6603 |
anupam.sin |
205 |
|
|
|
206 |
|
| 6135 |
anupam.sin |
207 |
} catch (Exception e) {
|
|
|
208 |
logger.error("Could not get providers", e);
|
|
|
209 |
}
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
| 1453 |
chandransh |
214 |
private static String getExportPath(){
|
| 1457 |
chandransh |
215 |
String exportPath=null;
|
| 1453 |
chandransh |
216 |
ConfigClient client = ConfigClient.getClient();
|
|
|
217 |
try{
|
|
|
218 |
exportPath = client.get("export_entities_path");
|
|
|
219 |
}catch(ConfigException ce){
|
| 2942 |
chandransh |
220 |
logger.error("Unable to read export path from the config client: ", ce);
|
|
|
221 |
logger.warn("Setting the default export path");
|
| 1475 |
chandransh |
222 |
exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
|
| 1453 |
chandransh |
223 |
}
|
|
|
224 |
return exportPath;
|
|
|
225 |
}
|
|
|
226 |
|
| 12620 |
amit.gupta |
227 |
|
|
|
228 |
public static Map<Long, ExclusiveAffiliateItemInfo> getExclusiveAffiliateItems(){
|
|
|
229 |
try{
|
|
|
230 |
CatalogClient client = new CatalogClient();
|
| 12626 |
amit.gupta |
231 |
Long currentTime = new Date().getTime();
|
|
|
232 |
if(exclusiveAffiliateItems == null || fifteenMinsCounter < currentTime) {
|
| 12620 |
amit.gupta |
233 |
exclusiveAffiliateItems = client.getClient().getExAffiliateItemInfo();
|
|
|
234 |
fifteenMinsCounter = new Date().getTime() + 15*60000;
|
|
|
235 |
}
|
|
|
236 |
}catch(Exception ce){
|
|
|
237 |
logger.error("Unable to fetch exclusive items from catalog", ce);
|
|
|
238 |
}
|
|
|
239 |
return exclusiveAffiliateItems;
|
|
|
240 |
}
|
|
|
241 |
|
| 822 |
vikas |
242 |
public static boolean validatePin(String pincode) {
|
|
|
243 |
int pin;
|
|
|
244 |
try {
|
|
|
245 |
pin = Integer.parseInt(pincode);
|
|
|
246 |
}
|
|
|
247 |
catch (NumberFormatException e) {
|
|
|
248 |
return false;
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
if (pin < 100000 || pin > 999999) {
|
|
|
252 |
return false;
|
|
|
253 |
}
|
|
|
254 |
return true;
|
|
|
255 |
}
|
| 4891 |
varun.gupt |
256 |
|
|
|
257 |
public static boolean isValidEmail(String emailAddress) {
|
|
|
258 |
|
|
|
259 |
if(emailAddress == null || emailAddress.isEmpty()) {
|
|
|
260 |
return false;
|
|
|
261 |
}
|
|
|
262 |
try {
|
|
|
263 |
InternetAddress address = new InternetAddress(emailAddress, true);
|
|
|
264 |
address.validate();
|
|
|
265 |
return true;
|
|
|
266 |
|
|
|
267 |
} catch (AddressException e) {
|
|
|
268 |
logger.error(emailAddress + " is not valid email address ", e);
|
|
|
269 |
return false;
|
|
|
270 |
}
|
|
|
271 |
}
|
| 822 |
vikas |
272 |
|
|
|
273 |
public static boolean validatePhone(String phone) {
|
| 839 |
vikas |
274 |
long iPhone;
|
| 822 |
vikas |
275 |
try {
|
| 839 |
vikas |
276 |
iPhone = Long.parseLong(phone);
|
| 822 |
vikas |
277 |
}
|
|
|
278 |
catch (NumberFormatException e) {
|
|
|
279 |
return false;
|
|
|
280 |
}
|
| 839 |
vikas |
281 |
|
|
|
282 |
if (iPhone < 1000000000l || iPhone > 9999999999l) {
|
|
|
283 |
return false;
|
|
|
284 |
}
|
| 822 |
vikas |
285 |
return true;
|
|
|
286 |
}
|
| 3209 |
vikas |
287 |
|
|
|
288 |
public static String getItemIdStringInCart(Cart cart) {
|
|
|
289 |
List<String> itemIds = new ArrayList<String>();
|
|
|
290 |
for (Line line : cart.getLines()) {
|
|
|
291 |
itemIds.add(Long.toString(line.getItemId()));
|
|
|
292 |
}
|
|
|
293 |
return StringUtils.join(itemIds, '_');
|
|
|
294 |
}
|
|
|
295 |
|
| 17646 |
amit.gupta |
296 |
public static String fetchUrl(String url) throws Exception{
|
|
|
297 |
HttpClient client = new DefaultHttpClient();
|
|
|
298 |
HttpGet request = new HttpGet(url);
|
|
|
299 |
HttpResponse response = client.execute(request);
|
|
|
300 |
StringBuffer textView = new StringBuffer();
|
|
|
301 |
|
|
|
302 |
// Get the response
|
|
|
303 |
BufferedReader rd = new BufferedReader
|
|
|
304 |
(new InputStreamReader(response.getEntity().getContent()));
|
|
|
305 |
|
|
|
306 |
String line = "";
|
|
|
307 |
while ((line = rd.readLine()) != null) {
|
|
|
308 |
textView.append(line);
|
|
|
309 |
}
|
|
|
310 |
return textView.toString();
|
|
|
311 |
}
|
|
|
312 |
|
| 3209 |
vikas |
313 |
public static String getItemIdStringFromOrders(List<Order> orders) {
|
|
|
314 |
List<String> itemIds = new ArrayList<String>();
|
|
|
315 |
if (orders != null) {
|
|
|
316 |
for (Order order : orders) {
|
|
|
317 |
for (LineItem lItem : order.getLineitems()) {
|
|
|
318 |
itemIds.add(Long.toString(lItem.getItem_id()));
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
return StringUtils.join(itemIds, '_');
|
| 6135 |
anupam.sin |
323 |
}
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
|
|
|
327 |
public static String getRechargeProviderName(long providerId) {
|
|
|
328 |
return providersMap.get(providerId);
|
|
|
329 |
}
|
| 6178 |
anupam.sin |
330 |
|
|
|
331 |
public static Map<Long, String> getMobileProvidersMap() {
|
|
|
332 |
return mobileProvidersMap;
|
|
|
333 |
}
|
|
|
334 |
|
|
|
335 |
public static Map<Long, String> getDthProvidersMap() {
|
|
|
336 |
return dthProvidersMap;
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
public static Map<Long, List<RechargePlan>> getOperatorPlanMap() {
|
|
|
340 |
return operatorPlanMap;
|
|
|
341 |
}
|
| 6204 |
rajveer |
342 |
|
| 6208 |
rajveer |
343 |
public static Map<String, Map<String, String>> getUriOperatorMap(){
|
|
|
344 |
return uriOperatorMap;
|
|
|
345 |
}
|
|
|
346 |
|
| 6204 |
rajveer |
347 |
public static Map<String, String> getOperatorByUri(String uri){
|
|
|
348 |
return uriOperatorMap.get(uri);
|
|
|
349 |
}
|
| 4891 |
varun.gupt |
350 |
}
|