Subversion Repositories SmartDukaan

Rev

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