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