Subversion Repositories SmartDukaan

Rev

Rev 2352 | Rev 2452 | 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(),
2352 chandransh 128
				t_order.getBilled_by(), t_order.getInvoice_number(), t_order.getJacket_number(), lineItem.getImei_number(),
1224 chandransh 129
				t_order.getBatchNo(), t_order.getSerialNo(),
130
				false);
966 chandransh 131
		return order;
671 chandransh 132
	}
133
 
2449 chandransh 134
	/**
135
	 * This method maps a given type to a list of statuses.
136
	 * 
137
	 * @param type
138
	 *            The type of orders to fetch.
139
	 * @return The list of Thrift statuses associated with a particular order
140
	 *         type.
141
	 */
142
	private static List<OrderStatus> getStatuses(OrderType type) {
143
		List<OrderStatus> statuses = new ArrayList<OrderStatus>();
144
 
145
		switch (type) {
146
		case ACCEPTED:
147
			statuses.add(OrderStatus.ACCEPTED);
148
			break;
149
 
150
		case ALL:
151
			break;
152
 
153
		case NEW:
154
			statuses.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
155
			statuses.add(OrderStatus.INVENTORY_LOW);
156
			break;
157
 
158
		case BILLED:
159
			statuses.add(OrderStatus.BILLED);
160
			break;
161
 
162
		case NO_STOCK:
163
			statuses.add(OrderStatus.INVENTORY_LOW);
164
			break;
165
 
166
		case REJECTED:
167
			statuses.add(OrderStatus.REJECTED);
168
			break;
169
 
170
		case SHIPPED:
171
			statuses.add(OrderStatus.SHIPPED_FROM_WH);
172
			statuses.add(OrderStatus.SHIPPED_TO_LOGST);
173
			break;
174
 
175
		case DELIVERED:
176
			statuses.add(OrderStatus.DELIVERY_SUCCESS);
177
			break;
178
 
179
		default:
180
			break;
181
		}
182
		return statuses;
183
	}
493 rajveer 184
}