| 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.InventoryService;
|
4 |
import in.shop2020.model.v1.catalog.InventoryService;
|
| 5 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
5 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 6 |
|
6 |
|
| 7 |
import java.util.ArrayList;
|
7 |
import java.util.ArrayList;
|
| 8 |
import java.util.List;
|
8 |
import java.util.List;
|
| 9 |
|
9 |
|
| 10 |
import com.google.gwt.core.client.GWT;
|
10 |
import com.google.gwt.core.client.GWT;
|
| Line 12... |
Line 12... |
| 12 |
public class CatalogUtils {
|
12 |
public class CatalogUtils {
|
| 13 |
public static List<Item> getAllItems(){
|
13 |
public static List<Item> getAllItems(){
|
| 14 |
List<Item> itemList = new ArrayList<Item>();
|
14 |
List<Item> itemList = new ArrayList<Item>();
|
| 15 |
|
15 |
|
| 16 |
try {
|
16 |
try {
|
| 17 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
17 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 18 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
18 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 19 |
|
19 |
|
| 20 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
|
20 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
|
| 21 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
21 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
| 22 |
itemList.add(getItemFromThriftItem(thriftItem));
|
22 |
itemList.add(getItemFromThriftItem(thriftItem));
|
| Line 31... |
Line 31... |
| 31 |
|
31 |
|
| 32 |
public static List<Item> getBestDeals(){
|
32 |
public static List<Item> getBestDeals(){
|
| 33 |
List<Item> itemList = new ArrayList<Item>();
|
33 |
List<Item> itemList = new ArrayList<Item>();
|
| 34 |
|
34 |
|
| 35 |
try {
|
35 |
try {
|
| 36 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
36 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 37 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
37 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 38 |
|
38 |
|
| 39 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
|
39 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
|
| 40 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
40 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
| 41 |
itemList.add(getItemFromThriftItem(thriftItem));
|
41 |
itemList.add(getItemFromThriftItem(thriftItem));
|
| Line 48... |
Line 48... |
| 48 |
|
48 |
|
| 49 |
public static List<Item> getBestSellers(){
|
49 |
public static List<Item> getBestSellers(){
|
| 50 |
List<Item> itemList = new ArrayList<Item>();
|
50 |
List<Item> itemList = new ArrayList<Item>();
|
| 51 |
|
51 |
|
| 52 |
try {
|
52 |
try {
|
| 53 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
53 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 54 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
54 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 55 |
|
55 |
|
| 56 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
|
56 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
|
| 57 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
57 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
| 58 |
itemList.add(getItemFromThriftItem(thriftItem));
|
58 |
itemList.add(getItemFromThriftItem(thriftItem));
|
| Line 65... |
Line 65... |
| 65 |
|
65 |
|
| 66 |
public static List<Item> getLatestArrivals(){
|
66 |
public static List<Item> getLatestArrivals(){
|
| 67 |
List<Item> itemList = new ArrayList<Item>();
|
67 |
List<Item> itemList = new ArrayList<Item>();
|
| 68 |
|
68 |
|
| 69 |
try {
|
69 |
try {
|
| 70 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
70 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 71 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
71 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 72 |
|
72 |
|
| 73 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
|
73 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
|
| 74 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
74 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
| 75 |
itemList.add(getItemFromThriftItem(thriftItem));
|
75 |
itemList.add(getItemFromThriftItem(thriftItem));
|
| Line 80... |
Line 80... |
| 80 |
return itemList;
|
80 |
return itemList;
|
| 81 |
}
|
81 |
}
|
| 82 |
|
82 |
|
| 83 |
public static Item getItem(long itemId){
|
83 |
public static Item getItem(long itemId){
|
| 84 |
try{
|
84 |
try{
|
| 85 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
85 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 86 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
86 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 87 |
in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
|
87 |
in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
|
| 88 |
return getItemFromThriftItem(thriftItem);
|
88 |
return getItemFromThriftItem(thriftItem);
|
| 89 |
}catch(Exception e){
|
89 |
}catch(Exception e){
|
| 90 |
// Oops! We didn't receive the details. We should let the user know
|
90 |
// Oops! We didn't receive the details. We should let the user know
|
| Line 95... |
Line 95... |
| 95 |
}
|
95 |
}
|
| 96 |
|
96 |
|
| 97 |
public static void reduceReservationCount(long itemId, long warehouseId, double quantity){
|
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);
|
98 |
GWT.log("Got a call to reduce the reservation count for item " + itemId + " and warehouse " + warehouseId);
|
| 99 |
try{
|
99 |
try{
|
| 100 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
100 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 101 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
101 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 102 |
catalogClient.reduceReservationCount(itemId, warehouseId, quantity);
|
102 |
catalogClient.reduceReservationCount(itemId, warehouseId, quantity);
|
| 103 |
}catch(Exception e){
|
103 |
}catch(Exception e){
|
| 104 |
// TODO: Oops! We couldn't reduce the item reservation count. This will
|
104 |
// TODO: Oops! We couldn't reduce the item reservation count. This will
|
| 105 |
// result in underestimation of inventory stock. Should be corrected
|
105 |
// result in underestimation of inventory stock. Should be corrected
|