| 1961 |
ankur.sing |
1 |
package in.shop2020.catalog.dashboard.server;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.catalog.dashboard.client.CatalogService;
|
|
|
4 |
import in.shop2020.catalog.dashboard.shared.Item;
|
|
|
5 |
import in.shop2020.model.v1.catalog.InventoryService;
|
|
|
6 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
|
|
7 |
|
|
|
8 |
import java.util.ArrayList;
|
|
|
9 |
import java.util.List;
|
|
|
10 |
|
|
|
11 |
import com.google.gwt.core.client.GWT;
|
|
|
12 |
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
13 |
|
|
|
14 |
@SuppressWarnings("serial")
|
|
|
15 |
public class CatalogServiceImpl extends RemoteServiceServlet implements CatalogService {
|
|
|
16 |
|
|
|
17 |
public List<Item> getAllItems(){
|
|
|
18 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
19 |
|
|
|
20 |
try {
|
|
|
21 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
22 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
23 |
|
|
|
24 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
|
|
|
25 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
|
|
26 |
itemList.add(getItemFromThriftItem(thriftItem));
|
|
|
27 |
} catch (Exception e) {
|
|
|
28 |
e.printStackTrace();
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
return itemList;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public List<Item> getBestDeals(){
|
|
|
35 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
36 |
|
|
|
37 |
try {
|
|
|
38 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
39 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
40 |
|
|
|
41 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
|
|
|
42 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
|
|
43 |
itemList.add(getItemFromThriftItem(thriftItem));
|
|
|
44 |
} catch(Exception e){
|
|
|
45 |
e.printStackTrace();
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
return itemList;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
public List<Item> getBestSellers(){
|
|
|
52 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
53 |
|
|
|
54 |
try {
|
|
|
55 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
56 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
57 |
|
|
|
58 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
|
|
|
59 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
|
|
60 |
itemList.add(getItemFromThriftItem(thriftItem));
|
|
|
61 |
} catch(Exception e){
|
|
|
62 |
e.printStackTrace();
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
return itemList;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
public List<Item> getLatestArrivals(){
|
|
|
69 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
70 |
|
|
|
71 |
try {
|
|
|
72 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
73 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
74 |
|
|
|
75 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
|
|
|
76 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems)
|
|
|
77 |
itemList.add(getItemFromThriftItem(thriftItem));
|
|
|
78 |
} catch(Exception e){
|
|
|
79 |
e.printStackTrace();
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
return itemList;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
public Item getItem(long itemId){
|
|
|
86 |
try{
|
|
|
87 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
88 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
89 |
in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
|
|
|
90 |
return getItemFromThriftItem(thriftItem);
|
|
|
91 |
}catch(Exception e){
|
|
|
92 |
// Oops! We didn't receive the details. We should let the user know
|
|
|
93 |
// that the catalog service is currently unavailable.
|
|
|
94 |
e.printStackTrace();
|
|
|
95 |
}
|
|
|
96 |
return null;
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
public void reduceReservationCount(long itemId, long warehouseId, double quantity){
|
|
|
100 |
GWT.log("Got a call to reduce the reservation count for item " + itemId + " and warehouse " + warehouseId);
|
|
|
101 |
try{
|
|
|
102 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
103 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
104 |
catalogClient.reduceReservationCount(itemId, warehouseId, quantity);
|
|
|
105 |
}catch(Exception e){
|
|
|
106 |
// TODO: Oops! We couldn't reduce the item reservation count. This will
|
|
|
107 |
// result in underestimation of inventory stock. Should be corrected
|
|
|
108 |
// periodically.
|
|
|
109 |
e.printStackTrace();
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem){
|
|
|
114 |
Item item = new Item(thriftItem.getId(),
|
|
|
115 |
thriftItem.getProductGroup(),
|
|
|
116 |
thriftItem.getBrand(),
|
|
|
117 |
thriftItem.getModelNumber(),
|
|
|
118 |
thriftItem.getModelName(),
|
|
|
119 |
thriftItem.getColor(),
|
|
|
120 |
thriftItem.getCategory(),
|
|
|
121 |
thriftItem.getComments(),
|
|
|
122 |
thriftItem.getCatalogItemId(),
|
|
|
123 |
thriftItem.getFeatureId(),
|
|
|
124 |
thriftItem.getFeatureDescription(),
|
|
|
125 |
//thriftItem.getItemInventory(),
|
|
|
126 |
thriftItem.getMrp(),
|
|
|
127 |
thriftItem.getMop(),
|
|
|
128 |
thriftItem.getSellingPrice(),
|
|
|
129 |
thriftItem.getDealerPrice(),
|
|
|
130 |
thriftItem.getWeight(),
|
|
|
131 |
thriftItem.getAddedOn(),
|
|
|
132 |
thriftItem.getStartDate(),
|
|
|
133 |
thriftItem.getRetireDate(),
|
|
|
134 |
thriftItem.getUpdatedOn(),
|
|
|
135 |
//thriftItem.getItemStatus(),
|
|
|
136 |
thriftItem.getOtherInfo(),
|
|
|
137 |
thriftItem.getBestDealText(),
|
|
|
138 |
thriftItem.getBestDealValue());
|
|
|
139 |
return item;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
@Override
|
|
|
143 |
public void updatePrice(long itemId, double sellingPrice) {
|
|
|
144 |
GWT.log("Got a call to update price of " + itemId + ", selling price " + sellingPrice);
|
|
|
145 |
try{
|
|
|
146 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
147 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
148 |
//TODO: Implement update price method in service
|
|
|
149 |
}catch(Exception e){
|
|
|
150 |
e.printStackTrace();
|
|
|
151 |
}
|
|
|
152 |
}
|
|
|
153 |
}
|