| 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;
|
|
|
5 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
|
|
6 |
|
|
|
7 |
import java.util.ArrayList;
|
|
|
8 |
import java.util.List;
|
|
|
9 |
|
|
|
10 |
public class CatalogUtils {
|
|
|
11 |
public static List<Item> getAllItems(){
|
|
|
12 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
13 |
|
|
|
14 |
try {
|
|
|
15 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
16 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
17 |
|
|
|
18 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
|
| 585 |
chandransh |
19 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
|
|
20 |
itemList.add(getItemFromThriftItem(thriftItem));
|
| 584 |
chandransh |
21 |
} catch (Exception e) {
|
| 585 |
chandransh |
22 |
// Not getting any items in the catalog is as good as not having any
|
|
|
23 |
// items in the catalog.
|
| 584 |
chandransh |
24 |
e.printStackTrace();
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
return itemList;
|
|
|
28 |
}
|
| 585 |
chandransh |
29 |
|
| 597 |
chandransh |
30 |
public static List<Item> getBestDeals(){
|
|
|
31 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
32 |
|
|
|
33 |
try {
|
|
|
34 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
35 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
36 |
|
|
|
37 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
|
|
|
38 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
|
|
39 |
itemList.add(getItemFromThriftItem(thriftItem));
|
|
|
40 |
} catch(Exception e){
|
|
|
41 |
e.printStackTrace();
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
return itemList;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public static List<Item> getBestSellers(){
|
|
|
48 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
49 |
|
|
|
50 |
try {
|
|
|
51 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
52 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
53 |
|
|
|
54 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
|
|
|
55 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
|
|
56 |
itemList.add(getItemFromThriftItem(thriftItem));
|
|
|
57 |
} catch(Exception e){
|
|
|
58 |
e.printStackTrace();
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
return itemList;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
public static List<Item> getLatestArrivals(){
|
|
|
65 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
66 |
|
|
|
67 |
try {
|
|
|
68 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
69 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
70 |
|
|
|
71 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
|
|
|
72 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
|
|
73 |
itemList.add(getItemFromThriftItem(thriftItem));
|
|
|
74 |
} catch(Exception e){
|
|
|
75 |
e.printStackTrace();
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
return itemList;
|
|
|
79 |
}
|
|
|
80 |
|
| 585 |
chandransh |
81 |
public static Item getItem(long itemId){
|
|
|
82 |
try{
|
|
|
83 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
84 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
85 |
in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
|
|
|
86 |
return getItemFromThriftItem(thriftItem);
|
|
|
87 |
}catch(Exception e){
|
|
|
88 |
// Oops! We didn't receive the details. We should let the user know
|
|
|
89 |
// that the catalog service is currently unavailable.
|
|
|
90 |
e.printStackTrace();
|
|
|
91 |
}
|
|
|
92 |
return null;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
private static Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem){
|
|
|
96 |
Item item = new Item(thriftItem.getId(),
|
|
|
97 |
thriftItem.getManufacturerName(),
|
|
|
98 |
thriftItem.getModelNumber(),
|
|
|
99 |
thriftItem.getModelName(),
|
| 608 |
chandransh |
100 |
thriftItem.getColor(),
|
| 585 |
chandransh |
101 |
thriftItem.getCategory(),
|
|
|
102 |
thriftItem.getComments(),
|
|
|
103 |
thriftItem.getCatalogItemId(),
|
|
|
104 |
thriftItem.getVendorItemId(),
|
|
|
105 |
thriftItem.getFeatureId(),
|
|
|
106 |
thriftItem.getFeatureDescription(),
|
|
|
107 |
//thriftItem.getItemInventory(),
|
|
|
108 |
thriftItem.getMrp(),
|
|
|
109 |
thriftItem.getMop(),
|
|
|
110 |
thriftItem.getSellingPrice(),
|
| 608 |
chandransh |
111 |
thriftItem.getDealerPrice(),
|
| 585 |
chandransh |
112 |
thriftItem.getWeight(),
|
|
|
113 |
thriftItem.getAddedOn(),
|
|
|
114 |
thriftItem.getStartDate(),
|
| 608 |
chandransh |
115 |
thriftItem.getRetireDate(),
|
|
|
116 |
thriftItem.getUpdatedOn(),
|
| 585 |
chandransh |
117 |
//thriftItem.getItemStatus(),
|
| 608 |
chandransh |
118 |
thriftItem.getOtherInfo(),
|
|
|
119 |
thriftItem.getBestDealText(),
|
|
|
120 |
thriftItem.getBestDealValue());
|
| 585 |
chandransh |
121 |
return item;
|
|
|
122 |
}
|
| 584 |
chandransh |
123 |
}
|