Subversion Repositories SmartDukaan

Rev

Rev 23929 | Rev 24271 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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