Subversion Repositories SmartDukaan

Rev

Rev 7410 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7410 Rev 8182
Line 65... Line 65...
65
})
65
})
66
public class SourceOrderCreationController extends ActionSupport implements ServletRequestAware {
66
public class SourceOrderCreationController extends ActionSupport implements ServletRequestAware {
67
 
67
 
68
    private static Logger logger = LoggerFactory.getLogger(SourceOrderCreationController.class);
68
    private static Logger logger = LoggerFactory.getLogger(SourceOrderCreationController.class);
69
    
69
    
-
 
70
    private static final int AMAZON_SOURCE_ID = 3;
-
 
71
    
70
    private static final int ITEM_ID_INDEX = 0;
72
    private static final int ITEM_ID_INDEX = 0;
71
    private static final int QUANTITY_INDEX = 1;
73
    private static final int QUANTITY_INDEX = 1;
72
    private static final int BILLING_NAME_INDEX = 2;
74
    private static final int BILLING_NAME_INDEX = 2;
73
    private static final int AMOUNT_PER_ORDER_INDEX = 3;
75
    private static final int AMOUNT_PER_ORDER_INDEX = 3;
74
    private static final int CUST_EMAIL_INDEX = 4;
76
    private static final int CUST_EMAIL_INDEX = 4;
Line 76... Line 78...
76
    private static final int CUST_ADDR1_INDEX = 6;
78
    private static final int CUST_ADDR1_INDEX = 6;
77
    private static final int CUST_ADDR2_INDEX = 7;
79
    private static final int CUST_ADDR2_INDEX = 7;
78
    private static final int CUST_CITY_INDEX = 8;
80
    private static final int CUST_CITY_INDEX = 8;
79
    private static final int CUST_STATE_INDEX = 9;
81
    private static final int CUST_STATE_INDEX = 9;
80
    private static final int CUST_PIN_INDEX = 10;
82
    private static final int CUST_PIN_INDEX = 10;
-
 
83
    private static final int AMAZON_ORDER_ID = 11;
81
    
84
    
82
    private static final String PAY_METHOD  = "payMethod";
85
    private static final String PAY_METHOD  = "payMethod";
83
    private static final int RTGS_GATEWAY_ID = 6;
86
    private static final int RTGS_GATEWAY_ID = 6;
84
    
87
    
85
    private HttpServletRequest request;
88
    private HttpServletRequest request;
Line 119... Line 122...
119
        
122
        
120
        //Parse the file and submit the data for update to the transaction service
123
        //Parse the file and submit the data for update to the transaction service
121
        Workbook wb = null;
124
        Workbook wb = null;
122
        try {
125
        try {
123
            wb = new HSSFWorkbook(new FileInputStream(fileToCreate));
126
            wb = new HSSFWorkbook(new FileInputStream(fileToCreate));
124
        } catch (FileNotFoundException e) {
127
        } catch (Exception e) {
125
            logger.error("Unable to open the File for Order Creation for SourceId " + sourceId, e);
128
            logger.error("Unable to open the File for Order Creation for SourceId " + sourceId, e);
126
            addActionError("Unable to open the File for Order creation");
129
            addActionError("Unable to open the File for Order creation");
127
        } catch (IOException e) {
-
 
128
        	logger.error("Unable to open the File for Order Creation for SourceId " + sourceId, e);
-
 
129
        	addActionError("Unable to open the File for Order creation");
-
 
130
        }
130
        }
131
        if(checkForErrors())
131
        if(checkForErrors())
132
            return "authsuccess";
132
            return "authsuccess";
133
        
133
        
134
        SourceDetail sourceDetail = null;
134
        SourceDetail sourceDetail = null;
135
        User user = null;
135
        User user = null;
136
        TransactionClient tsc = null;
136
        TransactionClient tsc = null;
137
        try {
137
        try {
138
            tsc = new TransactionClient();
138
            tsc = new TransactionClient();
139
			sourceDetail = tsc.getClient().getSourceDetail(sourceId);
139
			sourceDetail = tsc.getClient().getSourceDetail(sourceId);
140
        } catch (TTransportException e) {
-
 
141
            logger.error("Unable to establish connection to the transaction service", e);
-
 
142
            addActionError("Unable to establish connection to the transaction service");
-
 
143
        } catch (TException e) {
140
        } catch (Exception e) {
144
            logger.error("Unable to establish connection to the transaction service", e);
141
            logger.error("Unable to establish connection to the transaction service", e);
145
            addActionError("Unable to establish connection to the transaction service");
142
            addActionError("Unable to establish connection to the transaction service");
146
		}
143
		}
147
        
144
        
148
        if(checkForErrors())
145
        if(checkForErrors())
149
            return "authsuccess";
146
            return "authsuccess";
150
        
147
        
151
	    try {   
148
	    try {   
152
	        in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
149
	        in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
153
	        user = userClient.getUserByEmail(sourceDetail.getEmail());
150
	        user = userClient.getUserByEmail(sourceDetail.getEmail());
154
	    } catch (TTransportException e) {
151
	    } catch (Exception e) {
155
	        logger.error("Unable to establish connection to the User service", e);
152
	        logger.error("Unable to establish connection to the User service", e);
156
	        addActionError("Unable to establish connection to the User service");
153
	        addActionError("Unable to establish connection to the User service");
157
	    } catch (TException e) {
-
 
158
	        logger.error("Unable to establish connection to the User service", e);
-
 
159
	        addActionError("Unable to establish connection to the User service");
-
 
160
		} catch (UserContextException e) {
-
 
161
			logger.error("Unable to establish connection to the User service", e);
-
 
162
			addActionError("Unable to establish connection to the User service");
-
 
163
		}
154
		}
164
 
155
 
165
        if (user == null) {
156
        if (user == null) {
166
            addActionError("Could not find default user for SourceId: " + sourceId);
157
            addActionError("Could not find default user for SourceId: " + sourceId);
167
        }
158
        }
Line 199... Line 190...
199
            	LineItem lineItem = null;
190
            	LineItem lineItem = null;
200
            	try {
191
            	try {
201
            		lineItem = createLineItem(row.getCell(ITEM_ID_INDEX).getNumericCellValue());
192
            		lineItem = createLineItem(row.getCell(ITEM_ID_INDEX).getNumericCellValue());
202
            		lineItem.setTotal_price(row.getCell(AMOUNT_PER_ORDER_INDEX).getNumericCellValue());
193
            		lineItem.setTotal_price(row.getCell(AMOUNT_PER_ORDER_INDEX).getNumericCellValue());
203
            		lineItem.setUnit_price(row.getCell(AMOUNT_PER_ORDER_INDEX).getNumericCellValue());
194
            		lineItem.setUnit_price(row.getCell(AMOUNT_PER_ORDER_INDEX).getNumericCellValue());
204
            	} catch (TException tex) {
195
            	} catch (Exception tex) {
205
            		logger.error("Unable to establish connection to the Catalog service", tex);
196
            		logger.error("Unable to establish connection to the Catalog service", tex);
206
        	        addActionError("Unable to establish connection to the Catalog service");
197
        	        addActionError("Unable to establish connection to the Catalog service");
207
        	        return "authsuccess";
198
        	        return "authsuccess";
208
            	} catch (CatalogServiceException csex) {
-
 
209
            		logger.error("Unable to establish connection to the Catalog service", csex);
-
 
210
        	        addActionError("Unable to establish connection to the Catalog service");
-
 
211
        	        return "authsuccess";
-
 
212
            	}
199
            	}
213
                Order t_order = new Order();
200
                Order t_order = new Order();
214
                t_order.setCustomer_id(user.getUserId());
201
                t_order.setCustomer_id(user.getUserId());
215
                t_order.setCustomer_email(sourceDetail.getEmail());
202
                t_order.setCustomer_email(sourceDetail.getEmail());
216
                if(row.getCell(BILLING_NAME_INDEX)!=null && row.getCell(BILLING_NAME_INDEX).getStringCellValue()!=null && 
203
                if(row.getCell(BILLING_NAME_INDEX)!=null && row.getCell(BILLING_NAME_INDEX).getStringCellValue()!=null && 
Line 260... Line 247...
260
            
247
            
261
            txn.setOrders(orders);
248
            txn.setOrders(orders);
262
            Client transaction_client = new TransactionClient().getClient();
249
            Client transaction_client = new TransactionClient().getClient();
263
            try {
250
            try {
264
            	transactionId =  String.valueOf(transaction_client.createTransaction(txn));
251
            	transactionId =  String.valueOf(transaction_client.createTransaction(txn));
-
 
252
            	if(sourceDetail.getId()!= AMAZON_SOURCE_ID) {
265
            	createPayment(user);
253
	            	createPayment(user);
266
            	
254
	            	
267
            	in.shop2020.model.v1.order.Attribute orderAttribute = new in.shop2020.model.v1.order.Attribute();
255
	            	in.shop2020.model.v1.order.Attribute orderAttribute = new in.shop2020.model.v1.order.Attribute();
268
                orderAttribute.setName("tinNumber");
256
	                orderAttribute.setName("tinNumber");
269
                orderAttribute.setValue(sourceDetail.getTinNumber());
257
	                orderAttribute.setValue(sourceDetail.getTinNumber());
270
 
258
	
271
                if(!sourceDetail.getTinNumber().equals("") && !(sourceDetail.getTinNumber() == null)) {
259
	                if(!sourceDetail.getTinNumber().equals("") && !(sourceDetail.getTinNumber() == null)) {
272
                	transaction_client.setOrderAttributeForTransaction(Long.parseLong(transactionId), orderAttribute);
260
	                	transaction_client.setOrderAttributeForTransaction(Long.parseLong(transactionId), orderAttribute);
273
                }
261
	                }
-
 
262
            	} else {
-
 
263
            		
-
 
264
            	}
274
                transaction_client.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.AUTHORIZED, "Dummy Payment received for the order of Source " + sourceId, pickUpType, OrderType.findByValue(orderType.intValue()), OrderSource.findByValue(sourceId.intValue()));
265
                transaction_client.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.AUTHORIZED, "Dummy Payment received for the order of Source " + sourceId, pickUpType, OrderType.findByValue(orderType.intValue()), OrderSource.findByValue(sourceId.intValue()));
275
                transaction_client.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS, "Dummy RTGS Payment accepted for order of Source " + sourceId, pickUpType, OrderType.findByValue(orderType.intValue()), OrderSource.findByValue(sourceId.intValue()));
266
                transaction_client.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS, "Dummy RTGS Payment accepted for order of Source " + sourceId, pickUpType, OrderType.findByValue(orderType.intValue()), OrderSource.findByValue(sourceId.intValue()));
276
                logger.info("Successfully created transaction: " + transactionId + " for amount: " + amount);
267
                logger.info("Successfully created transaction: " + transactionId + " for amount: " + amount);
277
 
268
 
278
            } catch (TTransportException e) {
-
 
279
                logger.error("Unable to establish connection to the transaction service", e);
-
 
280
                addActionError("Unable to establish connection to the transaction service");
-
 
281
                return "authsuccess";
-
 
282
            } catch (TException e) {
269
            } catch (Exception e) {
283
                logger.error("Unable to establish connection to the transaction service", e);
-
 
284
                addActionError("Unable to establish connection to the transaction service");
-
 
285
                return "authsuccess";
-
 
286
    		} catch (TransactionServiceException e) {
-
 
287
                logger.error("Unable to establish connection to the transaction service", e);
-
 
288
                addActionError("Unable to establish connection to the transaction service");
-
 
289
                return "authsuccess";
-
 
290
    		} catch (PaymentException e) {
-
 
291
                logger.error("Unable to establish connection to the transaction service", e);
270
                logger.error("Unable to establish connection to the transaction service", e);
292
                addActionError("Unable to establish connection to the transaction service");
271
                addActionError("Unable to establish connection to the transaction service");
293
                return "authsuccess";
272
                return "authsuccess";
294
    		}
273
    		}
295
        }
274
        }