Subversion Repositories SmartDukaan

Rev

Rev 2209 | Rev 4363 | 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;
3132 rajveer 5
import in.shop2020.thrift.clients.CatalogClient;
584 chandransh 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 {
3132 rajveer 17
			CatalogClient catalogServiceClient = new CatalogClient();
584 chandransh 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 {
3132 rajveer 36
			CatalogClient catalogServiceClient = new CatalogClient();
597 chandransh 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 {
3132 rajveer 53
			CatalogClient catalogServiceClient = new CatalogClient();
597 chandransh 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 {
3132 rajveer 70
			CatalogClient catalogServiceClient = new CatalogClient();
597 chandransh 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{
3132 rajveer 85
			CatalogClient catalogServiceClient = new CatalogClient();
585 chandransh 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{
3132 rajveer 100
			CatalogClient catalogServiceClient = new CatalogClient();
892 chandransh 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(),
960 chandransh 113
				thriftItem.getProductGroup(),
114
				thriftItem.getBrand(),
585 chandransh 115
				thriftItem.getModelNumber(),
116
				thriftItem.getModelName(),
608 chandransh 117
				thriftItem.getColor(),
585 chandransh 118
				thriftItem.getCategory(),
119
				thriftItem.getComments(),
120
				thriftItem.getCatalogItemId(),
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
}