Subversion Repositories SmartDukaan

Rev

Rev 24271 | Rev 24444 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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