| 7226 |
anupam.sin |
1 |
package in.shop2020.serving.utils;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.config.ConfigException;
|
|
|
4 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
5 |
import in.shop2020.model.v1.order.Order;
|
|
|
6 |
import in.shop2020.model.v1.order.RechargeOrderStatus;
|
|
|
7 |
import in.shop2020.model.v1.order.RechargePlan;
|
|
|
8 |
import in.shop2020.model.v1.order.RechargeType;
|
|
|
9 |
import in.shop2020.model.v1.user.Cart;
|
|
|
10 |
import in.shop2020.model.v1.user.Line;
|
|
|
11 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
12 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
13 |
|
|
|
14 |
import java.util.ArrayList;
|
|
|
15 |
import java.util.Arrays;
|
|
|
16 |
import java.util.Collections;
|
|
|
17 |
import java.util.HashMap;
|
|
|
18 |
import java.util.List;
|
|
|
19 |
import java.util.Map;
|
|
|
20 |
|
|
|
21 |
import javax.mail.internet.AddressException;
|
|
|
22 |
import javax.mail.internet.InternetAddress;
|
|
|
23 |
|
|
|
24 |
import org.apache.commons.lang.StringUtils;
|
|
|
25 |
import org.apache.log4j.Logger;
|
|
|
26 |
|
|
|
27 |
public class Utils {
|
|
|
28 |
private static Logger logger = Logger.getLogger(Utils.class);
|
|
|
29 |
|
|
|
30 |
public static final String EXPORT_ENTITIES_PATH = getExportPath();
|
|
|
31 |
public static final String EXPORT_JAVASCRIPT_CONTENT_PATH = "/var/lib/tomcat6/webapps/export/javascripts/";
|
|
|
32 |
public static final long ROOT_CATEGORY = 10000;
|
|
|
33 |
public static final long MOBILE_PHONES_CATEGORY = 10001;
|
|
|
34 |
public static final long MOBILE_ACCESSORIES_CATEGORY = 10011;
|
|
|
35 |
public static final long TABLETS_CATEGORY = 10010;
|
|
|
36 |
public static final long LAPTOPS_CATEGORY = 10050;
|
|
|
37 |
public static final long CAMERAS_CATEGORY = 11001;
|
|
|
38 |
|
|
|
39 |
static Map<Long, String> providersMap;
|
|
|
40 |
static Map<Long, String> mobileProvidersMap;
|
|
|
41 |
static Map<Long, String> dthProvidersMap;
|
|
|
42 |
static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<Long, List<RechargePlan>>();
|
|
|
43 |
private static Map<String, Map<String, String>> uriOperatorMap = new HashMap<String, Map<String,String>>();
|
|
|
44 |
|
|
|
45 |
public static final List<RechargeOrderStatus> refundableRechargeStatusList = new ArrayList<RechargeOrderStatus>(Arrays.asList(new RechargeOrderStatus[]
|
|
|
46 |
{RechargeOrderStatus.RECHARGE_FAILED,
|
|
|
47 |
RechargeOrderStatus.RECHARGE_FAILED_REFUNDED,
|
|
|
48 |
RechargeOrderStatus.PAYMENT_SUCCESSFUL}));
|
|
|
49 |
|
|
|
50 |
public static Map<RechargeOrderStatus, String> statusMap = new HashMap<RechargeOrderStatus, String>();
|
|
|
51 |
|
|
|
52 |
//public static final List<String> multiValuedFacet = Arrays.asList("F_50006");
|
|
|
53 |
|
|
|
54 |
public static final List<String>rootfacetDefIDs = Arrays.asList("F_50010","F_50011","F_50002", "F_50001", "F_50028");
|
|
|
55 |
public static final Map<String, String> FACET_LABEL_MAP = Collections.unmodifiableMap(
|
|
|
56 |
new HashMap<String, String>(){
|
|
|
57 |
/**
|
|
|
58 |
*
|
|
|
59 |
*/
|
|
|
60 |
private static final long serialVersionUID = 1L;
|
|
|
61 |
|
|
|
62 |
{
|
|
|
63 |
put("F_50010","Category");
|
|
|
64 |
put("F_50011","Sub Category");
|
|
|
65 |
put("F_50002","Price");
|
|
|
66 |
put("F_50001","Brand");
|
|
|
67 |
put("F_50028","Availability");
|
|
|
68 |
put("F_50006","Data Connectivity");
|
|
|
69 |
put("F_50007","Camera Resolution");
|
|
|
70 |
put("F_50012","Display");
|
|
|
71 |
put("F_50013","Operating System");
|
|
|
72 |
put("F_50014","RAM");
|
|
|
73 |
put("F_50015","Storage Capacity");
|
|
|
74 |
put("F_50017","Processor");
|
|
|
75 |
put("F_50018","Capacity");
|
|
|
76 |
put("F_50019","Class");
|
|
|
77 |
put("F_50020","Capacity");
|
|
|
78 |
put("F_50021","Capacity");
|
|
|
79 |
put("F_50022","Type");
|
|
|
80 |
put("F_50023","Interface");
|
|
|
81 |
//Resolution for Composite
|
|
|
82 |
put("F_50024","Resolution");
|
|
|
83 |
put("F_50025","Optical Zoom");
|
|
|
84 |
put("F_50026","Display Size");
|
|
|
85 |
//Resolution for DSLR
|
|
|
86 |
put("F_50027","Resolution");
|
|
|
87 |
put("F_50028","Availability");
|
|
|
88 |
put("F_50031","Operating System");
|
|
|
89 |
put("F_50032","Screen Size"); //Screen size for mobiles
|
|
|
90 |
put("F_50033","Screen Size"); //Screen size for laptop
|
|
|
91 |
put("F_50034","Screen Size"); //Screen size for tablets
|
|
|
92 |
put("F_50035","Operating System"); //Screen size for tablets
|
|
|
93 |
put("F_50036","Camera Resolution"); //Screen size for tablets
|
|
|
94 |
}
|
|
|
95 |
});
|
|
|
96 |
|
|
|
97 |
static {
|
|
|
98 |
statusMap.put(RechargeOrderStatus.PAYMENT_FAILED, "Payment Unsuccessful");
|
|
|
99 |
statusMap.put(RechargeOrderStatus.PAYMENT_SUCCESSFUL, "Processing Recharge");
|
|
|
100 |
statusMap.put(RechargeOrderStatus.RECHARGE_FAILED, "Recharge Failed");
|
|
|
101 |
statusMap.put(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED, "Recharge Failed");
|
|
|
102 |
statusMap.put(RechargeOrderStatus.RECHARGE_SUCCESSFUL, "Recharge Successful");
|
|
|
103 |
statusMap.put(RechargeOrderStatus.REFUNDED, "Amount Refunded");
|
|
|
104 |
statusMap.put(RechargeOrderStatus.PARTIALLY_REFUNDED, "Amount Refunded");
|
|
|
105 |
|
|
|
106 |
TransactionClient tcl;
|
|
|
107 |
try {
|
|
|
108 |
tcl = new TransactionClient();
|
|
|
109 |
mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
|
|
|
110 |
dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
|
|
|
111 |
// providersMap.putAll(mobileProvidersMap);
|
|
|
112 |
// providersMap.putAll(dthProvidersMap);
|
|
|
113 |
for (Long operatorId : mobileProvidersMap.keySet()) {
|
|
|
114 |
List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);
|
|
|
115 |
if (!plans.isEmpty()) {
|
|
|
116 |
operatorPlanMap.put(operatorId, plans);
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
for (Long operatorId : mobileProvidersMap.keySet()) {
|
|
|
120 |
Map<String,String> valueMap = new HashMap<String,String>();
|
|
|
121 |
valueMap.put("Id", operatorId+"");
|
|
|
122 |
valueMap.put("Name", mobileProvidersMap.get(operatorId)+"");
|
|
|
123 |
valueMap.put("ServiceType", "1");
|
|
|
124 |
valueMap.put("ServiceName", "Prepaid Mobile");
|
|
|
125 |
uriOperatorMap.put(mobileProvidersMap.get(operatorId).toLowerCase().trim().replace(" ", "-")+"-online-recharge", valueMap);
|
|
|
126 |
}
|
|
|
127 |
for (Long operatorId : dthProvidersMap.keySet()) {
|
|
|
128 |
Map<String,String> valueMap = new HashMap<String,String>();
|
|
|
129 |
valueMap.put("Id", operatorId+"");
|
|
|
130 |
valueMap.put("Name", dthProvidersMap.get(operatorId)+"");
|
|
|
131 |
valueMap.put("ServiceType", "2");
|
|
|
132 |
valueMap.put("ServiceName", "DTH TV");
|
|
|
133 |
uriOperatorMap.put(dthProvidersMap.get(operatorId).toLowerCase().trim().replace(" ", "-")+"-online-recharge", valueMap);
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
Map<String,String> valueMap = new HashMap<String,String>();
|
|
|
137 |
valueMap.put("Id", "0");
|
|
|
138 |
valueMap.put("Name", "Mobile and DTH");
|
|
|
139 |
valueMap.put("ServiceType", "1");
|
|
|
140 |
valueMap.put("ServiceName", "");
|
|
|
141 |
uriOperatorMap.put("recharge", valueMap);
|
|
|
142 |
// providersMap.putAll(tcl.getClient().getServiceProviders(RechargeType.DTH));
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
} catch (Exception e) {
|
|
|
146 |
logger.error("Could not get providers", e);
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
private static String getExportPath(){
|
|
|
153 |
String exportPath=null;
|
|
|
154 |
ConfigClient client = ConfigClient.getClient();
|
|
|
155 |
try{
|
| 7677 |
anupam.sin |
156 |
exportPath = client.get("export_entities_path_for_storewebsite");
|
| 7226 |
anupam.sin |
157 |
}catch(ConfigException ce){
|
|
|
158 |
logger.error("Unable to read export path from the config client: ", ce);
|
|
|
159 |
logger.warn("Setting the default export path");
|
|
|
160 |
exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
|
|
|
161 |
}
|
|
|
162 |
return exportPath;
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
public static boolean validatePin(String pincode) {
|
|
|
166 |
int pin;
|
|
|
167 |
try {
|
|
|
168 |
pin = Integer.parseInt(pincode);
|
|
|
169 |
}
|
|
|
170 |
catch (NumberFormatException e) {
|
|
|
171 |
return false;
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
if (pin < 100000 || pin > 999999) {
|
|
|
175 |
return false;
|
|
|
176 |
}
|
|
|
177 |
return true;
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
public static boolean isValidEmail(String emailAddress) {
|
|
|
181 |
|
|
|
182 |
if(emailAddress == null || emailAddress.isEmpty()) {
|
|
|
183 |
return false;
|
|
|
184 |
}
|
|
|
185 |
try {
|
|
|
186 |
InternetAddress address = new InternetAddress(emailAddress, true);
|
|
|
187 |
address.validate();
|
|
|
188 |
return true;
|
|
|
189 |
|
|
|
190 |
} catch (AddressException e) {
|
|
|
191 |
logger.error(emailAddress + " is not valid email address ", e);
|
|
|
192 |
return false;
|
|
|
193 |
}
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
public static boolean validatePhone(String phone) {
|
|
|
197 |
long iPhone;
|
|
|
198 |
try {
|
|
|
199 |
iPhone = Long.parseLong(phone);
|
|
|
200 |
}
|
|
|
201 |
catch (NumberFormatException e) {
|
|
|
202 |
return false;
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
if (iPhone < 1000000000l || iPhone > 9999999999l) {
|
|
|
206 |
return false;
|
|
|
207 |
}
|
|
|
208 |
return true;
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
public static String getItemIdStringInCart(Cart cart) {
|
|
|
212 |
List<String> itemIds = new ArrayList<String>();
|
|
|
213 |
for (Line line : cart.getLines()) {
|
|
|
214 |
itemIds.add(Long.toString(line.getItemId()));
|
|
|
215 |
}
|
|
|
216 |
return StringUtils.join(itemIds, '_');
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
public static String getItemIdStringFromOrders(List<Order> orders) {
|
|
|
220 |
List<String> itemIds = new ArrayList<String>();
|
|
|
221 |
if (orders != null) {
|
|
|
222 |
for (Order order : orders) {
|
|
|
223 |
for (LineItem lItem : order.getLineitems()) {
|
|
|
224 |
itemIds.add(Long.toString(lItem.getItem_id()));
|
|
|
225 |
}
|
|
|
226 |
}
|
|
|
227 |
}
|
|
|
228 |
return StringUtils.join(itemIds, '_');
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
|
|
|
232 |
|
|
|
233 |
public static String getRechargeProviderName(long providerId) {
|
|
|
234 |
return providersMap.get(providerId);
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
public static Map<Long, String> getMobileProvidersMap() {
|
|
|
238 |
return mobileProvidersMap;
|
|
|
239 |
}
|
|
|
240 |
|
|
|
241 |
public static Map<Long, String> getDthProvidersMap() {
|
|
|
242 |
return dthProvidersMap;
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
public static Map<Long, List<RechargePlan>> getOperatorPlanMap() {
|
|
|
246 |
return operatorPlanMap;
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
public static Map<String, Map<String, String>> getUriOperatorMap(){
|
|
|
250 |
return uriOperatorMap;
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
public static Map<String, String> getOperatorByUri(String uri){
|
|
|
254 |
return uriOperatorMap.get(uri);
|
|
|
255 |
}
|
|
|
256 |
}
|