Subversion Repositories SmartDukaan

Rev

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