| 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 {
|
| 20776 |
amit.gupta |
19 |
|
|
|
20 |
private static Map<Long, Map<Long, Warehouse>> billingWarehouseMap = new HashMap<Long, Map<Long,Warehouse>>();
|
|
|
21 |
private static Map<Long, Map<Long, String>> billingWarehouseNameMap = new HashMap<Long, Map<Long,String>>();
|
| 584 |
chandransh |
22 |
public static List<Item> getAllItems(){
|
|
|
23 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
24 |
|
|
|
25 |
try {
|
| 3132 |
rajveer |
26 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 5948 |
mandeep.dh |
27 |
CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
| 584 |
chandransh |
28 |
|
|
|
29 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
|
| 585 |
chandransh |
30 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
|
|
31 |
itemList.add(getItemFromThriftItem(thriftItem));
|
| 584 |
chandransh |
32 |
} catch (Exception e) {
|
| 585 |
chandransh |
33 |
// Not getting any items in the catalog is as good as not having any
|
|
|
34 |
// items in the catalog.
|
| 584 |
chandransh |
35 |
e.printStackTrace();
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
return itemList;
|
|
|
39 |
}
|
| 585 |
chandransh |
40 |
|
| 597 |
chandransh |
41 |
public static List<Item> getBestDeals(){
|
|
|
42 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
43 |
|
|
|
44 |
try {
|
| 3132 |
rajveer |
45 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 5948 |
mandeep.dh |
46 |
CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
| 597 |
chandransh |
47 |
|
|
|
48 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
|
|
|
49 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
|
|
50 |
itemList.add(getItemFromThriftItem(thriftItem));
|
|
|
51 |
} catch(Exception e){
|
|
|
52 |
e.printStackTrace();
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
return itemList;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public static List<Item> getBestSellers(){
|
|
|
59 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
60 |
|
|
|
61 |
try {
|
| 3132 |
rajveer |
62 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 5948 |
mandeep.dh |
63 |
CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
| 597 |
chandransh |
64 |
|
|
|
65 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
|
|
|
66 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
|
|
67 |
itemList.add(getItemFromThriftItem(thriftItem));
|
|
|
68 |
} catch(Exception e){
|
|
|
69 |
e.printStackTrace();
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
return itemList;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
public static List<Item> getLatestArrivals(){
|
|
|
76 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
77 |
|
|
|
78 |
try {
|
| 3132 |
rajveer |
79 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 5948 |
mandeep.dh |
80 |
CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
| 597 |
chandransh |
81 |
|
|
|
82 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
|
|
|
83 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
|
|
84 |
itemList.add(getItemFromThriftItem(thriftItem));
|
|
|
85 |
} catch(Exception e){
|
|
|
86 |
e.printStackTrace();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
return itemList;
|
|
|
90 |
}
|
|
|
91 |
|
| 585 |
chandransh |
92 |
public static Item getItem(long itemId){
|
|
|
93 |
try{
|
| 3132 |
rajveer |
94 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 5948 |
mandeep.dh |
95 |
CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
| 585 |
chandransh |
96 |
in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
|
|
|
97 |
return getItemFromThriftItem(thriftItem);
|
|
|
98 |
}catch(Exception e){
|
|
|
99 |
// Oops! We didn't receive the details. We should let the user know
|
|
|
100 |
// that the catalog service is currently unavailable.
|
|
|
101 |
e.printStackTrace();
|
|
|
102 |
}
|
|
|
103 |
return null;
|
|
|
104 |
}
|
|
|
105 |
|
| 5110 |
mandeep.dh |
106 |
public static Map<Long, String> getWarehousesForBillingWarehouse(long warehouseId){
|
| 20776 |
amit.gupta |
107 |
if(billingWarehouseNameMap.get(warehouseId)==null){
|
|
|
108 |
try{
|
|
|
109 |
Map<Long, Warehouse> warehouseMap = getAllWarehousesForBillingWarehouse(warehouseId);
|
|
|
110 |
Map<Long, String> warehouseNameMap = new HashMap<Long, String>();
|
|
|
111 |
for(Warehouse warehouse: warehouseMap.values()){
|
|
|
112 |
warehouseNameMap.put(warehouse.getId(), warehouse.getDisplayName());
|
|
|
113 |
}
|
|
|
114 |
billingWarehouseNameMap.put(warehouseId, warehouseNameMap);
|
|
|
115 |
}catch(Exception e){
|
|
|
116 |
e.printStackTrace();
|
| 4363 |
rajveer |
117 |
}
|
| 20776 |
amit.gupta |
118 |
} else {
|
|
|
119 |
|
| 4363 |
rajveer |
120 |
}
|
| 20776 |
amit.gupta |
121 |
return billingWarehouseNameMap.get(warehouseId);
|
| 4363 |
rajveer |
122 |
}
|
| 19225 |
manish.sha |
123 |
|
|
|
124 |
public static Map<Long, Warehouse> getAllWarehousesForBillingWarehouse(long warehouseId){
|
| 20776 |
amit.gupta |
125 |
if(billingWarehouseMap.get(warehouseId)==null) {
|
|
|
126 |
try{
|
|
|
127 |
InventoryClient catalogServiceClient = new InventoryClient();
|
|
|
128 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
129 |
List<Warehouse> warehouses = catalogClient.getWarehouses(null, InventoryType.GOOD, 0, warehouseId, 0);
|
|
|
130 |
|
|
|
131 |
Map<Long, Warehouse> map = new HashMap<Long, Warehouse>();
|
|
|
132 |
for(Warehouse warehouse: warehouses){
|
|
|
133 |
map.put(warehouse.getId(), warehouse);
|
|
|
134 |
}
|
|
|
135 |
billingWarehouseMap.put(warehouseId, map);
|
|
|
136 |
}catch(Exception e){
|
|
|
137 |
e.printStackTrace();
|
| 19225 |
manish.sha |
138 |
}
|
|
|
139 |
}
|
| 20776 |
amit.gupta |
140 |
return billingWarehouseMap.get(warehouseId);
|
| 19225 |
manish.sha |
141 |
}
|
| 4363 |
rajveer |
142 |
|
| 5684 |
mandeep.dh |
143 |
public static Warehouse getWarehouse(long warehouseId) {
|
|
|
144 |
try{
|
| 5948 |
mandeep.dh |
145 |
InventoryClient catalogServiceClient = new InventoryClient();
|
| 5684 |
mandeep.dh |
146 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
147 |
return catalogClient.getWarehouse(warehouseId);
|
|
|
148 |
}catch(Exception e){
|
|
|
149 |
e.printStackTrace();
|
|
|
150 |
}
|
|
|
151 |
return null;
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
private static Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem){
|
| 585 |
chandransh |
155 |
Item item = new Item(thriftItem.getId(),
|
| 960 |
chandransh |
156 |
thriftItem.getProductGroup(),
|
|
|
157 |
thriftItem.getBrand(),
|
| 585 |
chandransh |
158 |
thriftItem.getModelNumber(),
|
|
|
159 |
thriftItem.getModelName(),
|
| 608 |
chandransh |
160 |
thriftItem.getColor(),
|
| 585 |
chandransh |
161 |
thriftItem.getCategory(),
|
|
|
162 |
thriftItem.getComments(),
|
|
|
163 |
thriftItem.getCatalogItemId(),
|
|
|
164 |
thriftItem.getFeatureId(),
|
|
|
165 |
thriftItem.getFeatureDescription(),
|
|
|
166 |
//thriftItem.getItemInventory(),
|
|
|
167 |
thriftItem.getMrp(),
|
| 4779 |
mandeep.dh |
168 |
//thriftItem.getMop(),
|
| 585 |
chandransh |
169 |
thriftItem.getSellingPrice(),
|
| 4779 |
mandeep.dh |
170 |
//thriftItem.getDealerPrice(),
|
| 585 |
chandransh |
171 |
thriftItem.getWeight(),
|
|
|
172 |
thriftItem.getAddedOn(),
|
|
|
173 |
thriftItem.getStartDate(),
|
| 608 |
chandransh |
174 |
thriftItem.getRetireDate(),
|
|
|
175 |
thriftItem.getUpdatedOn(),
|
| 585 |
chandransh |
176 |
//thriftItem.getItemStatus(),
|
| 608 |
chandransh |
177 |
thriftItem.getBestDealText(),
|
|
|
178 |
thriftItem.getBestDealValue());
|
| 585 |
chandransh |
179 |
return item;
|
|
|
180 |
}
|
| 584 |
chandransh |
181 |
}
|