Subversion Repositories SmartDukaan

Rev

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