Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
584 chandransh 1
package in.shop2020.hotspot.dashbaord.server;
2
 
3
import in.shop2020.hotspot.dashbaord.shared.actions.Item;
4
import in.shop2020.model.v1.catalog.InventoryService;
5
import in.shop2020.thrift.clients.CatalogServiceClient;
6
 
7
import java.util.ArrayList;
8
import java.util.List;
9
 
892 chandransh 10
import com.google.gwt.core.client.GWT;
11
 
584 chandransh 12
public class CatalogUtils {
13
	public static List<Item> getAllItems(){
14
		List<Item> itemList = new ArrayList<Item>();
15
 
16
		try {
17
			CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
18
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
19
 
20
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
585 chandransh 21
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
22
				itemList.add(getItemFromThriftItem(thriftItem));
584 chandransh 23
		} catch (Exception e) {
585 chandransh 24
			// Not getting any items in the catalog is as good as not having any
25
			// items in the catalog.
584 chandransh 26
			e.printStackTrace();
27
		}
28
 
29
		return itemList;
30
	}
585 chandransh 31
 
597 chandransh 32
	public static List<Item> getBestDeals(){
33
		List<Item> itemList = new ArrayList<Item>();
34
 
35
		try {
36
			CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
37
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
38
 
39
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
40
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
41
				itemList.add(getItemFromThriftItem(thriftItem));
42
		} catch(Exception e){
43
			e.printStackTrace();
44
		}
45
 
46
		return itemList;
47
	}
48
 
49
	public static List<Item> getBestSellers(){
50
		List<Item> itemList = new ArrayList<Item>();
51
 
52
		try {
53
			CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
54
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
55
 
56
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
57
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
58
				itemList.add(getItemFromThriftItem(thriftItem));
59
		} catch(Exception e){
60
			e.printStackTrace();
61
		}
62
 
63
		return itemList;		
64
	}
65
 
66
	public static List<Item> getLatestArrivals(){
67
		List<Item> itemList = new ArrayList<Item>();
68
 
69
		try {
70
			CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
71
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
72
 
73
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
74
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
75
				itemList.add(getItemFromThriftItem(thriftItem));
76
		} catch(Exception e){
77
			e.printStackTrace();
78
		}
79
 
80
		return itemList;
81
	}
82
 
585 chandransh 83
	public static Item getItem(long itemId){
84
		try{
85
			CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
86
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
87
			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
88
			return getItemFromThriftItem(thriftItem);
89
		}catch(Exception e){
90
			// Oops! We didn't receive the details. We should let the user know
91
			// that the catalog service is currently unavailable.
92
			e.printStackTrace();
93
		}
94
		return null;
95
	}
96
 
892 chandransh 97
	public static void reduceReservationCount(long itemId, long warehouseId, double quantity){
98
		GWT.log("Got a call to reduce the reservation count for item " + itemId + " and warehouse " + warehouseId);
99
		try{
100
			CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
101
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
102
			catalogClient.reduceReservationCount(itemId, warehouseId, quantity);
103
		}catch(Exception e){
104
			// TODO: Oops! We couldn't reduce the item reservation count. This will
105
			// result in underestimation of inventory stock. Should be corrected
106
			// periodically.
107
			e.printStackTrace();
108
		}
109
	}
110
 
585 chandransh 111
	private static Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem){
112
		Item item = new Item(thriftItem.getId(),
113
				thriftItem.getManufacturerName(),
114
				thriftItem.getModelNumber(),
115
				thriftItem.getModelName(),
608 chandransh 116
				thriftItem.getColor(),
585 chandransh 117
				thriftItem.getCategory(),
118
				thriftItem.getComments(),
119
				thriftItem.getCatalogItemId(),
120
				thriftItem.getVendorItemId(),
121
				thriftItem.getFeatureId(),
122
				thriftItem.getFeatureDescription(),
123
				//thriftItem.getItemInventory(),
124
				thriftItem.getMrp(),
125
				thriftItem.getMop(),
126
				thriftItem.getSellingPrice(),
608 chandransh 127
				thriftItem.getDealerPrice(),
585 chandransh 128
				thriftItem.getWeight(),
129
				thriftItem.getAddedOn(),
130
				thriftItem.getStartDate(),
608 chandransh 131
				thriftItem.getRetireDate(),
132
				thriftItem.getUpdatedOn(),
585 chandransh 133
				//thriftItem.getItemStatus(),
608 chandransh 134
				thriftItem.getOtherInfo(),
135
				thriftItem.getBestDealText(),
136
				thriftItem.getBestDealValue());
585 chandransh 137
		return item;
138
	}
584 chandransh 139
}