| 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;
|
| 6603 |
anupam.sin |
6 |
import in.shop2020.model.v1.order.RechargeOrderStatus;
|
| 6178 |
anupam.sin |
7 |
import in.shop2020.model.v1.order.RechargePlan;
|
| 6135 |
anupam.sin |
8 |
import in.shop2020.model.v1.order.RechargeType;
|
| 3209 |
vikas |
9 |
import in.shop2020.model.v1.user.Cart;
|
|
|
10 |
import in.shop2020.model.v1.user.Line;
|
| 6135 |
anupam.sin |
11 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 1453 |
chandransh |
12 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 419 |
rajveer |
13 |
|
| 3209 |
vikas |
14 |
import java.util.ArrayList;
|
| 6603 |
anupam.sin |
15 |
import java.util.Arrays;
|
| 6178 |
anupam.sin |
16 |
import java.util.HashMap;
|
| 3209 |
vikas |
17 |
import java.util.List;
|
| 6135 |
anupam.sin |
18 |
import java.util.Map;
|
| 3209 |
vikas |
19 |
|
| 4891 |
varun.gupt |
20 |
import javax.mail.internet.AddressException;
|
|
|
21 |
import javax.mail.internet.InternetAddress;
|
|
|
22 |
|
| 3209 |
vikas |
23 |
import org.apache.commons.lang.StringUtils;
|
|
|
24 |
import org.apache.log4j.Logger;
|
|
|
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>>();
|
| 6204 |
rajveer |
42 |
private static Map<String, Map<String, String>> uriOperatorMap = new HashMap<String, Map<String,String>>();
|
|
|
43 |
|
| 6603 |
anupam.sin |
44 |
public static final List<RechargeOrderStatus> refundableRechargeStatusList = new ArrayList<RechargeOrderStatus>(Arrays.asList(new RechargeOrderStatus[]
|
|
|
45 |
{RechargeOrderStatus.RECHARGE_FAILED,
|
|
|
46 |
RechargeOrderStatus.RECHARGE_FAILED_REFUNDED,
|
|
|
47 |
RechargeOrderStatus.PAYMENT_SUCCESSFUL}));
|
|
|
48 |
|
|
|
49 |
public static Map<RechargeOrderStatus, String> statusMap = new HashMap<RechargeOrderStatus, String>();
|
|
|
50 |
|
| 6896 |
amit.gupta |
51 |
public static final List<String> multiValuedFacet = Arrays.asList("F_50006");
|
| 4137 |
varun.gupt |
52 |
public static String[] facetDefIDs = new String[] {
|
| 6896 |
amit.gupta |
53 |
"F_50010","F_50011","F_50002","F_50001", "F_50028", "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", "F_50028", "F_50031", "F_50032" };
|
| 6706 |
amit.gupta |
54 |
public static String[] facetLabels = new String[] {"Category","Sub Category","Price", "Brand", "Availability", "Data Connectivity",
|
| 5439 |
phani.kuma |
55 |
"Camera Resolution", "Display", "Operating System", "RAM", "Storage Capacity", "Processor",
|
| 6896 |
amit.gupta |
56 |
"Capacity", "Class", "Capacity", "Capacity", "Type", "Interface", "Resolution", "Optical Zoom", "Display Size", "Effective Resolution", "Availability", "Operating System", "Screen Size" };
|
| 6887 |
amit.gupta |
57 |
|
| 6606 |
rajveer |
58 |
public static String[] rootfacetDefIDs = new String[] {"F_50010","F_50011","F_50002","F_50001","F_50028"};
|
|
|
59 |
public static String[] rootfacetLabels = new String[] {"Category","Sub Category","Price", "Brand","Availability"};
|
| 6135 |
anupam.sin |
60 |
|
|
|
61 |
static {
|
| 6603 |
anupam.sin |
62 |
statusMap.put(RechargeOrderStatus.PAYMENT_FAILED, "Payment Unsuccessful");
|
|
|
63 |
statusMap.put(RechargeOrderStatus.PAYMENT_SUCCESSFUL, "Processing Recharge");
|
|
|
64 |
statusMap.put(RechargeOrderStatus.RECHARGE_FAILED, "Recharge Failed");
|
|
|
65 |
statusMap.put(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED, "Recharge Failed");
|
|
|
66 |
statusMap.put(RechargeOrderStatus.RECHARGE_SUCCESSFUL, "Recharge Successful");
|
|
|
67 |
statusMap.put(RechargeOrderStatus.REFUNDED, "Amount Refunded");
|
|
|
68 |
statusMap.put(RechargeOrderStatus.PARTIALLY_REFUNDED, "Amount Refunded");
|
|
|
69 |
|
| 6135 |
anupam.sin |
70 |
TransactionClient tcl;
|
|
|
71 |
try {
|
|
|
72 |
tcl = new TransactionClient();
|
| 6206 |
rajveer |
73 |
mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
|
|
|
74 |
dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
|
| 6178 |
anupam.sin |
75 |
// providersMap.putAll(mobileProvidersMap);
|
|
|
76 |
// providersMap.putAll(dthProvidersMap);
|
|
|
77 |
for (Long operatorId : mobileProvidersMap.keySet()) {
|
|
|
78 |
List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);
|
|
|
79 |
if (!plans.isEmpty()) {
|
|
|
80 |
operatorPlanMap.put(operatorId, plans);
|
|
|
81 |
}
|
|
|
82 |
}
|
| 6204 |
rajveer |
83 |
for (Long operatorId : mobileProvidersMap.keySet()) {
|
|
|
84 |
Map<String,String> valueMap = new HashMap<String,String>();
|
|
|
85 |
valueMap.put("Id", operatorId+"");
|
|
|
86 |
valueMap.put("Name", mobileProvidersMap.get(operatorId)+"");
|
|
|
87 |
valueMap.put("ServiceType", "1");
|
|
|
88 |
valueMap.put("ServiceName", "Prepaid Mobile");
|
|
|
89 |
uriOperatorMap.put(mobileProvidersMap.get(operatorId).toLowerCase().trim().replace(" ", "-")+"-online-recharge", valueMap);
|
|
|
90 |
}
|
|
|
91 |
for (Long operatorId : dthProvidersMap.keySet()) {
|
|
|
92 |
Map<String,String> valueMap = new HashMap<String,String>();
|
|
|
93 |
valueMap.put("Id", operatorId+"");
|
|
|
94 |
valueMap.put("Name", dthProvidersMap.get(operatorId)+"");
|
|
|
95 |
valueMap.put("ServiceType", "2");
|
|
|
96 |
valueMap.put("ServiceName", "DTH TV");
|
|
|
97 |
uriOperatorMap.put(dthProvidersMap.get(operatorId).toLowerCase().trim().replace(" ", "-")+"-online-recharge", valueMap);
|
|
|
98 |
}
|
| 6603 |
anupam.sin |
99 |
|
| 6204 |
rajveer |
100 |
Map<String,String> valueMap = new HashMap<String,String>();
|
|
|
101 |
valueMap.put("Id", "0");
|
|
|
102 |
valueMap.put("Name", "Mobile and DTH");
|
|
|
103 |
valueMap.put("ServiceType", "1");
|
|
|
104 |
valueMap.put("ServiceName", "");
|
|
|
105 |
uriOperatorMap.put("recharge", valueMap);
|
| 6178 |
anupam.sin |
106 |
// providersMap.putAll(tcl.getClient().getServiceProviders(RechargeType.DTH));
|
| 6603 |
anupam.sin |
107 |
|
|
|
108 |
|
| 6135 |
anupam.sin |
109 |
} catch (Exception e) {
|
|
|
110 |
logger.error("Could not get providers", e);
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
| 1453 |
chandransh |
116 |
private static String getExportPath(){
|
| 1457 |
chandransh |
117 |
String exportPath=null;
|
| 1453 |
chandransh |
118 |
ConfigClient client = ConfigClient.getClient();
|
|
|
119 |
try{
|
|
|
120 |
exportPath = client.get("export_entities_path");
|
|
|
121 |
}catch(ConfigException ce){
|
| 2942 |
chandransh |
122 |
logger.error("Unable to read export path from the config client: ", ce);
|
|
|
123 |
logger.warn("Setting the default export path");
|
| 1475 |
chandransh |
124 |
exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
|
| 1453 |
chandransh |
125 |
}
|
|
|
126 |
return exportPath;
|
|
|
127 |
}
|
|
|
128 |
|
| 822 |
vikas |
129 |
public static boolean validatePin(String pincode) {
|
|
|
130 |
int pin;
|
|
|
131 |
try {
|
|
|
132 |
pin = Integer.parseInt(pincode);
|
|
|
133 |
}
|
|
|
134 |
catch (NumberFormatException e) {
|
|
|
135 |
return false;
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
if (pin < 100000 || pin > 999999) {
|
|
|
139 |
return false;
|
|
|
140 |
}
|
|
|
141 |
return true;
|
|
|
142 |
}
|
| 4891 |
varun.gupt |
143 |
|
|
|
144 |
public static boolean isValidEmail(String emailAddress) {
|
|
|
145 |
|
|
|
146 |
if(emailAddress == null || emailAddress.isEmpty()) {
|
|
|
147 |
return false;
|
|
|
148 |
}
|
|
|
149 |
try {
|
|
|
150 |
InternetAddress address = new InternetAddress(emailAddress, true);
|
|
|
151 |
address.validate();
|
|
|
152 |
return true;
|
|
|
153 |
|
|
|
154 |
} catch (AddressException e) {
|
|
|
155 |
logger.error(emailAddress + " is not valid email address ", e);
|
|
|
156 |
return false;
|
|
|
157 |
}
|
|
|
158 |
}
|
| 822 |
vikas |
159 |
|
|
|
160 |
public static boolean validatePhone(String phone) {
|
| 839 |
vikas |
161 |
long iPhone;
|
| 822 |
vikas |
162 |
try {
|
| 839 |
vikas |
163 |
iPhone = Long.parseLong(phone);
|
| 822 |
vikas |
164 |
}
|
|
|
165 |
catch (NumberFormatException e) {
|
|
|
166 |
return false;
|
|
|
167 |
}
|
| 839 |
vikas |
168 |
|
|
|
169 |
if (iPhone < 1000000000l || iPhone > 9999999999l) {
|
|
|
170 |
return false;
|
|
|
171 |
}
|
| 822 |
vikas |
172 |
return true;
|
|
|
173 |
}
|
| 3209 |
vikas |
174 |
|
|
|
175 |
public static String getItemIdStringInCart(Cart cart) {
|
|
|
176 |
List<String> itemIds = new ArrayList<String>();
|
|
|
177 |
for (Line line : cart.getLines()) {
|
|
|
178 |
itemIds.add(Long.toString(line.getItemId()));
|
|
|
179 |
}
|
|
|
180 |
return StringUtils.join(itemIds, '_');
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
public static String getItemIdStringFromOrders(List<Order> orders) {
|
|
|
184 |
List<String> itemIds = new ArrayList<String>();
|
|
|
185 |
if (orders != null) {
|
|
|
186 |
for (Order order : orders) {
|
|
|
187 |
for (LineItem lItem : order.getLineitems()) {
|
|
|
188 |
itemIds.add(Long.toString(lItem.getItem_id()));
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
return StringUtils.join(itemIds, '_');
|
| 6135 |
anupam.sin |
193 |
}
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
public static String getRechargeProviderName(long providerId) {
|
|
|
198 |
return providersMap.get(providerId);
|
|
|
199 |
}
|
| 6178 |
anupam.sin |
200 |
|
|
|
201 |
public static Map<Long, String> getMobileProvidersMap() {
|
|
|
202 |
return mobileProvidersMap;
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
public static Map<Long, String> getDthProvidersMap() {
|
|
|
206 |
return dthProvidersMap;
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
public static Map<Long, List<RechargePlan>> getOperatorPlanMap() {
|
|
|
210 |
return operatorPlanMap;
|
|
|
211 |
}
|
| 6204 |
rajveer |
212 |
|
| 6208 |
rajveer |
213 |
public static Map<String, Map<String, String>> getUriOperatorMap(){
|
|
|
214 |
return uriOperatorMap;
|
|
|
215 |
}
|
|
|
216 |
|
| 6204 |
rajveer |
217 |
public static Map<String, String> getOperatorByUri(String uri){
|
|
|
218 |
return uriOperatorMap.get(uri);
|
|
|
219 |
}
|
| 4891 |
varun.gupt |
220 |
}
|