Subversion Repositories SmartDukaan

Rev

Rev 26978 | Rev 27121 | 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
 
26978 tejbeer 222
	public static void sendMailWithAttachments(JavaMailSender mailSender, String[] emailTo, String[] cc, String[] bcc,
223
			String subject, String body, Attachment... attachments) throws Exception {
24593 amit.gupta 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
		}
26978 tejbeer 231
		if (bcc != null) {
232
			helper.setBcc(bcc);
233
		}
24593 amit.gupta 234
		helper.setTo(emailTo);
25764 amit.gupta 235
		for (Attachment attachment : attachments) {
24593 amit.gupta 236
			helper.addAttachment(attachment.getFileName(), attachment.getInputStreamSource());
237
		}
238
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
239
		helper.setFrom(senderAddress);
240
		mailSender.send(message);
241
	}
25764 amit.gupta 242
 
243
	public static void sendHtmlMailWithAttachments(JavaMailSender mailSender, String[] emailTo, String[] cc,
244
			String subject, String body, Attachment... attachments) throws Exception {
25743 amit.gupta 245
		MimeMessage message = mailSender.createMimeMessage();
246
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
247
		helper.setSubject(subject);
25754 amit.gupta 248
		message.setContent(body, "text/html");
25764 amit.gupta 249
		// helper.setText(body, true);
25743 amit.gupta 250
		if (cc != null) {
251
			helper.setCc(cc);
252
		}
253
		helper.setTo(emailTo);
25764 amit.gupta 254
		for (Attachment attachment : attachments) {
255
			if (attachment == null)
256
				break;
25743 amit.gupta 257
			helper.addAttachment(attachment.getFileName(), attachment.getInputStreamSource());
258
		}
259
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
260
		helper.setFrom(senderAddress);
261
		mailSender.send(message);
262
	}
24440 amit.gupta 263
 
264
	public static String[] getOrderStatus(RechargeOrderStatus status) {
265
		if (status == null) {
21543 ashik.ali 266
			status = RechargeOrderStatus.INIT;
267
		}
24440 amit.gupta 268
		if (status.equals(RechargeOrderStatus.PAYMENT_FAILED) || status.equals(RechargeOrderStatus.PAYMENT_PENDING)) {
269
			return new String[] { "false", "PAYMENT FAILED", "Payment failed at the payment gateway." };
270
		} else if (status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)
271
				|| status.equals(RechargeOrderStatus.RECHARGE_UNKNOWN)) {
272
			if (status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)) {
273
				return new String[] { "false", "PAYMENT SUCCESSFUL",
274
						"Your Payment was successful but due to some internal error with the operator's system we are not sure if the recharge was successful."
275
								+ " We have put your recharge under process."
276
								+ " As soon as we get a confirmation on this transaction, we will notify you." };
277
			} else {
278
				return new String[] { "false", "RECHARGE IN PROCESS",
279
						"Your Payment is successful.We have put your recharge under process."
280
								+ " Please wait while we check with the operator." };
21543 ashik.ali 281
			}
24440 amit.gupta 282
		} else if (status.equals(RechargeOrderStatus.RECHARGE_FAILED)
283
				|| status.equals(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED)) {
284
			return new String[] { "false", "RECHARGE FAILED",
285
					"Your Payment was successful but unfortunately the recharge failed.Don't worry your payment is safe with us."
286
							+ " The entire Amount has been refunded to your wallet." };
287
		} else if (status.equals(RechargeOrderStatus.RECHARGE_SUCCESSFUL)) {
288
			return new String[] { "false", "SUCCESS", "Congratulations! Your device is successfully recharged." };
289
		} else if (status.equals(RechargeOrderStatus.PARTIALLY_REFUNDED)
290
				|| status.equals(RechargeOrderStatus.REFUNDED)) {
291
			return new String[] { "false", "PAYMENT REFUNDED",
292
					"The payment associated with this recharge order has been refunded." };
21543 ashik.ali 293
		} else {
24440 amit.gupta 294
			return new String[] { "true", "ERROR", "INVALID INPUT" };
21543 ashik.ali 295
		}
296
	}
21986 kshitij.so 297
 
24440 amit.gupta 298
	public static String getIconUrl(int entityId, String host, int port, String webapp) {
25743 amit.gupta 299
		return "";
21986 kshitij.so 300
	}
25764 amit.gupta 301
 
302
 
303
	private static CatalogService.Client getCatalogClient() throws Exception {
304
		try {
21915 ashik.ali 305
			CatalogClient client = new CatalogClient();
306
			CatalogService.Client catalogClient = client.getClient();
307
			return catalogClient;
25764 amit.gupta 308
		} catch (Exception e) {
21915 ashik.ali 309
			throw e;
310
		}
311
	}
23509 amit.gupta 312
 
24440 amit.gupta 313
	private static WarehouseService.Client getWarehouseClient() throws Exception {
314
		try {
23509 amit.gupta 315
			WarehouseClient client = new WarehouseClient();
316
			WarehouseService.Client warehouseClient = client.getClient();
317
			return warehouseClient;
24440 amit.gupta 318
		} catch (Exception e) {
23509 amit.gupta 319
			throw e;
320
		}
321
	}
24440 amit.gupta 322
 
323
	public static Map<String, Warehouse> getWarehouseByImeis(List<String> imeis) throws Exception {
23509 amit.gupta 324
		List<InventoryItem> inventoryItems = getWarehouseClient().getInventoryItemsBySerailNumbers(imeis);
325
		Map<String, InventoryItem> imeiInventoryItemMap = new HashMap<>();
24440 amit.gupta 326
		for (InventoryItem inventoryItem : inventoryItems) {
23509 amit.gupta 327
			imeiInventoryItemMap.put(inventoryItem.getSerialNumber(), inventoryItem);
328
		}
24440 amit.gupta 329
		Map<Integer, Warehouse> warehouseMap = new HashMap<>();
23509 amit.gupta 330
		Map<String, Warehouse> serialNumberWarehouseMap = new HashMap<>();
331
		InventoryClient client = new InventoryClient();
332
		InventoryService.Client inventoryClient = client.getClient();
333
		logger.info("[imeiInventoryItemMap] {}", imeiInventoryItemMap);
24440 amit.gupta 334
		for (InventoryItem inventory : new HashSet<>(imeiInventoryItemMap.values())) {
23509 amit.gupta 335
			Warehouse phWarehouse = null;
24440 amit.gupta 336
			if (warehouseMap.containsKey(inventory.getPhysicalWarehouseId())) {
337
				phWarehouse = warehouseMap.get((int) inventory.getPhysicalWarehouseId());
23509 amit.gupta 338
			} else {
339
				phWarehouse = inventoryClient.getWarehouse(inventory.getPhysicalWarehouseId());
24440 amit.gupta 340
				warehouseMap.put((int) inventory.getPhysicalWarehouseId(), phWarehouse);
23509 amit.gupta 341
			}
342
			serialNumberWarehouseMap.put(inventory.getSerialNumber(), phWarehouse);
24440 amit.gupta 343
 
23509 amit.gupta 344
		}
345
		return serialNumberWarehouseMap;
346
	}
24440 amit.gupta 347
 
23615 amit.gupta 348
	public static Map<Integer, Warehouse> getWarehousesByIds(Set<Integer> warehouseIds) throws Exception {
349
		InventoryClient client = new InventoryClient();
350
		InventoryService.Client inventoryClient = client.getClient();
351
		Map<Integer, Warehouse> warehouseMap = new HashMap<>();
352
		for (Integer warehouseId : warehouseIds) {
353
			warehouseMap.put(warehouseId, inventoryClient.getWarehouse(warehouseId));
354
		}
355
		return warehouseMap;
356
	}
24440 amit.gupta 357
 
358
	public static String getStateCode(String stateName) throws Exception {
21902 ashik.ali 359
		return getStateInfo(stateName).getStateCode();
360
	}
24440 amit.gupta 361
 
23539 amit.gupta 362
	public static long getStateId(String stateName) throws ProfitMandiBusinessException {
363
		try {
364
			return getStateInfo(stateName).getId();
24440 amit.gupta 365
		} catch (Exception e) {
23539 amit.gupta 366
			e.printStackTrace();
367
			throw new ProfitMandiBusinessException("State Name", stateName, "Could not fetch state");
368
		}
21902 ashik.ali 369
	}
24440 amit.gupta 370
 
371
	public static StateInfo getStateByStateId(long stateId) throws Exception {
23509 amit.gupta 372
		InventoryClient client = new InventoryClient();
373
		InventoryService.Client inventoryClient = client.getClient();
374
		Map<Long, StateInfo> map = inventoryClient.getStateMaster();
375
		return map.get(stateId);
376
	}
24440 amit.gupta 377
 
378
	public static StateInfo getStateInfo(String stateName) throws Exception {
379
		try {
21894 ashik.ali 380
			InventoryClient client = new InventoryClient();
381
			InventoryService.Client inventoryClient = client.getClient();
382
			Map<Long, StateInfo> map = inventoryClient.getStateMaster();
21902 ashik.ali 383
			List<StateInfo> stateInfos = new ArrayList<>(map.values());
22664 amit.gupta 384
			logger.info("State Name: {}", stateName);
24440 amit.gupta 385
			for (StateInfo stateInfo : stateInfos) {
22664 amit.gupta 386
				logger.info("State Name from service: {}", stateInfo.getStateName());
24440 amit.gupta 387
				if (stateName.toUpperCase().equals(stateInfo.getStateName().toUpperCase())) {
21902 ashik.ali 388
					return stateInfo;
21894 ashik.ali 389
				}
390
			}
21902 ashik.ali 391
			throw new Exception("Not found");
24440 amit.gupta 392
		} catch (Exception e) {
21894 ashik.ali 393
			e.printStackTrace();
394
			throw e;
395
		}
396
	}
24440 amit.gupta 397
 
398
	public static List<String> getAllStateNames() {
23296 ashik.ali 399
		List<String> sortedStateNames = new ArrayList<>();
24440 amit.gupta 400
		try {
23296 ashik.ali 401
			InventoryClient client = new InventoryClient();
402
			InventoryService.Client inventoryClient = client.getClient();
403
			Map<Long, StateInfo> map = inventoryClient.getStateMaster();
404
			List<StateInfo> stateInfos = new ArrayList<>(map.values());
405
			Set<String> stateNames = new TreeSet<>();
406
 
24440 amit.gupta 407
			for (StateInfo stateInfo : stateInfos) {
23296 ashik.ali 408
				stateNames.add(stateInfo.getStateName());
409
			}
410
			sortedStateNames = new ArrayList<>(stateNames);
411
			return sortedStateNames;
24440 amit.gupta 412
		} catch (Exception e) {
23296 ashik.ali 413
			e.printStackTrace();
414
			return sortedStateNames;
415
		}
416
	}
23509 amit.gupta 417
 
24440 amit.gupta 418
	public static Map<Long, StateInfo> getAllStatesMap() throws Exception {
23509 amit.gupta 419
		InventoryClient client = new InventoryClient();
420
		InventoryService.Client inventoryClient = client.getClient();
24440 amit.gupta 421
		return inventoryClient.getStateMaster();
23509 amit.gupta 422
 
423
	}
24440 amit.gupta 424
 
425
	public static User createSaholicUser(String emailId) throws ProfitMandiBusinessException {
22351 ashik.ali 426
		in.shop2020.model.v1.user.User user = new in.shop2020.model.v1.user.User();
427
		user.setEmail(emailId);
428
		user.setPassword("");
429
		user.setCommunicationEmail(emailId);
430
		user.setSex(Sex.WONT_SAY);
431
 
432
		try {
433
			UserClient userContextServiceClient = new UserClient();
434
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
435
			user = userClient.createUser(user);
436
			return user;
24440 amit.gupta 437
		} catch (UserContextException ux) {
22351 ashik.ali 438
			logger.error("Unable to register user: " + ux.getMessage());
439
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
440
		} catch (TTransportException e) {
441
			logger.error("Unable to register user." + e);
442
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
24440 amit.gupta 443
		} catch (TException e) {
22351 ashik.ali 444
			logger.error("Unable to register user." + e);
445
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
24440 amit.gupta 446
		}
22351 ashik.ali 447
	}
24440 amit.gupta 448
 
449
	public static void main(String[] args) throws Exception {
22757 amit.gupta 450
		Utils.sendSms("Hello", "9990381569");
451
	}
23509 amit.gupta 452
 
24440 amit.gupta 453
	public static WarehouseAddress getWarehouseByWarehouseId(int warehouseAddressId) throws Exception {
23509 amit.gupta 454
		TransactionClient tcl = new TransactionClient();
24440 amit.gupta 455
		return tcl.getClient().getWarehouseAddress((long) warehouseAddressId);
23509 amit.gupta 456
	}
24440 amit.gupta 457
 
25766 amit.gupta 458
	public static void sendEmbeddedHtmlMail(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
459
			String body, Map<? extends Serializable, File> map) throws Exception {
460
		MimeMessage message = mailSender.createMimeMessage();
461
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
462
		helper.setSubject(subject);
25998 amit.gupta 463
		Multipart mp = new MimeMultipart();
26089 amit.gupta 464
 
25766 amit.gupta 465
		MimeBodyPart messageBodyPart = new MimeBodyPart();
26089 amit.gupta 466
        messageBodyPart.setContent(body, "text/html");
25998 amit.gupta 467
		mp.addBodyPart(messageBodyPart);
26089 amit.gupta 468
 
25766 amit.gupta 469
		// helper.setText(body, true);
470
		if (cc != null) {
471
			helper.setCc(cc);
472
		}
473
		helper.setTo(emailTo);
474
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
475
		helper.setFrom(senderAddress);
476
		for (Map.Entry<? extends Serializable, File> entry : map.entrySet()) {
25764 amit.gupta 477
			entry.getKey();
478
			entry.getValue();
479
			MimeBodyPart imagePart = new MimeBodyPart();
480
			imagePart.setHeader("Content-ID", entry.getKey() + "");
481
			imagePart.setDisposition(MimeBodyPart.INLINE);
482
			imagePart.attachFile(entry.getValue());
25766 amit.gupta 483
			mp.addBodyPart(imagePart);
25998 amit.gupta 484
 
25764 amit.gupta 485
		}
25768 amit.gupta 486
		message.setContent(mp);
25767 amit.gupta 487
		mailSender.send(message);
25764 amit.gupta 488
 
489
	}
26089 amit.gupta 490
 
26066 amit.gupta 491
	public String htmlJson(Object object) {
492
		return StringEscapeUtils.escapeHtml4(gson.toJson(object));
493
	}
26534 amit.gupta 494
 
25764 amit.gupta 495
 
26534 amit.gupta 496
	public static String getHyphenatedString(String s) {
497
		s = s.trim().replaceAll("\\s+", " ");
498
		s = s.replaceAll("\\s", "-");
499
		return s.toLowerCase();
500
	}
26989 amit.gupta 501
 
502
	public static void sendMailWithAttachments(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
503
			String body, Attachment... attachments) throws Exception {
504
		MimeMessage message = mailSender.createMimeMessage();
505
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
506
		helper.setSubject(subject);
507
		helper.setText(body);
508
		if (cc != null) {
509
			helper.setCc(cc);
510
		}
511
		helper.setTo(emailTo);
512
		for (Attachment attachment : attachments) {
513
			helper.addAttachment(attachment.getFileName(), attachment.getInputStreamSource());
514
		}
515
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
516
		helper.setFrom(senderAddress);
517
		mailSender.send(message);
518
	}
26534 amit.gupta 519
 
26084 amit.gupta 520
}