Subversion Repositories SmartDukaan

Rev

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