Subversion Repositories SmartDukaan

Rev

Rev 2700 | Rev 3065 | 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;
2697 chandransh 5
import in.shop2020.hotspot.dashbaord.shared.actions.ReturnOrder;
493 rajveer 6
import in.shop2020.model.v1.order.Alert;
914 chandransh 7
import in.shop2020.model.v1.order.LineItem;
493 rajveer 8
import in.shop2020.model.v1.order.OrderStatus;
9
import in.shop2020.model.v1.order.TransactionService.Client;
10
import in.shop2020.thrift.clients.TransactionServiceClient;
11
 
12
import java.util.ArrayList;
13
import java.util.Date;
14
import java.util.List;
15
 
2449 chandransh 16
/**
17
 * This class is a facade to the Transaction service and should be used to
18
 * access all order specific data.
19
 * 
20
 * @author Chandranshu
21
 * 
22
 */
493 rajveer 23
public class TransactionUtils {
2449 chandransh 24
	/**
25
	 * The human user is concerned only with a consolidated view of actionable
26
	 * orders. Orders with different statuses in the database can be part of the
27
	 * same consolidated view. This method uses a mapping of <i>type</i> to
28
	 * <i>status</i> to get all such orders and return them as order beans.
29
	 * 
30
	 * @param type
31
	 *            The type of orders to return.
32
	 * @param warehouseId
33
	 *            The warehouse for which the orders should be queried.
34
	 * @return A list of orders of the given type to be fulfilled from the given
35
	 *         warehouse
36
	 */
493 rajveer 37
	public static List<Order> getOrders(OrderType type, long warehouseId){
2449 chandransh 38
		List<OrderStatus> statuses = getStatuses(type);
493 rajveer 39
 
40
		List<Order> orders = new ArrayList<Order>();
41
		try{
42
			TransactionServiceClient client = new TransactionServiceClient();
43
			Client c = client.getClient();
44
 
45
			List<in.shop2020.model.v1.order.Order> t_orders = new ArrayList<in.shop2020.model.v1.order.Order>();
46
			if(statuses.isEmpty()){
47
				t_orders.addAll(c.getAllOrders(null, 0L, new Date().getTime(), warehouseId));
48
			}
49
			else {
50
				for(OrderStatus status: statuses){
51
					t_orders.addAll(c.getAllOrders(status, 0L, new Date().getTime(), warehouseId));
52
				}
53
			}
54
 
55
			for (in.shop2020.model.v1.order.Order t_order: t_orders){
671 chandransh 56
				Order o = getOrderFromThriftOrder(t_order);
493 rajveer 57
 
58
				orders.add(o);
59
				//check if it has an associated alert
60
				List<Alert> alerts = c.getAlerts(t_order.getId(), true);
2449 chandransh 61
				if(alerts != null && alerts.size() != 0){
62
					o.setAlert(true);
63
					o.setStatusMessage(alerts.iterator().next().getComment());
64
				} else {
493 rajveer 65
					o.setAlert(false);
66
				}
67
			}
68
		}catch(Exception e){
2449 chandransh 69
			e.printStackTrace();
493 rajveer 70
		}
71
		return orders;
72
	}
73
 
2449 chandransh 74
	/**
75
	 * Calls the same method of the transaction service and returns the status
76
	 * returned. Catches all exceptions that are raised and returns false in
77
	 * that case.
78
	 * 
79
	 * @param warehouseId
80
	 *            The warehouse for which the orders should be marked as
81
	 *            manifested.
82
	 * @param providerId
83
	 *            The provider for which the orders should be marked as
84
	 *            manifested.
85
	 * @return True if everything goes fine, false otherwise.
86
	 */
760 chandransh 87
	public static boolean markOrdersAsManifested(long warehouseId, String providerId){
88
		try {
89
			long provider_id = Long.parseLong(providerId);
90
			TransactionServiceClient client = new TransactionServiceClient();
91
			Client c = client.getClient();
92
			return c.markOrdersAsManifested(warehouseId, provider_id);
93
		}catch(Exception e){
94
			e.printStackTrace();
95
			return false;
96
		}
97
	}
2449 chandransh 98
 
671 chandransh 99
	/**
2449 chandransh 100
	 * 
671 chandransh 101
	 * @param t_order
2449 chandransh 102
	 *            A thrift order object with line items.
103
	 * @return an Order bean which can be used for rendering on the client side.
671 chandransh 104
	 */
105
	public static Order getOrderFromThriftOrder(in.shop2020.model.v1.order.Order t_order) {
914 chandransh 106
		LineItem lineItem = t_order.getLineitems().get(0);
966 chandransh 107
		Order order = new Order(t_order.getId(),
108
				t_order.getCustomer_id(),
109
				t_order.getCustomer_name(),
110
				t_order.getCustomer_mobilenumber(),
111
				t_order.getCustomer_pincode(),
112
				t_order.getCustomer_address1(),
113
				t_order.getCustomer_address2(),
114
				t_order.getCustomer_city(),
115
				t_order.getCustomer_state(),
116
				t_order.getCustomer_email(),
117
				t_order.getCreated_timestamp(),
118
				t_order.getExpected_delivery_time(),
119
				t_order.getStatus().getValue(),
120
				t_order.getStatusDescription(),
121
				lineItem.getItem_id(),
122
				lineItem.getProductGroup(),
123
				lineItem.getBrand(),
124
				lineItem.getModel_name(),
125
				lineItem.getModel_number(),
126
				lineItem.getColor(),
127
				lineItem.getExtra_info(),
2782 chandransh 128
				t_order.getTotal_amount(),
129
				t_order.getTotal_weight(),
130
				t_order.getAirwaybill_no(),
131
				t_order.getBilled_by(),
132
				t_order.getInvoice_number(),
133
				t_order.getJacket_number(),
134
				lineItem.getItem_number(),
135
				lineItem.getImei_number(),
1224 chandransh 136
				t_order.getBatchNo(), t_order.getSerialNo(),
2509 chandransh 137
				false,
138
				t_order.isDoaFlag(),
139
				t_order.getPickupRequestNo());
966 chandransh 140
		return order;
671 chandransh 141
	}
142
 
2449 chandransh 143
	/**
2697 chandransh 144
	 * Queries the transction server to get the list of all return orders that
145
	 * have to be processed.
146
	 * 
147
	 * @return A list of all return orders to be processed.
148
	 */
149
	public static List<ReturnOrder> getReturnOrders(long warehouseId){
150
		List<ReturnOrder> retOrders = new ArrayList<ReturnOrder>();
151
		try{
152
			TransactionServiceClient client = new TransactionServiceClient();
153
			Client c = client.getClient();
154
			List<in.shop2020.model.v1.order.ReturnOrder> tRetOrders =  c.getReturnOrders(warehouseId, 0L, new Date().getTime());
155
			for(in.shop2020.model.v1.order.ReturnOrder retOrder : tRetOrders){
156
				retOrders.add(getReturnOrderFromThriftRO(retOrder));
157
			}
158
		}catch(Exception e){
159
			e.printStackTrace();
160
		}
161
		return retOrders;
162
	}
163
 
2700 chandransh 164
	public static ReturnOrder getReturnOrderFromThriftRO(in.shop2020.model.v1.order.ReturnOrder tRetOrder){
165
		ReturnOrder retOrder = new ReturnOrder(tRetOrder.getOrderId(),
166
				tRetOrder.getWarehouseId(),
167
				tRetOrder.getItemId(),
168
				tRetOrder.getProductGroup(),
169
				tRetOrder.getBrand(),
170
				tRetOrder.getModelName(),
171
				tRetOrder.getModelNumber(),
172
				tRetOrder.getColor(),
173
				tRetOrder.getInvoiceNumber(),
174
				tRetOrder.getJacketNumber(),
175
				tRetOrder.getTotalPrice(),
176
				tRetOrder.getTransferPrice(),
177
				false,
178
				tRetOrder.getCreatedAt());
2697 chandransh 179
		return retOrder;
180
	}
181
 
182
	/**
2449 chandransh 183
	 * This method maps a given type to a list of statuses.
184
	 * 
185
	 * @param type
186
	 *            The type of orders to fetch.
187
	 * @return The list of Thrift statuses associated with a particular order
188
	 *         type.
189
	 */
190
	private static List<OrderStatus> getStatuses(OrderType type) {
191
		List<OrderStatus> statuses = new ArrayList<OrderStatus>();
192
 
193
		switch (type) {
194
		case ACCEPTED:
195
			statuses.add(OrderStatus.ACCEPTED);
196
			break;
197
 
198
		case ALL:
199
			break;
200
 
201
		case NEW:
202
			statuses.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
203
			statuses.add(OrderStatus.INVENTORY_LOW);
204
			break;
205
 
206
		case BILLED:
207
			statuses.add(OrderStatus.BILLED);
208
			break;
209
 
210
		case NO_STOCK:
211
			statuses.add(OrderStatus.INVENTORY_LOW);
212
			break;
213
 
214
		case REJECTED:
215
			statuses.add(OrderStatus.REJECTED);
216
			break;
217
 
218
		case SHIPPED:
219
			statuses.add(OrderStatus.SHIPPED_FROM_WH);
220
			statuses.add(OrderStatus.SHIPPED_TO_LOGST);
221
			break;
222
 
223
		case DELIVERED:
224
			statuses.add(OrderStatus.DELIVERY_SUCCESS);
2509 chandransh 225
			statuses.add(OrderStatus.DOA_PICKUP_REQUESTED);
2449 chandransh 226
			break;
2610 chandransh 227
 
228
		case DOA_AWAITED:
229
			statuses.add(OrderStatus.DOA_RETURN_AUTHORIZED);
230
			statuses.add(OrderStatus.DOA_RETURN_IN_TRANSIT);
231
			statuses.add(OrderStatus.DOA_RECEIVED);
232
			break;
2449 chandransh 233
 
2509 chandransh 234
		case SALES_RETURN_AWAITED:
235
			statuses.add(OrderStatus.SALES_RETURN_IN_TRANSIT);
236
			break;
237
 
2610 chandransh 238
		case DOA_RETURNED:
239
			statuses.add(OrderStatus.DOA_CERT_VALID);
240
			break;
241
 
2509 chandransh 242
		case SALES_RETURNED:
2610 chandransh 243
			statuses.add(OrderStatus.SALES_RET_RECEIVED);
244
			statuses.add(OrderStatus.DOA_CERT_INVALID);
2509 chandransh 245
			break;
246
 
2628 chandransh 247
		case RESHIPPED:
248
			statuses.add(OrderStatus.SALES_RET_RESHIPPED);
249
			statuses.add(OrderStatus.DOA_INVALID_RESHIPPED);
250
			statuses.add(OrderStatus.DOA_RESHIPPED);
251
			break;
252
 
253
		case REFUNDED:
254
			statuses.add(OrderStatus.SALES_RET_REFUNDED);
255
			statuses.add(OrderStatus.DOA_INVALID_REFUNDED);
256
			statuses.add(OrderStatus.DOA_VALID_REFUNDED);
257
			statuses.add(OrderStatus.REFUNDED);
258
			break;
2509 chandransh 259
 
2449 chandransh 260
		default:
261
			break;
262
		}
263
		return statuses;
264
	}
493 rajveer 265
}