Subversion Repositories SmartDukaan

Rev

Rev 4363 | Rev 5110 | Go to most recent revision | Details | Compare with Previous | 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;
4363 rajveer 5
import in.shop2020.model.v1.catalog.Vendor;
3132 rajveer 6
import in.shop2020.thrift.clients.CatalogClient;
584 chandransh 7
 
8
import java.util.ArrayList;
4363 rajveer 9
import java.util.HashMap;
584 chandransh 10
import java.util.List;
4363 rajveer 11
import java.util.Map;
584 chandransh 12
 
892 chandransh 13
import com.google.gwt.core.client.GWT;
14
 
584 chandransh 15
public class CatalogUtils {
16
	public static List<Item> getAllItems(){
17
		List<Item> itemList = new ArrayList<Item>();
18
 
19
		try {
3132 rajveer 20
			CatalogClient catalogServiceClient = new CatalogClient();
584 chandransh 21
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
22
 
23
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
585 chandransh 24
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
25
				itemList.add(getItemFromThriftItem(thriftItem));
584 chandransh 26
		} catch (Exception e) {
585 chandransh 27
			// Not getting any items in the catalog is as good as not having any
28
			// items in the catalog.
584 chandransh 29
			e.printStackTrace();
30
		}
31
 
32
		return itemList;
33
	}
585 chandransh 34
 
597 chandransh 35
	public static List<Item> getBestDeals(){
36
		List<Item> itemList = new ArrayList<Item>();
37
 
38
		try {
3132 rajveer 39
			CatalogClient catalogServiceClient = new CatalogClient();
597 chandransh 40
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
41
 
42
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
43
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
44
				itemList.add(getItemFromThriftItem(thriftItem));
45
		} catch(Exception e){
46
			e.printStackTrace();
47
		}
48
 
49
		return itemList;
50
	}
51
 
52
	public static List<Item> getBestSellers(){
53
		List<Item> itemList = new ArrayList<Item>();
54
 
55
		try {
3132 rajveer 56
			CatalogClient catalogServiceClient = new CatalogClient();
597 chandransh 57
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
58
 
59
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
60
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
61
				itemList.add(getItemFromThriftItem(thriftItem));
62
		} catch(Exception e){
63
			e.printStackTrace();
64
		}
65
 
66
		return itemList;		
67
	}
68
 
69
	public static List<Item> getLatestArrivals(){
70
		List<Item> itemList = new ArrayList<Item>();
71
 
72
		try {
3132 rajveer 73
			CatalogClient catalogServiceClient = new CatalogClient();
597 chandransh 74
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
75
 
76
			List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
77
			for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
78
				itemList.add(getItemFromThriftItem(thriftItem));
79
		} catch(Exception e){
80
			e.printStackTrace();
81
		}
82
 
83
		return itemList;
84
	}
85
 
585 chandransh 86
	public static Item getItem(long itemId){
87
		try{
3132 rajveer 88
			CatalogClient catalogServiceClient = new CatalogClient();
585 chandransh 89
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
90
			in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
91
			return getItemFromThriftItem(thriftItem);
92
		}catch(Exception e){
93
			// Oops! We didn't receive the details. We should let the user know
94
			// that the catalog service is currently unavailable.
95
			e.printStackTrace();
96
		}
97
		return null;
98
	}
99
 
892 chandransh 100
	public static void reduceReservationCount(long itemId, long warehouseId, double quantity){
101
		GWT.log("Got a call to reduce the reservation count for item " + itemId + " and warehouse " + warehouseId);
102
		try{
3132 rajveer 103
			CatalogClient catalogServiceClient = new CatalogClient();
892 chandransh 104
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
105
			catalogClient.reduceReservationCount(itemId, warehouseId, quantity);
106
		}catch(Exception e){
107
			// TODO: Oops! We couldn't reduce the item reservation count. This will
108
			// result in underestimation of inventory stock. Should be corrected
109
			// periodically.
110
			e.printStackTrace();
111
		}
112
	}
113
 
4363 rajveer 114
 
115
	public static Map<Long, String> getVendorsForWarehouse(long warehouseId){
116
		try{
117
			CatalogClient catalogServiceClient = new CatalogClient();
118
			InventoryService.Client catalogClient = catalogServiceClient.getClient();
119
			List<Vendor> vendors = catalogClient.getVendorsForWarehouse(warehouseId);
120
			Map<Long, String> vendorMapping = new HashMap<Long, String>();
121
			for(Vendor vendor: vendors){
122
				vendorMapping.put(vendor.getId(), vendor.getName());
123
			}
124
			return vendorMapping;
125
		}catch(Exception e){
126
			// TODO: Oops! We couldn't reduce the item reservation count. This will
127
			// result in underestimation of inventory stock. Should be corrected
128
			// periodically.
129
			e.printStackTrace();
130
		}
131
		return null;
132
	}
133
 
585 chandransh 134
	private static Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem){
135
		Item item = new Item(thriftItem.getId(),
960 chandransh 136
				thriftItem.getProductGroup(),
137
				thriftItem.getBrand(),
585 chandransh 138
				thriftItem.getModelNumber(),
139
				thriftItem.getModelName(),
608 chandransh 140
				thriftItem.getColor(),
585 chandransh 141
				thriftItem.getCategory(),
142
				thriftItem.getComments(),
143
				thriftItem.getCatalogItemId(),
144
				thriftItem.getFeatureId(),
145
				thriftItem.getFeatureDescription(),
146
				//thriftItem.getItemInventory(),
147
				thriftItem.getMrp(),
4779 mandeep.dh 148
				//thriftItem.getMop(),
585 chandransh 149
				thriftItem.getSellingPrice(),
4779 mandeep.dh 150
				//thriftItem.getDealerPrice(),
585 chandransh 151
				thriftItem.getWeight(),
152
				thriftItem.getAddedOn(),
153
				thriftItem.getStartDate(),
608 chandransh 154
				thriftItem.getRetireDate(),
155
				thriftItem.getUpdatedOn(),
585 chandransh 156
				//thriftItem.getItemStatus(),
608 chandransh 157
				thriftItem.getOtherInfo(),
158
				thriftItem.getBestDealText(),
159
				thriftItem.getBestDealValue());
585 chandransh 160
		return item;
161
	}
584 chandransh 162
}