Subversion Repositories SmartDukaan

Rev

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