Subversion Repositories SmartDukaan

Rev

Rev 23884 | Rev 23910 | 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);
233
    	helper.setCc(cc);
234
    	helper.setTo(emailTo);
235
    	InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
236
    	helper.setFrom(senderAddress);
237
    	for (File file : attachments) {
238
    		helper.addAttachment(file.getName(), file);
239
    	}
240
    	mailSender.send(message);
22757 amit.gupta 241
	}
242
 
21543 ashik.ali 243
	public static String[] getOrderStatus(RechargeOrderStatus status){
244
		if (status == null){
245
			status = RechargeOrderStatus.INIT;
246
		}
247
		if(status.equals(RechargeOrderStatus.PAYMENT_FAILED)||status.equals(RechargeOrderStatus.PAYMENT_PENDING)){
248
			return new String[]{"false", "PAYMENT FAILED", "Payment failed at the payment gateway."};
249
		}
250
		else if(status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL) || status.equals(RechargeOrderStatus.RECHARGE_UNKNOWN)) {
251
			if(status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)){
252
				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."
253
						+ " We have put your recharge under process."
254
						+ " As soon as we get a confirmation on this transaction, we will notify you."};
255
			}
256
			else{
257
				return new String[]{"false", "RECHARGE IN PROCESS", "Your Payment is successful.We have put your recharge under process." +
258
				" Please wait while we check with the operator."};
259
			}
260
		}
261
		else if (status.equals(RechargeOrderStatus.RECHARGE_FAILED) || status.equals(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED)){
22391 amit.gupta 262
			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 263
					+ " The entire Amount has been refunded to your wallet."};
264
		} else if(status.equals(RechargeOrderStatus.RECHARGE_SUCCESSFUL)){
265
			return new String[] {"false", "SUCCESS", "Congratulations! Your device is successfully recharged."};
266
		} else if (status.equals(RechargeOrderStatus.PARTIALLY_REFUNDED) || status.equals(RechargeOrderStatus.REFUNDED)) {
267
			return new String[]{"false", "PAYMENT REFUNDED","The payment associated with this recharge order has been refunded."};
268
		} else {
269
			return new String[]{"true", "ERROR", "INVALID INPUT"};
270
		}
271
	}
21986 kshitij.so 272
 
273
 
274
	public static String getIconUrl(int entityId,String host, int port, String webapp){
23526 ashik.ali 275
		RestClient rc = new RestClient();
21986 kshitij.so 276
		Map<String, String> params = new HashMap<String, String>();
277
		String response = null;
278
		String uri = webapp+"/entity/"+entityId;
22215 ashik.ali 279
		Map<String, String> headers = new HashMap<>(1);
280
		headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
21986 kshitij.so 281
		try {
23526 ashik.ali 282
			response = rc.get(SchemeType.HTTP, host , port, uri, params, headers);
23376 amit.gupta 283
		} catch (Throwable e) {
21986 kshitij.so 284
			// TODO Auto-generated catch block
285
			e.printStackTrace();
286
			return "";
287
		}
288
		JSONObject obj = new JSONObject(response);
289
		String iconUrl = null;
290
		try{
291
		iconUrl = obj.getJSONObject("entity").getString("iconImageUrl");
292
		}
293
		catch(Exception e){
294
			return "";
295
		}
296
		return iconUrl==null?"":iconUrl;
297
	}
21894 ashik.ali 298
 
23147 ashik.ali 299
	public static Map<Integer, GstRate> getStateTaxRate(List<Integer> itemIds, int stateId) throws ProfitMandiBusinessException{
23152 ashik.ali 300
		List<Long> longItemIds = new ArrayList<>();
301
		for(int itemId : itemIds){
302
			longItemIds.add(Long.valueOf(itemId));
303
		}
23147 ashik.ali 304
		try{
305
			CatalogService.Client catalogClient = getCatalogClient();
23152 ashik.ali 306
			Map<Long, in.shop2020.model.v1.catalog.GstRate> totalTaxRateMap = catalogClient.getStateTaxRate(longItemIds, stateId);
23147 ashik.ali 307
			Map<Integer, GstRate> itemIdGstRateMap = new HashMap<>();
23152 ashik.ali 308
			for(Map.Entry<Long, in.shop2020.model.v1.catalog.GstRate> totalTaxRateEntry : totalTaxRateMap.entrySet()){
23147 ashik.ali 309
				GstRate gstRate = new GstRate();
310
				gstRate.setIgstRate(Double.valueOf(totalTaxRateEntry.getValue().getIgstRate()).floatValue());
311
				gstRate.setCgstRate(Double.valueOf(totalTaxRateEntry.getValue().getCgstRate()).floatValue());
312
				gstRate.setSgstRate(Double.valueOf(totalTaxRateEntry.getValue().getSgstRate()).floatValue());
23152 ashik.ali 313
				itemIdGstRateMap.put(totalTaxRateEntry.getKey().intValue(), gstRate);
23147 ashik.ali 314
			}
315
			return itemIdGstRateMap;
316
		}catch(Exception e){
317
			e.printStackTrace();
23780 ashik.ali 318
			throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID + ", " + ProfitMandiConstants.STATE_ID, itemIds +", " + stateId, "THRFT_1000");
23147 ashik.ali 319
		}
320
	}
321
 
322
	public static Map<Integer, Float> getIgstTaxRate(List<Integer> itemIds) throws ProfitMandiBusinessException{
23152 ashik.ali 323
		List<Long> longItemIds = new ArrayList<>();
324
		for(int itemId : itemIds){
325
			longItemIds.add(Long.valueOf(itemId));
326
		}
23147 ashik.ali 327
		try{
328
			CatalogService.Client catalogClient = getCatalogClient();
23152 ashik.ali 329
			Map<Long, Double> totalTaxRateMap = catalogClient.getIgstTaxRate(longItemIds);
23147 ashik.ali 330
			Map<Integer, Float> itemIdIgstRateMap = new HashMap<>();
23152 ashik.ali 331
			for(Map.Entry<Long, Double> totalTaxRateEntry : totalTaxRateMap.entrySet()){
332
				itemIdIgstRateMap.put(totalTaxRateEntry.getKey().intValue(), Double.valueOf(totalTaxRateEntry.getValue()).floatValue());
23147 ashik.ali 333
			}
334
			return itemIdIgstRateMap;
335
		}catch(Exception e){
336
			e.printStackTrace();
23780 ashik.ali 337
			throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID, itemIds, "THRFT_1001");
23147 ashik.ali 338
		}
339
	}
340
 
21915 ashik.ali 341
	private static CatalogService.Client getCatalogClient() throws Exception{
342
		try{
343
			CatalogClient client = new CatalogClient();
344
			CatalogService.Client catalogClient = client.getClient();
345
			return catalogClient;
346
		}catch (Exception e) {
347
			throw e;
348
		}
349
	}
23509 amit.gupta 350
 
351
	private static WarehouseService.Client getWarehouseClient() throws Exception{
352
		try{
353
			WarehouseClient client = new WarehouseClient();
354
			WarehouseService.Client warehouseClient = client.getClient();
355
			return warehouseClient;
356
		}catch (Exception e) {
357
			throw e;
358
		}
359
	}
21915 ashik.ali 360
 
361
 
23509 amit.gupta 362
	public static Map<String, Warehouse> getWarehouseByImeis(List<String> imeis) throws Exception{
363
		List<InventoryItem> inventoryItems = getWarehouseClient().getInventoryItemsBySerailNumbers(imeis);
364
		Map<String, InventoryItem> imeiInventoryItemMap = new HashMap<>();
365
		for(InventoryItem inventoryItem : inventoryItems) {
366
			imeiInventoryItemMap.put(inventoryItem.getSerialNumber(), inventoryItem);
367
		}
368
		Map<Integer, Warehouse> warehouseMap = new HashMap<>(); 
369
		Map<String, Warehouse> serialNumberWarehouseMap = new HashMap<>();
370
		InventoryClient client = new InventoryClient();
371
		InventoryService.Client inventoryClient = client.getClient();
372
		logger.info("[imeiInventoryItemMap] {}", imeiInventoryItemMap);
373
		for(InventoryItem inventory : new HashSet<>(imeiInventoryItemMap.values())) {
374
			Warehouse phWarehouse = null;
375
			if(warehouseMap.containsKey(inventory.getPhysicalWarehouseId())) {
376
				phWarehouse = warehouseMap.get((int)inventory.getPhysicalWarehouseId());
377
			} else {
378
				phWarehouse = inventoryClient.getWarehouse(inventory.getPhysicalWarehouseId());
379
				warehouseMap.put((int)inventory.getPhysicalWarehouseId(), phWarehouse);
380
			}
381
			serialNumberWarehouseMap.put(inventory.getSerialNumber(), phWarehouse);
382
 
383
		}
384
		return serialNumberWarehouseMap;
385
	}
386
 
23615 amit.gupta 387
	public static Map<Integer, Warehouse> getWarehousesByIds(Set<Integer> warehouseIds) throws Exception {
388
		InventoryClient client = new InventoryClient();
389
		InventoryService.Client inventoryClient = client.getClient();
390
		Map<Integer, Warehouse> warehouseMap = new HashMap<>();
391
		for (Integer warehouseId : warehouseIds) {
392
			warehouseMap.put(warehouseId, inventoryClient.getWarehouse(warehouseId));
393
		}
394
		return warehouseMap;
395
	}
23509 amit.gupta 396
 
23615 amit.gupta 397
 
21902 ashik.ali 398
	public static String getStateCode(String stateName) throws Exception{
399
		return getStateInfo(stateName).getStateCode();
400
	}
401
 
23539 amit.gupta 402
	public static long getStateId(String stateName) throws ProfitMandiBusinessException {
403
		try {
404
			return getStateInfo(stateName).getId();
405
		} catch(Exception e) {
406
			e.printStackTrace();
407
			throw new ProfitMandiBusinessException("State Name", stateName, "Could not fetch state");
408
		}
21902 ashik.ali 409
	}
410
 
23509 amit.gupta 411
	public static StateInfo getStateByStateId(long stateId) throws Exception{
412
		InventoryClient client = new InventoryClient();
413
		InventoryService.Client inventoryClient = client.getClient();
414
		Map<Long, StateInfo> map = inventoryClient.getStateMaster();
415
		return map.get(stateId);
416
	}
417
 
21902 ashik.ali 418
	public static StateInfo getStateInfo(String stateName) throws Exception{
21894 ashik.ali 419
		try{
420
			InventoryClient client = new InventoryClient();
421
			InventoryService.Client inventoryClient = client.getClient();
422
			Map<Long, StateInfo> map = inventoryClient.getStateMaster();
21902 ashik.ali 423
			List<StateInfo> stateInfos = new ArrayList<>(map.values());
22664 amit.gupta 424
			logger.info("State Name: {}", stateName);
21894 ashik.ali 425
			for(StateInfo stateInfo : stateInfos){
22664 amit.gupta 426
				logger.info("State Name from service: {}", stateInfo.getStateName());
22938 amit.gupta 427
				if(stateName.toUpperCase().equals(stateInfo.getStateName().toUpperCase())){
21902 ashik.ali 428
					return stateInfo;
21894 ashik.ali 429
				}
430
			}
21902 ashik.ali 431
			throw new Exception("Not found");
21894 ashik.ali 432
		}catch (Exception e) {
433
			e.printStackTrace();
434
			throw e;
435
		}
436
	}
22351 ashik.ali 437
 
23296 ashik.ali 438
	public static List<String> getAllStateNames(){
439
		List<String> sortedStateNames = new ArrayList<>();
440
		try{
441
			InventoryClient client = new InventoryClient();
442
			InventoryService.Client inventoryClient = client.getClient();
443
			Map<Long, StateInfo> map = inventoryClient.getStateMaster();
444
			List<StateInfo> stateInfos = new ArrayList<>(map.values());
445
			Set<String> stateNames = new TreeSet<>();
446
 
447
			for(StateInfo stateInfo : stateInfos){
448
				stateNames.add(stateInfo.getStateName());
449
			}
450
			sortedStateNames = new ArrayList<>(stateNames);
451
			return sortedStateNames;
452
		}catch (Exception e) {
453
			e.printStackTrace();
454
			return sortedStateNames;
455
		}
456
	}
23509 amit.gupta 457
 
458
	public static Map<Long, StateInfo> getAllStatesMap() throws Exception{
459
		InventoryClient client = new InventoryClient();
460
		InventoryService.Client inventoryClient = client.getClient();
461
		return  inventoryClient.getStateMaster();
462
 
463
	}
23296 ashik.ali 464
 
22351 ashik.ali 465
	public static User createSaholicUser(String emailId) throws ProfitMandiBusinessException{
466
		in.shop2020.model.v1.user.User user = new in.shop2020.model.v1.user.User();
467
		user.setEmail(emailId);
468
		user.setPassword("");
469
		user.setCommunicationEmail(emailId);
470
		user.setSex(Sex.WONT_SAY);
471
 
472
		try {
473
			UserClient userContextServiceClient = new UserClient();
474
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
475
			user = userClient.createUser(user);
476
			return user;
477
		}catch (UserContextException ux){
478
			logger.error("Unable to register user: " + ux.getMessage());
479
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
480
		} catch (TTransportException e) {
481
			logger.error("Unable to register user." + e);
482
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
483
		}catch (TException e) {
484
			logger.error("Unable to register user." + e);
485
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
486
		} 
487
	}
22757 amit.gupta 488
 
489
	public static void main (String[] args) throws Exception{
490
		Utils.sendSms("Hello", "9990381569");
491
	}
23509 amit.gupta 492
 
493
	public static WarehouseAddress getWarehouseByWarehouseId(int warehouseAddressId) throws Exception{
494
		TransactionClient tcl = new TransactionClient();
495
		return tcl.getClient().getWarehouseAddress((long)warehouseAddressId);
496
	}
23074 ashik.ali 497
 
23884 amit.gupta 498
 
21543 ashik.ali 499
}