Subversion Repositories SmartDukaan

Rev

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