Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
2674 vikas 1
package in.shop2020.serving.controllers;
2
 
7065 kshitij.so 3
import in.shop2020.config.ConfigException;
4689 anupam.sin 4
import in.shop2020.crm.Activity;
5
import in.shop2020.crm.ActivityType;
3578 mandeep.dh 6
import in.shop2020.crm.SearchFilter;
7
import in.shop2020.crm.Ticket;
8
import in.shop2020.crm.TicketCategory;
4689 anupam.sin 9
import in.shop2020.crm.TicketPriority;
3578 mandeep.dh 10
import in.shop2020.crm.TicketStatus;
7826 manish.sha 11
import in.shop2020.logistics.LogisticsServiceException;
5845 mandeep.dh 12
import in.shop2020.logistics.PickupStore;
7826 manish.sha 13
import in.shop2020.logistics.Provider;
7190 amar.kumar 14
import in.shop2020.model.v1.catalog.CatalogService;
15
import in.shop2020.model.v1.catalog.CatalogServiceException;
16
import in.shop2020.model.v1.catalog.Item;
7826 manish.sha 17
import in.shop2020.model.v1.order.AmazonOrder;
7399 anupam.sin 18
import in.shop2020.model.v1.order.HotspotStore;
2674 vikas 19
import in.shop2020.model.v1.order.LineItem;
20
import in.shop2020.model.v1.order.Order;
3578 mandeep.dh 21
import in.shop2020.model.v1.order.OrderStatus;
7393 anupam.sin 22
import in.shop2020.model.v1.order.StoreOrderDetail;
4689 anupam.sin 23
import in.shop2020.model.v1.order.TransactionServiceException;
4142 mandeep.dh 24
import in.shop2020.model.v1.user.Address;
4689 anupam.sin 25
import in.shop2020.model.v1.user.UserContextException;
2728 vikas 26
import in.shop2020.payments.Attribute;
27
import in.shop2020.payments.Constants;
2674 vikas 28
import in.shop2020.payments.Payment;
2728 vikas 29
import in.shop2020.payments.PaymentException;
4142 mandeep.dh 30
import in.shop2020.payments.PaymentService.Client;
4689 anupam.sin 31
import in.shop2020.serving.auth.CRMAuthorizingRealm;
3090 mandeep.dh 32
import in.shop2020.serving.model.ShipmentUpdate;
5845 mandeep.dh 33
import in.shop2020.serving.services.AramexTrackingService;
3090 mandeep.dh 34
import in.shop2020.serving.services.BlueDartTrackingService;
5303 phani.kuma 35
import in.shop2020.serving.services.DelhiveryTrackingService;
7200 kshitij.so 36
import in.shop2020.serving.services.RedExpressTrackingService;
3578 mandeep.dh 37
import in.shop2020.thrift.clients.CRMClient;
7190 amar.kumar 38
import in.shop2020.thrift.clients.CatalogClient;
6322 amar.kumar 39
import in.shop2020.thrift.clients.HelperClient;
5845 mandeep.dh 40
import in.shop2020.thrift.clients.LogisticsClient;
3128 rajveer 41
import in.shop2020.thrift.clients.PaymentClient;
42
import in.shop2020.thrift.clients.TransactionClient;
4142 mandeep.dh 43
import in.shop2020.thrift.clients.UserClient;
7065 kshitij.so 44
import in.shop2020.thrift.clients.config.ConfigClient;
3546 mandeep.dh 45
import in.shop2020.utils.ModelUtils;
6322 amar.kumar 46
import in.shop2020.warehouse.WarehouseService;
2674 vikas 47
 
6322 amar.kumar 48
import java.io.BufferedInputStream;
49
import java.io.File;
50
import java.io.FileInputStream;
51
import java.io.FileWriter;
52
import java.io.IOException;
53
import java.io.InputStream;
6912 anupam.sin 54
import java.text.SimpleDateFormat;
2674 vikas 55
import java.util.ArrayList;
6912 anupam.sin 56
import java.util.Calendar;
4416 mandeep.dh 57
import java.util.Collections;
6912 anupam.sin 58
import java.util.Date;
7836 anupam.sin 59
import java.util.HashMap;
4689 anupam.sin 60
import java.util.HashSet;
2674 vikas 61
import java.util.List;
7836 anupam.sin 62
import java.util.Map;
4689 anupam.sin 63
import java.util.Set;
4416 mandeep.dh 64
import java.util.concurrent.Callable;
65
import java.util.concurrent.Executors;
66
import java.util.concurrent.TimeUnit;
2674 vikas 67
 
6322 amar.kumar 68
import javax.servlet.ServletOutputStream;
69
 
4689 anupam.sin 70
import net.htmlparser.jericho.Source;
71
 
5845 mandeep.dh 72
import org.apache.commons.lang.StringUtils;
2674 vikas 73
import org.apache.log4j.Logger;
2728 vikas 74
import org.apache.thrift.TException;
4142 mandeep.dh 75
import org.apache.thrift.transport.TTransportException;
2674 vikas 76
 
77
/**
78
 * @author vikas
3578 mandeep.dh 79
 * 
2674 vikas 80
 */
81
@SuppressWarnings("serial")
82
public class UserOrderInfoController extends BaseController {
7372 kshitij.so 83
	private static Logger                  log                     = Logger.getLogger(Class.class);
84
	private static BlueDartTrackingService blueDartTrackingService = new BlueDartTrackingService();
85
	private static AramexTrackingService aramexTrackingService     = new AramexTrackingService();
86
	private static DelhiveryTrackingService delhiveryTrackingService     = new DelhiveryTrackingService();
87
	private static RedExpressTrackingService redexpressTrackingService = new RedExpressTrackingService();
3090 mandeep.dh 88
 
7372 kshitij.so 89
	private long                 orderId;
90
	private Order                order;
91
	private List<Payment>        payments;
92
	private List<ShipmentUpdate> shipmentUpdates = new ArrayList<ShipmentUpdate>();
93
	private Long                 codTicketId;
94
	private List<Address>        addresses;
95
	private Set<OrderStatus>     setOfcancellableStates;
96
	private String               cancellationInitiator;
97
	private String               cancelReason;
98
	private String               body;
99
	private String               line1;
100
	private String               line2;
101
	private String               city;
102
	private String               state;
103
	private String               pin;
104
	private String				 freebieItem;
105
	private String				 dealText;
106
	private String 				 parentOrderIdForFreebieOrder;
107
	private String				 freebieOrderId;
7393 anupam.sin 108
	private double               cashAmount;
109
	private double               cardAmount;
110
    private StoreOrderDetail     storeOrderDetail;
7826 manish.sha 111
    //Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
7830 anupam.sin 112
    private AmazonOrder          amazonOrder = null;
7836 anupam.sin 113
    private String               providerName = "N/A";
7826 manish.sha 114
    //End:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
2674 vikas 115
 
7372 kshitij.so 116
	public UserOrderInfoController() {
117
		super();
118
		setOfcancellableStates = new HashSet<OrderStatus>();
119
		setOfcancellableStates.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
120
		setOfcancellableStates.add(OrderStatus.INVENTORY_LOW);
121
		setOfcancellableStates.add(OrderStatus.LOW_INV_PO_RAISED);
122
		setOfcancellableStates.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);
123
		setOfcancellableStates.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);
124
		setOfcancellableStates.add(OrderStatus.ACCEPTED);
125
		setOfcancellableStates.add(OrderStatus.BILLED);
126
	}
7836 anupam.sin 127
 
128
	public static final Map<Long, String> providerNameMap = new HashMap<Long, String>() {
129
        {
130
            put(1l, "BlueDart");
131
            put(2l, "Aramex");
132
            put(3l, "Delhivery");
133
            put(4l, "SelfPickup");
134
            put(5l, "Runner");
135
            put(6l, "RedExpress");
136
        }
137
	};
138
 
7372 kshitij.so 139
	public String index() {
140
		try {
141
			PaymentClient paymentServiceClient = new PaymentClient();
142
			TransactionClient transactionServiceClient = new TransactionClient();
7826 manish.sha 143
			LogisticsClient logisticsServiceClient = new LogisticsClient();
144
 
7372 kshitij.so 145
			order = transactionServiceClient.getClient().getOrder(orderId);
7826 manish.sha 146
			//Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
7830 anupam.sin 147
			try {
148
			    amazonOrder = transactionServiceClient.getClient().getAmazonOrder(orderId);
149
			} catch (Exception e) {
150
			    log.error("No Amazon order found with orderId " + orderId, e);
151
			}
7836 anupam.sin 152
			if (order.getLogistics_provider_id() > 0) {
153
			    setProviderName(providerNameMap.get(order.getLogistics_provider_id()));
154
			}
7826 manish.sha 155
			//End:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
7393 anupam.sin 156
			if(order.getSource() == 2) {
157
    			storeOrderDetail = transactionServiceClient.getClient().getStoreOrderDetail(order.getId(),order.getStoreId());
7399 anupam.sin 158
    			if(order.getStatus().getValue() == 15 || order.getStatus().getValue() == 34) {
159
    			    setCashAmount(storeOrderDetail.getCashRefundAmount());
160
                    setCardAmount(storeOrderDetail.getCardRefundAmount()); 
161
    			} else {
162
        			setCashAmount(storeOrderDetail.getCashAmount());
163
        			setCardAmount(storeOrderDetail.getCardAmount());
164
    			}
7393 anupam.sin 165
			}
7372 kshitij.so 166
			if(order.getFreebieItemId()>0) {
167
				CatalogService.Client catalogClient = new CatalogClient().getClient();
168
				Item item = catalogClient.getItem(order.getFreebieItemId());
169
				freebieItem = item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + " " + item.getColor();
170
			}
3090 mandeep.dh 171
 
7372 kshitij.so 172
			if(order.getLineitems().get(0).getDealText()!=null && !order.getLineitems().get(0).getDealText().isEmpty()) {
173
				dealText = order.getLineitems().get(0).getDealText();
174
			}
175
			List<in.shop2020.model.v1.order.Attribute> attributes = 
176
				transactionServiceClient.getClient().getAllAttributesForOrderId(orderId);
3578 mandeep.dh 177
 
7372 kshitij.so 178
			for(in.shop2020.model.v1.order.Attribute attribute: attributes){
179
				if(attribute.getName().equals("parentOrderIdForFreebie")){
180
					parentOrderIdForFreebieOrder = attribute.getValue();
181
				} else if (attribute.getName().equals("freebieOrderId")){
182
					freebieOrderId = attribute.getValue();
183
				}
184
			}
4689 anupam.sin 185
 
7372 kshitij.so 186
			payments = paymentServiceClient.getClient()
187
			.getPaymentForTxnId(order.getTransactionId());
4689 anupam.sin 188
 
4416 mandeep.dh 189
 
3578 mandeep.dh 190
 
7372 kshitij.so 191
			// Spawning a thread to capture shipment updates from Bluedart
192
			// This is done to ensure that response from Crm web app is sent
193
			// within given time limits. Also, we wont be affected in the cases 
194
			// where bluedart site is down or slow
195
			Executors.newSingleThreadExecutor().invokeAll(Collections.singletonList(new Callable<Boolean>() {
196
				public Boolean call() throws Exception {
197
					if (order.getLogistics_provider_id() == 1)
198
						shipmentUpdates = blueDartTrackingService.getUpdates(order.getAirwaybill_no());
199
					else if (order.getLogistics_provider_id() == 2) {
200
						shipmentUpdates = aramexTrackingService.getUpdates(order.getAirwaybill_no());
201
					}
202
					else if (order.getLogistics_provider_id() == 3) {
203
						shipmentUpdates = delhiveryTrackingService.getUpdates(order.getAirwaybill_no());
204
					}
205
					else if (order.getLogistics_provider_id() == 6) {
206
						shipmentUpdates = redexpressTrackingService.getUpdates(order.getAirwaybill_no());
207
					}
208
					else {
209
						shipmentUpdates = new ArrayList<ShipmentUpdate>();
210
						log.error("Error : providerId = " + order.getLogistics_provider_id() + "for orderId : " + order.getId());
211
					}
212
					return true;
213
				}
214
			}), 60, TimeUnit.SECONDS);
2674 vikas 215
 
7372 kshitij.so 216
			if (order.isCod() && OrderStatus.COD_VERIFICATION_PENDING.equals(order.getStatus())) {
217
				populateCODTicketId(order.getCustomer_id());
218
			}
4142 mandeep.dh 219
 
7372 kshitij.so 220
			if (canEditOrderAddress()) {
221
				userContextServiceClient = new UserClient().getClient();
222
				addresses = userContextServiceClient.getAllAddressesForUser(order.getCustomer_id());
223
			}
3578 mandeep.dh 224
 
7372 kshitij.so 225
		} catch (TTransportException e) {
226
			log.error("Unable to create thrift Client", e);
227
		} catch (TransactionServiceException e) {
228
			addActionError("Invalid order id or no order selected.");
229
		} catch (TException e) {
230
			log.error("Unable to get thrift Client", e);
231
		} catch (PaymentException e) {
232
			log.error("Unable to get payments for transctionId : " + order.getTransactionId(), e);
233
		} catch (InterruptedException e) {
234
			log.error("Thread was interrupted", e);
235
		} catch (UserContextException e) {
236
			log.error("Unable to get addresses for user : " + order.getCustomer_id(), e);
237
		} catch(CatalogServiceException csex) {
238
			log.error("Unable to get item details for itemId: " + order.getFreebieItemId(), csex);
239
		}
240
		return INDEX;
241
	}
4689 anupam.sin 242
 
7372 kshitij.so 243
	private boolean canEditOrderAddress() {
244
		return false;
245
	}
4689 anupam.sin 246
 
7372 kshitij.so 247
	private void populateCODTicketId(long customerId) {
248
		try {
249
			SearchFilter searchFilter = new SearchFilter();
250
			searchFilter.setTicketCategory(TicketCategory.COD_VERIFICATION);
251
			searchFilter.setTicketStatuses(new ArrayList<TicketStatus>());
252
			searchFilter.getTicketStatuses().add(TicketStatus.OPEN);
253
			searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);
254
			searchFilter.setCustomerId(customerId);
255
			crmServiceClient = new CRMClient().getClient();
256
			List<Ticket> tickets = crmServiceClient.getTickets(searchFilter);
257
			if (tickets != null && !tickets.isEmpty()) {
258
				codTicketId = tickets.get(0).getId();
259
			}
260
		} catch (TException e) {
261
			log.error("Error fetching tickets for customerId: " + customerId, e);
262
		}
263
	}
4689 anupam.sin 264
 
7372 kshitij.so 265
	public String markOrderForCancellation() {
266
		try{
267
			TransactionClient transactionServiceClient = new TransactionClient();
268
			log.info("URL = " + request.getRequestURI());
269
			log.info("Initiator = " + request.getParameter("cancellationInitiator"));
270
			log.info("orderId = " + request.getParameter("orderId"));
7393 anupam.sin 271
 
272
			order = transactionServiceClient.getClient().getOrder(orderId);
273
 
7499 anupam.sin 274
			/**
275
			 * If the order is from store then refund the order directly.
276
			 */
7393 anupam.sin 277
			if (order.getSource() == 2) {
278
			    String plainTextbody = "";
279
			    if(body!=null && !body.isEmpty()){
280
                    plainTextbody = new Source(body).getTextExtractor().toString();
281
                }
7612 anupam.sin 282
 
283
			    if(cashAmount + cardAmount > order.getAdvanceAmount()) {
284
			        log.error("Could not mark order for Cancellation, OrderId : " + orderId);
285
			        return "index";
286
			    }
287
 
288
			    transactionServiceClient.getClient().saveRefundAmountsForStoreOrder(orderId, order.getStoreId(), cashAmount, cardAmount);
7399 anupam.sin 289
			    if (cancellationInitiator.equals("CUSTOMER")) {
290
			        transactionServiceClient.getClient().markOrderCancellationRequestReceived(orderId);
291
			        transactionServiceClient.getClient().markOrderCancellationRequestConfirmed(orderId);
292
			    }
7393 anupam.sin 293
			    transactionServiceClient.getClient().refundOrder(orderId, currentAgentEmailId, cancelReason + " : " + plainTextbody);
7499 anupam.sin 294
			} else {
295
		         if (cancellationInitiator.equals("CUSTOMER")) {
296
	                transactionServiceClient.getClient().markOrderCancellationRequestReceived(orderId);
297
	                long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
298
	                Ticket ticket = new Ticket();
299
	                String plainTextbody = "";
300
	                if(body!=null && !body.isEmpty()){
301
	                    plainTextbody = new Source(body).getTextExtractor().toString();
302
	                }
303
	                ticket.setDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
304
	                ticket.setCreatorId(creatorId);
305
	                ticket.setStatus(TicketStatus.OPEN);
306
	                ticket.setPriority(TicketPriority.HIGH);
307
	                ticket.setCategory(TicketCategory.ORDER_CANCELLATION);
308
	                ticket.setOrderId(orderId);
4689 anupam.sin 309
 
7499 anupam.sin 310
	                Activity activity = new Activity();
311
	                activity.setDescription("Creating Ticket");
312
	                activity.setType(ActivityType.OTHER);
313
	                activity.setTicketPriority(TicketPriority.HIGH);
314
	                activity.setTicketStatus(TicketStatus.OPEN);
315
	                activity.setCreatorId(creatorId);
316
	                activity.setTicketDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
317
	                activity.setTicketCategory(TicketCategory.ORDER_CANCELLATION);
4689 anupam.sin 318
 
7499 anupam.sin 319
	                ticket.setCustomerId(order.getCustomer_id());
320
	                activity.setCustomerId(order.getCustomer_id());
321
	                ticket.setCustomerName(order.getCustomer_name());
322
	                activity.setCustomerName(order.getCustomer_name());
323
	                ticket.setCustomerEmailId(order.getCustomer_email());
324
	                activity.setCustomerEmailId(order.getCustomer_email());
325
	                ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
326
	                activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
4689 anupam.sin 327
 
7499 anupam.sin 328
	                crmServiceClient = new CRMClient().getClient();
329
	                crmServiceClient.insertTicket(ticket, activity);
330
	            } 
331
	            else if (cancellationInitiator.equals("INTERNAL")) {
332
	                String plainTextbody = "";
333
	                if(body!=null && !body.isEmpty()){
334
	                    plainTextbody = new Source(body).getTextExtractor().toString();
335
	                }
336
	                boolean status_returned = transactionServiceClient.getClient().refundOrder(orderId, currentAgentEmailId, cancelReason + " : " + plainTextbody);
337
	                if (status_returned) {
338
	                    order = transactionServiceClient.getClient().getOrder(orderId);
339
	                    long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
340
	                    Ticket ticket = new Ticket();
341
	                    ticket.setDescription("Creating ticket for Order Cancellation due to Low inventory");
342
	                    ticket.setCreatorId(creatorId);
343
	                    ticket.setAssigneeId(36);
344
	                    ticket.setStatus(TicketStatus.OPEN);
345
	                    ticket.setPriority(TicketPriority.MEDIUM);
346
	                    ticket.setCategory(TicketCategory.LOW_INVENTORY_CANCELLED_ORDERS);
347
	                    ticket.setOrderId(orderId);
348
	                    ticket.setCustomerId(order.getCustomer_id());
349
	                    ticket.setCustomerName(order.getCustomer_name());
350
	                    ticket.setCustomerEmailId(order.getCustomer_email());
351
	                    ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
6322 amar.kumar 352
 
7499 anupam.sin 353
	                    Activity activity = new Activity();
354
	                    activity.setDescription("Creating Ticket");
355
	                    activity.setType(ActivityType.OTHER);
356
	                    activity.setTicketPriority(TicketPriority.MEDIUM);
357
	                    activity.setTicketStatus(TicketStatus.OPEN);
358
	                    activity.setCreatorId(creatorId);
359
	                    activity.setTicketAssigneeId(36);
360
	                    activity.setTicketCategory(TicketCategory.LOW_INVENTORY_CANCELLED_ORDERS);
361
	                    activity.setTicketDescription("Creating ticket for Order Cancellation due to Low inventory");
362
	                    activity.setCustomerId(order.getCustomer_id());
363
	                    activity.setCustomerName(order.getCustomer_name());
364
	                    activity.setCustomerEmailId(order.getCustomer_email());
365
	                    activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
6322 amar.kumar 366
 
7499 anupam.sin 367
	                    crmServiceClient = new CRMClient().getClient();
368
	                    crmServiceClient.insertTicket(ticket, activity);
369
	                }
370
	            }
7372 kshitij.so 371
			}
372
		} catch(Exception e) {
373
			log.error("Could not mark order for Cancellation, OrderId : " + orderId, e);
374
		}
375
		return index();
376
	}
7221 kshitij.so 377
 
7372 kshitij.so 378
	public void getOrderConfirmationMail() throws IOException, TException, ConfigException, TransactionServiceException {
379
		TransactionClient transactionServiceClient = new TransactionClient();
380
		order = transactionServiceClient.getClient().getOrder(orderId);
381
		long source = order.getTransactionId();
382
		HelperClient helperClient = new HelperClient("helper_service_server","helper_service_server_port");
383
		String mail = helperClient.getClient().getOrderConfirmationMail(source);
384
		File file = new File("/tmp/temp");
7643 manish.sha 385
		//Start:- Added by Manish Sharma for resolving Exception for getting order delivery and confirmation mail on 27-Jun-2013
386
		if(mail.isEmpty() || mail==null || mail=="")
387
			mail="<html><body><p>Sorry, Required e-mail for mentioned order does not exist in the system !!!</p></body></html>";
388
		//End:- Added by Manish Sharma for resolving Exception for getting order delivery and confirmation mail on 27-Jun-2013
7221 kshitij.so 389
 
7372 kshitij.so 390
		FileWriter writer = new FileWriter(file);
391
		writer.append(mail);
392
		writer.close();
4689 anupam.sin 393
 
7372 kshitij.so 394
		byte[] buffer = new byte[(int)file.length()];
395
		InputStream input = null;
396
		try {
397
			int totalBytesRead = 0;
398
			input = new BufferedInputStream(new FileInputStream(file));
399
			while(totalBytesRead < buffer.length){
400
				int bytesRemaining = buffer.length - totalBytesRead;
401
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
402
				if (bytesRead > 0){
403
					totalBytesRead = totalBytesRead + bytesRead;
404
				}
405
			}
406
		}
407
		finally {
408
			input.close();
409
			file.delete();
410
		}
3578 mandeep.dh 411
 
4142 mandeep.dh 412
 
7372 kshitij.so 413
		response.setHeader("Content-disposition", "inline; filename=" + "OrderDetail_"+orderId );
2674 vikas 414
 
7372 kshitij.so 415
		ServletOutputStream sos;
416
		try {
417
			sos = response.getOutputStream();
418
			sos.write(buffer);
419
			sos.flush();
420
		} catch (IOException e) {
421
			System.out.println("Unable to stream the manifest file");
422
		}   
423
	}
4142 mandeep.dh 424
 
7372 kshitij.so 425
	public void getOrderDeliveryMail() throws IOException, TException, ConfigException, TransactionServiceException {
426
		HelperClient helperClient = new HelperClient("helper_service_server","helper_service_server_port");
427
		String mail = helperClient.getClient().getOrderDeliveryMail(orderId);
428
		File file = new File("/tmp/temp");
7643 manish.sha 429
		//Start:- Added by Manish Sharma for resolving Exception for getting order delivery and confirmation mail on 27-Jun-2013
430
		if(mail.isEmpty() || mail==null || mail=="")
431
			mail="<html><body><p>Sorry, Required e-mail for mentioned order does not exist in the system anymore !!!</p></body></html>";
432
		//End:- Added by Manish Sharma for resolving Exception for getting order delivery and confirmation mail on 27-Jun-2013
7372 kshitij.so 433
		FileWriter writer = new FileWriter(file);
434
		writer.append(mail);
435
		writer.close();
2674 vikas 436
 
7372 kshitij.so 437
		byte[] buffer = new byte[(int)file.length()];
438
		InputStream input = null;
439
		try {
440
			int totalBytesRead = 0;
441
			input = new BufferedInputStream(new FileInputStream(file));
442
			while(totalBytesRead < buffer.length){
443
				int bytesRemaining = buffer.length - totalBytesRead;
444
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
445
				if (bytesRead > 0){
446
					totalBytesRead = totalBytesRead + bytesRead;
447
				}
448
			}
449
		}
450
		finally {
451
			input.close();
452
			file.delete();
453
		}
3578 mandeep.dh 454
 
5845 mandeep.dh 455
 
7372 kshitij.so 456
		response.setHeader("Content-disposition", "inline; filename=" + "OrderDetail_"+orderId );
4142 mandeep.dh 457
 
7372 kshitij.so 458
		ServletOutputStream sos;
459
		try {
460
			sos = response.getOutputStream();
461
			sos.write(buffer);
462
			sos.flush();
463
		} catch (IOException e) {
464
			System.out.println("Unable to stream the manifest file");
465
		}   
466
	}
2674 vikas 467
 
7372 kshitij.so 468
	public boolean canOrderBeCancelled() {
469
		if (setOfcancellableStates.contains(order.getStatus())) {
470
			return true;
471
		}
472
		return false;
473
	}
2674 vikas 474
 
7372 kshitij.so 475
	public String getPaymentGateway(Payment payment) {
476
		String gatewayName = "";
2674 vikas 477
 
7372 kshitij.so 478
		try {
479
			Client paymentServiceClient = new PaymentClient().getClient();
480
			gatewayName = paymentServiceClient.getPaymentGateway(payment.getGatewayId()).getName();
481
		} catch (TTransportException e) {
482
		} catch (PaymentException e) {
483
		} catch (TException e) {
484
		}
3090 mandeep.dh 485
 
7372 kshitij.so 486
		return gatewayName;
487
	}
3499 mandeep.dh 488
 
7372 kshitij.so 489
	public int convertDouble(double value) {
490
		return (int)value;
491
	}
4142 mandeep.dh 492
 
7372 kshitij.so 493
	public String getInsuranceExpiryDate(long DeliveryDate) {
494
		if (DeliveryDate == 0) {
495
			return "N/A";
496
		}
497
		Calendar cal = Calendar.getInstance();
498
		cal.setTimeInMillis(DeliveryDate);
499
		cal.add(Calendar.YEAR, 1);
500
		SimpleDateFormat sdf = new SimpleDateFormat("dd MMM, yyyy");
501
		return sdf.format(cal.getTime());
502
	}
4142 mandeep.dh 503
 
7372 kshitij.so 504
	public String getShippingAddressOfStore(long storeId) {
505
		try {
506
			in.shop2020.logistics.LogisticsService.Client client = new LogisticsClient().getClient();
507
			PickupStore store = client.getPickupStore(storeId);
508
			return StringUtils.join(new String[] {
509
					store.getName(),
510
					store.getLine1(),
511
					store.getLine2(),
512
					store.getPin(),
513
					store.getCity(),
514
					store.getState(),
515
					store.getPhone()}, ",");
516
		} catch (Exception e) {
517
			return "";
518
		}
519
	}
4241 anupam.sin 520
 
7372 kshitij.so 521
	public String getAddress(Order order) {
522
		return ModelUtils.extractAddressFromOrder(order);
523
	}
4241 anupam.sin 524
 
7372 kshitij.so 525
	public String changeShippingAddress() {
526
		try {
527
			TransactionClient transactionServiceClient = new TransactionClient();
528
			transactionServiceClient.getClient().changeShippingAddress(orderId, line1, line2, city, state, pin);
529
		} catch(Exception e) {
530
			log.error("Unable to update address for orderId : " + orderId + "and address : " + 
531
					line1 + ", " + line2+ ", " + city + ", " + state + ", " + pin, e);
532
		}
533
		return null;
534
	}
7399 anupam.sin 535
 
7730 anupam.sin 536
	public String convertStoreToNormal() {
537
	    try{
538
	        TransactionClient transactionServiceClient = new TransactionClient();
539
	        transactionServiceClient.getClient().convertStoreToNormal(orderId);
540
	    } catch(Exception e) {
541
	        log.error("Unable to convert to normal order", e);
542
	    }
543
	    return null;
544
	}
545
 
7399 anupam.sin 546
	public String getStoreDetails(long storeId) {
547
	    try {
548
	        TransactionClient tcl = new TransactionClient();
549
	        HotspotStore store = tcl.getClient().getHotspotStore(storeId, "");
550
	        return store.getHotspotId() + " - " + store.getCity(); 
551
	    } catch (Exception e) {
552
	        log.error("Unable to get hostspotStore for id : " + storeId, e);
553
	    }
554
	    return "N/A";
555
	}
4689 anupam.sin 556
 
7372 kshitij.so 557
	public Address getShippingAddress(Order order) {
558
		Address address = new Address();
559
		address.setLine1(order.getCustomer_address1());
560
		address.setLine2(order.getCustomer_address2());
561
		address.setCity(order.getCustomer_city());
562
		address.setState(order.getCustomer_state());
563
		address.setPin(order.getCustomer_pincode());
564
		return address;
565
	}
4689 anupam.sin 566
 
7372 kshitij.so 567
	public String getPaymentMethod(List<Attribute> paymentAttributes) {
568
		String paymentMethod = null;
569
		if (paymentAttributes == null || paymentAttributes.isEmpty()) {
570
			return "N/A";
571
		}
572
		for (Attribute a : paymentAttributes) {
573
			if ("payMethod".equals(a.getName())) {
574
				paymentMethod = Constants.PAYMENT_METHOD.get(a.getValue());
575
				break;
576
			}
577
		}
578
		return paymentMethod != null ? paymentMethod : "N/A";
579
	}
4689 anupam.sin 580
 
7372 kshitij.so 581
	public void setOrderId(String orderId) {
582
		try {
583
			this.orderId = Long.parseLong(orderId);
584
		} catch (NumberFormatException e) {
585
			log.error(e);
586
		}
587
	}
4689 anupam.sin 588
 
7372 kshitij.so 589
	public List<Payment> getPayments() {
590
		return payments;
591
	}
4689 anupam.sin 592
 
7372 kshitij.so 593
	public List<ShipmentUpdate> getShipmentUpdates() {
594
		return shipmentUpdates;
595
	}
4689 anupam.sin 596
 
7372 kshitij.so 597
	public void setShipmentUpdates(List<ShipmentUpdate> shipmentUpdates) {
598
		this.shipmentUpdates = shipmentUpdates;
599
	}
6985 anupam.sin 600
 
7372 kshitij.so 601
	public Order getOrder() {
602
		return order;
603
	}
6985 anupam.sin 604
 
7372 kshitij.so 605
	public void setOrder(Order order) {
606
		this.order = order;
607
	}
6985 anupam.sin 608
 
7372 kshitij.so 609
	public Long getCodTicketId() {
610
		return codTicketId;
611
	}
6985 anupam.sin 612
 
7372 kshitij.so 613
	public void setCodTicketId(Long codTicketId) {
614
		this.codTicketId = codTicketId;
615
	}
6985 anupam.sin 616
 
7372 kshitij.so 617
	public List<Address> getAddresses() {
618
		return addresses;
619
	}
6985 anupam.sin 620
 
7372 kshitij.so 621
	public void setAddresses(List<Address> addresses) {
622
		this.addresses = addresses;
623
	}
6985 anupam.sin 624
 
7372 kshitij.so 625
	public String getOrderStatusDescription(Order order) {
626
		String status = order.getStatus().getDescription();
6985 anupam.sin 627
 
7372 kshitij.so 628
		if (order.getStatus() == OrderStatus.DELIVERY_SUCCESS) {
629
			status = "Completed";
630
		}
6985 anupam.sin 631
 
7372 kshitij.so 632
		return status;
633
	}
6985 anupam.sin 634
 
7372 kshitij.so 635
	public String getCancellationInitiator() {
636
		return cancellationInitiator;
637
	}
7190 amar.kumar 638
 
7372 kshitij.so 639
	public void setCancellationInitiator(String cancellationInitiator) {
640
		this.cancellationInitiator = cancellationInitiator;
641
	}
642
 
643
	public String getCancelReason() {
644
		return cancelReason;
645
	}
646
 
647
	public void setCancelReason(String cancelReason) {
648
		this.cancelReason = cancelReason;
649
	}
650
 
651
	public String getBody() {
652
		return body;
653
	}
654
 
655
	public void setBody(String body) {
656
		this.body = body;
657
	}
658
 
659
	public String getLine1() {
660
		return line1;
661
	}
662
 
663
	public void setLine1(String line1) {
664
		this.line1 = line1;
665
	}
666
 
667
	public String getLine2() {
668
		return line2;
669
	}
670
 
671
	public void setLine2(String line2) {
672
		this.line2 = line2;
673
	}
674
 
675
	public String getCity() {
676
		return city;
677
	}
678
 
679
	public void setCity(String city) {
680
		this.city = city;
681
	}
682
 
683
	public String getState() {
684
		return state;
685
	}
686
 
687
	public void setState(String state) {
688
		this.state = state;
689
	}
690
 
691
	public String getPin() {
692
		return pin;
693
	}
694
 
695
	public void setPin(String pin) {
696
		this.pin = pin;
697
	}
698
 
7190 amar.kumar 699
	public String getFreebieItem() {
700
		return freebieItem;
701
	}
702
 
703
	public void setFreebieItem(String freebieItem) {
704
		this.freebieItem = freebieItem;
705
	}
706
 
707
	public String getDealText() {
708
		return dealText;
709
	}
710
 
711
	public void setDealText(String dealText) {
712
		this.dealText = dealText;
713
	}
714
 
715
	public String getParentOrderIdForFreebieOrder() {
716
		return parentOrderIdForFreebieOrder;
717
	}
718
 
719
	public void setParentOrderIdForFreebieOrder(String parentOrderIdForFreebieOrder) {
720
		this.parentOrderIdForFreebieOrder = parentOrderIdForFreebieOrder;
721
	}
722
 
723
	public String getFreebieOrderId() {
724
		return freebieOrderId;
725
	}
726
 
727
	public void setFreebieOrderId(String freebieOrderId) {
728
		this.freebieOrderId = freebieOrderId;
729
	}
7372 kshitij.so 730
 
7393 anupam.sin 731
    public void setCashAmount(double cashAmount) {
732
        this.cashAmount = cashAmount;
733
    }
734
 
735
    public double getCashAmount() {
736
        return cashAmount;
737
    }
738
 
739
    public void setCardAmount(double cardAmount) {
740
        this.cardAmount = cardAmount;
741
    }
742
 
743
    public double getCardAmount() {
744
        return cardAmount;
745
    }
746
 
747
    public long getOrderId() {
748
        return orderId;
749
    }
750
 
751
    public void setOrderId(long orderId) {
752
        this.orderId = orderId;
753
    }
754
 
755
    public StoreOrderDetail getStoreOrderDetail() {
756
        return storeOrderDetail;
757
    }
758
 
759
    public void setStoreOrderDetail(StoreOrderDetail storeOrderDetail) {
760
        this.storeOrderDetail = storeOrderDetail;
761
    }
7826 manish.sha 762
 
763
  //Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
764
    public AmazonOrder getAmazonOrder() {
765
		return amazonOrder;
766
	}
7393 anupam.sin 767
 
7826 manish.sha 768
	public void setAmazonOrder(AmazonOrder amazonOrder) {
769
		this.amazonOrder = amazonOrder;
770
	}
771
 
772
	//End:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
773
 
7836 anupam.sin 774
    public void setProviderName(String providerName) {
775
        this.providerName = providerName;
776
    }
777
 
778
    public String getProviderName() {
779
        return providerName;
780
    }
781
 
782
    public static void main(String[] args) {
783
        System.out.println(providerNameMap.get(5l));
784
        System.out.println(providerNameMap.get(10l));
785
    }
786
 
2674 vikas 787
}