Subversion Repositories SmartDukaan

Rev

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

Rev 7295 Rev 7372
Line 71... Line 71...
71
 * @author vikas
71
 * @author vikas
72
 * 
72
 * 
73
 */
73
 */
74
@SuppressWarnings("serial")
74
@SuppressWarnings("serial")
75
public class UserOrderInfoController extends BaseController {
75
public class UserOrderInfoController extends BaseController {
76
    private static Logger                  log                     = Logger.getLogger(Class.class);
76
	private static Logger                  log                     = Logger.getLogger(Class.class);
77
    private static BlueDartTrackingService blueDartTrackingService = new BlueDartTrackingService();
77
	private static BlueDartTrackingService blueDartTrackingService = new BlueDartTrackingService();
78
    private static AramexTrackingService aramexTrackingService     = new AramexTrackingService();
78
	private static AramexTrackingService aramexTrackingService     = new AramexTrackingService();
79
    private static DelhiveryTrackingService delhiveryTrackingService     = new DelhiveryTrackingService();
79
	private static DelhiveryTrackingService delhiveryTrackingService     = new DelhiveryTrackingService();
80
    private static RedExpressTrackingService redexpressTrackingService = new RedExpressTrackingService();
80
	private static RedExpressTrackingService redexpressTrackingService = new RedExpressTrackingService();
81
 
81
 
82
    private long                 orderId;
82
	private long                 orderId;
83
    private Order                order;
83
	private Order                order;
84
    private List<Payment>        payments;
84
	private List<Payment>        payments;
85
    private List<ShipmentUpdate> shipmentUpdates = new ArrayList<ShipmentUpdate>();
85
	private List<ShipmentUpdate> shipmentUpdates = new ArrayList<ShipmentUpdate>();
86
    private Long                 codTicketId;
86
	private Long                 codTicketId;
87
    private List<Address>        addresses;
87
	private List<Address>        addresses;
88
    private Set<OrderStatus>     setOfcancellableStates;
88
	private Set<OrderStatus>     setOfcancellableStates;
89
    private String               cancellationInitiator;
89
	private String               cancellationInitiator;
90
    private String               cancelReason;
90
	private String               cancelReason;
91
    private String               body;
91
	private String               body;
92
    private String               line1;
92
	private String               line1;
93
    private String               line2;
93
	private String               line2;
94
    private String               city;
94
	private String               city;
95
    private String               state;
95
	private String               state;
96
    private String               pin;
96
	private String               pin;
97
    private String				 freebieItem;
97
	private String				 freebieItem;
98
    private String				 dealText;
98
	private String				 dealText;
99
    private String 				 parentOrderIdForFreebieOrder;
99
	private String 				 parentOrderIdForFreebieOrder;
100
    private String				 freebieOrderId;
100
	private String				 freebieOrderId;
101
 
101
 
102
    public UserOrderInfoController() {
102
	public UserOrderInfoController() {
103
        super();
103
		super();
104
        setOfcancellableStates = new HashSet<OrderStatus>();
104
		setOfcancellableStates = new HashSet<OrderStatus>();
105
        setOfcancellableStates.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
105
		setOfcancellableStates.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
106
        setOfcancellableStates.add(OrderStatus.INVENTORY_LOW);
106
		setOfcancellableStates.add(OrderStatus.INVENTORY_LOW);
107
        setOfcancellableStates.add(OrderStatus.LOW_INV_PO_RAISED);
107
		setOfcancellableStates.add(OrderStatus.LOW_INV_PO_RAISED);
108
        setOfcancellableStates.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);
108
		setOfcancellableStates.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);
109
        setOfcancellableStates.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);
109
		setOfcancellableStates.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);
110
        setOfcancellableStates.add(OrderStatus.ACCEPTED);
110
		setOfcancellableStates.add(OrderStatus.ACCEPTED);
111
        setOfcancellableStates.add(OrderStatus.BILLED);
111
		setOfcancellableStates.add(OrderStatus.BILLED);
112
    }
112
	}
113
 
113
 
114
    public String index() {
114
	public String index() {
115
        try {
115
		try {
116
            PaymentClient paymentServiceClient = new PaymentClient();
116
			PaymentClient paymentServiceClient = new PaymentClient();
117
            TransactionClient transactionServiceClient = new TransactionClient();
117
			TransactionClient transactionServiceClient = new TransactionClient();
118
 
118
 
119
            order = transactionServiceClient.getClient().getOrder(orderId);
119
			order = transactionServiceClient.getClient().getOrder(orderId);
120
            if(order.getFreebieItemId()>0) {
120
			if(order.getFreebieItemId()>0) {
121
            	CatalogService.Client catalogClient = new CatalogClient().getClient();
121
				CatalogService.Client catalogClient = new CatalogClient().getClient();
122
            	Item item = catalogClient.getItem(order.getFreebieItemId());
122
				Item item = catalogClient.getItem(order.getFreebieItemId());
123
            	freebieItem = item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + " " + item.getColor();
123
				freebieItem = item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + " " + item.getColor();
124
            }
124
			}
125
            
125
 
126
            if(order.getLineitems().get(0).getDealText()!=null && !order.getLineitems().get(0).getDealText().isEmpty()) {
126
			if(order.getLineitems().get(0).getDealText()!=null && !order.getLineitems().get(0).getDealText().isEmpty()) {
127
            	dealText = order.getLineitems().get(0).getDealText();
127
				dealText = order.getLineitems().get(0).getDealText();
128
            }
128
			}
129
            List<in.shop2020.model.v1.order.Attribute> attributes = 
129
			List<in.shop2020.model.v1.order.Attribute> attributes = 
130
            	transactionServiceClient.getClient().getAllAttributesForOrderId(orderId);
130
				transactionServiceClient.getClient().getAllAttributesForOrderId(orderId);
131
            
131
 
132
            for(in.shop2020.model.v1.order.Attribute attribute: attributes){
132
			for(in.shop2020.model.v1.order.Attribute attribute: attributes){
133
            	if(attribute.getName().equals("parentOrderIdForFreebie")){
133
				if(attribute.getName().equals("parentOrderIdForFreebie")){
134
            		parentOrderIdForFreebieOrder = attribute.getValue();
134
					parentOrderIdForFreebieOrder = attribute.getValue();
135
            	} else if (attribute.getName().equals("freebieOrderId")){
135
				} else if (attribute.getName().equals("freebieOrderId")){
136
            		freebieOrderId = attribute.getValue();
136
					freebieOrderId = attribute.getValue();
137
            	}
137
				}
138
            }
138
			}
139
            
139
 
140
            payments = paymentServiceClient.getClient()
140
			payments = paymentServiceClient.getClient()
141
            .getPaymentForTxnId(order.getTransactionId());
141
			.getPaymentForTxnId(order.getTransactionId());
142
 
142
 
143
 
143
 
144
 
144
 
145
            // Spawning a thread to capture shipment updates from Bluedart
145
			// Spawning a thread to capture shipment updates from Bluedart
146
            // This is done to ensure that response from Crm web app is sent
146
			// This is done to ensure that response from Crm web app is sent
147
            // within given time limits. Also, we wont be affected in the cases 
147
			// within given time limits. Also, we wont be affected in the cases 
148
            // where bluedart site is down or slow
148
			// where bluedart site is down or slow
149
            Executors.newSingleThreadExecutor().invokeAll(Collections.singletonList(new Callable<Boolean>() {
149
			Executors.newSingleThreadExecutor().invokeAll(Collections.singletonList(new Callable<Boolean>() {
150
                public Boolean call() throws Exception {
150
				public Boolean call() throws Exception {
151
                    if (order.getLogistics_provider_id() == 1)
151
					if (order.getLogistics_provider_id() == 1)
152
                        shipmentUpdates = blueDartTrackingService.getUpdates(order.getAirwaybill_no());
152
						shipmentUpdates = blueDartTrackingService.getUpdates(order.getAirwaybill_no());
153
                    else if (order.getLogistics_provider_id() == 2) {
153
					else if (order.getLogistics_provider_id() == 2) {
154
                        shipmentUpdates = aramexTrackingService.getUpdates(order.getAirwaybill_no());
154
						shipmentUpdates = aramexTrackingService.getUpdates(order.getAirwaybill_no());
155
                    }
155
					}
156
                    else if (order.getLogistics_provider_id() == 3) {
156
					else if (order.getLogistics_provider_id() == 3) {
157
                        shipmentUpdates = delhiveryTrackingService.getUpdates(order.getAirwaybill_no());
157
						shipmentUpdates = delhiveryTrackingService.getUpdates(order.getAirwaybill_no());
158
                    }
158
					}
159
                    else if (order.getLogistics_provider_id() == 6) {
159
					else if (order.getLogistics_provider_id() == 6) {
160
                        shipmentUpdates = redexpressTrackingService.getUpdates(order.getAirwaybill_no());
160
						shipmentUpdates = redexpressTrackingService.getUpdates(order.getAirwaybill_no());
161
                    }
161
					}
162
                    else {
162
					else {
163
                        shipmentUpdates = new ArrayList<ShipmentUpdate>();
163
						shipmentUpdates = new ArrayList<ShipmentUpdate>();
164
                        log.error("Error : providerId = " + order.getLogistics_provider_id() + "for orderId : " + order.getId());
164
						log.error("Error : providerId = " + order.getLogistics_provider_id() + "for orderId : " + order.getId());
165
                    }
165
					}
166
                    return true;
166
					return true;
167
                }
167
				}
168
            }), 60, TimeUnit.SECONDS);
168
			}), 60, TimeUnit.SECONDS);
169
 
169
 
170
            if (order.isCod() && OrderStatus.COD_VERIFICATION_PENDING.equals(order.getStatus())) {
170
			if (order.isCod() && OrderStatus.COD_VERIFICATION_PENDING.equals(order.getStatus())) {
171
                populateCODTicketId(order.getCustomer_id());
171
				populateCODTicketId(order.getCustomer_id());
172
            }
172
			}
173
 
173
 
174
            if (canEditOrderAddress()) {
174
			if (canEditOrderAddress()) {
175
                userContextServiceClient = new UserClient().getClient();
175
				userContextServiceClient = new UserClient().getClient();
176
                addresses = userContextServiceClient.getAllAddressesForUser(order.getCustomer_id());
176
				addresses = userContextServiceClient.getAllAddressesForUser(order.getCustomer_id());
177
            }
177
			}
178
 
178
 
179
        } catch (TTransportException e) {
179
		} catch (TTransportException e) {
180
            log.error("Unable to create thrift Client", e);
180
			log.error("Unable to create thrift Client", e);
181
        } catch (TransactionServiceException e) {
181
		} catch (TransactionServiceException e) {
182
            addActionError("Invalid order id or no order selected.");
182
			addActionError("Invalid order id or no order selected.");
183
        } catch (TException e) {
183
		} catch (TException e) {
184
            log.error("Unable to get thrift Client", e);
184
			log.error("Unable to get thrift Client", e);
185
        } catch (PaymentException e) {
185
		} catch (PaymentException e) {
186
            log.error("Unable to get payments for transctionId : " + order.getTransactionId(), e);
186
			log.error("Unable to get payments for transctionId : " + order.getTransactionId(), e);
187
        } catch (InterruptedException e) {
187
		} catch (InterruptedException e) {
188
            log.error("Thread was interrupted", e);
188
			log.error("Thread was interrupted", e);
189
        } catch (UserContextException e) {
189
		} catch (UserContextException e) {
190
            log.error("Unable to get addresses for user : " + order.getCustomer_id(), e);
190
			log.error("Unable to get addresses for user : " + order.getCustomer_id(), e);
191
        } catch(CatalogServiceException csex) {
191
		} catch(CatalogServiceException csex) {
192
        	log.error("Unable to get item details for itemId: " + order.getFreebieItemId(), csex);
192
			log.error("Unable to get item details for itemId: " + order.getFreebieItemId(), csex);
193
        }
193
		}
194
        return INDEX;
194
		return INDEX;
195
    }
195
	}
196
 
196
 
197
    private boolean canEditOrderAddress() {
197
	private boolean canEditOrderAddress() {
198
        return false;
198
		return false;
199
    }
199
	}
200
 
200
 
201
    private void populateCODTicketId(long customerId) {
201
	private void populateCODTicketId(long customerId) {
202
        try {
202
		try {
203
            SearchFilter searchFilter = new SearchFilter();
203
			SearchFilter searchFilter = new SearchFilter();
204
            searchFilter.setTicketCategory(TicketCategory.COD_VERIFICATION);
204
			searchFilter.setTicketCategory(TicketCategory.COD_VERIFICATION);
205
            searchFilter.setTicketStatuses(new ArrayList<TicketStatus>());
205
			searchFilter.setTicketStatuses(new ArrayList<TicketStatus>());
206
            searchFilter.getTicketStatuses().add(TicketStatus.OPEN);
206
			searchFilter.getTicketStatuses().add(TicketStatus.OPEN);
207
            searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);
207
			searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);
208
            searchFilter.setCustomerId(customerId);
208
			searchFilter.setCustomerId(customerId);
209
            crmServiceClient = new CRMClient().getClient();
209
			crmServiceClient = new CRMClient().getClient();
210
            List<Ticket> tickets = crmServiceClient.getTickets(searchFilter);
210
			List<Ticket> tickets = crmServiceClient.getTickets(searchFilter);
211
            if (tickets != null && !tickets.isEmpty()) {
211
			if (tickets != null && !tickets.isEmpty()) {
212
                codTicketId = tickets.get(0).getId();
212
				codTicketId = tickets.get(0).getId();
213
            }
213
			}
214
        } catch (TException e) {
214
		} catch (TException e) {
215
            log.error("Error fetching tickets for customerId: " + customerId, e);
215
			log.error("Error fetching tickets for customerId: " + customerId, e);
216
        }
216
		}
217
    }
217
	}
218
 
218
 
219
    public String markOrderForCancellation() {
219
	public String markOrderForCancellation() {
220
        try{
220
		try{
221
            TransactionClient transactionServiceClient = new TransactionClient();
221
			TransactionClient transactionServiceClient = new TransactionClient();
222
            log.info("URL = " + request.getRequestURI());
222
			log.info("URL = " + request.getRequestURI());
223
            log.info("Initiator = " + request.getParameter("cancellationInitiator"));
223
			log.info("Initiator = " + request.getParameter("cancellationInitiator"));
224
            log.info("orderId = " + request.getParameter("orderId"));
224
			log.info("orderId = " + request.getParameter("orderId"));
225
            if (cancellationInitiator.equals("CUSTOMER")) {
225
			if (cancellationInitiator.equals("CUSTOMER")) {
226
                order = transactionServiceClient.getClient().getOrder(orderId);
226
				order = transactionServiceClient.getClient().getOrder(orderId);
227
                transactionServiceClient.getClient().markOrderCancellationRequestReceived(orderId);
227
				transactionServiceClient.getClient().markOrderCancellationRequestReceived(orderId);
228
                long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
228
				long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
229
                Ticket ticket = new Ticket();
229
				Ticket ticket = new Ticket();
230
                String plainTextbody = "";
230
				String plainTextbody = "";
231
                if(body!=null && !body.isEmpty()){
231
				if(body!=null && !body.isEmpty()){
232
                    plainTextbody = new Source(body).getTextExtractor().toString();
232
					plainTextbody = new Source(body).getTextExtractor().toString();
233
                }
233
				}
234
                ticket.setDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
234
				ticket.setDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
235
                ticket.setCreatorId(creatorId);
235
				ticket.setCreatorId(creatorId);
236
                ticket.setStatus(TicketStatus.OPEN);
236
				ticket.setStatus(TicketStatus.OPEN);
237
                ticket.setPriority(TicketPriority.HIGH);
237
				ticket.setPriority(TicketPriority.HIGH);
238
                ticket.setCategory(TicketCategory.ORDER_CANCELLATION);
238
				ticket.setCategory(TicketCategory.ORDER_CANCELLATION);
239
                ticket.setOrderId(orderId);
239
				ticket.setOrderId(orderId);
240
 
240
 
241
                Activity activity = new Activity();
241
				Activity activity = new Activity();
242
                activity.setDescription("Creating Ticket");
242
				activity.setDescription("Creating Ticket");
243
                activity.setType(ActivityType.OTHER);
243
				activity.setType(ActivityType.OTHER);
244
                activity.setTicketPriority(TicketPriority.HIGH);
244
				activity.setTicketPriority(TicketPriority.HIGH);
245
                activity.setTicketStatus(TicketStatus.OPEN);
245
				activity.setTicketStatus(TicketStatus.OPEN);
246
                activity.setCreatorId(creatorId);
246
				activity.setCreatorId(creatorId);
247
                activity.setTicketDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
247
				activity.setTicketDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
248
                activity.setTicketCategory(TicketCategory.ORDER_CANCELLATION);
248
				activity.setTicketCategory(TicketCategory.ORDER_CANCELLATION);
249
 
249
 
250
                ticket.setCustomerId(order.getCustomer_id());
250
				ticket.setCustomerId(order.getCustomer_id());
251
                activity.setCustomerId(order.getCustomer_id());
251
				activity.setCustomerId(order.getCustomer_id());
252
                ticket.setCustomerName(order.getCustomer_name());
252
				ticket.setCustomerName(order.getCustomer_name());
253
                activity.setCustomerName(order.getCustomer_name());
253
				activity.setCustomerName(order.getCustomer_name());
254
                ticket.setCustomerEmailId(order.getCustomer_email());
254
				ticket.setCustomerEmailId(order.getCustomer_email());
255
                activity.setCustomerEmailId(order.getCustomer_email());
255
				activity.setCustomerEmailId(order.getCustomer_email());
256
                ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
256
				ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
257
                activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
257
				activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
258
 
258
 
259
                crmServiceClient = new CRMClient().getClient();
259
				crmServiceClient = new CRMClient().getClient();
260
                crmServiceClient.insertTicket(ticket, activity);
260
				crmServiceClient.insertTicket(ticket, activity);
261
            } 
261
			} 
262
            else if (cancellationInitiator.equals("INTERNAL")) {
262
			else if (cancellationInitiator.equals("INTERNAL")) {
263
                String plainTextbody = "";
263
				String plainTextbody = "";
264
                if(body!=null && !body.isEmpty()){
264
				if(body!=null && !body.isEmpty()){
265
                    plainTextbody = new Source(body).getTextExtractor().toString();
265
					plainTextbody = new Source(body).getTextExtractor().toString();
266
                }
266
				}
267
                transactionServiceClient.getClient().refundOrder(orderId, currentAgentEmailId, cancelReason + " : " + plainTextbody);
267
				boolean status_returned = transactionServiceClient.getClient().refundOrder(orderId, currentAgentEmailId, cancelReason + " : " + plainTextbody);
268
                long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
268
				if (status_returned) {
269
                Ticket ticket = new Ticket();
269
					order = transactionServiceClient.getClient().getOrder(orderId);
270
                ticket.setDescription("Creating ticket for Order Cancellation due to Low inventory");
270
					long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
271
                ticket.setCreatorId(creatorId);
271
					Ticket ticket = new Ticket();
272
                ticket.setStatus(TicketStatus.CLOSED);
272
					ticket.setDescription("Creating ticket for Order Cancellation due to Low inventory");
273
                ticket.setPriority(TicketPriority.MEDIUM);
273
					ticket.setCreatorId(creatorId);
274
                ticket.setCategory(TicketCategory.ORDER_CANCELLATION);
274
					ticket.setAssigneeId(36);
275
                ticket.setOrderId(orderId);
275
					ticket.setStatus(TicketStatus.OPEN);
276
 
276
					ticket.setPriority(TicketPriority.MEDIUM);
277
                Activity activity = new Activity();
277
					ticket.setCategory(TicketCategory.LOW_INVENTORY_CANCELLED_ORDERS);
278
                activity.setDescription("Creating Ticket");
278
					ticket.setOrderId(orderId);
279
                activity.setType(ActivityType.OTHER);
279
					ticket.setCustomerId(order.getCustomer_id());
280
                activity.setTicketPriority(TicketPriority.MEDIUM);
280
					ticket.setCustomerName(order.getCustomer_name());
281
                activity.setTicketStatus(TicketStatus.CLOSED);
281
					ticket.setCustomerEmailId(order.getCustomer_email());
282
                activity.setCreatorId(creatorId);
282
					ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
283
                activity.setTicketCategory(TicketCategory.ORDER_CANCELLATION);
283
 
284
                activity.setTicketDescription("Creating ticket for Order Cancellation due to Low inventory");
284
					Activity activity = new Activity();
285
 
285
					activity.setDescription("Creating Ticket");
286
                ticket.setCustomerId(order.getCustomer_id());
286
					activity.setType(ActivityType.OTHER);
287
                activity.setCustomerId(order.getCustomer_id());
287
					activity.setTicketPriority(TicketPriority.MEDIUM);
288
                ticket.setCustomerName(order.getCustomer_name());
288
					activity.setTicketStatus(TicketStatus.OPEN);
289
                activity.setCustomerName(order.getCustomer_name());
289
					activity.setCreatorId(creatorId);
290
                ticket.setCustomerEmailId(order.getCustomer_email());
290
					activity.setTicketAssigneeId(36);
291
                activity.setCustomerEmailId(order.getCustomer_email());
291
					activity.setTicketCategory(TicketCategory.LOW_INVENTORY_CANCELLED_ORDERS);
292
                ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
292
					activity.setTicketDescription("Creating ticket for Order Cancellation due to Low inventory");
293
                activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
293
					activity.setCustomerId(order.getCustomer_id());
294
 
294
					activity.setCustomerName(order.getCustomer_name());
295
                crmServiceClient = new CRMClient().getClient();
295
					activity.setCustomerEmailId(order.getCustomer_email());
296
                crmServiceClient.insertTicket(ticket, activity);
296
					activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
297
            }
297
 
298
        } catch(Exception e) {
298
					crmServiceClient = new CRMClient().getClient();
299
            log.error("Could not mark order for Cancellation, OrderId : " + orderId, e);
299
					crmServiceClient.insertTicket(ticket, activity);
300
        }
300
				}
301
        return index();
301
			}
302
    }
302
		} catch(Exception e) {
303
    
303
			log.error("Could not mark order for Cancellation, OrderId : " + orderId, e);
304
    public void getOrderConfirmationMail() throws IOException, TException, ConfigException, TransactionServiceException {
304
		}
305
    	TransactionClient transactionServiceClient = new TransactionClient();
305
		return index();
306
    	order = transactionServiceClient.getClient().getOrder(orderId);
306
	}
307
    	long source = order.getTransactionId();
307
 
308
    	HelperClient helperClient = new HelperClient("helper_service_server","helper_service_server_port");
308
	public void getOrderConfirmationMail() throws IOException, TException, ConfigException, TransactionServiceException {
309
    	String mail = helperClient.getClient().getOrderConfirmationMail(source);
309
		TransactionClient transactionServiceClient = new TransactionClient();
310
    	File file = new File("/tmp/temp");
310
		order = transactionServiceClient.getClient().getOrder(orderId);
311
    	
311
		long source = order.getTransactionId();
312
    	FileWriter writer = new FileWriter(file);
312
		HelperClient helperClient = new HelperClient("helper_service_server","helper_service_server_port");
313
    	writer.append(mail);
313
		String mail = helperClient.getClient().getOrderConfirmationMail(source);
314
    	writer.close();
314
		File file = new File("/tmp/temp");
315
 
315
 
316
    	byte[] buffer = new byte[(int)file.length()];
316
		FileWriter writer = new FileWriter(file);
317
        InputStream input = null;
317
		writer.append(mail);
318
    	try {
318
		writer.close();
319
            int totalBytesRead = 0;
319
 
320
            input = new BufferedInputStream(new FileInputStream(file));
320
		byte[] buffer = new byte[(int)file.length()];
321
            while(totalBytesRead < buffer.length){
321
		InputStream input = null;
322
                int bytesRemaining = buffer.length - totalBytesRead;
322
		try {
323
                int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
323
			int totalBytesRead = 0;
324
                if (bytesRead > 0){
324
			input = new BufferedInputStream(new FileInputStream(file));
325
                    totalBytesRead = totalBytesRead + bytesRead;
325
			while(totalBytesRead < buffer.length){
326
                }
326
				int bytesRemaining = buffer.length - totalBytesRead;
327
            }
327
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
328
        }
328
				if (bytesRead > 0){
329
        finally {
329
					totalBytesRead = totalBytesRead + bytesRead;
330
            input.close();
330
				}
331
            file.delete();
331
			}
332
        }
332
		}
333
    	
333
		finally {
334
    	
334
			input.close();
335
    	response.setHeader("Content-disposition", "inline; filename=" + "OrderDetail_"+orderId );
335
			file.delete();
336
 
336
		}
337
        ServletOutputStream sos;
337
 
338
        try {
338
 
339
            sos = response.getOutputStream();
339
		response.setHeader("Content-disposition", "inline; filename=" + "OrderDetail_"+orderId );
340
            sos.write(buffer);
340
 
341
            sos.flush();
341
		ServletOutputStream sos;
342
        } catch (IOException e) {
342
		try {
343
            System.out.println("Unable to stream the manifest file");
343
			sos = response.getOutputStream();
344
        }   
344
			sos.write(buffer);
345
    }
345
			sos.flush();
346
    
346
		} catch (IOException e) {
347
    public void getOrderDeliveryMail() throws IOException, TException, ConfigException, TransactionServiceException {
347
			System.out.println("Unable to stream the manifest file");
348
    	HelperClient helperClient = new HelperClient("helper_service_server","helper_service_server_port");
348
		}   
349
    	String mail = helperClient.getClient().getOrderDeliveryMail(orderId);
349
	}
350
    	File file = new File("/tmp/temp");
350
 
351
    	
351
	public void getOrderDeliveryMail() throws IOException, TException, ConfigException, TransactionServiceException {
352
    	FileWriter writer = new FileWriter(file);
352
		HelperClient helperClient = new HelperClient("helper_service_server","helper_service_server_port");
353
    	writer.append(mail);
353
		String mail = helperClient.getClient().getOrderDeliveryMail(orderId);
354
    	writer.close();
354
		File file = new File("/tmp/temp");
355
 
355
 
356
    	byte[] buffer = new byte[(int)file.length()];
356
		FileWriter writer = new FileWriter(file);
357
        InputStream input = null;
357
		writer.append(mail);
358
    	try {
358
		writer.close();
359
            int totalBytesRead = 0;
359
 
360
            input = new BufferedInputStream(new FileInputStream(file));
360
		byte[] buffer = new byte[(int)file.length()];
361
            while(totalBytesRead < buffer.length){
361
		InputStream input = null;
362
                int bytesRemaining = buffer.length - totalBytesRead;
362
		try {
363
                int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
363
			int totalBytesRead = 0;
364
                if (bytesRead > 0){
364
			input = new BufferedInputStream(new FileInputStream(file));
365
                    totalBytesRead = totalBytesRead + bytesRead;
365
			while(totalBytesRead < buffer.length){
366
                }
366
				int bytesRemaining = buffer.length - totalBytesRead;
367
            }
367
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
368
        }
368
				if (bytesRead > 0){
369
        finally {
369
					totalBytesRead = totalBytesRead + bytesRead;
370
            input.close();
370
				}
371
            file.delete();
371
			}
372
        }
372
		}
373
    	
373
		finally {
374
    	
374
			input.close();
375
    	response.setHeader("Content-disposition", "inline; filename=" + "OrderDetail_"+orderId );
375
			file.delete();
376
 
376
		}
377
        ServletOutputStream sos;
377
 
378
        try {
378
 
379
            sos = response.getOutputStream();
379
		response.setHeader("Content-disposition", "inline; filename=" + "OrderDetail_"+orderId );
380
            sos.write(buffer);
380
 
381
            sos.flush();
381
		ServletOutputStream sos;
382
        } catch (IOException e) {
382
		try {
383
            System.out.println("Unable to stream the manifest file");
383
			sos = response.getOutputStream();
384
        }   
384
			sos.write(buffer);
385
    }
385
			sos.flush();
386
    
386
		} catch (IOException e) {
387
    public boolean canOrderBeCancelled() {
387
			System.out.println("Unable to stream the manifest file");
388
        if (setOfcancellableStates.contains(order.getStatus())) {
388
		}   
389
            return true;
389
	}
390
        }
390
 
391
        return false;
391
	public boolean canOrderBeCancelled() {
392
    }
392
		if (setOfcancellableStates.contains(order.getStatus())) {
393
 
393
			return true;
394
    public String getPaymentGateway(Payment payment) {
394
		}
395
        String gatewayName = "";
395
		return false;
396
 
396
	}
397
        try {
397
 
398
            Client paymentServiceClient = new PaymentClient().getClient();
398
	public String getPaymentGateway(Payment payment) {
399
            gatewayName = paymentServiceClient.getPaymentGateway(payment.getGatewayId()).getName();
399
		String gatewayName = "";
400
        } catch (TTransportException e) {
400
 
401
        } catch (PaymentException e) {
401
		try {
402
        } catch (TException e) {
402
			Client paymentServiceClient = new PaymentClient().getClient();
403
        }
403
			gatewayName = paymentServiceClient.getPaymentGateway(payment.getGatewayId()).getName();
404
 
404
		} catch (TTransportException e) {
405
        return gatewayName;
405
		} catch (PaymentException e) {
406
    }
406
		} catch (TException e) {
407
 
407
		}
408
    public String getProductName(LineItem lineItem) {
408
 
409
        String name = ModelUtils.extractProductNameFromLineItem(lineItem);
409
		return gatewayName;
410
 
410
	}
411
        if (lineItem.getColor() != null && !lineItem.getColor().isEmpty()) {
411
 
412
            name += "(" + lineItem.getColor() + ")";
412
	public String getProductName(LineItem lineItem) {
413
        }
413
		String name = ModelUtils.extractProductNameFromLineItem(lineItem);
414
 
414
 
415
        return name;
415
		if (lineItem.getColor() != null && !lineItem.getColor().isEmpty()) {
416
    }
416
			name += "(" + lineItem.getColor() + ")";
417
 
417
		}
418
    public int convertDouble(double value) {
418
 
419
        return (int)value;
419
		return name;
420
    }
420
	}
421
    
421
 
422
    public String getInsuranceExpiryDate(long DeliveryDate) {
422
	public int convertDouble(double value) {
423
        if (DeliveryDate == 0) {
423
		return (int)value;
424
            return "N/A";
424
	}
425
        }
425
 
426
        Calendar cal = Calendar.getInstance();
426
	public String getInsuranceExpiryDate(long DeliveryDate) {
427
        cal.setTimeInMillis(DeliveryDate);
427
		if (DeliveryDate == 0) {
428
        cal.add(Calendar.YEAR, 1);
428
			return "N/A";
429
        SimpleDateFormat sdf = new SimpleDateFormat("dd MMM, yyyy");
429
		}
430
        return sdf.format(cal.getTime());
430
		Calendar cal = Calendar.getInstance();
431
    }
431
		cal.setTimeInMillis(DeliveryDate);
432
 
432
		cal.add(Calendar.YEAR, 1);
433
    public String getShippingAddressOfStore(long storeId) {
433
		SimpleDateFormat sdf = new SimpleDateFormat("dd MMM, yyyy");
434
        try {
434
		return sdf.format(cal.getTime());
435
            in.shop2020.logistics.LogisticsService.Client client = new LogisticsClient().getClient();
435
	}
436
            PickupStore store = client.getPickupStore(storeId);
436
 
437
            return StringUtils.join(new String[] {
437
	public String getShippingAddressOfStore(long storeId) {
438
                    store.getName(),
438
		try {
439
                    store.getLine1(),
439
			in.shop2020.logistics.LogisticsService.Client client = new LogisticsClient().getClient();
440
                    store.getLine2(),
440
			PickupStore store = client.getPickupStore(storeId);
441
                    store.getPin(),
441
			return StringUtils.join(new String[] {
442
                    store.getCity(),
442
					store.getName(),
443
                    store.getState(),
443
					store.getLine1(),
444
                    store.getPhone()}, ",");
444
					store.getLine2(),
445
        } catch (Exception e) {
445
					store.getPin(),
446
            return "";
446
					store.getCity(),
447
        }
447
					store.getState(),
448
    }
448
					store.getPhone()}, ",");
449
 
449
		} catch (Exception e) {
450
    public String getAddress(Order order) {
450
			return "";
451
        return ModelUtils.extractAddressFromOrder(order);
451
		}
452
    }
452
	}
453
    
453
 
454
    public String changeShippingAddress() {
454
	public String getAddress(Order order) {
455
        try {
455
		return ModelUtils.extractAddressFromOrder(order);
456
            TransactionClient transactionServiceClient = new TransactionClient();
456
	}
457
            transactionServiceClient.getClient().changeShippingAddress(orderId, line1, line2, city, state, pin);
457
 
458
        } catch(Exception e) {
458
	public String changeShippingAddress() {
459
            log.error("Unable to update address for orderId : " + orderId + "and address : " + 
459
		try {
460
                    line1 + ", " + line2+ ", " + city + ", " + state + ", " + pin, e);
460
			TransactionClient transactionServiceClient = new TransactionClient();
461
        }
461
			transactionServiceClient.getClient().changeShippingAddress(orderId, line1, line2, city, state, pin);
462
        return null;
462
		} catch(Exception e) {
463
    }
463
			log.error("Unable to update address for orderId : " + orderId + "and address : " + 
464
    
464
					line1 + ", " + line2+ ", " + city + ", " + state + ", " + pin, e);
465
    public Address getShippingAddress(Order order) {
465
		}
466
        Address address = new Address();
466
		return null;
467
        address.setLine1(order.getCustomer_address1());
467
	}
468
        address.setLine2(order.getCustomer_address2());
468
 
469
        address.setCity(order.getCustomer_city());
469
	public Address getShippingAddress(Order order) {
470
        address.setState(order.getCustomer_state());
470
		Address address = new Address();
471
        address.setPin(order.getCustomer_pincode());
471
		address.setLine1(order.getCustomer_address1());
472
        return address;
472
		address.setLine2(order.getCustomer_address2());
473
    }
473
		address.setCity(order.getCustomer_city());
474
 
474
		address.setState(order.getCustomer_state());
475
    public String getPaymentMethod(List<Attribute> paymentAttributes) {
475
		address.setPin(order.getCustomer_pincode());
476
        String paymentMethod = null;
476
		return address;
477
        if (paymentAttributes == null || paymentAttributes.isEmpty()) {
477
	}
478
            return "N/A";
478
 
479
        }
479
	public String getPaymentMethod(List<Attribute> paymentAttributes) {
480
        for (Attribute a : paymentAttributes) {
480
		String paymentMethod = null;
481
            if ("payMethod".equals(a.getName())) {
481
		if (paymentAttributes == null || paymentAttributes.isEmpty()) {
482
                paymentMethod = Constants.PAYMENT_METHOD.get(a.getValue());
482
			return "N/A";
483
                break;
483
		}
484
            }
484
		for (Attribute a : paymentAttributes) {
485
        }
485
			if ("payMethod".equals(a.getName())) {
486
        return paymentMethod != null ? paymentMethod : "N/A";
486
				paymentMethod = Constants.PAYMENT_METHOD.get(a.getValue());
487
    }
487
				break;
488
 
488
			}
489
    public void setOrderId(String orderId) {
489
		}
490
        try {
490
		return paymentMethod != null ? paymentMethod : "N/A";
491
            this.orderId = Long.parseLong(orderId);
491
	}
492
        } catch (NumberFormatException e) {
492
 
493
            log.error(e);
493
	public void setOrderId(String orderId) {
494
        }
494
		try {
495
    }
495
			this.orderId = Long.parseLong(orderId);
496
 
496
		} catch (NumberFormatException e) {
497
    public List<Payment> getPayments() {
497
			log.error(e);
498
        return payments;
498
		}
499
    }
499
	}
500
 
500
 
501
    public List<ShipmentUpdate> getShipmentUpdates() {
501
	public List<Payment> getPayments() {
502
        return shipmentUpdates;
502
		return payments;
503
    }
503
	}
504
 
504
 
505
    public void setShipmentUpdates(List<ShipmentUpdate> shipmentUpdates) {
505
	public List<ShipmentUpdate> getShipmentUpdates() {
506
        this.shipmentUpdates = shipmentUpdates;
506
		return shipmentUpdates;
507
    }
507
	}
508
 
508
 
509
    public Order getOrder() {
509
	public void setShipmentUpdates(List<ShipmentUpdate> shipmentUpdates) {
510
        return order;
510
		this.shipmentUpdates = shipmentUpdates;
511
    }
511
	}
512
 
512
 
513
    public void setOrder(Order order) {
513
	public Order getOrder() {
514
        this.order = order;
514
		return order;
515
    }
515
	}
516
 
516
 
517
    public Long getCodTicketId() {
517
	public void setOrder(Order order) {
518
        return codTicketId;
518
		this.order = order;
519
    }
519
	}
520
 
520
 
521
    public void setCodTicketId(Long codTicketId) {
521
	public Long getCodTicketId() {
522
        this.codTicketId = codTicketId;
522
		return codTicketId;
523
    }
523
	}
524
 
524
 
525
    public List<Address> getAddresses() {
525
	public void setCodTicketId(Long codTicketId) {
526
        return addresses;
526
		this.codTicketId = codTicketId;
527
    }
527
	}
528
 
528
 
529
    public void setAddresses(List<Address> addresses) {
529
	public List<Address> getAddresses() {
530
        this.addresses = addresses;
530
		return addresses;
531
    }
531
	}
532
    
532
 
533
    public String getOrderStatusDescription(Order order) {
533
	public void setAddresses(List<Address> addresses) {
534
        String status = order.getStatus().getDescription();
534
		this.addresses = addresses;
535
 
535
	}
536
        if (order.getStatus() == OrderStatus.DELIVERY_SUCCESS) {
536
 
537
            status = "Completed";
537
	public String getOrderStatusDescription(Order order) {
538
        }
538
		String status = order.getStatus().getDescription();
539
 
539
 
540
        return status;
540
		if (order.getStatus() == OrderStatus.DELIVERY_SUCCESS) {
541
    }
541
			status = "Completed";
542
 
542
		}
543
    public String getCancellationInitiator() {
543
 
544
        return cancellationInitiator;
544
		return status;
545
    }
545
	}
546
 
546
 
547
    public void setCancellationInitiator(String cancellationInitiator) {
547
	public String getCancellationInitiator() {
548
        this.cancellationInitiator = cancellationInitiator;
548
		return cancellationInitiator;
549
    }
549
	}
550
 
550
 
551
    public String getCancelReason() {
551
	public void setCancellationInitiator(String cancellationInitiator) {
552
        return cancelReason;
552
		this.cancellationInitiator = cancellationInitiator;
553
    }
553
	}
554
 
554
 
555
    public void setCancelReason(String cancelReason) {
555
	public String getCancelReason() {
556
        this.cancelReason = cancelReason;
556
		return cancelReason;
557
    }
557
	}
558
 
558
 
559
    public String getBody() {
559
	public void setCancelReason(String cancelReason) {
560
        return body;
560
		this.cancelReason = cancelReason;
561
    }
561
	}
562
 
562
 
563
    public void setBody(String body) {
563
	public String getBody() {
564
        this.body = body;
564
		return body;
565
    }
565
	}
566
 
566
 
567
    public String getLine1() {
567
	public void setBody(String body) {
568
        return line1;
568
		this.body = body;
569
    }
569
	}
570
 
570
 
571
    public void setLine1(String line1) {
571
	public String getLine1() {
572
        this.line1 = line1;
572
		return line1;
573
    }
573
	}
574
 
574
 
575
    public String getLine2() {
575
	public void setLine1(String line1) {
576
        return line2;
576
		this.line1 = line1;
577
    }
577
	}
578
 
578
 
579
    public void setLine2(String line2) {
579
	public String getLine2() {
580
        this.line2 = line2;
580
		return line2;
581
    }
581
	}
582
 
582
 
583
    public String getCity() {
583
	public void setLine2(String line2) {
584
        return city;
584
		this.line2 = line2;
585
    }
585
	}
586
 
586
 
587
    public void setCity(String city) {
587
	public String getCity() {
588
        this.city = city;
588
		return city;
589
    }
589
	}
590
 
590
 
591
    public String getState() {
591
	public void setCity(String city) {
592
        return state;
592
		this.city = city;
593
    }
593
	}
594
 
594
 
595
    public void setState(String state) {
595
	public String getState() {
596
        this.state = state;
596
		return state;
597
    }
597
	}
598
 
598
 
599
    public String getPin() {
599
	public void setState(String state) {
600
        return pin;
600
		this.state = state;
601
    }
601
	}
602
 
602
 
603
    public void setPin(String pin) {
603
	public String getPin() {
604
        this.pin = pin;
604
		return pin;
605
    }
605
	}
-
 
606
 
-
 
607
	public void setPin(String pin) {
-
 
608
		this.pin = pin;
-
 
609
	}
606
 
610
 
607
	public String getFreebieItem() {
611
	public String getFreebieItem() {
608
		return freebieItem;
612
		return freebieItem;
609
	}
613
	}
610
 
614
 
Line 633... Line 637...
633
	}
637
	}
634
 
638
 
635
	public void setFreebieOrderId(String freebieOrderId) {
639
	public void setFreebieOrderId(String freebieOrderId) {
636
		this.freebieOrderId = freebieOrderId;
640
		this.freebieOrderId = freebieOrderId;
637
	}
641
	}
638
	
642
 
639
}
643
}
640
644