Subversion Repositories SmartDukaan

Rev

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