Subversion Repositories SmartDukaan

Rev

Rev 25998 | Rev 26079 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21543 ashik.ali 1
package com.spice.profitmandi.common.util;
2
 
3
import java.io.File;
4
import java.io.IOException;
5
import java.io.InputStream;
25764 amit.gupta 6
import java.io.Serializable;
21543 ashik.ali 7
import java.net.URISyntaxException;
8
import java.net.URL;
21902 ashik.ali 9
import java.util.ArrayList;
25995 amit.gupta 10
import java.util.Arrays;
21543 ashik.ali 11
import java.util.Collections;
12
import java.util.HashMap;
23509 amit.gupta 13
import java.util.HashSet;
21543 ashik.ali 14
import java.util.List;
15
import java.util.Map;
23296 ashik.ali 16
import java.util.Set;
17
import java.util.TreeSet;
21894 ashik.ali 18
 
25766 amit.gupta 19
import javax.mail.Multipart;
23909 amit.gupta 20
import javax.mail.internet.InternetAddress;
25764 amit.gupta 21
import javax.mail.internet.MimeBodyPart;
23909 amit.gupta 22
import javax.mail.internet.MimeMessage;
25766 amit.gupta 23
import javax.mail.internet.MimeMultipart;
23909 amit.gupta 24
 
21543 ashik.ali 25
import org.apache.commons.io.FileUtils;
26
import org.apache.commons.io.IOUtils;
26066 amit.gupta 27
import org.apache.commons.lang3.StringEscapeUtils;
28
import org.apache.commons.lang3.StringUtils;
21543 ashik.ali 29
import org.apache.http.client.utils.URIBuilder;
23929 amit.gupta 30
import org.apache.logging.log4j.LogManager;
31
import org.apache.logging.log4j.Logger;
22351 ashik.ali 32
import org.apache.thrift.TException;
33
import org.apache.thrift.transport.TTransportException;
23929 amit.gupta 34
import org.springframework.core.io.InputStreamSource;
23909 amit.gupta 35
import org.springframework.mail.javamail.JavaMailSender;
36
import org.springframework.mail.javamail.MimeMessageHelper;
23074 ashik.ali 37
 
26066 amit.gupta 38
import com.google.gson.Gson;
22215 ashik.ali 39
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
21894 ashik.ali 40
import com.spice.profitmandi.common.model.GstRate;
22351 ashik.ali 41
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21894 ashik.ali 42
import com.spice.profitmandi.thrift.clients.CatalogClient;
43
import com.spice.profitmandi.thrift.clients.InventoryClient;
44
import com.spice.profitmandi.thrift.clients.TransactionClient;
22351 ashik.ali 45
import com.spice.profitmandi.thrift.clients.UserClient;
23509 amit.gupta 46
import com.spice.profitmandi.thrift.clients.WarehouseClient;
21894 ashik.ali 47
import com.spice.profitmandi.thrift.clients.config.ConfigClient;
21543 ashik.ali 48
 
21894 ashik.ali 49
import in.shop2020.model.v1.catalog.CatalogService;
50
import in.shop2020.model.v1.inventory.InventoryService;
51
import in.shop2020.model.v1.inventory.StateInfo;
23509 amit.gupta 52
import in.shop2020.model.v1.inventory.Warehouse;
23884 amit.gupta 53
import in.shop2020.model.v1.order.OrderStatusGroups;
21894 ashik.ali 54
import in.shop2020.model.v1.order.RechargeOrderStatus;
55
import in.shop2020.model.v1.order.RechargePlan;
56
import in.shop2020.model.v1.order.RechargeType;
23509 amit.gupta 57
import in.shop2020.model.v1.order.SellerInfo;
58
import in.shop2020.model.v1.order.WarehouseAddress;
22351 ashik.ali 59
import in.shop2020.model.v1.user.Sex;
60
import in.shop2020.model.v1.user.User;
61
import in.shop2020.model.v1.user.UserContextException;
23509 amit.gupta 62
import in.shop2020.warehouse.InventoryItem;
63
import in.shop2020.warehouse.WarehouseService;
21543 ashik.ali 64
 
65
public class Utils {
21986 kshitij.so 66
 
23568 govind 67
	private static final Logger logger = LogManager.getLogger(Utils.class);
21986 kshitij.so 68
	public static final String EXPORT_ENTITIES_PATH = getExportPath();
69
	public static final String PRODUCT_PROPERTIES_SNIPPET = "ProductPropertiesSnippet.html";
70
	public static final String DOCUMENT_STORE = "/profitmandi/documents/";
26066 amit.gupta 71
	private Gson gson = new Gson();
23017 ashik.ali 72
	private static final Map<Integer, String> helpMap = new HashMap<>(6);
73
	private static final Map<Integer, String> dthIdAliasMap = new HashMap<>(7);
74
	private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<>(20);
21986 kshitij.so 75
	private static Map<Long, String> mobileProvidersMap;
76
	private static Map<Long, String> dthProvidersMap;
25764 amit.gupta 77
	// private static final String SMS_GATEWAY =
78
	// "http://103.15.179.45:8085/SMSGateway/sendingSMS";
22757 amit.gupta 79
	private static final String SMS_GATEWAY = "http://103.15.179.45:8085/MessagingGateway/SendTransSMS";
21986 kshitij.so 80
	private static Map<Long, String> allProviders;
23017 ashik.ali 81
	public static Map<RechargeOrderStatus, String> rechargeStatusMap = new HashMap<>();
23884 amit.gupta 82
	public static OrderStatusGroups ORDER_STATUS_GROUPS = new OrderStatusGroups();
25764 amit.gupta 83
	public static final String SYSTEM_PARTNER = "testpxps@gmail.com";
84
 
21986 kshitij.so 85
	static {
86
		helpMap.put(Integer.valueOf(1), "Your VC number starts with 0 and is 11 digits long.");
87
		helpMap.put(Integer.valueOf(2), "Smart card number starts with 2 and is 12 digits long.");
88
		helpMap.put(Integer.valueOf(3), "Smart card number starts with 4 and is 11 digits long.");
89
		helpMap.put(Integer.valueOf(4), "Subscriber ID starts with 1 and is 10 digits long.");
90
		helpMap.put(Integer.valueOf(5), "For customer ID, SMS ID to 9212012299 from your registered mobile no.");
91
		helpMap.put(Integer.valueOf(26), "Customer ID starts with 3 and is 10 digits long.");
21543 ashik.ali 92
 
21986 kshitij.so 93
		dthIdAliasMap.put(Integer.valueOf(1), "VC Number :");
94
		dthIdAliasMap.put(Integer.valueOf(2), "Smart Card Number :");
95
		dthIdAliasMap.put(Integer.valueOf(3), "Smart Card Number :");
96
		dthIdAliasMap.put(Integer.valueOf(4), "Subscriber Id :");
97
		dthIdAliasMap.put(Integer.valueOf(5), "Customer Id :");
98
		dthIdAliasMap.put(Integer.valueOf(0), "Account Number :");
99
		dthIdAliasMap.put(Integer.valueOf(26), "Customer Id :");
21543 ashik.ali 100
 
21986 kshitij.so 101
		rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_FAILED, "Payment Unsuccessful");
102
		rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_SUCCESSFUL, "Processing Recharge");
103
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_FAILED, "Recharge Failed");
104
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED, "Recharge Failed Refunded");
105
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_SUCCESSFUL, "Recharge Successful");
106
		rechargeStatusMap.put(RechargeOrderStatus.REFUNDED, "Amount Refunded");
107
		rechargeStatusMap.put(RechargeOrderStatus.PARTIALLY_REFUNDED, "Amount Refunded");
108
		rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_PENDING, "Payment Failed");
109
		rechargeStatusMap.put(RechargeOrderStatus.INIT, "Payment Initiated");
110
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_UNKNOWN, "Recharge In Process");
111
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_IN_PROCESS, "Recharge In Process");
112
 
113
		TransactionClient tcl;
24440 amit.gupta 114
		try {
21986 kshitij.so 115
			tcl = new TransactionClient();
116
			mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
117
			dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
118
			logger.info("mobileProvidersMap" + mobileProvidersMap);
119
			logger.info("dthProvidersMap" + dthProvidersMap);
22390 amit.gupta 120
			allProviders = new HashMap<>(mobileProvidersMap);
21986 kshitij.so 121
			logger.info("allProviders" + allProviders);
122
			allProviders.putAll(dthProvidersMap);
123
			logger.info("allProviders" + allProviders);
124
 
125
			for (Long operatorId : mobileProvidersMap.keySet()) {
126
				List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId.longValue());
127
				if (!plans.isEmpty())
128
					operatorPlanMap.put(operatorId, plans);
129
			}
130
		} catch (Exception e) {
131
			logger.error("Could not get providers", e);
132
		}
133
	}
134
 
23509 amit.gupta 135
	public static SellerInfo getSellerInfoBySellerId(int sellerId) throws Exception {
136
		TransactionClient tcl = new TransactionClient();
24440 amit.gupta 137
		return tcl.getClient().getSellerInfo((long) sellerId);
23509 amit.gupta 138
	}
24440 amit.gupta 139
 
21543 ashik.ali 140
	@SuppressWarnings("serial")
24440 amit.gupta 141
	public static final Map<String, String> MIME_TYPE = Collections.unmodifiableMap(new HashMap<String, String>() {
142
		{
143
			put("image/png", "png");
144
			put("image/jpeg", "jpeg");
145
			put("image/pjpeg", "jpeg");
146
			put("application/pdf", "pdf");
147
		}
148
	});
21543 ashik.ali 149
 
24440 amit.gupta 150
	private static String getExportPath() {
151
		String exportPath = null;
21543 ashik.ali 152
 
153
		ConfigClient client = ConfigClient.getClient();
24440 amit.gupta 154
		try {
21543 ashik.ali 155
			exportPath = client.get("export_entities_path");
24440 amit.gupta 156
		} catch (Exception ce) {
21543 ashik.ali 157
			logger.error("Unable to read export path from the config client: ", ce);
158
			logger.warn("Setting the default export path");
159
			exportPath = "/var/lib/tomcat7/webapps/export/html/entities/";
160
		}
161
		return exportPath;
162
	}
21986 kshitij.so 163
 
21646 kshitij.so 164
	public static String getRechargeDisplayStatus(RechargeOrderStatus status) {
21986 kshitij.so 165
		if (status == null) {
166
			status = RechargeOrderStatus.INIT;
167
		}
24440 amit.gupta 168
		String displayStatus = (String) rechargeStatusMap.get(status);
21986 kshitij.so 169
		if (displayStatus == null) {
170
			return "";
171
		}
172
		return displayStatus;
173
	}
21543 ashik.ali 174
 
24440 amit.gupta 175
	public static boolean copyDocument(String documentPath) {
21543 ashik.ali 176
		File source = new File(documentPath);
24440 amit.gupta 177
		File dest = new File(DOCUMENT_STORE + source.getName());
21543 ashik.ali 178
		try {
179
			FileUtils.copyFile(source, dest);
180
		} catch (IOException e) {
181
			e.printStackTrace();
182
			return false;
183
		}
184
		return true;
185
	}
186
 
187
	public static Map<Long, String> getMobileProvidersMap() {
188
		return mobileProvidersMap;
189
	}
190
 
191
	public static Map<Long, String> getDthProvidersMap() {
192
		return dthProvidersMap;
193
	}
21986 kshitij.so 194
 
21543 ashik.ali 195
	public static Map<Long, String> getAllProviders() {
196
		return allProviders;
197
	}
21986 kshitij.so 198
 
21543 ashik.ali 199
	public static String getProvider(long operatorId) {
21986 kshitij.so 200
		return allProviders.get(operatorId);
201
	}
21543 ashik.ali 202
 
24440 amit.gupta 203
	public static void sendSms(String text, String mobileNumber) throws URISyntaxException, IOException {
21543 ashik.ali 204
		URIBuilder generalSearchUrl = new URIBuilder(SMS_GATEWAY);
24440 amit.gupta 205
		generalSearchUrl.addParameter("Mobile", "91" + mobileNumber);
25982 amit.gupta 206
		generalSearchUrl.addParameter("Username", "smartdukaan");
207
		generalSearchUrl.addParameter("Password", "spice@123");
24440 amit.gupta 208
		generalSearchUrl.addParameter("SenderID", "SMTDKN");
22757 amit.gupta 209
		generalSearchUrl.setParameter("Message", text);
210
		generalSearchUrl.setParameter("MessageType", "txt");
24256 amit.gupta 211
		URL url = generalSearchUrl.build().toURL();
22889 amit.gupta 212
		System.out.println(url);
21543 ashik.ali 213
		InputStream is = url.openStream();
214
		String response;
24440 amit.gupta 215
		try {
21543 ashik.ali 216
			response = IOUtils.toString(is, "UTF-8");
24440 amit.gupta 217
			System.out.println("response sms gateway " + response);
218
		} finally {
21543 ashik.ali 219
			is.close();
220
		}
221
	}
24440 amit.gupta 222
 
223
	public static void sendMailWithAttachments(JavaMailSender mailSender, String emailTo, String[] cc, String subject,
224
			String body, List<File> attachments) throws Exception {
23909 amit.gupta 225
		MimeMessage message = mailSender.createMimeMessage();
24440 amit.gupta 226
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
227
		helper.setSubject(subject);
228
		helper.setText(body);
229
		if (cc != null) {
230
			helper.setCc(cc);
231
		}
232
		helper.setTo(emailTo);
233
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
234
		helper.setFrom(senderAddress);
235
		if (attachments != null) {
236
			for (File file : attachments) {
237
				helper.addAttachment(file.getName(), file);
238
			}
239
		}
240
		mailSender.send(message);
22757 amit.gupta 241
	}
25764 amit.gupta 242
 
24593 amit.gupta 243
	public static class Attachment {
244
		public Attachment(String fileName, InputStreamSource inputStreamSource) {
245
			this.fileName = fileName;
246
			this.inputStreamSource = inputStreamSource;
247
		}
25764 amit.gupta 248
 
249
		private String fileName;
24593 amit.gupta 250
		private InputStreamSource inputStreamSource;
25764 amit.gupta 251
 
24593 amit.gupta 252
		public String getFileName() {
253
			return fileName;
254
		}
25764 amit.gupta 255
 
24593 amit.gupta 256
		public void setFileName(String fileName) {
257
			this.fileName = fileName;
258
		}
25764 amit.gupta 259
 
24593 amit.gupta 260
		public InputStreamSource getInputStreamSource() {
261
			return inputStreamSource;
262
		}
25764 amit.gupta 263
 
24593 amit.gupta 264
		public void setInputStreamSource(InputStreamSource inputStreamSource) {
265
			this.inputStreamSource = inputStreamSource;
266
		}
25764 amit.gupta 267
 
24593 amit.gupta 268
		@Override
269
		public String toString() {
270
			return "Attachment [fileName=" + fileName + ", inputStreamSource=" + inputStreamSource + "]";
271
		}
272
	}
25764 amit.gupta 273
 
24440 amit.gupta 274
	public static void sendMailWithAttachment(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
275
			String body, String fileName, InputStreamSource inputStreamSource) throws Exception {
23929 amit.gupta 276
		MimeMessage message = mailSender.createMimeMessage();
24440 amit.gupta 277
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
23929 amit.gupta 278
		helper.setSubject(subject);
279
		helper.setText(body);
24440 amit.gupta 280
		if (cc != null) {
23929 amit.gupta 281
			helper.setCc(cc);
282
		}
283
		helper.setTo(emailTo);
284
		helper.addAttachment(fileName, inputStreamSource);
285
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
286
		helper.setFrom(senderAddress);
287
		mailSender.send(message);
288
	}
25764 amit.gupta 289
 
24593 amit.gupta 290
	public static void sendMailWithAttachments(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
291
			String body, Attachment... attachments) throws Exception {
292
		MimeMessage message = mailSender.createMimeMessage();
293
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
294
		helper.setSubject(subject);
295
		helper.setText(body);
296
		if (cc != null) {
297
			helper.setCc(cc);
298
		}
299
		helper.setTo(emailTo);
25764 amit.gupta 300
		for (Attachment attachment : attachments) {
24593 amit.gupta 301
			helper.addAttachment(attachment.getFileName(), attachment.getInputStreamSource());
302
		}
303
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
304
		helper.setFrom(senderAddress);
305
		mailSender.send(message);
306
	}
25764 amit.gupta 307
 
308
	public static void sendHtmlMailWithAttachments(JavaMailSender mailSender, String[] emailTo, String[] cc,
309
			String subject, String body, Attachment... attachments) throws Exception {
25743 amit.gupta 310
		MimeMessage message = mailSender.createMimeMessage();
311
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
312
		helper.setSubject(subject);
25754 amit.gupta 313
		message.setContent(body, "text/html");
25764 amit.gupta 314
		// helper.setText(body, true);
25743 amit.gupta 315
		if (cc != null) {
316
			helper.setCc(cc);
317
		}
318
		helper.setTo(emailTo);
25764 amit.gupta 319
		for (Attachment attachment : attachments) {
320
			if (attachment == null)
321
				break;
25743 amit.gupta 322
			helper.addAttachment(attachment.getFileName(), attachment.getInputStreamSource());
323
		}
324
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
325
		helper.setFrom(senderAddress);
326
		mailSender.send(message);
327
	}
24440 amit.gupta 328
 
329
	public static String[] getOrderStatus(RechargeOrderStatus status) {
330
		if (status == null) {
21543 ashik.ali 331
			status = RechargeOrderStatus.INIT;
332
		}
24440 amit.gupta 333
		if (status.equals(RechargeOrderStatus.PAYMENT_FAILED) || status.equals(RechargeOrderStatus.PAYMENT_PENDING)) {
334
			return new String[] { "false", "PAYMENT FAILED", "Payment failed at the payment gateway." };
335
		} else if (status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)
336
				|| status.equals(RechargeOrderStatus.RECHARGE_UNKNOWN)) {
337
			if (status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)) {
338
				return new String[] { "false", "PAYMENT SUCCESSFUL",
339
						"Your Payment was successful but due to some internal error with the operator's system we are not sure if the recharge was successful."
340
								+ " We have put your recharge under process."
341
								+ " As soon as we get a confirmation on this transaction, we will notify you." };
342
			} else {
343
				return new String[] { "false", "RECHARGE IN PROCESS",
344
						"Your Payment is successful.We have put your recharge under process."
345
								+ " Please wait while we check with the operator." };
21543 ashik.ali 346
			}
24440 amit.gupta 347
		} else if (status.equals(RechargeOrderStatus.RECHARGE_FAILED)
348
				|| status.equals(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED)) {
349
			return new String[] { "false", "RECHARGE FAILED",
350
					"Your Payment was successful but unfortunately the recharge failed.Don't worry your payment is safe with us."
351
							+ " The entire Amount has been refunded to your wallet." };
352
		} else if (status.equals(RechargeOrderStatus.RECHARGE_SUCCESSFUL)) {
353
			return new String[] { "false", "SUCCESS", "Congratulations! Your device is successfully recharged." };
354
		} else if (status.equals(RechargeOrderStatus.PARTIALLY_REFUNDED)
355
				|| status.equals(RechargeOrderStatus.REFUNDED)) {
356
			return new String[] { "false", "PAYMENT REFUNDED",
357
					"The payment associated with this recharge order has been refunded." };
21543 ashik.ali 358
		} else {
24440 amit.gupta 359
			return new String[] { "true", "ERROR", "INVALID INPUT" };
21543 ashik.ali 360
		}
361
	}
21986 kshitij.so 362
 
24440 amit.gupta 363
	public static String getIconUrl(int entityId, String host, int port, String webapp) {
25743 amit.gupta 364
		return "";
21986 kshitij.so 365
	}
25764 amit.gupta 366
 
367
	public static Map<Integer, GstRate> getStateTaxRate(List<Integer> itemIds, int stateId)
368
			throws ProfitMandiBusinessException {
23152 ashik.ali 369
		List<Long> longItemIds = new ArrayList<>();
25764 amit.gupta 370
		for (int itemId : itemIds) {
23152 ashik.ali 371
			longItemIds.add(Long.valueOf(itemId));
372
		}
25764 amit.gupta 373
		try {
24444 amit.gupta 374
			CatalogService.Client catalogClient = getCatalogClient();
25764 amit.gupta 375
			Map<Long, in.shop2020.model.v1.catalog.GstRate> totalTaxRateMap = catalogClient.getStateTaxRate(longItemIds,
376
					stateId);
23147 ashik.ali 377
			Map<Integer, GstRate> itemIdGstRateMap = new HashMap<>();
25764 amit.gupta 378
			for (Map.Entry<Long, in.shop2020.model.v1.catalog.GstRate> totalTaxRateEntry : totalTaxRateMap.entrySet()) {
23147 ashik.ali 379
				GstRate gstRate = new GstRate();
24444 amit.gupta 380
				gstRate.setIgstRate(Double.valueOf(totalTaxRateEntry.getValue().getIgstRate()).floatValue());
381
				gstRate.setCgstRate(Double.valueOf(totalTaxRateEntry.getValue().getCgstRate()).floatValue());
382
				gstRate.setSgstRate(Double.valueOf(totalTaxRateEntry.getValue().getSgstRate()).floatValue());
383
				itemIdGstRateMap.put(totalTaxRateEntry.getKey().intValue(), gstRate);
23147 ashik.ali 384
			}
385
			return itemIdGstRateMap;
25764 amit.gupta 386
		} catch (Exception e) {
23147 ashik.ali 387
			e.printStackTrace();
25764 amit.gupta 388
			throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID + ", " + ProfitMandiConstants.STATE_ID,
389
					itemIds + ", " + stateId, "THRFT_1000");
23147 ashik.ali 390
		}
391
	}
25764 amit.gupta 392
 
393
	public static Map<Integer, Float> getIgstTaxRate(List<Integer> itemIds) throws ProfitMandiBusinessException {
23152 ashik.ali 394
		List<Long> longItemIds = new ArrayList<>();
25764 amit.gupta 395
		for (int itemId : itemIds) {
23152 ashik.ali 396
			longItemIds.add(Long.valueOf(itemId));
397
		}
25764 amit.gupta 398
		try {
24444 amit.gupta 399
			CatalogService.Client catalogClient = getCatalogClient();
400
			Map<Long, Double> totalTaxRateMap = catalogClient.getIgstTaxRate(longItemIds);
401
			Map<Integer, Float> itemIdIgstRateMap = new HashMap<>();
25764 amit.gupta 402
			for (Map.Entry<Long, Double> totalTaxRateEntry : totalTaxRateMap.entrySet()) {
24444 amit.gupta 403
				itemIdIgstRateMap.put(totalTaxRateEntry.getKey().intValue(), 12f);
404
			}
405
			return itemIdIgstRateMap;
25764 amit.gupta 406
		} catch (Exception e) {
24444 amit.gupta 407
			e.printStackTrace();
408
			throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID, itemIds, "THRFT_1001");
23147 ashik.ali 409
		}
410
	}
25764 amit.gupta 411
 
412
	private static CatalogService.Client getCatalogClient() throws Exception {
413
		try {
21915 ashik.ali 414
			CatalogClient client = new CatalogClient();
415
			CatalogService.Client catalogClient = client.getClient();
416
			return catalogClient;
25764 amit.gupta 417
		} catch (Exception e) {
21915 ashik.ali 418
			throw e;
419
		}
420
	}
23509 amit.gupta 421
 
24440 amit.gupta 422
	private static WarehouseService.Client getWarehouseClient() throws Exception {
423
		try {
23509 amit.gupta 424
			WarehouseClient client = new WarehouseClient();
425
			WarehouseService.Client warehouseClient = client.getClient();
426
			return warehouseClient;
24440 amit.gupta 427
		} catch (Exception e) {
23509 amit.gupta 428
			throw e;
429
		}
430
	}
24440 amit.gupta 431
 
432
	public static Map<String, Warehouse> getWarehouseByImeis(List<String> imeis) throws Exception {
23509 amit.gupta 433
		List<InventoryItem> inventoryItems = getWarehouseClient().getInventoryItemsBySerailNumbers(imeis);
434
		Map<String, InventoryItem> imeiInventoryItemMap = new HashMap<>();
24440 amit.gupta 435
		for (InventoryItem inventoryItem : inventoryItems) {
23509 amit.gupta 436
			imeiInventoryItemMap.put(inventoryItem.getSerialNumber(), inventoryItem);
437
		}
24440 amit.gupta 438
		Map<Integer, Warehouse> warehouseMap = new HashMap<>();
23509 amit.gupta 439
		Map<String, Warehouse> serialNumberWarehouseMap = new HashMap<>();
440
		InventoryClient client = new InventoryClient();
441
		InventoryService.Client inventoryClient = client.getClient();
442
		logger.info("[imeiInventoryItemMap] {}", imeiInventoryItemMap);
24440 amit.gupta 443
		for (InventoryItem inventory : new HashSet<>(imeiInventoryItemMap.values())) {
23509 amit.gupta 444
			Warehouse phWarehouse = null;
24440 amit.gupta 445
			if (warehouseMap.containsKey(inventory.getPhysicalWarehouseId())) {
446
				phWarehouse = warehouseMap.get((int) inventory.getPhysicalWarehouseId());
23509 amit.gupta 447
			} else {
448
				phWarehouse = inventoryClient.getWarehouse(inventory.getPhysicalWarehouseId());
24440 amit.gupta 449
				warehouseMap.put((int) inventory.getPhysicalWarehouseId(), phWarehouse);
23509 amit.gupta 450
			}
451
			serialNumberWarehouseMap.put(inventory.getSerialNumber(), phWarehouse);
24440 amit.gupta 452
 
23509 amit.gupta 453
		}
454
		return serialNumberWarehouseMap;
455
	}
24440 amit.gupta 456
 
23615 amit.gupta 457
	public static Map<Integer, Warehouse> getWarehousesByIds(Set<Integer> warehouseIds) throws Exception {
458
		InventoryClient client = new InventoryClient();
459
		InventoryService.Client inventoryClient = client.getClient();
460
		Map<Integer, Warehouse> warehouseMap = new HashMap<>();
461
		for (Integer warehouseId : warehouseIds) {
462
			warehouseMap.put(warehouseId, inventoryClient.getWarehouse(warehouseId));
463
		}
464
		return warehouseMap;
465
	}
24440 amit.gupta 466
 
467
	public static String getStateCode(String stateName) throws Exception {
21902 ashik.ali 468
		return getStateInfo(stateName).getStateCode();
469
	}
24440 amit.gupta 470
 
23539 amit.gupta 471
	public static long getStateId(String stateName) throws ProfitMandiBusinessException {
472
		try {
473
			return getStateInfo(stateName).getId();
24440 amit.gupta 474
		} catch (Exception e) {
23539 amit.gupta 475
			e.printStackTrace();
476
			throw new ProfitMandiBusinessException("State Name", stateName, "Could not fetch state");
477
		}
21902 ashik.ali 478
	}
24440 amit.gupta 479
 
480
	public static StateInfo getStateByStateId(long stateId) throws Exception {
23509 amit.gupta 481
		InventoryClient client = new InventoryClient();
482
		InventoryService.Client inventoryClient = client.getClient();
483
		Map<Long, StateInfo> map = inventoryClient.getStateMaster();
484
		return map.get(stateId);
485
	}
24440 amit.gupta 486
 
487
	public static StateInfo getStateInfo(String stateName) throws Exception {
488
		try {
21894 ashik.ali 489
			InventoryClient client = new InventoryClient();
490
			InventoryService.Client inventoryClient = client.getClient();
491
			Map<Long, StateInfo> map = inventoryClient.getStateMaster();
21902 ashik.ali 492
			List<StateInfo> stateInfos = new ArrayList<>(map.values());
22664 amit.gupta 493
			logger.info("State Name: {}", stateName);
24440 amit.gupta 494
			for (StateInfo stateInfo : stateInfos) {
22664 amit.gupta 495
				logger.info("State Name from service: {}", stateInfo.getStateName());
24440 amit.gupta 496
				if (stateName.toUpperCase().equals(stateInfo.getStateName().toUpperCase())) {
21902 ashik.ali 497
					return stateInfo;
21894 ashik.ali 498
				}
499
			}
21902 ashik.ali 500
			throw new Exception("Not found");
24440 amit.gupta 501
		} catch (Exception e) {
21894 ashik.ali 502
			e.printStackTrace();
503
			throw e;
504
		}
505
	}
24440 amit.gupta 506
 
507
	public static List<String> getAllStateNames() {
23296 ashik.ali 508
		List<String> sortedStateNames = new ArrayList<>();
24440 amit.gupta 509
		try {
23296 ashik.ali 510
			InventoryClient client = new InventoryClient();
511
			InventoryService.Client inventoryClient = client.getClient();
512
			Map<Long, StateInfo> map = inventoryClient.getStateMaster();
513
			List<StateInfo> stateInfos = new ArrayList<>(map.values());
514
			Set<String> stateNames = new TreeSet<>();
515
 
24440 amit.gupta 516
			for (StateInfo stateInfo : stateInfos) {
23296 ashik.ali 517
				stateNames.add(stateInfo.getStateName());
518
			}
519
			sortedStateNames = new ArrayList<>(stateNames);
520
			return sortedStateNames;
24440 amit.gupta 521
		} catch (Exception e) {
23296 ashik.ali 522
			e.printStackTrace();
523
			return sortedStateNames;
524
		}
525
	}
23509 amit.gupta 526
 
24440 amit.gupta 527
	public static Map<Long, StateInfo> getAllStatesMap() throws Exception {
23509 amit.gupta 528
		InventoryClient client = new InventoryClient();
529
		InventoryService.Client inventoryClient = client.getClient();
24440 amit.gupta 530
		return inventoryClient.getStateMaster();
23509 amit.gupta 531
 
532
	}
24440 amit.gupta 533
 
534
	public static User createSaholicUser(String emailId) throws ProfitMandiBusinessException {
22351 ashik.ali 535
		in.shop2020.model.v1.user.User user = new in.shop2020.model.v1.user.User();
536
		user.setEmail(emailId);
537
		user.setPassword("");
538
		user.setCommunicationEmail(emailId);
539
		user.setSex(Sex.WONT_SAY);
540
 
541
		try {
542
			UserClient userContextServiceClient = new UserClient();
543
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
544
			user = userClient.createUser(user);
545
			return user;
24440 amit.gupta 546
		} catch (UserContextException ux) {
22351 ashik.ali 547
			logger.error("Unable to register user: " + ux.getMessage());
548
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
549
		} catch (TTransportException e) {
550
			logger.error("Unable to register user." + e);
551
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
24440 amit.gupta 552
		} catch (TException e) {
22351 ashik.ali 553
			logger.error("Unable to register user." + e);
554
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
24440 amit.gupta 555
		}
22351 ashik.ali 556
	}
24440 amit.gupta 557
 
558
	public static void main(String[] args) throws Exception {
22757 amit.gupta 559
		Utils.sendSms("Hello", "9990381569");
560
	}
23509 amit.gupta 561
 
24440 amit.gupta 562
	public static WarehouseAddress getWarehouseByWarehouseId(int warehouseAddressId) throws Exception {
23509 amit.gupta 563
		TransactionClient tcl = new TransactionClient();
24440 amit.gupta 564
		return tcl.getClient().getWarehouseAddress((long) warehouseAddressId);
23509 amit.gupta 565
	}
24440 amit.gupta 566
 
25766 amit.gupta 567
	public static void sendEmbeddedHtmlMail(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
568
			String body, Map<? extends Serializable, File> map) throws Exception {
569
		MimeMessage message = mailSender.createMimeMessage();
570
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
571
		helper.setSubject(subject);
25998 amit.gupta 572
		Multipart mp = new MimeMultipart();
573
 
25766 amit.gupta 574
		MimeBodyPart messageBodyPart = new MimeBodyPart();
25998 amit.gupta 575
        messageBodyPart.setContent(body, "text/html");
576
		mp.addBodyPart(messageBodyPart);
577
 
25766 amit.gupta 578
		// helper.setText(body, true);
579
		if (cc != null) {
580
			helper.setCc(cc);
581
		}
582
		helper.setTo(emailTo);
583
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
584
		helper.setFrom(senderAddress);
585
		for (Map.Entry<? extends Serializable, File> entry : map.entrySet()) {
25764 amit.gupta 586
			entry.getKey();
587
			entry.getValue();
588
			MimeBodyPart imagePart = new MimeBodyPart();
589
			imagePart.setHeader("Content-ID", entry.getKey() + "");
590
			imagePart.setDisposition(MimeBodyPart.INLINE);
591
			imagePart.attachFile(entry.getValue());
25766 amit.gupta 592
			mp.addBodyPart(imagePart);
25998 amit.gupta 593
 
25764 amit.gupta 594
		}
25768 amit.gupta 595
		message.setContent(mp);
25767 amit.gupta 596
		mailSender.send(message);
25764 amit.gupta 597
 
598
	}
26066 amit.gupta 599
 
600
	public String htmlJson(Object object) {
601
		return StringEscapeUtils.escapeHtml4(gson.toJson(object));
602
	}
25764 amit.gupta 603
 
21543 ashik.ali 604
}