Subversion Repositories SmartDukaan

Rev

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