Subversion Repositories SmartDukaan

Rev

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

Rev 4004 Rev 4133
Line 12... Line 12...
12
import java.util.Date;
12
import java.util.Date;
13
import java.util.List;
13
import java.util.List;
14
 
14
 
15
/**
15
/**
16
 * This class is a facade to the Transaction service and should be used to
16
 * This class is a facade to the Transaction service and should be used to
17
 * access all order specific data.
17
 * access all order specific data which requires some kind of transformation.
18
 * 
18
 * 
19
 * @author Chandranshu
19
 * @author Chandranshu
20
 * 
20
 * 
21
 */
21
 */
22
public class TransactionUtils {
22
public class TransactionUtils {
Line 26... Line 26...
26
	 * same consolidated view. This method uses a mapping of <i>type</i> to
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.
27
	 * <i>status</i> to get all such orders and return them as order beans.
28
	 * 
28
	 * 
29
	 * @param type
29
	 * @param type
30
	 *            The type of orders to return.
30
	 *            The type of orders to return.
-
 
31
	 * @param offset
-
 
32
	 *            Offset to start from
-
 
33
	 * @param limit
-
 
34
	 *            No. of orders to return
31
	 * @param warehouseId
35
	 * @param warehouseId
32
	 *            The warehouse for which the orders should be queried.
36
	 *            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
37
	 * @return A list of orders of the given type to be fulfilled from the given
34
	 *         warehouse
38
	 *         warehouse
35
	 */
39
	 */
36
	public static List<Order> getOrders(OrderType type, long warehouseId){
40
	public static List<Order> getOrders(OrderType type, long offset, long limit, long warehouseId){
37
		List<OrderStatus> statuses = getStatuses(type);
41
		List<OrderStatus> statuses = getStatuses(type);
38
		
42
		
39
		List<Order> orders = new ArrayList<Order>();
43
		List<Order> orders = new ArrayList<Order>();
40
		try{
44
		try{
41
			TransactionClient client = new TransactionClient();
45
			TransactionClient txnClient = new TransactionClient();
42
			Client c = client.getClient();
46
			Client client = txnClient.getClient();
43
			
47
			
44
			List<in.shop2020.model.v1.order.Order> t_orders = new ArrayList<in.shop2020.model.v1.order.Order>();
48
			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));
49
			t_orders.addAll(client.getOrdersInBatch(statuses, offset, limit, warehouseId));
47
			}
-
 
48
			else {
-
 
49
				for(OrderStatus status: statuses){
-
 
50
					t_orders.addAll(c.getAllOrders(status, 0L, new Date().getTime(), warehouseId));
-
 
51
				}
-
 
52
			}
-
 
53
			
50
			
54
			for (in.shop2020.model.v1.order.Order t_order: t_orders){
51
			for (in.shop2020.model.v1.order.Order t_order: t_orders){
55
				Order o = getOrderFromThriftOrder(t_order);
52
				Order o = getOrderFromThriftOrder(t_order);
56
 
-
 
57
				orders.add(o);
53
				orders.add(o);
58
				//TODO: We'll figure out how to show an alert. I don't think we need another thrift call for that.
-
 
59
				//check if it has an associated alert
-
 
60
//				List<Alert> alerts = c.getAlerts(t_order.getId(), true);
-
 
61
//				if(alerts != null && alerts.size() != 0){
-
 
62
//					o.setAlert(true);
-
 
63
//					o.setStatusMessage(alerts.iterator().next().getComment());
-
 
64
//				} else {
-
 
65
//					o.setAlert(false);
-
 
66
//				}
-
 
67
			}
54
			}
68
		}catch(Exception e){
55
		}catch(Exception e){
69
			e.printStackTrace();
56
			e.printStackTrace();
70
		}
57
		}
71
		return orders;
58
		return orders;
72
	}
59
	}
73
 
60
 
74
	/**
61
	/**
-
 
62
	 * Wrapper around the method of same name in the transaction service. This
-
 
63
	 * method uses a mapping of <i>type</i> to <i>status</i> to get the count of
-
 
64
	 * all orders with a given status.
-
 
65
	 * 
-
 
66
	 * @param type
-
 
67
	 *            The type of orders to return.
-
 
68
	 * @param warehouseId
-
 
69
	 *            The warehouse for which the orders should be queried.
-
 
70
	 * @return The count of orders of the given type assigned to the given
-
 
71
	 *         warehouse.
-
 
72
	 */
-
 
73
	public static int getOrderCount(OrderType type, long warehouseId){
-
 
74
		List<OrderStatus> statuses = getStatuses(type);
-
 
75
		
-
 
76
		int count = 0;
-
 
77
		try{
-
 
78
			TransactionClient txnClient = new TransactionClient();
-
 
79
			Client client = txnClient.getClient();
-
 
80
			count += client.getOrderCount(statuses, warehouseId);
-
 
81
		}catch(Exception e){
-
 
82
			e.printStackTrace();
-
 
83
		}
-
 
84
		return count;
-
 
85
	}
-
 
86
	
-
 
87
	/**
75
	 * Calls the same method of the transaction service and returns the status
88
	 * Calls the same method of the transaction service and returns the status
76
	 * returned. Catches all exceptions that are raised and returns false in
89
	 * returned. Catches all exceptions that are raised and returns false in
77
	 * that case.
90
	 * that case.
78
	 * 
91
	 * 
79
	 * @param warehouseId
92
	 * @param warehouseId