Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
493 rajveer 1
package in.shop2020.hotspot.dashbaord.server;
2
 
3
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
4
import in.shop2020.hotspot.dashbaord.shared.actions.OrderType;
5
import in.shop2020.model.v1.order.Alert;
914 chandransh 6
import in.shop2020.model.v1.order.LineItem;
493 rajveer 7
import in.shop2020.model.v1.order.OrderStatus;
8
import in.shop2020.model.v1.order.TransactionService.Client;
9
import in.shop2020.thrift.clients.TransactionServiceClient;
10
 
11
import java.util.ArrayList;
12
import java.util.Date;
13
import java.util.List;
14
 
2449 chandransh 15
/**
16
 * This class is a facade to the Transaction service and should be used to
17
 * access all order specific data.
18
 * 
19
 * @author Chandranshu
20
 * 
21
 */
493 rajveer 22
public class TransactionUtils {
2449 chandransh 23
	/**
24
	 * The human user is concerned only with a consolidated view of actionable
25
	 * orders. Orders with different statuses in the database can be part of the
26
	 * same consolidated view. This method uses a mapping of <i>type</i> to
27
	 * <i>status</i> to get all such orders and return them as order beans.
28
	 * 
29
	 * @param type
30
	 *            The type of orders to return.
31
	 * @param warehouseId
32
	 *            The warehouse for which the orders should be queried.
33
	 * @return A list of orders of the given type to be fulfilled from the given
34
	 *         warehouse
35
	 */
493 rajveer 36
	public static List<Order> getOrders(OrderType type, long warehouseId){
2449 chandransh 37
		List<OrderStatus> statuses = getStatuses(type);
493 rajveer 38
 
39
		List<Order> orders = new ArrayList<Order>();
40
		try{
41
			TransactionServiceClient client = new TransactionServiceClient();
42
			Client c = client.getClient();
43
 
44
			List<in.shop2020.model.v1.order.Order> t_orders = new ArrayList<in.shop2020.model.v1.order.Order>();
45
			if(statuses.isEmpty()){
46
				t_orders.addAll(c.getAllOrders(null, 0L, new Date().getTime(), warehouseId));
47
			}
48
			else {
49
				for(OrderStatus status: statuses){
50
					t_orders.addAll(c.getAllOrders(status, 0L, new Date().getTime(), warehouseId));
51
				}
52
			}
53
 
54
			for (in.shop2020.model.v1.order.Order t_order: t_orders){
671 chandransh 55
				Order o = getOrderFromThriftOrder(t_order);
493 rajveer 56
 
57
				orders.add(o);
58
				//check if it has an associated alert
59
				List<Alert> alerts = c.getAlerts(t_order.getId(), true);
2449 chandransh 60
				if(alerts != null && alerts.size() != 0){
61
					o.setAlert(true);
62
					o.setStatusMessage(alerts.iterator().next().getComment());
63
				} else {
493 rajveer 64
					o.setAlert(false);
65
				}
66
			}
67
		}catch(Exception e){
2449 chandransh 68
			e.printStackTrace();
493 rajveer 69
		}
70
		return orders;
71
	}
72
 
2449 chandransh 73
	/**
74
	 * Calls the same method of the transaction service and returns the status
75
	 * returned. Catches all exceptions that are raised and returns false in
76
	 * that case.
77
	 * 
78
	 * @param warehouseId
79
	 *            The warehouse for which the orders should be marked as
80
	 *            manifested.
81
	 * @param providerId
82
	 *            The provider for which the orders should be marked as
83
	 *            manifested.
84
	 * @return True if everything goes fine, false otherwise.
85
	 */
760 chandransh 86
	public static boolean markOrdersAsManifested(long warehouseId, String providerId){
87
		try {
88
			long provider_id = Long.parseLong(providerId);
89
			TransactionServiceClient client = new TransactionServiceClient();
90
			Client c = client.getClient();
91
			return c.markOrdersAsManifested(warehouseId, provider_id);
92
		}catch(Exception e){
93
			e.printStackTrace();
94
			return false;
95
		}
96
	}
2449 chandransh 97
 
671 chandransh 98
	/**
2449 chandransh 99
	 * 
671 chandransh 100
	 * @param t_order
2449 chandransh 101
	 *            A thrift order object with line items.
102
	 * @return an Order bean which can be used for rendering on the client side.
671 chandransh 103
	 */
104
	public static Order getOrderFromThriftOrder(in.shop2020.model.v1.order.Order t_order) {
914 chandransh 105
		LineItem lineItem = t_order.getLineitems().get(0);
966 chandransh 106
		Order order = new Order(t_order.getId(),
107
				t_order.getCustomer_id(),
108
				t_order.getCustomer_name(),
109
				t_order.getCustomer_mobilenumber(),
110
				t_order.getCustomer_pincode(),
111
				t_order.getCustomer_address1(),
112
				t_order.getCustomer_address2(),
113
				t_order.getCustomer_city(),
114
				t_order.getCustomer_state(),
115
				t_order.getCustomer_email(),
116
				t_order.getCreated_timestamp(),
117
				t_order.getExpected_delivery_time(),
118
				t_order.getStatus().getValue(),
119
				t_order.getStatusDescription(),
120
				lineItem.getItem_id(),
121
				lineItem.getProductGroup(),
122
				lineItem.getBrand(),
123
				lineItem.getModel_name(),
124
				lineItem.getModel_number(),
125
				lineItem.getColor(),
126
				lineItem.getExtra_info(),
127
				t_order.getTotal_amount(), t_order.getTotal_weight(), t_order.getAirwaybill_no(),
2452 chandransh 128
				t_order.getBilled_by(), t_order.getInvoice_number(), t_order.getJacket_number(),
129
				-1, //FIXME This parameter should be lineItem.getImei_number()
1224 chandransh 130
				t_order.getBatchNo(), t_order.getSerialNo(),
2509 chandransh 131
				false,
132
				t_order.isDoaFlag(),
133
				t_order.getPickupRequestNo());
966 chandransh 134
		return order;
671 chandransh 135
	}
136
 
2449 chandransh 137
	/**
138
	 * This method maps a given type to a list of statuses.
139
	 * 
140
	 * @param type
141
	 *            The type of orders to fetch.
142
	 * @return The list of Thrift statuses associated with a particular order
143
	 *         type.
144
	 */
145
	private static List<OrderStatus> getStatuses(OrderType type) {
146
		List<OrderStatus> statuses = new ArrayList<OrderStatus>();
147
 
148
		switch (type) {
149
		case ACCEPTED:
150
			statuses.add(OrderStatus.ACCEPTED);
151
			break;
152
 
153
		case ALL:
154
			break;
155
 
156
		case NEW:
157
			statuses.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
158
			statuses.add(OrderStatus.INVENTORY_LOW);
2588 chandransh 159
			statuses.add(OrderStatus.DOA_PENDING);
2449 chandransh 160
			break;
161
 
162
		case BILLED:
163
			statuses.add(OrderStatus.BILLED);
164
			break;
165
 
166
		case NO_STOCK:
167
			statuses.add(OrderStatus.INVENTORY_LOW);
168
			break;
169
 
170
		case REJECTED:
171
			statuses.add(OrderStatus.REJECTED);
172
			break;
173
 
174
		case SHIPPED:
175
			statuses.add(OrderStatus.SHIPPED_FROM_WH);
176
			statuses.add(OrderStatus.SHIPPED_TO_LOGST);
177
			break;
178
 
179
		case DELIVERED:
180
			statuses.add(OrderStatus.DELIVERY_SUCCESS);
2509 chandransh 181
			statuses.add(OrderStatus.DOA_PICKUP_REQUESTED);
2449 chandransh 182
			break;
183
 
2509 chandransh 184
		case SALES_RETURN_AWAITED:
185
			statuses.add(OrderStatus.SALES_RETURN_IN_TRANSIT);
186
			break;
187
 
188
		case SALES_RETURNED:
189
			statuses.add(OrderStatus.SALES_RETURNED);
190
			break;
191
 
192
		case DOA_AWAITED:
193
			statuses.add(OrderStatus.DOA_RETURN_AUTHORIZED);
194
			statuses.add(OrderStatus.DOA_RETURN_IN_TRANSIT);
2588 chandransh 195
			statuses.add(OrderStatus.DOA_RETURNED);
2509 chandransh 196
			break;
197
 
2588 chandransh 198
		case DOA_INVALID:
199
			statuses.add(OrderStatus.DOA_CERT_INVALID);
200
			break;
2449 chandransh 201
		default:
202
			break;
203
		}
204
		return statuses;
205
	}
493 rajveer 206
}