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