| 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;
|
| 2068 |
ankur.sing |
5 |
import in.shop2020.catalog.dashboard.shared.ItemsComparator;
|
| 1961 |
ankur.sing |
6 |
import in.shop2020.model.v1.catalog.InventoryService;
|
| 1992 |
ankur.sing |
7 |
import in.shop2020.model.v1.catalog.VendorItemPricing;
|
| 1961 |
ankur.sing |
8 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
|
|
9 |
|
|
|
10 |
import java.util.ArrayList;
|
| 2068 |
ankur.sing |
11 |
import java.util.Collections;
|
|
|
12 |
import java.util.Comparator;
|
| 1992 |
ankur.sing |
13 |
import java.util.HashMap;
|
| 1961 |
ankur.sing |
14 |
import java.util.List;
|
| 1992 |
ankur.sing |
15 |
import java.util.Map;
|
|
|
16 |
import java.util.Map.Entry;
|
| 1961 |
ankur.sing |
17 |
|
|
|
18 |
import com.google.gwt.core.client.GWT;
|
|
|
19 |
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
20 |
|
|
|
21 |
@SuppressWarnings("serial")
|
|
|
22 |
public class CatalogServiceImpl extends RemoteServiceServlet implements CatalogService {
|
|
|
23 |
|
|
|
24 |
public List<Item> getAllItems(){
|
|
|
25 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
26 |
|
|
|
27 |
try {
|
|
|
28 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
29 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
30 |
|
|
|
31 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);
|
| 1992 |
ankur.sing |
32 |
|
|
|
33 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
|
|
|
34 |
List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
|
|
|
35 |
itemList.add(getItemFromThriftItem(thriftItem, vip));
|
|
|
36 |
}
|
| 1961 |
ankur.sing |
37 |
} catch (Exception e) {
|
|
|
38 |
e.printStackTrace();
|
|
|
39 |
}
|
| 2068 |
ankur.sing |
40 |
Collections.sort(itemList, new ItemsComparator());
|
| 1961 |
ankur.sing |
41 |
return itemList;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
public List<Item> getBestDeals(){
|
|
|
45 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
46 |
|
|
|
47 |
try {
|
|
|
48 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
49 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
50 |
|
|
|
51 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
|
| 1992 |
ankur.sing |
52 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
|
|
|
53 |
List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
|
|
|
54 |
itemList.add(getItemFromThriftItem(thriftItem, vip));
|
|
|
55 |
}
|
| 1961 |
ankur.sing |
56 |
} catch(Exception e){
|
|
|
57 |
e.printStackTrace();
|
|
|
58 |
}
|
| 2068 |
ankur.sing |
59 |
Collections.sort(itemList, new ItemsComparator());
|
| 1961 |
ankur.sing |
60 |
return itemList;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
public List<Item> getBestSellers(){
|
|
|
64 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
65 |
|
|
|
66 |
try {
|
|
|
67 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
68 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
69 |
|
|
|
70 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
|
| 1992 |
ankur.sing |
71 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
|
|
|
72 |
List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
|
|
|
73 |
itemList.add(getItemFromThriftItem(thriftItem, vip));
|
|
|
74 |
}
|
| 1961 |
ankur.sing |
75 |
} catch(Exception e){
|
|
|
76 |
e.printStackTrace();
|
|
|
77 |
}
|
| 2068 |
ankur.sing |
78 |
Collections.sort(itemList, new ItemsComparator());
|
| 1961 |
ankur.sing |
79 |
return itemList;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
public List<Item> getLatestArrivals(){
|
|
|
83 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
84 |
|
|
|
85 |
try {
|
|
|
86 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
87 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
88 |
|
|
|
89 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
|
| 1992 |
ankur.sing |
90 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
|
|
|
91 |
List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
|
|
|
92 |
itemList.add(getItemFromThriftItem(thriftItem, vip));
|
|
|
93 |
}
|
| 1961 |
ankur.sing |
94 |
} catch(Exception e){
|
|
|
95 |
e.printStackTrace();
|
|
|
96 |
}
|
| 2068 |
ankur.sing |
97 |
Collections.sort(itemList, new ItemsComparator());
|
| 1961 |
ankur.sing |
98 |
return itemList;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
public Item getItem(long itemId){
|
|
|
102 |
try{
|
|
|
103 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
104 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
105 |
in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
|
| 1992 |
ankur.sing |
106 |
|
|
|
107 |
List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
|
|
|
108 |
return getItemFromThriftItem(thriftItem, vip);
|
| 1961 |
ankur.sing |
109 |
}catch(Exception e){
|
|
|
110 |
// Oops! We didn't receive the details. We should let the user know
|
|
|
111 |
// that the catalog service is currently unavailable.
|
|
|
112 |
e.printStackTrace();
|
|
|
113 |
}
|
|
|
114 |
return null;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
public void reduceReservationCount(long itemId, long warehouseId, double quantity){
|
|
|
118 |
GWT.log("Got a call to reduce the reservation count for item " + itemId + " and warehouse " + warehouseId);
|
|
|
119 |
try{
|
|
|
120 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
121 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
122 |
catalogClient.reduceReservationCount(itemId, warehouseId, quantity);
|
|
|
123 |
}catch(Exception e){
|
|
|
124 |
// TODO: Oops! We couldn't reduce the item reservation count. This will
|
|
|
125 |
// result in underestimation of inventory stock. Should be corrected
|
|
|
126 |
// periodically.
|
|
|
127 |
e.printStackTrace();
|
|
|
128 |
}
|
|
|
129 |
}
|
|
|
130 |
|
| 1992 |
ankur.sing |
131 |
private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, List<in.shop2020.model.v1.catalog.VendorItemPricing> thriftItemPricings){
|
|
|
132 |
|
|
|
133 |
Map<Long, double[]> vendorPricings = new HashMap<Long, double[]>();
|
|
|
134 |
double[] prices;
|
|
|
135 |
if(thriftItemPricings != null) {
|
|
|
136 |
for(VendorItemPricing v : thriftItemPricings) {
|
|
|
137 |
prices = new double[3];
|
|
|
138 |
prices[0] = v.getMop();
|
|
|
139 |
prices[1] = v.getDealerPrice();
|
|
|
140 |
prices[2] = v.getTransferPrice();
|
|
|
141 |
vendorPricings.put(v.getVendorId(), prices);
|
|
|
142 |
}
|
|
|
143 |
}
|
| 1961 |
ankur.sing |
144 |
Item item = new Item(thriftItem.getId(),
|
|
|
145 |
thriftItem.getProductGroup(),
|
|
|
146 |
thriftItem.getBrand(),
|
|
|
147 |
thriftItem.getModelNumber(),
|
|
|
148 |
thriftItem.getModelName(),
|
|
|
149 |
thriftItem.getColor(),
|
|
|
150 |
thriftItem.getCategory(),
|
| 2027 |
ankur.sing |
151 |
//CategoryManager.getCategoryManager().getCategoryLabel(thriftItem.getCategory()),
|
| 1961 |
ankur.sing |
152 |
thriftItem.getComments(),
|
|
|
153 |
thriftItem.getCatalogItemId(),
|
|
|
154 |
thriftItem.getFeatureId(),
|
|
|
155 |
thriftItem.getFeatureDescription(),
|
|
|
156 |
thriftItem.getMrp(),
|
|
|
157 |
thriftItem.getMop(),
|
|
|
158 |
thriftItem.getSellingPrice(),
|
|
|
159 |
thriftItem.getDealerPrice(),
|
|
|
160 |
thriftItem.getWeight(),
|
|
|
161 |
thriftItem.getAddedOn(),
|
|
|
162 |
thriftItem.getStartDate(),
|
|
|
163 |
thriftItem.getRetireDate(),
|
|
|
164 |
thriftItem.getUpdatedOn(),
|
| 1992 |
ankur.sing |
165 |
thriftItem.getItemStatus().name(),
|
| 1961 |
ankur.sing |
166 |
thriftItem.getOtherInfo(),
|
|
|
167 |
thriftItem.getBestDealText(),
|
| 1992 |
ankur.sing |
168 |
thriftItem.getBestDealValue(),
|
| 2066 |
ankur.sing |
169 |
thriftItem.getBestSellingRank(),
|
|
|
170 |
thriftItem.isDefaultForEntity(),
|
| 1992 |
ankur.sing |
171 |
(thriftItem.getItemInventory() != null ? thriftItem.getItemInventory().getAvailability() : null),
|
|
|
172 |
vendorPricings
|
|
|
173 |
);
|
| 1961 |
ankur.sing |
174 |
return item;
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
@Override
|
| 1992 |
ankur.sing |
178 |
public boolean updateItem(Item item) {
|
|
|
179 |
GWT.log("Got a call to update item, Item Id: " + item.getId());
|
| 1961 |
ankur.sing |
180 |
try{
|
|
|
181 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
182 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 1992 |
ankur.sing |
183 |
|
|
|
184 |
in.shop2020.model.v1.catalog.Item tItem = catalogClient.getItem(item.getId());
|
| 2027 |
ankur.sing |
185 |
tItem.setProductGroup(item.getProductGroup());
|
|
|
186 |
tItem.setBrand(item.getBrand());
|
|
|
187 |
tItem.setModelName(item.getModelName());
|
|
|
188 |
tItem.setModelNumber(item.getModelNumber());
|
|
|
189 |
tItem.setColor(item.getColor());
|
| 1992 |
ankur.sing |
190 |
|
| 2027 |
ankur.sing |
191 |
tItem.setComments(item.getComments());
|
|
|
192 |
|
| 1992 |
ankur.sing |
193 |
tItem.setMrp(item.getMrp());
|
|
|
194 |
tItem.setSellingPrice(item.getSellingPrice());
|
|
|
195 |
tItem.setWeight(item.getWeight());
|
|
|
196 |
|
| 2027 |
ankur.sing |
197 |
tItem.setMop(item.getMop());
|
|
|
198 |
tItem.setDealerPrice(item.getDealerPrice());
|
|
|
199 |
tItem.setTransferPrice(item.getTransferPrice());
|
|
|
200 |
|
|
|
201 |
tItem.setBestDealText(item.getBestDealsText());
|
|
|
202 |
tItem.setBestDealValue(item.getBestDealsValue());
|
| 2066 |
ankur.sing |
203 |
tItem.setBestSellingRank(item.getBestSellingRank());
|
|
|
204 |
tItem.setDefaultForEntity(item.isDefaultForEntity());
|
| 2027 |
ankur.sing |
205 |
|
| 2068 |
ankur.sing |
206 |
tItem.setStartDate(item.getStartDate());
|
| 2027 |
ankur.sing |
207 |
// tItem.setAddedOn(item.getAddedOn());
|
|
|
208 |
|
|
|
209 |
// tItem.setCatalogItemId(item.getCatalogItemId());
|
|
|
210 |
// tItem.setCategory(item.getCategory());
|
|
|
211 |
|
|
|
212 |
// tItem.setFeatureId(item.getFeatureId());
|
|
|
213 |
// tItem.setFeatureDescription(item.getFeatureDescription());
|
|
|
214 |
|
| 2066 |
ankur.sing |
215 |
/*List<VendorItemPricing> tVendorPrices = tItem.getVendorPrices();
|
|
|
216 |
if(tVendorPrices == null) {
|
|
|
217 |
tVendorPrices = new ArrayList<VendorItemPricing>();
|
|
|
218 |
}
|
|
|
219 |
for(Entry<Long, double[]> vendorItemPricing : item.getVendorPricings().entrySet()) {
|
|
|
220 |
VendorItemPricing vip = null;
|
|
|
221 |
for(VendorItemPricing v : tVendorPrices) {
|
|
|
222 |
if(v.getVendorId() == vendorItemPricing.getKey()) {
|
|
|
223 |
vip = v;
|
|
|
224 |
break;
|
|
|
225 |
}
|
|
|
226 |
}
|
|
|
227 |
if(vip == null) {
|
|
|
228 |
vip = new VendorItemPricing();
|
|
|
229 |
tVendorPrices.add(vip);
|
|
|
230 |
}
|
|
|
231 |
vip.setItemId(item.getId());
|
|
|
232 |
vip.setVendorId(vendorItemPricing.getKey());
|
|
|
233 |
vip.setMop(vendorItemPricing.getValue()[Item.INDEX_MOP]);
|
|
|
234 |
vip.setDealerPrice(vendorItemPricing.getValue()[Item.INDEX_DP]);
|
|
|
235 |
vip.setTransferPrice(vendorItemPricing.getValue()[Item.INDEX_TP]);
|
|
|
236 |
//catalogClient.updateVendorItemPricing(vip);
|
|
|
237 |
}*/
|
|
|
238 |
|
| 1992 |
ankur.sing |
239 |
VendorItemPricing vip = new VendorItemPricing();
|
|
|
240 |
for(Entry<Long, double[]> vendorItemPricing : item.getVendorPricings().entrySet()) {
|
|
|
241 |
vip.setItemId(item.getId());
|
|
|
242 |
vip.setVendorId(vendorItemPricing.getKey());
|
|
|
243 |
vip.setMop(vendorItemPricing.getValue()[Item.INDEX_MOP]);
|
|
|
244 |
vip.setDealerPrice(vendorItemPricing.getValue()[Item.INDEX_DP]);
|
|
|
245 |
vip.setTransferPrice(vendorItemPricing.getValue()[Item.INDEX_TP]);
|
|
|
246 |
catalogClient.updateVendorItemPricing(vip);
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
if(catalogClient.updateItem(tItem) == item.getId());
|
|
|
250 |
return true;
|
|
|
251 |
|
| 1961 |
ankur.sing |
252 |
}catch(Exception e){
|
|
|
253 |
e.printStackTrace();
|
|
|
254 |
}
|
| 1992 |
ankur.sing |
255 |
return false;
|
| 1961 |
ankur.sing |
256 |
}
|
| 2066 |
ankur.sing |
257 |
|
|
|
258 |
|
|
|
259 |
@Override
|
|
|
260 |
public Map<Long, String> getAllVendors() {
|
|
|
261 |
Map<Long, String> vendorMap = new HashMap<Long, String>();
|
|
|
262 |
try {
|
|
|
263 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
264 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
265 |
|
|
|
266 |
List<in.shop2020.model.v1.catalog.Vendor> vendors = catalogClient.getAllVendors();
|
|
|
267 |
|
|
|
268 |
for(in.shop2020.model.v1.catalog.Vendor v : vendors) {
|
|
|
269 |
vendorMap.put(v.getId(), v.getName());
|
|
|
270 |
}
|
|
|
271 |
} catch (Exception e) {
|
|
|
272 |
e.printStackTrace();
|
|
|
273 |
}
|
|
|
274 |
return vendorMap;
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
@Override
|
|
|
278 |
public Map<Long, String> getAllWarehouses() {
|
|
|
279 |
Map<Long, String> warehouseMap = new HashMap<Long, String>();
|
|
|
280 |
try {
|
|
|
281 |
CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
282 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
283 |
|
|
|
284 |
List<in.shop2020.model.v1.catalog.Warehouse> warehouses = catalogClient.getAllWarehouses(true);
|
|
|
285 |
|
|
|
286 |
for(in.shop2020.model.v1.catalog.Warehouse w : warehouses) {
|
|
|
287 |
warehouseMap.put(w.getId(), w.getDisplayName());
|
|
|
288 |
}
|
|
|
289 |
} catch (Exception e) {
|
|
|
290 |
e.printStackTrace();
|
|
|
291 |
}
|
|
|
292 |
return warehouseMap;
|
|
|
293 |
}
|
| 1961 |
ankur.sing |
294 |
}
|