| Line 1... |
Line 1... |
| 1 |
package in.shop2020.hotspot.dashbaord.server;
|
1 |
package in.shop2020.hotspot.dashbaord.server;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.hotspot.dashbaord.shared.actions.Item;
|
3 |
import in.shop2020.hotspot.dashbaord.shared.actions.Item;
|
| - |
|
4 |
import in.shop2020.model.v1.catalog.CatalogService;
|
| 4 |
import in.shop2020.model.v1.catalog.InventoryService;
|
5 |
import in.shop2020.model.v1.inventory.InventoryService;
|
| 5 |
import in.shop2020.model.v1.inventory.InventoryType;
|
6 |
import in.shop2020.model.v1.inventory.InventoryType;
|
| 6 |
import in.shop2020.model.v1.inventory.Warehouse;
|
7 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| 7 |
import in.shop2020.thrift.clients.CatalogClient;
|
8 |
import in.shop2020.thrift.clients.CatalogClient;
|
| - |
|
9 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 8 |
|
10 |
|
| 9 |
import java.util.ArrayList;
|
11 |
import java.util.ArrayList;
|
| 10 |
import java.util.HashMap;
|
12 |
import java.util.HashMap;
|
| 11 |
import java.util.List;
|
13 |
import java.util.List;
|
| 12 |
import java.util.Map;
|
14 |
import java.util.Map;
|
| Line 17... |
Line 19... |
| 17 |
public static List<Item> getAllItems(){
|
19 |
public static List<Item> getAllItems(){
|
| 18 |
List<Item> itemList = new ArrayList<Item>();
|
20 |
List<Item> itemList = new ArrayList<Item>();
|
| 19 |
|
21 |
|
| 20 |
try {
|
22 |
try {
|
| 21 |
CatalogClient catalogServiceClient = new CatalogClient();
|
23 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 22 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
24 |
CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
| 23 |
|
25 |
|
| 24 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
|
26 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
|
| 25 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
27 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
| 26 |
itemList.add(getItemFromThriftItem(thriftItem));
|
28 |
itemList.add(getItemFromThriftItem(thriftItem));
|
| 27 |
} catch (Exception e) {
|
29 |
} catch (Exception e) {
|
| Line 36... |
Line 38... |
| 36 |
public static List<Item> getBestDeals(){
|
38 |
public static List<Item> getBestDeals(){
|
| 37 |
List<Item> itemList = new ArrayList<Item>();
|
39 |
List<Item> itemList = new ArrayList<Item>();
|
| 38 |
|
40 |
|
| 39 |
try {
|
41 |
try {
|
| 40 |
CatalogClient catalogServiceClient = new CatalogClient();
|
42 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 41 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
43 |
CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
| 42 |
|
44 |
|
| 43 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
|
45 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
|
| 44 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
46 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
| 45 |
itemList.add(getItemFromThriftItem(thriftItem));
|
47 |
itemList.add(getItemFromThriftItem(thriftItem));
|
| 46 |
} catch(Exception e){
|
48 |
} catch(Exception e){
|
| Line 53... |
Line 55... |
| 53 |
public static List<Item> getBestSellers(){
|
55 |
public static List<Item> getBestSellers(){
|
| 54 |
List<Item> itemList = new ArrayList<Item>();
|
56 |
List<Item> itemList = new ArrayList<Item>();
|
| 55 |
|
57 |
|
| 56 |
try {
|
58 |
try {
|
| 57 |
CatalogClient catalogServiceClient = new CatalogClient();
|
59 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 58 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
60 |
CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
| 59 |
|
61 |
|
| 60 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
|
62 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
|
| 61 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
63 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
| 62 |
itemList.add(getItemFromThriftItem(thriftItem));
|
64 |
itemList.add(getItemFromThriftItem(thriftItem));
|
| 63 |
} catch(Exception e){
|
65 |
} catch(Exception e){
|
| Line 70... |
Line 72... |
| 70 |
public static List<Item> getLatestArrivals(){
|
72 |
public static List<Item> getLatestArrivals(){
|
| 71 |
List<Item> itemList = new ArrayList<Item>();
|
73 |
List<Item> itemList = new ArrayList<Item>();
|
| 72 |
|
74 |
|
| 73 |
try {
|
75 |
try {
|
| 74 |
CatalogClient catalogServiceClient = new CatalogClient();
|
76 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 75 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
77 |
CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
| 76 |
|
78 |
|
| 77 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
|
79 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
|
| 78 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
80 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
| 79 |
itemList.add(getItemFromThriftItem(thriftItem));
|
81 |
itemList.add(getItemFromThriftItem(thriftItem));
|
| 80 |
} catch(Exception e){
|
82 |
} catch(Exception e){
|
| Line 85... |
Line 87... |
| 85 |
}
|
87 |
}
|
| 86 |
|
88 |
|
| 87 |
public static Item getItem(long itemId){
|
89 |
public static Item getItem(long itemId){
|
| 88 |
try{
|
90 |
try{
|
| 89 |
CatalogClient catalogServiceClient = new CatalogClient();
|
91 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 90 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
92 |
CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
| 91 |
in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
|
93 |
in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
|
| 92 |
return getItemFromThriftItem(thriftItem);
|
94 |
return getItemFromThriftItem(thriftItem);
|
| 93 |
}catch(Exception e){
|
95 |
}catch(Exception e){
|
| 94 |
// Oops! We didn't receive the details. We should let the user know
|
96 |
// Oops! We didn't receive the details. We should let the user know
|
| 95 |
// that the catalog service is currently unavailable.
|
97 |
// that the catalog service is currently unavailable.
|
| Line 99... |
Line 101... |
| 99 |
}
|
101 |
}
|
| 100 |
|
102 |
|
| 101 |
public static void reduceReservationCount(long itemId, long warehouseId, double quantity){
|
103 |
public static void reduceReservationCount(long itemId, long warehouseId, double quantity){
|
| 102 |
GWT.log("Got a call to reduce the reservation count for item " + itemId + " and warehouse " + warehouseId);
|
104 |
GWT.log("Got a call to reduce the reservation count for item " + itemId + " and warehouse " + warehouseId);
|
| 103 |
try{
|
105 |
try{
|
| 104 |
CatalogClient catalogServiceClient = new CatalogClient();
|
106 |
InventoryClient catalogServiceClient = new InventoryClient();
|
| 105 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
107 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 106 |
catalogClient.reduceReservationCount(itemId, warehouseId, quantity);
|
108 |
catalogClient.reduceReservationCount(itemId, warehouseId, quantity);
|
| 107 |
}catch(Exception e){
|
109 |
}catch(Exception e){
|
| 108 |
// TODO: Oops! We couldn't reduce the item reservation count. This will
|
110 |
// TODO: Oops! We couldn't reduce the item reservation count. This will
|
| 109 |
// result in underestimation of inventory stock. Should be corrected
|
111 |
// result in underestimation of inventory stock. Should be corrected
|
| Line 113... |
Line 115... |
| 113 |
}
|
115 |
}
|
| 114 |
|
116 |
|
| 115 |
|
117 |
|
| 116 |
public static Map<Long, String> getWarehousesForBillingWarehouse(long warehouseId){
|
118 |
public static Map<Long, String> getWarehousesForBillingWarehouse(long warehouseId){
|
| 117 |
try{
|
119 |
try{
|
| 118 |
CatalogClient catalogServiceClient = new CatalogClient();
|
120 |
InventoryClient catalogServiceClient = new InventoryClient();
|
| 119 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
121 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 120 |
List<Warehouse> warehouses = catalogClient.getWarehouses(null, InventoryType.GOOD, 0, warehouseId, 0);
|
122 |
List<Warehouse> warehouses = catalogClient.getWarehouses(null, InventoryType.GOOD, 0, warehouseId, 0);
|
| 121 |
Map<Long, String> warehouseMap = new HashMap<Long, String>();
|
123 |
Map<Long, String> warehouseMap = new HashMap<Long, String>();
|
| 122 |
for(Warehouse warehouse: warehouses){
|
124 |
for(Warehouse warehouse: warehouses){
|
| 123 |
warehouseMap.put(warehouse.getId(), warehouse.getDisplayName());
|
125 |
warehouseMap.put(warehouse.getId(), warehouse.getDisplayName());
|
| Line 132... |
Line 134... |
| 132 |
return null;
|
134 |
return null;
|
| 133 |
}
|
135 |
}
|
| 134 |
|
136 |
|
| 135 |
public static Warehouse getWarehouse(long warehouseId) {
|
137 |
public static Warehouse getWarehouse(long warehouseId) {
|
| 136 |
try{
|
138 |
try{
|
| 137 |
CatalogClient catalogServiceClient = new CatalogClient();
|
139 |
InventoryClient catalogServiceClient = new InventoryClient();
|
| 138 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
140 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 139 |
return catalogClient.getWarehouse(warehouseId);
|
141 |
return catalogClient.getWarehouse(warehouseId);
|
| 140 |
}catch(Exception e){
|
142 |
}catch(Exception e){
|
| 141 |
e.printStackTrace();
|
143 |
e.printStackTrace();
|
| 142 |
}
|
144 |
}
|