| 21543 |
ashik.ali |
1 |
package com.spice.profitmandi.common.util;
|
|
|
2 |
|
|
|
3 |
import java.io.File;
|
|
|
4 |
import java.io.IOException;
|
| 25764 |
amit.gupta |
5 |
import java.io.Serializable;
|
| 28925 |
amit.gupta |
6 |
import java.time.LocalTime;
|
| 21902 |
ashik.ali |
7 |
import java.util.ArrayList;
|
| 21543 |
ashik.ali |
8 |
import java.util.Collections;
|
|
|
9 |
import java.util.HashMap;
|
| 23509 |
amit.gupta |
10 |
import java.util.HashSet;
|
| 21543 |
ashik.ali |
11 |
import java.util.List;
|
|
|
12 |
import java.util.Map;
|
| 23296 |
ashik.ali |
13 |
import java.util.Set;
|
|
|
14 |
import java.util.TreeSet;
|
| 28395 |
amit.gupta |
15 |
import java.util.regex.Matcher;
|
|
|
16 |
import java.util.regex.Pattern;
|
| 21894 |
ashik.ali |
17 |
|
| 25766 |
amit.gupta |
18 |
import javax.mail.Multipart;
|
| 23909 |
amit.gupta |
19 |
import javax.mail.internet.InternetAddress;
|
| 25764 |
amit.gupta |
20 |
import javax.mail.internet.MimeBodyPart;
|
| 23909 |
amit.gupta |
21 |
import javax.mail.internet.MimeMessage;
|
| 25766 |
amit.gupta |
22 |
import javax.mail.internet.MimeMultipart;
|
| 23909 |
amit.gupta |
23 |
|
| 21543 |
ashik.ali |
24 |
import org.apache.commons.io.FileUtils;
|
| 26066 |
amit.gupta |
25 |
import org.apache.commons.lang3.StringEscapeUtils;
|
| 23929 |
amit.gupta |
26 |
import org.apache.logging.log4j.LogManager;
|
|
|
27 |
import org.apache.logging.log4j.Logger;
|
| 22351 |
ashik.ali |
28 |
import org.apache.thrift.TException;
|
|
|
29 |
import org.apache.thrift.transport.TTransportException;
|
| 23929 |
amit.gupta |
30 |
import org.springframework.core.io.InputStreamSource;
|
| 23909 |
amit.gupta |
31 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
32 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 23074 |
ashik.ali |
33 |
|
| 26066 |
amit.gupta |
34 |
import com.google.gson.Gson;
|
| 22215 |
ashik.ali |
35 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 22351 |
ashik.ali |
36 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 26079 |
amit.gupta |
37 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 21894 |
ashik.ali |
38 |
import com.spice.profitmandi.thrift.clients.CatalogClient;
|
|
|
39 |
import com.spice.profitmandi.thrift.clients.InventoryClient;
|
|
|
40 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
| 22351 |
ashik.ali |
41 |
import com.spice.profitmandi.thrift.clients.UserClient;
|
| 23509 |
amit.gupta |
42 |
import com.spice.profitmandi.thrift.clients.WarehouseClient;
|
| 21543 |
ashik.ali |
43 |
|
| 21894 |
ashik.ali |
44 |
import in.shop2020.model.v1.catalog.CatalogService;
|
|
|
45 |
import in.shop2020.model.v1.inventory.InventoryService;
|
|
|
46 |
import in.shop2020.model.v1.inventory.StateInfo;
|
| 23509 |
amit.gupta |
47 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| 23884 |
amit.gupta |
48 |
import in.shop2020.model.v1.order.OrderStatusGroups;
|
| 21894 |
ashik.ali |
49 |
import in.shop2020.model.v1.order.RechargeOrderStatus;
|
|
|
50 |
import in.shop2020.model.v1.order.RechargePlan;
|
| 23509 |
amit.gupta |
51 |
import in.shop2020.model.v1.order.SellerInfo;
|
|
|
52 |
import in.shop2020.model.v1.order.WarehouseAddress;
|
| 22351 |
ashik.ali |
53 |
import in.shop2020.model.v1.user.Sex;
|
|
|
54 |
import in.shop2020.model.v1.user.User;
|
|
|
55 |
import in.shop2020.model.v1.user.UserContextException;
|
| 23509 |
amit.gupta |
56 |
import in.shop2020.warehouse.InventoryItem;
|
|
|
57 |
import in.shop2020.warehouse.WarehouseService;
|
| 21543 |
ashik.ali |
58 |
|
|
|
59 |
public class Utils {
|
| 21986 |
kshitij.so |
60 |
|
| 23568 |
govind |
61 |
private static final Logger logger = LogManager.getLogger(Utils.class);
|
| 21986 |
kshitij.so |
62 |
public static final String EXPORT_ENTITIES_PATH = getExportPath();
|
|
|
63 |
public static final String PRODUCT_PROPERTIES_SNIPPET = "ProductPropertiesSnippet.html";
|
|
|
64 |
public static final String DOCUMENT_STORE = "/profitmandi/documents/";
|
| 26066 |
amit.gupta |
65 |
private Gson gson = new Gson();
|
| 23017 |
ashik.ali |
66 |
private static final Map<Integer, String> helpMap = new HashMap<>(6);
|
|
|
67 |
private static final Map<Integer, String> dthIdAliasMap = new HashMap<>(7);
|
|
|
68 |
private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<>(20);
|
| 21986 |
kshitij.so |
69 |
private static Map<Long, String> mobileProvidersMap;
|
|
|
70 |
private static Map<Long, String> dthProvidersMap;
|
|
|
71 |
private static Map<Long, String> allProviders;
|
| 23017 |
ashik.ali |
72 |
public static Map<RechargeOrderStatus, String> rechargeStatusMap = new HashMap<>();
|
| 23884 |
amit.gupta |
73 |
public static OrderStatusGroups ORDER_STATUS_GROUPS = new OrderStatusGroups();
|
| 25764 |
amit.gupta |
74 |
public static final String SYSTEM_PARTNER = "testpxps@gmail.com";
|
| 27121 |
amit.gupta |
75 |
public static final int SYSTEM_PARTNER_ID = 175120474;
|
| 26079 |
amit.gupta |
76 |
private static final RestClient rc = new RestClient();
|
| 28395 |
amit.gupta |
77 |
private static final String regex = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$";
|
| 28925 |
amit.gupta |
78 |
public static final LocalTime MAX_TIME=LocalTime.of(23, 59, 59);
|
| 28395 |
amit.gupta |
79 |
//Compile regular expression to get the pattern
|
|
|
80 |
private static final Pattern pattern = Pattern.compile(regex);
|
| 25764 |
amit.gupta |
81 |
|
| 23509 |
amit.gupta |
82 |
public static SellerInfo getSellerInfoBySellerId(int sellerId) throws Exception {
|
|
|
83 |
TransactionClient tcl = new TransactionClient();
|
| 24440 |
amit.gupta |
84 |
return tcl.getClient().getSellerInfo((long) sellerId);
|
| 23509 |
amit.gupta |
85 |
}
|
| 28395 |
amit.gupta |
86 |
|
|
|
87 |
|
|
|
88 |
public static boolean validateEmail(String email) {
|
|
|
89 |
if(email== null) {
|
|
|
90 |
return false;
|
|
|
91 |
}
|
|
|
92 |
Matcher matcher = pattern.matcher(email);
|
|
|
93 |
return matcher.matches();
|
|
|
94 |
}
|
| 24440 |
amit.gupta |
95 |
|
| 21543 |
ashik.ali |
96 |
@SuppressWarnings("serial")
|
| 24440 |
amit.gupta |
97 |
public static final Map<String, String> MIME_TYPE = Collections.unmodifiableMap(new HashMap<String, String>() {
|
|
|
98 |
{
|
|
|
99 |
put("image/png", "png");
|
|
|
100 |
put("image/jpeg", "jpeg");
|
|
|
101 |
put("image/pjpeg", "jpeg");
|
|
|
102 |
put("application/pdf", "pdf");
|
| 27285 |
tejbeer |
103 |
put("application/msword", "doc");
|
|
|
104 |
put("application/vnd.openxmlformats-officedocument.wordprocessingml.document", "docx");
|
|
|
105 |
put("application/vnd.ms-excel", "xls");
|
|
|
106 |
put("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "xlsx");
|
| 24440 |
amit.gupta |
107 |
}
|
|
|
108 |
});
|
| 21543 |
ashik.ali |
109 |
|
| 24440 |
amit.gupta |
110 |
private static String getExportPath() {
|
| 26534 |
amit.gupta |
111 |
String exportPath = "/var/lib/tomcat7/webapps/export/html/entities/";
|
| 27285 |
tejbeer |
112 |
/*
|
|
|
113 |
* String exportPath = null;
|
|
|
114 |
*
|
|
|
115 |
* try { ConfigClient client = ConfigClient.getClient(); exportPath =
|
|
|
116 |
* client.get("export_entities_path"); } catch (Exception ce) {
|
|
|
117 |
* logger.error("Unable to read export path from the config client: ", ce);
|
|
|
118 |
* logger.warn("Setting the default export path"); exportPath =
|
|
|
119 |
* "/var/lib/tomcat7/webapps/export/html/entities/"; }
|
|
|
120 |
*/
|
| 21543 |
ashik.ali |
121 |
return exportPath;
|
|
|
122 |
}
|
| 21986 |
kshitij.so |
123 |
|
| 21646 |
kshitij.so |
124 |
public static String getRechargeDisplayStatus(RechargeOrderStatus status) {
|
| 21986 |
kshitij.so |
125 |
if (status == null) {
|
|
|
126 |
status = RechargeOrderStatus.INIT;
|
|
|
127 |
}
|
| 24440 |
amit.gupta |
128 |
String displayStatus = (String) rechargeStatusMap.get(status);
|
| 21986 |
kshitij.so |
129 |
if (displayStatus == null) {
|
|
|
130 |
return "";
|
|
|
131 |
}
|
|
|
132 |
return displayStatus;
|
|
|
133 |
}
|
| 21543 |
ashik.ali |
134 |
|
| 24440 |
amit.gupta |
135 |
public static boolean copyDocument(String documentPath) {
|
| 21543 |
ashik.ali |
136 |
File source = new File(documentPath);
|
| 24440 |
amit.gupta |
137 |
File dest = new File(DOCUMENT_STORE + source.getName());
|
| 21543 |
ashik.ali |
138 |
try {
|
|
|
139 |
FileUtils.copyFile(source, dest);
|
|
|
140 |
} catch (IOException e) {
|
|
|
141 |
e.printStackTrace();
|
|
|
142 |
return false;
|
|
|
143 |
}
|
|
|
144 |
return true;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
public static Map<Long, String> getMobileProvidersMap() {
|
|
|
148 |
return mobileProvidersMap;
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
public static Map<Long, String> getDthProvidersMap() {
|
|
|
152 |
return dthProvidersMap;
|
|
|
153 |
}
|
| 21986 |
kshitij.so |
154 |
|
| 21543 |
ashik.ali |
155 |
public static Map<Long, String> getAllProviders() {
|
|
|
156 |
return allProviders;
|
|
|
157 |
}
|
| 21986 |
kshitij.so |
158 |
|
| 21543 |
ashik.ali |
159 |
public static String getProvider(long operatorId) {
|
| 21986 |
kshitij.so |
160 |
return allProviders.get(operatorId);
|
|
|
161 |
}
|
| 21543 |
ashik.ali |
162 |
|
| 26079 |
amit.gupta |
163 |
public static void sendSms(String text, String mobileNumber) throws Exception {
|
| 26089 |
amit.gupta |
164 |
Map<String, String> paramsMap = new HashMap<>();
|
| 26673 |
amit.gupta |
165 |
paramsMap.put("username", "SmartDukaanT");
|
|
|
166 |
paramsMap.put("password", "Smart@91");
|
|
|
167 |
paramsMap.put("senderID", "SMTDKN");
|
|
|
168 |
paramsMap.put("message", text);
|
|
|
169 |
paramsMap.put("mobile", mobileNumber);
|
|
|
170 |
paramsMap.put("messageType", "Text");
|
| 27285 |
tejbeer |
171 |
// rc.getResponse(SMS_GATEWAY, paramsMap, null);
|
| 21543 |
ashik.ali |
172 |
}
|
| 24440 |
amit.gupta |
173 |
|
|
|
174 |
public static void sendMailWithAttachments(JavaMailSender mailSender, String emailTo, String[] cc, String subject,
|
|
|
175 |
String body, List<File> attachments) throws Exception {
|
| 23909 |
amit.gupta |
176 |
MimeMessage message = mailSender.createMimeMessage();
|
| 24440 |
amit.gupta |
177 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
178 |
helper.setSubject(subject);
|
|
|
179 |
helper.setText(body);
|
|
|
180 |
if (cc != null) {
|
|
|
181 |
helper.setCc(cc);
|
|
|
182 |
}
|
| 27123 |
amit.gupta |
183 |
helper.setTo(emailTo);
|
| 27285 |
tejbeer |
184 |
// helper.setTo("amit.gupta@smartdukaan.com");
|
| 24440 |
amit.gupta |
185 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
|
|
|
186 |
helper.setFrom(senderAddress);
|
|
|
187 |
if (attachments != null) {
|
|
|
188 |
for (File file : attachments) {
|
|
|
189 |
helper.addAttachment(file.getName(), file);
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
mailSender.send(message);
|
| 22757 |
amit.gupta |
193 |
}
|
| 25764 |
amit.gupta |
194 |
|
| 24593 |
amit.gupta |
195 |
public static class Attachment {
|
|
|
196 |
public Attachment(String fileName, InputStreamSource inputStreamSource) {
|
|
|
197 |
this.fileName = fileName;
|
|
|
198 |
this.inputStreamSource = inputStreamSource;
|
|
|
199 |
}
|
| 25764 |
amit.gupta |
200 |
|
|
|
201 |
private String fileName;
|
| 24593 |
amit.gupta |
202 |
private InputStreamSource inputStreamSource;
|
| 25764 |
amit.gupta |
203 |
|
| 24593 |
amit.gupta |
204 |
public String getFileName() {
|
|
|
205 |
return fileName;
|
|
|
206 |
}
|
| 25764 |
amit.gupta |
207 |
|
| 24593 |
amit.gupta |
208 |
public void setFileName(String fileName) {
|
|
|
209 |
this.fileName = fileName;
|
|
|
210 |
}
|
| 25764 |
amit.gupta |
211 |
|
| 24593 |
amit.gupta |
212 |
public InputStreamSource getInputStreamSource() {
|
|
|
213 |
return inputStreamSource;
|
|
|
214 |
}
|
| 25764 |
amit.gupta |
215 |
|
| 24593 |
amit.gupta |
216 |
public void setInputStreamSource(InputStreamSource inputStreamSource) {
|
|
|
217 |
this.inputStreamSource = inputStreamSource;
|
|
|
218 |
}
|
| 25764 |
amit.gupta |
219 |
|
| 24593 |
amit.gupta |
220 |
@Override
|
|
|
221 |
public String toString() {
|
|
|
222 |
return "Attachment [fileName=" + fileName + ", inputStreamSource=" + inputStreamSource + "]";
|
|
|
223 |
}
|
|
|
224 |
}
|
| 25764 |
amit.gupta |
225 |
|
| 24440 |
amit.gupta |
226 |
public static void sendMailWithAttachment(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
|
|
|
227 |
String body, String fileName, InputStreamSource inputStreamSource) throws Exception {
|
| 23929 |
amit.gupta |
228 |
MimeMessage message = mailSender.createMimeMessage();
|
| 24440 |
amit.gupta |
229 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 23929 |
amit.gupta |
230 |
helper.setSubject(subject);
|
|
|
231 |
helper.setText(body);
|
| 24440 |
amit.gupta |
232 |
if (cc != null) {
|
| 23929 |
amit.gupta |
233 |
helper.setCc(cc);
|
|
|
234 |
}
|
|
|
235 |
helper.setTo(emailTo);
|
|
|
236 |
helper.addAttachment(fileName, inputStreamSource);
|
|
|
237 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
|
|
|
238 |
helper.setFrom(senderAddress);
|
|
|
239 |
mailSender.send(message);
|
|
|
240 |
}
|
| 25764 |
amit.gupta |
241 |
|
| 26978 |
tejbeer |
242 |
public static void sendMailWithAttachments(JavaMailSender mailSender, String[] emailTo, String[] cc, String[] bcc,
|
|
|
243 |
String subject, String body, Attachment... attachments) throws Exception {
|
| 24593 |
amit.gupta |
244 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
245 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
246 |
helper.setSubject(subject);
|
|
|
247 |
helper.setText(body);
|
|
|
248 |
if (cc != null) {
|
|
|
249 |
helper.setCc(cc);
|
|
|
250 |
}
|
| 26978 |
tejbeer |
251 |
if (bcc != null) {
|
|
|
252 |
helper.setBcc(bcc);
|
|
|
253 |
}
|
| 24593 |
amit.gupta |
254 |
helper.setTo(emailTo);
|
| 25764 |
amit.gupta |
255 |
for (Attachment attachment : attachments) {
|
| 24593 |
amit.gupta |
256 |
helper.addAttachment(attachment.getFileName(), attachment.getInputStreamSource());
|
|
|
257 |
}
|
|
|
258 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
|
|
|
259 |
helper.setFrom(senderAddress);
|
|
|
260 |
mailSender.send(message);
|
|
|
261 |
}
|
| 25764 |
amit.gupta |
262 |
|
|
|
263 |
public static void sendHtmlMailWithAttachments(JavaMailSender mailSender, String[] emailTo, String[] cc,
|
|
|
264 |
String subject, String body, Attachment... attachments) throws Exception {
|
| 25743 |
amit.gupta |
265 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
266 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
267 |
helper.setSubject(subject);
|
| 25754 |
amit.gupta |
268 |
message.setContent(body, "text/html");
|
| 25764 |
amit.gupta |
269 |
// helper.setText(body, true);
|
| 25743 |
amit.gupta |
270 |
if (cc != null) {
|
|
|
271 |
helper.setCc(cc);
|
|
|
272 |
}
|
|
|
273 |
helper.setTo(emailTo);
|
| 25764 |
amit.gupta |
274 |
for (Attachment attachment : attachments) {
|
|
|
275 |
if (attachment == null)
|
|
|
276 |
break;
|
| 25743 |
amit.gupta |
277 |
helper.addAttachment(attachment.getFileName(), attachment.getInputStreamSource());
|
|
|
278 |
}
|
|
|
279 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
|
|
|
280 |
helper.setFrom(senderAddress);
|
|
|
281 |
mailSender.send(message);
|
|
|
282 |
}
|
| 24440 |
amit.gupta |
283 |
|
|
|
284 |
public static String[] getOrderStatus(RechargeOrderStatus status) {
|
|
|
285 |
if (status == null) {
|
| 21543 |
ashik.ali |
286 |
status = RechargeOrderStatus.INIT;
|
|
|
287 |
}
|
| 24440 |
amit.gupta |
288 |
if (status.equals(RechargeOrderStatus.PAYMENT_FAILED) || status.equals(RechargeOrderStatus.PAYMENT_PENDING)) {
|
|
|
289 |
return new String[] { "false", "PAYMENT FAILED", "Payment failed at the payment gateway." };
|
|
|
290 |
} else if (status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)
|
|
|
291 |
|| status.equals(RechargeOrderStatus.RECHARGE_UNKNOWN)) {
|
|
|
292 |
if (status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)) {
|
|
|
293 |
return new String[] { "false", "PAYMENT SUCCESSFUL",
|
|
|
294 |
"Your Payment was successful but due to some internal error with the operator's system we are not sure if the recharge was successful."
|
|
|
295 |
+ " We have put your recharge under process."
|
|
|
296 |
+ " As soon as we get a confirmation on this transaction, we will notify you." };
|
|
|
297 |
} else {
|
|
|
298 |
return new String[] { "false", "RECHARGE IN PROCESS",
|
|
|
299 |
"Your Payment is successful.We have put your recharge under process."
|
|
|
300 |
+ " Please wait while we check with the operator." };
|
| 21543 |
ashik.ali |
301 |
}
|
| 24440 |
amit.gupta |
302 |
} else if (status.equals(RechargeOrderStatus.RECHARGE_FAILED)
|
|
|
303 |
|| status.equals(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED)) {
|
|
|
304 |
return new String[] { "false", "RECHARGE FAILED",
|
|
|
305 |
"Your Payment was successful but unfortunately the recharge failed.Don't worry your payment is safe with us."
|
|
|
306 |
+ " The entire Amount has been refunded to your wallet." };
|
|
|
307 |
} else if (status.equals(RechargeOrderStatus.RECHARGE_SUCCESSFUL)) {
|
|
|
308 |
return new String[] { "false", "SUCCESS", "Congratulations! Your device is successfully recharged." };
|
|
|
309 |
} else if (status.equals(RechargeOrderStatus.PARTIALLY_REFUNDED)
|
|
|
310 |
|| status.equals(RechargeOrderStatus.REFUNDED)) {
|
|
|
311 |
return new String[] { "false", "PAYMENT REFUNDED",
|
|
|
312 |
"The payment associated with this recharge order has been refunded." };
|
| 21543 |
ashik.ali |
313 |
} else {
|
| 24440 |
amit.gupta |
314 |
return new String[] { "true", "ERROR", "INVALID INPUT" };
|
| 21543 |
ashik.ali |
315 |
}
|
|
|
316 |
}
|
| 21986 |
kshitij.so |
317 |
|
| 24440 |
amit.gupta |
318 |
public static String getIconUrl(int entityId, String host, int port, String webapp) {
|
| 25743 |
amit.gupta |
319 |
return "";
|
| 21986 |
kshitij.so |
320 |
}
|
| 25764 |
amit.gupta |
321 |
|
|
|
322 |
private static CatalogService.Client getCatalogClient() throws Exception {
|
|
|
323 |
try {
|
| 21915 |
ashik.ali |
324 |
CatalogClient client = new CatalogClient();
|
|
|
325 |
CatalogService.Client catalogClient = client.getClient();
|
|
|
326 |
return catalogClient;
|
| 25764 |
amit.gupta |
327 |
} catch (Exception e) {
|
| 21915 |
ashik.ali |
328 |
throw e;
|
|
|
329 |
}
|
|
|
330 |
}
|
| 23509 |
amit.gupta |
331 |
|
| 24440 |
amit.gupta |
332 |
private static WarehouseService.Client getWarehouseClient() throws Exception {
|
|
|
333 |
try {
|
| 23509 |
amit.gupta |
334 |
WarehouseClient client = new WarehouseClient();
|
|
|
335 |
WarehouseService.Client warehouseClient = client.getClient();
|
|
|
336 |
return warehouseClient;
|
| 24440 |
amit.gupta |
337 |
} catch (Exception e) {
|
| 23509 |
amit.gupta |
338 |
throw e;
|
|
|
339 |
}
|
|
|
340 |
}
|
| 24440 |
amit.gupta |
341 |
|
|
|
342 |
public static Map<String, Warehouse> getWarehouseByImeis(List<String> imeis) throws Exception {
|
| 23509 |
amit.gupta |
343 |
List<InventoryItem> inventoryItems = getWarehouseClient().getInventoryItemsBySerailNumbers(imeis);
|
|
|
344 |
Map<String, InventoryItem> imeiInventoryItemMap = new HashMap<>();
|
| 24440 |
amit.gupta |
345 |
for (InventoryItem inventoryItem : inventoryItems) {
|
| 23509 |
amit.gupta |
346 |
imeiInventoryItemMap.put(inventoryItem.getSerialNumber(), inventoryItem);
|
|
|
347 |
}
|
| 24440 |
amit.gupta |
348 |
Map<Integer, Warehouse> warehouseMap = new HashMap<>();
|
| 23509 |
amit.gupta |
349 |
Map<String, Warehouse> serialNumberWarehouseMap = new HashMap<>();
|
|
|
350 |
InventoryClient client = new InventoryClient();
|
|
|
351 |
InventoryService.Client inventoryClient = client.getClient();
|
|
|
352 |
logger.info("[imeiInventoryItemMap] {}", imeiInventoryItemMap);
|
| 24440 |
amit.gupta |
353 |
for (InventoryItem inventory : new HashSet<>(imeiInventoryItemMap.values())) {
|
| 23509 |
amit.gupta |
354 |
Warehouse phWarehouse = null;
|
| 24440 |
amit.gupta |
355 |
if (warehouseMap.containsKey(inventory.getPhysicalWarehouseId())) {
|
|
|
356 |
phWarehouse = warehouseMap.get((int) inventory.getPhysicalWarehouseId());
|
| 23509 |
amit.gupta |
357 |
} else {
|
|
|
358 |
phWarehouse = inventoryClient.getWarehouse(inventory.getPhysicalWarehouseId());
|
| 24440 |
amit.gupta |
359 |
warehouseMap.put((int) inventory.getPhysicalWarehouseId(), phWarehouse);
|
| 23509 |
amit.gupta |
360 |
}
|
|
|
361 |
serialNumberWarehouseMap.put(inventory.getSerialNumber(), phWarehouse);
|
| 24440 |
amit.gupta |
362 |
|
| 23509 |
amit.gupta |
363 |
}
|
|
|
364 |
return serialNumberWarehouseMap;
|
|
|
365 |
}
|
| 24440 |
amit.gupta |
366 |
|
| 23615 |
amit.gupta |
367 |
public static Map<Integer, Warehouse> getWarehousesByIds(Set<Integer> warehouseIds) throws Exception {
|
|
|
368 |
InventoryClient client = new InventoryClient();
|
|
|
369 |
InventoryService.Client inventoryClient = client.getClient();
|
|
|
370 |
Map<Integer, Warehouse> warehouseMap = new HashMap<>();
|
|
|
371 |
for (Integer warehouseId : warehouseIds) {
|
|
|
372 |
warehouseMap.put(warehouseId, inventoryClient.getWarehouse(warehouseId));
|
|
|
373 |
}
|
|
|
374 |
return warehouseMap;
|
|
|
375 |
}
|
| 24440 |
amit.gupta |
376 |
|
|
|
377 |
public static String getStateCode(String stateName) throws Exception {
|
| 21902 |
ashik.ali |
378 |
return getStateInfo(stateName).getStateCode();
|
|
|
379 |
}
|
| 24440 |
amit.gupta |
380 |
|
| 23539 |
amit.gupta |
381 |
public static long getStateId(String stateName) throws ProfitMandiBusinessException {
|
|
|
382 |
try {
|
|
|
383 |
return getStateInfo(stateName).getId();
|
| 24440 |
amit.gupta |
384 |
} catch (Exception e) {
|
| 23539 |
amit.gupta |
385 |
e.printStackTrace();
|
|
|
386 |
throw new ProfitMandiBusinessException("State Name", stateName, "Could not fetch state");
|
|
|
387 |
}
|
| 21902 |
ashik.ali |
388 |
}
|
| 24440 |
amit.gupta |
389 |
|
|
|
390 |
public static StateInfo getStateByStateId(long stateId) throws Exception {
|
| 23509 |
amit.gupta |
391 |
InventoryClient client = new InventoryClient();
|
|
|
392 |
InventoryService.Client inventoryClient = client.getClient();
|
|
|
393 |
Map<Long, StateInfo> map = inventoryClient.getStateMaster();
|
|
|
394 |
return map.get(stateId);
|
|
|
395 |
}
|
| 24440 |
amit.gupta |
396 |
|
|
|
397 |
public static StateInfo getStateInfo(String stateName) throws Exception {
|
|
|
398 |
try {
|
| 21894 |
ashik.ali |
399 |
InventoryClient client = new InventoryClient();
|
|
|
400 |
InventoryService.Client inventoryClient = client.getClient();
|
|
|
401 |
Map<Long, StateInfo> map = inventoryClient.getStateMaster();
|
| 21902 |
ashik.ali |
402 |
List<StateInfo> stateInfos = new ArrayList<>(map.values());
|
| 22664 |
amit.gupta |
403 |
logger.info("State Name: {}", stateName);
|
| 24440 |
amit.gupta |
404 |
for (StateInfo stateInfo : stateInfos) {
|
| 22664 |
amit.gupta |
405 |
logger.info("State Name from service: {}", stateInfo.getStateName());
|
| 24440 |
amit.gupta |
406 |
if (stateName.toUpperCase().equals(stateInfo.getStateName().toUpperCase())) {
|
| 21902 |
ashik.ali |
407 |
return stateInfo;
|
| 21894 |
ashik.ali |
408 |
}
|
|
|
409 |
}
|
| 21902 |
ashik.ali |
410 |
throw new Exception("Not found");
|
| 24440 |
amit.gupta |
411 |
} catch (Exception e) {
|
| 21894 |
ashik.ali |
412 |
e.printStackTrace();
|
|
|
413 |
throw e;
|
|
|
414 |
}
|
|
|
415 |
}
|
| 24440 |
amit.gupta |
416 |
|
|
|
417 |
public static List<String> getAllStateNames() {
|
| 23296 |
ashik.ali |
418 |
List<String> sortedStateNames = new ArrayList<>();
|
| 24440 |
amit.gupta |
419 |
try {
|
| 23296 |
ashik.ali |
420 |
InventoryClient client = new InventoryClient();
|
|
|
421 |
InventoryService.Client inventoryClient = client.getClient();
|
|
|
422 |
Map<Long, StateInfo> map = inventoryClient.getStateMaster();
|
|
|
423 |
List<StateInfo> stateInfos = new ArrayList<>(map.values());
|
|
|
424 |
Set<String> stateNames = new TreeSet<>();
|
|
|
425 |
|
| 24440 |
amit.gupta |
426 |
for (StateInfo stateInfo : stateInfos) {
|
| 23296 |
ashik.ali |
427 |
stateNames.add(stateInfo.getStateName());
|
|
|
428 |
}
|
|
|
429 |
sortedStateNames = new ArrayList<>(stateNames);
|
|
|
430 |
return sortedStateNames;
|
| 24440 |
amit.gupta |
431 |
} catch (Exception e) {
|
| 23296 |
ashik.ali |
432 |
e.printStackTrace();
|
|
|
433 |
return sortedStateNames;
|
|
|
434 |
}
|
|
|
435 |
}
|
| 23509 |
amit.gupta |
436 |
|
| 24440 |
amit.gupta |
437 |
public static Map<Long, StateInfo> getAllStatesMap() throws Exception {
|
| 23509 |
amit.gupta |
438 |
InventoryClient client = new InventoryClient();
|
|
|
439 |
InventoryService.Client inventoryClient = client.getClient();
|
| 24440 |
amit.gupta |
440 |
return inventoryClient.getStateMaster();
|
| 23509 |
amit.gupta |
441 |
|
|
|
442 |
}
|
| 24440 |
amit.gupta |
443 |
|
|
|
444 |
public static User createSaholicUser(String emailId) throws ProfitMandiBusinessException {
|
| 22351 |
ashik.ali |
445 |
in.shop2020.model.v1.user.User user = new in.shop2020.model.v1.user.User();
|
|
|
446 |
user.setEmail(emailId);
|
|
|
447 |
user.setPassword("");
|
|
|
448 |
user.setCommunicationEmail(emailId);
|
|
|
449 |
user.setSex(Sex.WONT_SAY);
|
|
|
450 |
|
|
|
451 |
try {
|
|
|
452 |
UserClient userContextServiceClient = new UserClient();
|
|
|
453 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
454 |
user = userClient.createUser(user);
|
|
|
455 |
return user;
|
| 24440 |
amit.gupta |
456 |
} catch (UserContextException ux) {
|
| 22351 |
ashik.ali |
457 |
logger.error("Unable to register user: " + ux.getMessage());
|
|
|
458 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
|
|
|
459 |
} catch (TTransportException e) {
|
|
|
460 |
logger.error("Unable to register user." + e);
|
|
|
461 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
|
| 24440 |
amit.gupta |
462 |
} catch (TException e) {
|
| 22351 |
ashik.ali |
463 |
logger.error("Unable to register user." + e);
|
|
|
464 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
|
| 24440 |
amit.gupta |
465 |
}
|
| 22351 |
ashik.ali |
466 |
}
|
| 24440 |
amit.gupta |
467 |
|
|
|
468 |
public static void main(String[] args) throws Exception {
|
| 22757 |
amit.gupta |
469 |
Utils.sendSms("Hello", "9990381569");
|
|
|
470 |
}
|
| 23509 |
amit.gupta |
471 |
|
| 24440 |
amit.gupta |
472 |
public static WarehouseAddress getWarehouseByWarehouseId(int warehouseAddressId) throws Exception {
|
| 23509 |
amit.gupta |
473 |
TransactionClient tcl = new TransactionClient();
|
| 24440 |
amit.gupta |
474 |
return tcl.getClient().getWarehouseAddress((long) warehouseAddressId);
|
| 23509 |
amit.gupta |
475 |
}
|
| 24440 |
amit.gupta |
476 |
|
| 25766 |
amit.gupta |
477 |
public static void sendEmbeddedHtmlMail(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
|
|
|
478 |
String body, Map<? extends Serializable, File> map) throws Exception {
|
|
|
479 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
480 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
481 |
helper.setSubject(subject);
|
| 25998 |
amit.gupta |
482 |
Multipart mp = new MimeMultipart();
|
| 27285 |
tejbeer |
483 |
|
| 25766 |
amit.gupta |
484 |
MimeBodyPart messageBodyPart = new MimeBodyPart();
|
| 27285 |
tejbeer |
485 |
messageBodyPart.setContent(body, "text/html");
|
| 25998 |
amit.gupta |
486 |
mp.addBodyPart(messageBodyPart);
|
| 27285 |
tejbeer |
487 |
|
| 25766 |
amit.gupta |
488 |
// helper.setText(body, true);
|
|
|
489 |
if (cc != null) {
|
|
|
490 |
helper.setCc(cc);
|
|
|
491 |
}
|
|
|
492 |
helper.setTo(emailTo);
|
|
|
493 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
|
|
|
494 |
helper.setFrom(senderAddress);
|
|
|
495 |
for (Map.Entry<? extends Serializable, File> entry : map.entrySet()) {
|
| 25764 |
amit.gupta |
496 |
entry.getKey();
|
|
|
497 |
entry.getValue();
|
|
|
498 |
MimeBodyPart imagePart = new MimeBodyPart();
|
|
|
499 |
imagePart.setHeader("Content-ID", entry.getKey() + "");
|
|
|
500 |
imagePart.setDisposition(MimeBodyPart.INLINE);
|
|
|
501 |
imagePart.attachFile(entry.getValue());
|
| 25766 |
amit.gupta |
502 |
mp.addBodyPart(imagePart);
|
| 25998 |
amit.gupta |
503 |
|
| 25764 |
amit.gupta |
504 |
}
|
| 25768 |
amit.gupta |
505 |
message.setContent(mp);
|
| 25767 |
amit.gupta |
506 |
mailSender.send(message);
|
| 25764 |
amit.gupta |
507 |
|
|
|
508 |
}
|
| 27285 |
tejbeer |
509 |
|
| 26066 |
amit.gupta |
510 |
public String htmlJson(Object object) {
|
|
|
511 |
return StringEscapeUtils.escapeHtml4(gson.toJson(object));
|
|
|
512 |
}
|
| 25764 |
amit.gupta |
513 |
|
| 26534 |
amit.gupta |
514 |
public static String getHyphenatedString(String s) {
|
|
|
515 |
s = s.trim().replaceAll("\\s+", " ");
|
|
|
516 |
s = s.replaceAll("\\s", "-");
|
|
|
517 |
return s.toLowerCase();
|
|
|
518 |
}
|
| 27285 |
tejbeer |
519 |
|
| 26989 |
amit.gupta |
520 |
public static void sendMailWithAttachments(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
|
|
|
521 |
String body, Attachment... attachments) throws Exception {
|
|
|
522 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
523 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
524 |
helper.setSubject(subject);
|
|
|
525 |
helper.setText(body);
|
|
|
526 |
if (cc != null) {
|
|
|
527 |
helper.setCc(cc);
|
|
|
528 |
}
|
|
|
529 |
helper.setTo(emailTo);
|
|
|
530 |
for (Attachment attachment : attachments) {
|
|
|
531 |
helper.addAttachment(attachment.getFileName(), attachment.getInputStreamSource());
|
|
|
532 |
}
|
|
|
533 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
|
|
|
534 |
helper.setFrom(senderAddress);
|
|
|
535 |
mailSender.send(message);
|
|
|
536 |
}
|
| 26534 |
amit.gupta |
537 |
|
| 26084 |
amit.gupta |
538 |
}
|