Subversion Repositories SmartDukaan

Rev

Rev 24271 | Rev 24444 | 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;
5
import java.io.InputStream;
6
import java.net.URISyntaxException;
7
import java.net.URL;
21902 ashik.ali 8
import java.util.ArrayList;
21543 ashik.ali 9
import java.util.Collections;
10
import java.util.HashMap;
23509 amit.gupta 11
import java.util.HashSet;
21543 ashik.ali 12
import java.util.List;
13
import java.util.Map;
23296 ashik.ali 14
import java.util.Set;
15
import java.util.TreeSet;
21894 ashik.ali 16
 
23909 amit.gupta 17
import javax.mail.internet.InternetAddress;
18
import javax.mail.internet.MimeMessage;
19
 
21543 ashik.ali 20
import org.apache.commons.io.FileUtils;
21
import org.apache.commons.io.IOUtils;
22
import org.apache.http.client.utils.URIBuilder;
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;
21986 kshitij.so 27
import org.json.JSONObject;
23929 amit.gupta 28
import org.springframework.core.io.InputStreamSource;
22215 ashik.ali 29
import org.springframework.http.HttpHeaders;
30
import org.springframework.http.MediaType;
23909 amit.gupta 31
import org.springframework.mail.javamail.JavaMailSender;
32
import org.springframework.mail.javamail.MimeMessageHelper;
23074 ashik.ali 33
 
22215 ashik.ali 34
import com.spice.profitmandi.common.enumuration.SchemeType;
35
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
21894 ashik.ali 36
import com.spice.profitmandi.common.model.GstRate;
22351 ashik.ali 37
import com.spice.profitmandi.common.model.ProfitMandiConstants;
22215 ashik.ali 38
import com.spice.profitmandi.common.web.client.RestClient;
21894 ashik.ali 39
import com.spice.profitmandi.thrift.clients.CatalogClient;
40
import com.spice.profitmandi.thrift.clients.InventoryClient;
41
import com.spice.profitmandi.thrift.clients.TransactionClient;
22351 ashik.ali 42
import com.spice.profitmandi.thrift.clients.UserClient;
23509 amit.gupta 43
import com.spice.profitmandi.thrift.clients.WarehouseClient;
21894 ashik.ali 44
import com.spice.profitmandi.thrift.clients.config.ConfigClient;
21543 ashik.ali 45
 
21894 ashik.ali 46
import in.shop2020.model.v1.catalog.CatalogService;
47
import in.shop2020.model.v1.inventory.InventoryService;
48
import in.shop2020.model.v1.inventory.StateInfo;
23509 amit.gupta 49
import in.shop2020.model.v1.inventory.Warehouse;
23884 amit.gupta 50
import in.shop2020.model.v1.order.OrderStatusGroups;
21894 ashik.ali 51
import in.shop2020.model.v1.order.RechargeOrderStatus;
52
import in.shop2020.model.v1.order.RechargePlan;
53
import in.shop2020.model.v1.order.RechargeType;
23509 amit.gupta 54
import in.shop2020.model.v1.order.SellerInfo;
55
import in.shop2020.model.v1.order.WarehouseAddress;
22351 ashik.ali 56
import in.shop2020.model.v1.user.Sex;
57
import in.shop2020.model.v1.user.User;
58
import in.shop2020.model.v1.user.UserContextException;
23509 amit.gupta 59
import in.shop2020.warehouse.InventoryItem;
60
import in.shop2020.warehouse.WarehouseService;
21543 ashik.ali 61
 
62
public class Utils {
21986 kshitij.so 63
 
23568 govind 64
	private static final Logger logger = LogManager.getLogger(Utils.class);
21986 kshitij.so 65
	public static final String EXPORT_ENTITIES_PATH = getExportPath();
66
	public static final String PRODUCT_PROPERTIES_SNIPPET = "ProductPropertiesSnippet.html";
67
	public static final String DOCUMENT_STORE = "/profitmandi/documents/";
23017 ashik.ali 68
	private static final Map<Integer, String> helpMap = new HashMap<>(6);
69
	private static final Map<Integer, String> dthIdAliasMap = new HashMap<>(7);
70
	private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<>(20);
21986 kshitij.so 71
	private static Map<Long, String> mobileProvidersMap;
72
	private static Map<Long, String> dthProvidersMap;
24440 amit.gupta 73
	// private static final String SMS_GATEWAY =
74
	// "http://103.15.179.45:8085/SMSGateway/sendingSMS";
22757 amit.gupta 75
	private static final String SMS_GATEWAY = "http://103.15.179.45:8085/MessagingGateway/SendTransSMS";
21986 kshitij.so 76
	private static Map<Long, String> allProviders;
23017 ashik.ali 77
	public static Map<RechargeOrderStatus, String> rechargeStatusMap = new HashMap<>();
23884 amit.gupta 78
	public static OrderStatusGroups ORDER_STATUS_GROUPS = new OrderStatusGroups();
24440 amit.gupta 79
 
21986 kshitij.so 80
	static {
81
		helpMap.put(Integer.valueOf(1), "Your VC number starts with 0 and is 11 digits long.");
82
		helpMap.put(Integer.valueOf(2), "Smart card number starts with 2 and is 12 digits long.");
83
		helpMap.put(Integer.valueOf(3), "Smart card number starts with 4 and is 11 digits long.");
84
		helpMap.put(Integer.valueOf(4), "Subscriber ID starts with 1 and is 10 digits long.");
85
		helpMap.put(Integer.valueOf(5), "For customer ID, SMS ID to 9212012299 from your registered mobile no.");
86
		helpMap.put(Integer.valueOf(26), "Customer ID starts with 3 and is 10 digits long.");
21543 ashik.ali 87
 
21986 kshitij.so 88
		dthIdAliasMap.put(Integer.valueOf(1), "VC Number :");
89
		dthIdAliasMap.put(Integer.valueOf(2), "Smart Card Number :");
90
		dthIdAliasMap.put(Integer.valueOf(3), "Smart Card Number :");
91
		dthIdAliasMap.put(Integer.valueOf(4), "Subscriber Id :");
92
		dthIdAliasMap.put(Integer.valueOf(5), "Customer Id :");
93
		dthIdAliasMap.put(Integer.valueOf(0), "Account Number :");
94
		dthIdAliasMap.put(Integer.valueOf(26), "Customer Id :");
21543 ashik.ali 95
 
21986 kshitij.so 96
		rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_FAILED, "Payment Unsuccessful");
97
		rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_SUCCESSFUL, "Processing Recharge");
98
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_FAILED, "Recharge Failed");
99
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED, "Recharge Failed Refunded");
100
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_SUCCESSFUL, "Recharge Successful");
101
		rechargeStatusMap.put(RechargeOrderStatus.REFUNDED, "Amount Refunded");
102
		rechargeStatusMap.put(RechargeOrderStatus.PARTIALLY_REFUNDED, "Amount Refunded");
103
		rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_PENDING, "Payment Failed");
104
		rechargeStatusMap.put(RechargeOrderStatus.INIT, "Payment Initiated");
105
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_UNKNOWN, "Recharge In Process");
106
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_IN_PROCESS, "Recharge In Process");
107
 
108
		TransactionClient tcl;
24440 amit.gupta 109
		try {
21986 kshitij.so 110
			tcl = new TransactionClient();
111
			mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
112
			dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
113
			logger.info("mobileProvidersMap" + mobileProvidersMap);
114
			logger.info("dthProvidersMap" + dthProvidersMap);
22390 amit.gupta 115
			allProviders = new HashMap<>(mobileProvidersMap);
21986 kshitij.so 116
			logger.info("allProviders" + allProviders);
117
			allProviders.putAll(dthProvidersMap);
118
			logger.info("allProviders" + allProviders);
119
 
120
			for (Long operatorId : mobileProvidersMap.keySet()) {
121
				List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId.longValue());
122
				if (!plans.isEmpty())
123
					operatorPlanMap.put(operatorId, plans);
124
			}
125
		} catch (Exception e) {
126
			logger.error("Could not get providers", e);
127
		}
128
	}
129
 
23509 amit.gupta 130
	public static SellerInfo getSellerInfoBySellerId(int sellerId) throws Exception {
131
		TransactionClient tcl = new TransactionClient();
24440 amit.gupta 132
		return tcl.getClient().getSellerInfo((long) sellerId);
23509 amit.gupta 133
	}
24440 amit.gupta 134
 
21543 ashik.ali 135
	@SuppressWarnings("serial")
24440 amit.gupta 136
	public static final Map<String, String> MIME_TYPE = Collections.unmodifiableMap(new HashMap<String, String>() {
137
		{
138
			put("image/png", "png");
139
			put("image/jpeg", "jpeg");
140
			put("image/pjpeg", "jpeg");
141
			put("application/pdf", "pdf");
142
		}
143
	});
21543 ashik.ali 144
 
24440 amit.gupta 145
	private static String getExportPath() {
146
		String exportPath = null;
21543 ashik.ali 147
 
148
		ConfigClient client = ConfigClient.getClient();
24440 amit.gupta 149
		try {
21543 ashik.ali 150
			exportPath = client.get("export_entities_path");
24440 amit.gupta 151
		} catch (Exception ce) {
21543 ashik.ali 152
			logger.error("Unable to read export path from the config client: ", ce);
153
			logger.warn("Setting the default export path");
154
			exportPath = "/var/lib/tomcat7/webapps/export/html/entities/";
155
		}
156
		return exportPath;
157
	}
21986 kshitij.so 158
 
21646 kshitij.so 159
	public static String getRechargeDisplayStatus(RechargeOrderStatus status) {
21986 kshitij.so 160
		if (status == null) {
161
			status = RechargeOrderStatus.INIT;
162
		}
24440 amit.gupta 163
		String displayStatus = (String) rechargeStatusMap.get(status);
21986 kshitij.so 164
		if (displayStatus == null) {
165
			return "";
166
		}
167
		return displayStatus;
168
	}
21543 ashik.ali 169
 
24440 amit.gupta 170
	public static boolean copyDocument(String documentPath) {
21543 ashik.ali 171
		File source = new File(documentPath);
24440 amit.gupta 172
		File dest = new File(DOCUMENT_STORE + source.getName());
21543 ashik.ali 173
		try {
174
			FileUtils.copyFile(source, dest);
175
		} catch (IOException e) {
176
			e.printStackTrace();
177
			return false;
178
		}
179
		return true;
180
	}
181
 
182
	public static Map<Long, String> getMobileProvidersMap() {
183
		return mobileProvidersMap;
184
	}
185
 
186
	public static Map<Long, String> getDthProvidersMap() {
187
		return dthProvidersMap;
188
	}
21986 kshitij.so 189
 
21543 ashik.ali 190
	public static Map<Long, String> getAllProviders() {
191
		return allProviders;
192
	}
21986 kshitij.so 193
 
21543 ashik.ali 194
	public static String getProvider(long operatorId) {
21986 kshitij.so 195
		return allProviders.get(operatorId);
196
	}
21543 ashik.ali 197
 
24440 amit.gupta 198
	public static void sendSms(String text, String mobileNumber) throws URISyntaxException, IOException {
21543 ashik.ali 199
		URIBuilder generalSearchUrl = new URIBuilder(SMS_GATEWAY);
24440 amit.gupta 200
		generalSearchUrl.addParameter("Mobile", "91" + mobileNumber);
201
		generalSearchUrl.addParameter("Username", "srlsaholic");
202
		generalSearchUrl.addParameter("Password", "sr18mar");
203
		generalSearchUrl.addParameter("SenderID", "SMTDKN");
22757 amit.gupta 204
		generalSearchUrl.setParameter("Message", text);
205
		generalSearchUrl.setParameter("MessageType", "txt");
24256 amit.gupta 206
		URL url = generalSearchUrl.build().toURL();
22889 amit.gupta 207
		System.out.println(url);
21543 ashik.ali 208
		InputStream is = url.openStream();
209
		String response;
24440 amit.gupta 210
		try {
21543 ashik.ali 211
			response = IOUtils.toString(is, "UTF-8");
24440 amit.gupta 212
			System.out.println("response sms gateway " + response);
213
		} finally {
21543 ashik.ali 214
			is.close();
215
		}
216
	}
24440 amit.gupta 217
 
218
	public static void sendMailWithAttachments(JavaMailSender mailSender, String emailTo, String[] cc, String subject,
219
			String body, List<File> attachments) throws Exception {
23909 amit.gupta 220
		MimeMessage message = mailSender.createMimeMessage();
24440 amit.gupta 221
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
222
		helper.setSubject(subject);
223
		helper.setText(body);
224
		if (cc != null) {
225
			helper.setCc(cc);
226
		}
227
		helper.setTo(emailTo);
228
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
229
		helper.setFrom(senderAddress);
230
		if (attachments != null) {
231
			for (File file : attachments) {
232
				helper.addAttachment(file.getName(), file);
233
			}
234
		}
235
		mailSender.send(message);
22757 amit.gupta 236
	}
23929 amit.gupta 237
 
24440 amit.gupta 238
	public static void sendMailWithAttachment(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
239
			String body, String fileName, InputStreamSource inputStreamSource) throws Exception {
23929 amit.gupta 240
		MimeMessage message = mailSender.createMimeMessage();
24440 amit.gupta 241
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
23929 amit.gupta 242
		helper.setSubject(subject);
243
		helper.setText(body);
24440 amit.gupta 244
		if (cc != null) {
23929 amit.gupta 245
			helper.setCc(cc);
246
		}
247
		helper.setTo(emailTo);
248
		helper.addAttachment(fileName, inputStreamSource);
249
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
250
		helper.setFrom(senderAddress);
251
		mailSender.send(message);
252
	}
24440 amit.gupta 253
 
254
	public static String[] getOrderStatus(RechargeOrderStatus status) {
255
		if (status == null) {
21543 ashik.ali 256
			status = RechargeOrderStatus.INIT;
257
		}
24440 amit.gupta 258
		if (status.equals(RechargeOrderStatus.PAYMENT_FAILED) || status.equals(RechargeOrderStatus.PAYMENT_PENDING)) {
259
			return new String[] { "false", "PAYMENT FAILED", "Payment failed at the payment gateway." };
260
		} else if (status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)
261
				|| status.equals(RechargeOrderStatus.RECHARGE_UNKNOWN)) {
262
			if (status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)) {
263
				return new String[] { "false", "PAYMENT SUCCESSFUL",
264
						"Your Payment was successful but due to some internal error with the operator's system we are not sure if the recharge was successful."
265
								+ " We have put your recharge under process."
266
								+ " As soon as we get a confirmation on this transaction, we will notify you." };
267
			} else {
268
				return new String[] { "false", "RECHARGE IN PROCESS",
269
						"Your Payment is successful.We have put your recharge under process."
270
								+ " Please wait while we check with the operator." };
21543 ashik.ali 271
			}
24440 amit.gupta 272
		} else if (status.equals(RechargeOrderStatus.RECHARGE_FAILED)
273
				|| status.equals(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED)) {
274
			return new String[] { "false", "RECHARGE FAILED",
275
					"Your Payment was successful but unfortunately the recharge failed.Don't worry your payment is safe with us."
276
							+ " The entire Amount has been refunded to your wallet." };
277
		} else if (status.equals(RechargeOrderStatus.RECHARGE_SUCCESSFUL)) {
278
			return new String[] { "false", "SUCCESS", "Congratulations! Your device is successfully recharged." };
279
		} else if (status.equals(RechargeOrderStatus.PARTIALLY_REFUNDED)
280
				|| status.equals(RechargeOrderStatus.REFUNDED)) {
281
			return new String[] { "false", "PAYMENT REFUNDED",
282
					"The payment associated with this recharge order has been refunded." };
21543 ashik.ali 283
		} else {
24440 amit.gupta 284
			return new String[] { "true", "ERROR", "INVALID INPUT" };
21543 ashik.ali 285
		}
286
	}
21986 kshitij.so 287
 
24440 amit.gupta 288
	public static String getIconUrl(int entityId, String host, int port, String webapp) {
23526 ashik.ali 289
		RestClient rc = new RestClient();
21986 kshitij.so 290
		Map<String, String> params = new HashMap<String, String>();
291
		String response = null;
24440 amit.gupta 292
		String uri = webapp + "/entity/" + entityId;
22215 ashik.ali 293
		Map<String, String> headers = new HashMap<>(1);
294
		headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
21986 kshitij.so 295
		try {
24440 amit.gupta 296
			response = rc.get(SchemeType.HTTP, host, port, uri, params, headers);
23376 amit.gupta 297
		} catch (Throwable e) {
21986 kshitij.so 298
			// TODO Auto-generated catch block
299
			e.printStackTrace();
300
			return "";
301
		}
302
		JSONObject obj = new JSONObject(response);
303
		String iconUrl = null;
24440 amit.gupta 304
		try {
305
			iconUrl = obj.getJSONObject("entity").getString("iconImageUrl");
306
		} catch (Exception e) {
21986 kshitij.so 307
			return "";
308
		}
24440 amit.gupta 309
		return iconUrl == null ? "" : iconUrl;
21986 kshitij.so 310
	}
24440 amit.gupta 311
 
312
	public static Map<Integer, GstRate> getStateTaxRate(List<Integer> itemIds, int stateId)
313
			throws ProfitMandiBusinessException {
23152 ashik.ali 314
		List<Long> longItemIds = new ArrayList<>();
24440 amit.gupta 315
		for (int itemId : itemIds) {
23152 ashik.ali 316
			longItemIds.add(Long.valueOf(itemId));
317
		}
24440 amit.gupta 318
		try {
23147 ashik.ali 319
			Map<Integer, GstRate> itemIdGstRateMap = new HashMap<>();
24440 amit.gupta 320
			for (int itemId : itemIds) {
23147 ashik.ali 321
				GstRate gstRate = new GstRate();
24440 amit.gupta 322
				gstRate.setIgstRate(12f);
323
				gstRate.setCgstRate(0);
324
				gstRate.setSgstRate(0);
325
				itemIdGstRateMap.put(itemId, gstRate);
23147 ashik.ali 326
			}
327
			return itemIdGstRateMap;
24440 amit.gupta 328
		} catch (Exception e) {
23147 ashik.ali 329
			e.printStackTrace();
24440 amit.gupta 330
			throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID + ", " + ProfitMandiConstants.STATE_ID,
331
					itemIds + ", " + stateId, "THRFT_1000");
23147 ashik.ali 332
		}
333
	}
24440 amit.gupta 334
 
335
	public static Map<Integer, Float> getIgstTaxRate(List<Integer> itemIds) throws ProfitMandiBusinessException {
23152 ashik.ali 336
		List<Long> longItemIds = new ArrayList<>();
24440 amit.gupta 337
		for (int itemId : itemIds) {
23152 ashik.ali 338
			longItemIds.add(Long.valueOf(itemId));
339
		}
24440 amit.gupta 340
		Map<Integer, Float> itemIdIgstRateMap = new HashMap<>();
341
		for (int itemId : itemIds) {
342
			// To be reverted
343
			itemIdIgstRateMap.put(itemId, 12f);
23147 ashik.ali 344
		}
24440 amit.gupta 345
		return itemIdIgstRateMap;
23147 ashik.ali 346
	}
24440 amit.gupta 347
 
348
	public static Map<Integer, Float> getStateRate(List<Integer> itemIds) throws ProfitMandiBusinessException {
349
		List<Long> longItemIds = new ArrayList<>();
350
		for (int itemId : itemIds) {
351
			longItemIds.add(Long.valueOf(itemId));
352
		}
353
		Map<Integer, Float> itemIdIgstRateMap = new HashMap<>();
354
		for (int itemId : itemIds) {
355
			// To be reverted
356
			itemIdIgstRateMap.put(itemId, 12f);
357
		}
358
		return itemIdIgstRateMap;
359
	}
360
 
361
	private static CatalogService.Client getCatalogClient() throws Exception {
362
		try {
21915 ashik.ali 363
			CatalogClient client = new CatalogClient();
364
			CatalogService.Client catalogClient = client.getClient();
365
			return catalogClient;
24440 amit.gupta 366
		} catch (Exception e) {
21915 ashik.ali 367
			throw e;
368
		}
369
	}
23509 amit.gupta 370
 
24440 amit.gupta 371
	private static WarehouseService.Client getWarehouseClient() throws Exception {
372
		try {
23509 amit.gupta 373
			WarehouseClient client = new WarehouseClient();
374
			WarehouseService.Client warehouseClient = client.getClient();
375
			return warehouseClient;
24440 amit.gupta 376
		} catch (Exception e) {
23509 amit.gupta 377
			throw e;
378
		}
379
	}
24440 amit.gupta 380
 
381
	public static Map<String, Warehouse> getWarehouseByImeis(List<String> imeis) throws Exception {
23509 amit.gupta 382
		List<InventoryItem> inventoryItems = getWarehouseClient().getInventoryItemsBySerailNumbers(imeis);
383
		Map<String, InventoryItem> imeiInventoryItemMap = new HashMap<>();
24440 amit.gupta 384
		for (InventoryItem inventoryItem : inventoryItems) {
23509 amit.gupta 385
			imeiInventoryItemMap.put(inventoryItem.getSerialNumber(), inventoryItem);
386
		}
24440 amit.gupta 387
		Map<Integer, Warehouse> warehouseMap = new HashMap<>();
23509 amit.gupta 388
		Map<String, Warehouse> serialNumberWarehouseMap = new HashMap<>();
389
		InventoryClient client = new InventoryClient();
390
		InventoryService.Client inventoryClient = client.getClient();
391
		logger.info("[imeiInventoryItemMap] {}", imeiInventoryItemMap);
24440 amit.gupta 392
		for (InventoryItem inventory : new HashSet<>(imeiInventoryItemMap.values())) {
23509 amit.gupta 393
			Warehouse phWarehouse = null;
24440 amit.gupta 394
			if (warehouseMap.containsKey(inventory.getPhysicalWarehouseId())) {
395
				phWarehouse = warehouseMap.get((int) inventory.getPhysicalWarehouseId());
23509 amit.gupta 396
			} else {
397
				phWarehouse = inventoryClient.getWarehouse(inventory.getPhysicalWarehouseId());
24440 amit.gupta 398
				warehouseMap.put((int) inventory.getPhysicalWarehouseId(), phWarehouse);
23509 amit.gupta 399
			}
400
			serialNumberWarehouseMap.put(inventory.getSerialNumber(), phWarehouse);
24440 amit.gupta 401
 
23509 amit.gupta 402
		}
403
		return serialNumberWarehouseMap;
404
	}
24440 amit.gupta 405
 
23615 amit.gupta 406
	public static Map<Integer, Warehouse> getWarehousesByIds(Set<Integer> warehouseIds) throws Exception {
407
		InventoryClient client = new InventoryClient();
408
		InventoryService.Client inventoryClient = client.getClient();
409
		Map<Integer, Warehouse> warehouseMap = new HashMap<>();
410
		for (Integer warehouseId : warehouseIds) {
411
			warehouseMap.put(warehouseId, inventoryClient.getWarehouse(warehouseId));
412
		}
413
		return warehouseMap;
414
	}
24440 amit.gupta 415
 
416
	public static String getStateCode(String stateName) throws Exception {
21902 ashik.ali 417
		return getStateInfo(stateName).getStateCode();
418
	}
24440 amit.gupta 419
 
23539 amit.gupta 420
	public static long getStateId(String stateName) throws ProfitMandiBusinessException {
421
		try {
422
			return getStateInfo(stateName).getId();
24440 amit.gupta 423
		} catch (Exception e) {
23539 amit.gupta 424
			e.printStackTrace();
425
			throw new ProfitMandiBusinessException("State Name", stateName, "Could not fetch state");
426
		}
21902 ashik.ali 427
	}
24440 amit.gupta 428
 
429
	public static StateInfo getStateByStateId(long stateId) throws Exception {
23509 amit.gupta 430
		InventoryClient client = new InventoryClient();
431
		InventoryService.Client inventoryClient = client.getClient();
432
		Map<Long, StateInfo> map = inventoryClient.getStateMaster();
433
		return map.get(stateId);
434
	}
24440 amit.gupta 435
 
436
	public static StateInfo getStateInfo(String stateName) throws Exception {
437
		try {
21894 ashik.ali 438
			InventoryClient client = new InventoryClient();
439
			InventoryService.Client inventoryClient = client.getClient();
440
			Map<Long, StateInfo> map = inventoryClient.getStateMaster();
21902 ashik.ali 441
			List<StateInfo> stateInfos = new ArrayList<>(map.values());
22664 amit.gupta 442
			logger.info("State Name: {}", stateName);
24440 amit.gupta 443
			for (StateInfo stateInfo : stateInfos) {
22664 amit.gupta 444
				logger.info("State Name from service: {}", stateInfo.getStateName());
24440 amit.gupta 445
				if (stateName.toUpperCase().equals(stateInfo.getStateName().toUpperCase())) {
21902 ashik.ali 446
					return stateInfo;
21894 ashik.ali 447
				}
448
			}
21902 ashik.ali 449
			throw new Exception("Not found");
24440 amit.gupta 450
		} catch (Exception e) {
21894 ashik.ali 451
			e.printStackTrace();
452
			throw e;
453
		}
454
	}
24440 amit.gupta 455
 
456
	public static List<String> getAllStateNames() {
23296 ashik.ali 457
		List<String> sortedStateNames = new ArrayList<>();
24440 amit.gupta 458
		try {
23296 ashik.ali 459
			InventoryClient client = new InventoryClient();
460
			InventoryService.Client inventoryClient = client.getClient();
461
			Map<Long, StateInfo> map = inventoryClient.getStateMaster();
462
			List<StateInfo> stateInfos = new ArrayList<>(map.values());
463
			Set<String> stateNames = new TreeSet<>();
464
 
24440 amit.gupta 465
			for (StateInfo stateInfo : stateInfos) {
23296 ashik.ali 466
				stateNames.add(stateInfo.getStateName());
467
			}
468
			sortedStateNames = new ArrayList<>(stateNames);
469
			return sortedStateNames;
24440 amit.gupta 470
		} catch (Exception e) {
23296 ashik.ali 471
			e.printStackTrace();
472
			return sortedStateNames;
473
		}
474
	}
23509 amit.gupta 475
 
24440 amit.gupta 476
	public static Map<Long, StateInfo> getAllStatesMap() throws Exception {
23509 amit.gupta 477
		InventoryClient client = new InventoryClient();
478
		InventoryService.Client inventoryClient = client.getClient();
24440 amit.gupta 479
		return inventoryClient.getStateMaster();
23509 amit.gupta 480
 
481
	}
24440 amit.gupta 482
 
483
	public static User createSaholicUser(String emailId) throws ProfitMandiBusinessException {
22351 ashik.ali 484
		in.shop2020.model.v1.user.User user = new in.shop2020.model.v1.user.User();
485
		user.setEmail(emailId);
486
		user.setPassword("");
487
		user.setCommunicationEmail(emailId);
488
		user.setSex(Sex.WONT_SAY);
489
 
490
		try {
491
			UserClient userContextServiceClient = new UserClient();
492
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
493
			user = userClient.createUser(user);
494
			return user;
24440 amit.gupta 495
		} catch (UserContextException ux) {
22351 ashik.ali 496
			logger.error("Unable to register user: " + ux.getMessage());
497
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
498
		} catch (TTransportException e) {
499
			logger.error("Unable to register user." + e);
500
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
24440 amit.gupta 501
		} catch (TException e) {
22351 ashik.ali 502
			logger.error("Unable to register user." + e);
503
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
24440 amit.gupta 504
		}
22351 ashik.ali 505
	}
24440 amit.gupta 506
 
507
	public static void main(String[] args) throws Exception {
22757 amit.gupta 508
		Utils.sendSms("Hello", "9990381569");
509
	}
23509 amit.gupta 510
 
24440 amit.gupta 511
	public static WarehouseAddress getWarehouseByWarehouseId(int warehouseAddressId) throws Exception {
23509 amit.gupta 512
		TransactionClient tcl = new TransactionClient();
24440 amit.gupta 513
		return tcl.getClient().getWarehouseAddress((long) warehouseAddressId);
23509 amit.gupta 514
	}
24440 amit.gupta 515
 
21543 ashik.ali 516
}