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