| 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;
|
| 4431 |
phani.kuma |
5 |
import in.shop2020.catalog.dashboard.shared.ItemInventory;
|
| 3850 |
chandransh |
6 |
import in.shop2020.catalog.dashboard.shared.ItemStatus;
|
| 2068 |
ankur.sing |
7 |
import in.shop2020.catalog.dashboard.shared.ItemsComparator;
|
| 3558 |
rajveer |
8 |
import in.shop2020.catalog.dashboard.shared.SourcePricings;
|
| 2119 |
ankur.sing |
9 |
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
|
|
|
10 |
import in.shop2020.catalog.dashboard.shared.VendorPricings;
|
| 2378 |
ankur.sing |
11 |
import in.shop2020.config.ConfigException;
|
| 3907 |
chandransh |
12 |
import in.shop2020.content.ContentService;
|
|
|
13 |
import in.shop2020.content.ContentServiceException;
|
| 1961 |
ankur.sing |
14 |
import in.shop2020.model.v1.catalog.InventoryService;
|
| 3911 |
chandransh |
15 |
import in.shop2020.model.v1.catalog.SourceItemPricing;
|
| 2105 |
ankur.sing |
16 |
import in.shop2020.model.v1.catalog.status;
|
| 3129 |
rajveer |
17 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 3907 |
chandransh |
18 |
import in.shop2020.thrift.clients.ContentClient;
|
| 2378 |
ankur.sing |
19 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 2119 |
ankur.sing |
20 |
import in.shop2020.utils.CategoryManager;
|
| 2359 |
ankur.sing |
21 |
import in.shop2020.utils.ConfigClientKeys;
|
| 1961 |
ankur.sing |
22 |
|
| 2427 |
ankur.sing |
23 |
import java.io.BufferedReader;
|
|
|
24 |
import java.io.FileReader;
|
| 2359 |
ankur.sing |
25 |
import java.io.IOException;
|
| 2427 |
ankur.sing |
26 |
import java.text.DateFormat;
|
|
|
27 |
import java.text.SimpleDateFormat;
|
| 1961 |
ankur.sing |
28 |
import java.util.ArrayList;
|
| 2105 |
ankur.sing |
29 |
import java.util.Calendar;
|
| 2068 |
ankur.sing |
30 |
import java.util.Collections;
|
| 2427 |
ankur.sing |
31 |
import java.util.Date;
|
| 1992 |
ankur.sing |
32 |
import java.util.HashMap;
|
| 1961 |
ankur.sing |
33 |
import java.util.List;
|
| 1992 |
ankur.sing |
34 |
import java.util.Map;
|
| 2359 |
ankur.sing |
35 |
import java.util.Map.Entry;
|
| 1961 |
ankur.sing |
36 |
|
| 2427 |
ankur.sing |
37 |
import org.apache.log4j.Logger;
|
| 3907 |
chandransh |
38 |
import org.apache.thrift.TException;
|
|
|
39 |
import org.apache.thrift.transport.TTransportException;
|
| 2359 |
ankur.sing |
40 |
|
| 1961 |
ankur.sing |
41 |
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
42 |
|
|
|
43 |
@SuppressWarnings("serial")
|
|
|
44 |
public class CatalogServiceImpl extends RemoteServiceServlet implements CatalogService {
|
|
|
45 |
|
| 3354 |
chandransh |
46 |
private static Logger logger = Logger.getLogger(CatalogServiceImpl.class);
|
|
|
47 |
|
| 3922 |
chandransh |
48 |
private static Logger pushToProdLogger = Logger.getLogger("pushToProdLogger");
|
|
|
49 |
|
| 2427 |
ankur.sing |
50 |
private static Date pushToProdDate;
|
|
|
51 |
|
| 3922 |
chandransh |
52 |
private static String logFile;
|
|
|
53 |
|
|
|
54 |
private static int maxCount;
|
|
|
55 |
|
|
|
56 |
static {
|
|
|
57 |
try {
|
|
|
58 |
logFile = ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_log_file.toString());
|
|
|
59 |
maxCount = Integer.parseInt(ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_max_count.toString()));
|
|
|
60 |
} catch(ConfigException ce) {
|
|
|
61 |
logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
|
|
|
62 |
logFile = "/var/log/services/pushToProductionCount/pushToProd.log";
|
|
|
63 |
maxCount = 5;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
}
|
|
|
67 |
|
| 3850 |
chandransh |
68 |
@Override
|
|
|
69 |
public int getItemCountByStatus(boolean useStatus, ItemStatus itemStatus){
|
|
|
70 |
int count = 0;
|
|
|
71 |
try{
|
|
|
72 |
CatalogClient catalogServiceClient = new CatalogClient();
|
|
|
73 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
74 |
|
|
|
75 |
status stat = status.findByValue(itemStatus.getValue());
|
|
|
76 |
count = catalogClient.getItemCountByStatus(useStatus, stat);
|
|
|
77 |
}catch(Exception e){
|
|
|
78 |
logger.error("Error while getting the count of items from the catalog service", e);
|
|
|
79 |
}
|
|
|
80 |
return count;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
@Override
|
|
|
84 |
public List<Item> getAllItems(int start, int limit) {
|
| 1961 |
ankur.sing |
85 |
List<Item> itemList = new ArrayList<Item>();
|
| 2359 |
ankur.sing |
86 |
|
| 1961 |
ankur.sing |
87 |
try {
|
| 3129 |
rajveer |
88 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 1961 |
ankur.sing |
89 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2359 |
ankur.sing |
90 |
|
| 3850 |
chandransh |
91 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsInRange(start, limit);
|
| 2359 |
ankur.sing |
92 |
|
| 2119 |
ankur.sing |
93 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
|
| 4423 |
phani.kuma |
94 |
itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null));
|
| 2119 |
ankur.sing |
95 |
}
|
|
|
96 |
} catch (Exception e) {
|
| 3354 |
chandransh |
97 |
logger.error("Error while getting all items from the catalog service", e);
|
| 2119 |
ankur.sing |
98 |
}
|
|
|
99 |
return itemList;
|
|
|
100 |
}
|
| 2208 |
ankur.sing |
101 |
|
| 3850 |
chandransh |
102 |
public List<Item> getAllActiveItems(int start, int limit){
|
|
|
103 |
return getItemsByStatus(status.ACTIVE, start, limit);
|
| 2208 |
ankur.sing |
104 |
}
|
| 2359 |
ankur.sing |
105 |
|
|
|
106 |
@Override
|
| 3850 |
chandransh |
107 |
public List<Item> getAllPhasedOutItems(int start, int limit){
|
|
|
108 |
return getItemsByStatus(status.PHASED_OUT, start, limit);
|
| 2359 |
ankur.sing |
109 |
}
|
|
|
110 |
|
|
|
111 |
@Override
|
| 3850 |
chandransh |
112 |
public List<Item> getAllPausedItems(int start, int limit){
|
|
|
113 |
return getItemsByStatus(status.PAUSED, start, limit);
|
| 2208 |
ankur.sing |
114 |
}
|
| 2359 |
ankur.sing |
115 |
|
|
|
116 |
@Override
|
| 3850 |
chandransh |
117 |
public List<Item> getAllInProcessItems(int start, int limit) {
|
|
|
118 |
return getItemsByStatus(status.IN_PROCESS, start, limit);
|
| 2359 |
ankur.sing |
119 |
}
|
|
|
120 |
|
|
|
121 |
@Override
|
| 3850 |
chandransh |
122 |
public List<Item> getAllContentCompleteItems(int start, int limit) {
|
|
|
123 |
return getItemsByStatus(status.CONTENT_COMPLETE, start, limit);
|
| 2359 |
ankur.sing |
124 |
}
|
|
|
125 |
|
|
|
126 |
public List<Item> getBestDeals(){
|
| 2119 |
ankur.sing |
127 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
128 |
try {
|
| 3129 |
rajveer |
129 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 2119 |
ankur.sing |
130 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2359 |
ankur.sing |
131 |
|
|
|
132 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();
|
| 1992 |
ankur.sing |
133 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
|
| 4423 |
phani.kuma |
134 |
itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null));
|
| 1992 |
ankur.sing |
135 |
}
|
| 2359 |
ankur.sing |
136 |
} catch(Exception e){
|
| 3354 |
chandransh |
137 |
logger.error("Error while getting the best deals from the catalog service", e);
|
| 1961 |
ankur.sing |
138 |
}
|
| 2562 |
chandransh |
139 |
//Collections.sort(itemList, new ItemsComparator());
|
| 1961 |
ankur.sing |
140 |
return itemList;
|
|
|
141 |
}
|
|
|
142 |
|
| 2359 |
ankur.sing |
143 |
@Override
|
|
|
144 |
public List<Item> getRiskyItems() {
|
| 1961 |
ankur.sing |
145 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
146 |
try {
|
| 3129 |
rajveer |
147 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 1961 |
ankur.sing |
148 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2359 |
ankur.sing |
149 |
|
|
|
150 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();
|
| 1992 |
ankur.sing |
151 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
|
| 4423 |
phani.kuma |
152 |
itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null));
|
| 1992 |
ankur.sing |
153 |
}
|
| 1961 |
ankur.sing |
154 |
} catch(Exception e){
|
| 3354 |
chandransh |
155 |
logger.error("Error while getting the risky items from the catalog service", e);
|
| 1961 |
ankur.sing |
156 |
}
|
| 2068 |
ankur.sing |
157 |
Collections.sort(itemList, new ItemsComparator());
|
| 1961 |
ankur.sing |
158 |
return itemList;
|
|
|
159 |
}
|
| 2359 |
ankur.sing |
160 |
|
| 1961 |
ankur.sing |
161 |
public List<Item> getBestSellers(){
|
|
|
162 |
List<Item> itemList = new ArrayList<Item>();
|
| 2359 |
ankur.sing |
163 |
|
| 1961 |
ankur.sing |
164 |
try {
|
| 3129 |
rajveer |
165 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 1961 |
ankur.sing |
166 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2359 |
ankur.sing |
167 |
|
| 1961 |
ankur.sing |
168 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();
|
| 1992 |
ankur.sing |
169 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
|
| 4423 |
phani.kuma |
170 |
itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null));
|
| 1992 |
ankur.sing |
171 |
}
|
| 1961 |
ankur.sing |
172 |
} catch(Exception e){
|
| 3354 |
chandransh |
173 |
logger.error("Error while getting the best sellers from the catalog service", e);
|
| 1961 |
ankur.sing |
174 |
}
|
|
|
175 |
return itemList;
|
|
|
176 |
}
|
| 2359 |
ankur.sing |
177 |
|
| 3872 |
chandransh |
178 |
@Override
|
| 1961 |
ankur.sing |
179 |
public List<Item> getLatestArrivals(){
|
|
|
180 |
List<Item> itemList = new ArrayList<Item>();
|
| 2359 |
ankur.sing |
181 |
|
| 1961 |
ankur.sing |
182 |
try {
|
| 3129 |
rajveer |
183 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 1961 |
ankur.sing |
184 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2359 |
ankur.sing |
185 |
|
| 1961 |
ankur.sing |
186 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();
|
| 1992 |
ankur.sing |
187 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
|
| 2105 |
ankur.sing |
188 |
//List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
|
| 4423 |
phani.kuma |
189 |
itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null));
|
| 1992 |
ankur.sing |
190 |
}
|
| 1961 |
ankur.sing |
191 |
} catch(Exception e){
|
| 3354 |
chandransh |
192 |
logger.error("Error while getting the latest arrivals from the catalog service", e);
|
| 1961 |
ankur.sing |
193 |
}
|
|
|
194 |
return itemList;
|
|
|
195 |
}
|
| 2359 |
ankur.sing |
196 |
|
| 3872 |
chandransh |
197 |
@Override
|
|
|
198 |
public List<Item> searchItems(int start, int limit, List<String> searchTerms) {
|
|
|
199 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
200 |
|
|
|
201 |
try {
|
|
|
202 |
CatalogClient catalogServiceClient = new CatalogClient();
|
|
|
203 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
204 |
|
|
|
205 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.searchItemsInRange(searchTerms, start, limit);
|
|
|
206 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
|
| 4423 |
phani.kuma |
207 |
itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null));
|
| 3872 |
chandransh |
208 |
}
|
|
|
209 |
} catch(Exception e){
|
|
|
210 |
logger.error("Error while getting the search results from the catalog service", e);
|
|
|
211 |
}
|
|
|
212 |
return itemList;
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
@Override
|
|
|
216 |
public int getSearchResultCount(List<String> searchTerms){
|
|
|
217 |
int count = 0;
|
|
|
218 |
try {
|
|
|
219 |
CatalogClient catalogServiceClient = new CatalogClient();
|
|
|
220 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
221 |
|
|
|
222 |
count = catalogClient.getSearchResultCount(searchTerms);
|
|
|
223 |
} catch(Exception e){
|
|
|
224 |
logger.error("Error while getting the search results from the catalog service", e);
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
return count;
|
|
|
228 |
}
|
|
|
229 |
|
| 1961 |
ankur.sing |
230 |
public Item getItem(long itemId){
|
|
|
231 |
try{
|
| 3129 |
rajveer |
232 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 1961 |
ankur.sing |
233 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
234 |
in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
|
| 2359 |
ankur.sing |
235 |
|
| 1992 |
ankur.sing |
236 |
List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
|
| 2119 |
ankur.sing |
237 |
List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
|
| 3558 |
rajveer |
238 |
List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
|
| 4423 |
phani.kuma |
239 |
List<in.shop2020.model.v1.catalog.Item> sit = catalogClient.getAllSimilarItems(thriftItem.getId());
|
|
|
240 |
return getItemFromThriftItem(thriftItem, vip, vim, sip, sit);
|
| 1961 |
ankur.sing |
241 |
}catch(Exception e){
|
| 3354 |
chandransh |
242 |
logger.error("Error while getting the item from the catalog service", e);
|
| 1961 |
ankur.sing |
243 |
}
|
|
|
244 |
return null;
|
|
|
245 |
}
|
| 2359 |
ankur.sing |
246 |
|
| 1961 |
ankur.sing |
247 |
@Override
|
| 1992 |
ankur.sing |
248 |
public boolean updateItem(Item item) {
|
| 3354 |
chandransh |
249 |
logger.info("Updating item with Id: " + item.getId());
|
| 1961 |
ankur.sing |
250 |
try{
|
| 3129 |
rajveer |
251 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 1961 |
ankur.sing |
252 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2359 |
ankur.sing |
253 |
|
| 1992 |
ankur.sing |
254 |
in.shop2020.model.v1.catalog.Item tItem = catalogClient.getItem(item.getId());
|
| 2126 |
ankur.sing |
255 |
setThriftItemParams(tItem, item);
|
| 2359 |
ankur.sing |
256 |
|
| 2105 |
ankur.sing |
257 |
long rItemId;
|
|
|
258 |
if((rItemId = catalogClient.updateItem(tItem)) != item.getId()) {
|
| 3354 |
chandransh |
259 |
logger.error("Error updating item, returned Item Id: " + rItemId);
|
| 2105 |
ankur.sing |
260 |
return false;
|
|
|
261 |
}
|
| 3354 |
chandransh |
262 |
logger.info("Successfully updated item with id: " + item.getId());
|
| 2359 |
ankur.sing |
263 |
|
|
|
264 |
Map<String, VendorItemMapping> vendorMappings = item.getVendorKeysMap();
|
| 2119 |
ankur.sing |
265 |
if(vendorMappings != null && !vendorMappings.isEmpty()) {
|
|
|
266 |
in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;
|
| 2359 |
ankur.sing |
267 |
|
|
|
268 |
for(Entry<String, VendorItemMapping> e : vendorMappings.entrySet()) {
|
| 2119 |
ankur.sing |
269 |
tVendorMapping = new in.shop2020.model.v1.catalog.VendorItemMapping();
|
| 2359 |
ankur.sing |
270 |
VendorItemMapping v = e.getValue();
|
| 2119 |
ankur.sing |
271 |
tVendorMapping.setVendorId(v.getVendorId());
|
|
|
272 |
tVendorMapping.setItemKey(v.getItemKey());
|
|
|
273 |
tVendorMapping.setItemId(item.getId());
|
| 2359 |
ankur.sing |
274 |
catalogClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
|
| 3354 |
chandransh |
275 |
logger.info("Updates VendorItemMapping: " + tVendorMapping.toString());
|
| 2119 |
ankur.sing |
276 |
}
|
|
|
277 |
}
|
| 2359 |
ankur.sing |
278 |
|
| 2119 |
ankur.sing |
279 |
Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
|
|
|
280 |
if(vendorPricings != null && !vendorPricings.isEmpty()) {
|
| 2105 |
ankur.sing |
281 |
in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
|
| 2119 |
ankur.sing |
282 |
for(VendorPricings v : vendorPricings.values()) {
|
|
|
283 |
tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();
|
| 2105 |
ankur.sing |
284 |
tVendorPricing.setVendorId(v.getVendorId());
|
|
|
285 |
tVendorPricing.setItemId(item.getId());
|
|
|
286 |
tVendorPricing.setMop(v.getMop());
|
|
|
287 |
tVendorPricing.setTransferPrice(v.getTransferPrice());
|
|
|
288 |
tVendorPricing.setDealerPrice(v.getDealerPrice());
|
|
|
289 |
catalogClient.addVendorItemPricing(tVendorPricing);
|
| 3354 |
chandransh |
290 |
logger.info("Updated VendorItemPricing: " + tVendorPricing.toString());
|
| 2105 |
ankur.sing |
291 |
}
|
|
|
292 |
}
|
| 3558 |
rajveer |
293 |
|
|
|
294 |
Map<Long, SourcePricings> sourcePricings = item.getSourcePricesMap();
|
|
|
295 |
if(sourcePricings != null && !sourcePricings.isEmpty()) {
|
|
|
296 |
in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricings;
|
|
|
297 |
for(SourcePricings s : sourcePricings.values()) {
|
|
|
298 |
tSourcePricings = new in.shop2020.model.v1.catalog.SourceItemPricing();
|
|
|
299 |
tSourcePricings.setSourceId(s.getSourceId());
|
|
|
300 |
tSourcePricings.setItemId(item.getId());
|
|
|
301 |
tSourcePricings.setMrp(s.getMrp());
|
|
|
302 |
tSourcePricings.setSellingPrice(s.getSellingPrice());
|
|
|
303 |
catalogClient.addSourceItemPricing(tSourcePricings);
|
|
|
304 |
logger.info("Updated SourceItemPricing: " + tSourcePricings.toString());
|
|
|
305 |
}
|
|
|
306 |
}
|
|
|
307 |
|
| 2105 |
ankur.sing |
308 |
}catch(Exception e){
|
| 3354 |
chandransh |
309 |
logger.error("Error while updating item: ", e);
|
| 2427 |
ankur.sing |
310 |
return false;
|
| 2105 |
ankur.sing |
311 |
}
|
|
|
312 |
return true;
|
| 1961 |
ankur.sing |
313 |
}
|
| 2359 |
ankur.sing |
314 |
|
|
|
315 |
|
| 2066 |
ankur.sing |
316 |
@Override
|
|
|
317 |
public Map<Long, String> getAllVendors() {
|
|
|
318 |
Map<Long, String> vendorMap = new HashMap<Long, String>();
|
|
|
319 |
try {
|
| 3129 |
rajveer |
320 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 2066 |
ankur.sing |
321 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2359 |
ankur.sing |
322 |
|
| 2066 |
ankur.sing |
323 |
List<in.shop2020.model.v1.catalog.Vendor> vendors = catalogClient.getAllVendors();
|
| 2359 |
ankur.sing |
324 |
|
| 2066 |
ankur.sing |
325 |
for(in.shop2020.model.v1.catalog.Vendor v : vendors) {
|
|
|
326 |
vendorMap.put(v.getId(), v.getName());
|
|
|
327 |
}
|
|
|
328 |
} catch (Exception e) {
|
| 3354 |
chandransh |
329 |
logger.error("Error while getting all the vendors: ", e);
|
| 2066 |
ankur.sing |
330 |
}
|
|
|
331 |
return vendorMap;
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
@Override
|
| 3558 |
rajveer |
335 |
public Map<Long, String> getAllSources() {
|
|
|
336 |
Map<Long, String> sourceMap = new HashMap<Long, String>();
|
|
|
337 |
try {
|
|
|
338 |
CatalogClient catalogServiceClient = new CatalogClient();
|
|
|
339 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
340 |
|
|
|
341 |
List<in.shop2020.model.v1.catalog.Source> sources = catalogClient.getAllSources();
|
|
|
342 |
|
|
|
343 |
for(in.shop2020.model.v1.catalog.Source s : sources) {
|
|
|
344 |
sourceMap.put(s.getId(), s.getName());
|
|
|
345 |
}
|
|
|
346 |
} catch (Exception e) {
|
|
|
347 |
logger.error("Error while getting all the vendors: ", e);
|
|
|
348 |
}
|
|
|
349 |
return sourceMap;
|
|
|
350 |
}
|
|
|
351 |
|
|
|
352 |
@Override
|
| 2066 |
ankur.sing |
353 |
public Map<Long, String> getAllWarehouses() {
|
|
|
354 |
Map<Long, String> warehouseMap = new HashMap<Long, String>();
|
|
|
355 |
try {
|
| 3129 |
rajveer |
356 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 2066 |
ankur.sing |
357 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2359 |
ankur.sing |
358 |
|
| 2066 |
ankur.sing |
359 |
List<in.shop2020.model.v1.catalog.Warehouse> warehouses = catalogClient.getAllWarehouses(true);
|
| 2359 |
ankur.sing |
360 |
|
| 2066 |
ankur.sing |
361 |
for(in.shop2020.model.v1.catalog.Warehouse w : warehouses) {
|
|
|
362 |
warehouseMap.put(w.getId(), w.getDisplayName());
|
|
|
363 |
}
|
|
|
364 |
} catch (Exception e) {
|
| 3354 |
chandransh |
365 |
logger.error("Error while getting all the warehouses:", e );
|
| 2066 |
ankur.sing |
366 |
}
|
|
|
367 |
return warehouseMap;
|
|
|
368 |
}
|
| 2105 |
ankur.sing |
369 |
|
|
|
370 |
@Override
|
|
|
371 |
public long addItem(Item item) {
|
|
|
372 |
long itemId = 0;
|
|
|
373 |
try {
|
| 3129 |
rajveer |
374 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 2105 |
ankur.sing |
375 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2126 |
ankur.sing |
376 |
|
| 2359 |
ankur.sing |
377 |
|
| 2105 |
ankur.sing |
378 |
in.shop2020.model.v1.catalog.Item tItem = new in.shop2020.model.v1.catalog.Item();
|
| 2126 |
ankur.sing |
379 |
setThriftItemParams(tItem, item);
|
| 2105 |
ankur.sing |
380 |
itemId = catalogClient.addItem(tItem);
|
|
|
381 |
|
| 2119 |
ankur.sing |
382 |
Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
|
|
|
383 |
if(vendorPricings != null && !vendorPricings.isEmpty()) {
|
| 2105 |
ankur.sing |
384 |
in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
|
| 2119 |
ankur.sing |
385 |
for(VendorPricings v : vendorPricings.values()) {
|
|
|
386 |
tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();
|
|
|
387 |
tVendorPricing.setVendorId(v.getVendorId());
|
|
|
388 |
tVendorPricing.setItemId(itemId);
|
|
|
389 |
tVendorPricing.setMop(v.getMop());
|
|
|
390 |
tVendorPricing.setTransferPrice(v.getTransferPrice());
|
|
|
391 |
tVendorPricing.setDealerPrice(v.getDealerPrice());
|
|
|
392 |
catalogClient.addVendorItemPricing(tVendorPricing);
|
|
|
393 |
}
|
|
|
394 |
}
|
| 2359 |
ankur.sing |
395 |
|
|
|
396 |
Map<String, VendorItemMapping> vendorKeysMap = item.getVendorKeysMap();
|
| 2119 |
ankur.sing |
397 |
if(vendorKeysMap != null && !vendorKeysMap.isEmpty()) {
|
| 2105 |
ankur.sing |
398 |
in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;
|
| 2359 |
ankur.sing |
399 |
for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()) {
|
| 2119 |
ankur.sing |
400 |
tVendorMapping = new in.shop2020.model.v1.catalog.VendorItemMapping();
|
| 2359 |
ankur.sing |
401 |
VendorItemMapping v = e.getValue();
|
| 2105 |
ankur.sing |
402 |
tVendorMapping.setVendorId(v.getVendorId());
|
|
|
403 |
tVendorMapping.setItemKey(v.getItemKey());
|
|
|
404 |
tVendorMapping.setItemId(itemId);
|
| 2359 |
ankur.sing |
405 |
catalogClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);
|
| 2105 |
ankur.sing |
406 |
}
|
|
|
407 |
}
|
|
|
408 |
} catch (Exception e) {
|
| 3354 |
chandransh |
409 |
logger.error("Error while adding an item: ", e);
|
| 2105 |
ankur.sing |
410 |
}
|
|
|
411 |
return itemId;
|
|
|
412 |
}
|
| 2119 |
ankur.sing |
413 |
|
|
|
414 |
@Override
|
| 4725 |
phani.kuma |
415 |
public long checkSimilarItem(String brand, String modelNumber, String modelName, String color) {
|
| 2359 |
ankur.sing |
416 |
|
| 2119 |
ankur.sing |
417 |
try {
|
| 3129 |
rajveer |
418 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 2119 |
ankur.sing |
419 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 4725 |
phani.kuma |
420 |
return catalogClient.checkSimilarItem(brand, modelNumber, modelName, color);
|
| 2119 |
ankur.sing |
421 |
} catch (Exception e) {
|
| 3354 |
chandransh |
422 |
logger.error("Error while checking for a similar item: ", e);
|
| 2119 |
ankur.sing |
423 |
}
|
|
|
424 |
return 0;
|
|
|
425 |
}
|
| 2359 |
ankur.sing |
426 |
|
| 2126 |
ankur.sing |
427 |
private void setThriftItemParams(in.shop2020.model.v1.catalog.Item tItem, Item item) {
|
|
|
428 |
tItem.setId(tItem.getId());
|
|
|
429 |
tItem.setProductGroup(item.getProductGroup());
|
|
|
430 |
tItem.setBrand(item.getBrand());
|
|
|
431 |
tItem.setModelName(item.getModelName());
|
|
|
432 |
tItem.setModelNumber(item.getModelNumber());
|
|
|
433 |
tItem.setColor(item.getColor());
|
| 2359 |
ankur.sing |
434 |
|
|
|
435 |
tItem.setStatus_description(item.getItemStatusDesc());
|
| 2126 |
ankur.sing |
436 |
tItem.setComments(item.getComments());
|
| 2359 |
ankur.sing |
437 |
|
| 2489 |
ankur.sing |
438 |
if(item.getMrp() != null) {
|
| 2126 |
ankur.sing |
439 |
tItem.setMrp(item.getMrp());
|
|
|
440 |
}
|
| 3354 |
chandransh |
441 |
|
| 2489 |
ankur.sing |
442 |
if(item.getSellingPrice() != null) {
|
| 2126 |
ankur.sing |
443 |
tItem.setSellingPrice(item.getSellingPrice());
|
|
|
444 |
}
|
| 3354 |
chandransh |
445 |
|
| 2489 |
ankur.sing |
446 |
if(item.getWeight() != null) {
|
| 2126 |
ankur.sing |
447 |
tItem.setWeight(item.getWeight());
|
|
|
448 |
}
|
| 3354 |
chandransh |
449 |
|
| 3359 |
chandransh |
450 |
if(item.getExpectedDelay() != null) {
|
|
|
451 |
tItem.setExpectedDelay(item.getExpectedDelay());
|
| 2489 |
ankur.sing |
452 |
}
|
| 3354 |
chandransh |
453 |
|
| 3359 |
chandransh |
454 |
if(item.getPreferredWarehouse() != null) {
|
|
|
455 |
tItem.setPreferredWarehouse(item.getPreferredWarehouse());
|
| 2489 |
ankur.sing |
456 |
}
|
| 3354 |
chandransh |
457 |
|
| 4413 |
anupam.sin |
458 |
if(item.getDefaultWarehouse() != null) {
|
|
|
459 |
tItem.setDefaultWarehouse(item.getDefaultWarehouse());
|
|
|
460 |
}
|
|
|
461 |
|
|
|
462 |
tItem.setIsWarehousePreferenceSticky(item.isWarehouseStickiness());
|
|
|
463 |
|
| 4506 |
phani.kuma |
464 |
if(item.getPreferredVendor() != null) {
|
|
|
465 |
tItem.setPreferredVendor(item.getPreferredVendor());
|
|
|
466 |
}
|
|
|
467 |
|
| 2126 |
ankur.sing |
468 |
tItem.setBestDealText(item.getBestDealsText());
|
| 2489 |
ankur.sing |
469 |
if(item.getBestDealsValue() != null) {
|
| 2126 |
ankur.sing |
470 |
tItem.setBestDealValue(item.getBestDealsValue());
|
|
|
471 |
}
|
| 3354 |
chandransh |
472 |
|
| 2489 |
ankur.sing |
473 |
if(item.getBestSellingRank() != null) {
|
| 2126 |
ankur.sing |
474 |
tItem.setBestSellingRank(item.getBestSellingRank());
|
|
|
475 |
}
|
| 3354 |
chandransh |
476 |
|
| 2126 |
ankur.sing |
477 |
tItem.setDefaultForEntity(item.isDefaultForEntity());
|
| 2252 |
ankur.sing |
478 |
tItem.setRisky(item.isRisky());
|
| 2359 |
ankur.sing |
479 |
|
| 2489 |
ankur.sing |
480 |
if(item.getStartDate() != null) {
|
|
|
481 |
tItem.setStartDate(item.getStartDate());
|
|
|
482 |
}
|
| 3354 |
chandransh |
483 |
|
| 2489 |
ankur.sing |
484 |
if(item.getRetireDate() != null) {
|
|
|
485 |
tItem.setRetireDate(item.getRetireDate());
|
|
|
486 |
}
|
| 3354 |
chandransh |
487 |
|
| 2126 |
ankur.sing |
488 |
tItem.setUpdatedOn(Calendar.getInstance().getTimeInMillis());
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
@Override
|
|
|
492 |
public void pauseItem(long itemId) {
|
|
|
493 |
try {
|
| 3129 |
rajveer |
494 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 2126 |
ankur.sing |
495 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2359 |
ankur.sing |
496 |
|
| 2126 |
ankur.sing |
497 |
catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PAUSED);
|
|
|
498 |
} catch (Exception e) {
|
| 3354 |
chandransh |
499 |
logger.error("Error while pausing the item: " + itemId, e);
|
| 2126 |
ankur.sing |
500 |
}
|
| 2359 |
ankur.sing |
501 |
|
| 2126 |
ankur.sing |
502 |
}
|
|
|
503 |
|
|
|
504 |
@Override
|
|
|
505 |
public void markInProcess(long itemId) {
|
|
|
506 |
try {
|
| 3129 |
rajveer |
507 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 2126 |
ankur.sing |
508 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2359 |
ankur.sing |
509 |
|
| 2126 |
ankur.sing |
510 |
catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.IN_PROCESS);
|
|
|
511 |
} catch (Exception e) {
|
| 3354 |
chandransh |
512 |
logger.error("Error while marking in-process the item: " + itemId, e);
|
| 2126 |
ankur.sing |
513 |
}
|
|
|
514 |
}
|
| 2359 |
ankur.sing |
515 |
|
| 2126 |
ankur.sing |
516 |
@Override
|
|
|
517 |
public void phaseoutItem(long itemId) {
|
|
|
518 |
try {
|
| 3129 |
rajveer |
519 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 2126 |
ankur.sing |
520 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2359 |
ankur.sing |
521 |
|
| 2126 |
ankur.sing |
522 |
catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PHASED_OUT);
|
|
|
523 |
} catch (Exception e) {
|
| 3354 |
chandransh |
524 |
logger.error("Error while phasing out the item: " + itemId, e);
|
| 2126 |
ankur.sing |
525 |
}
|
|
|
526 |
}
|
| 2359 |
ankur.sing |
527 |
|
| 2126 |
ankur.sing |
528 |
@Override
|
|
|
529 |
public void activateItem(long itemId) {
|
|
|
530 |
try {
|
| 3129 |
rajveer |
531 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 2126 |
ankur.sing |
532 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| 2359 |
ankur.sing |
533 |
|
| 2126 |
ankur.sing |
534 |
catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.ACTIVE);
|
|
|
535 |
} catch (Exception e) {
|
| 3354 |
chandransh |
536 |
logger.error("Error while activating the item: " + itemId, e);
|
| 2126 |
ankur.sing |
537 |
}
|
|
|
538 |
}
|
| 2359 |
ankur.sing |
539 |
|
|
|
540 |
@Override
|
|
|
541 |
public boolean changeItemRiskyFlag(long itemId, boolean risky) {
|
|
|
542 |
try {
|
| 4354 |
mandeep.dh |
543 |
logger.info("Updating risky flag for item id: " + itemId + " to " + risky);
|
| 2359 |
ankur.sing |
544 |
// Initialize client for staging server
|
| 3129 |
rajveer |
545 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 2359 |
ankur.sing |
546 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
547 |
|
|
|
548 |
// Initialize client for production server
|
| 3165 |
chandransh |
549 |
CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
|
| 2359 |
ankur.sing |
550 |
ConfigClientKeys.catalog_service_server_port.toString());
|
|
|
551 |
InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
|
|
|
552 |
catalogClient.changeItemRiskyFlag(itemId, risky);
|
|
|
553 |
|
|
|
554 |
try{
|
|
|
555 |
catalogClient_Prod.changeItemRiskyFlag(itemId, risky);
|
|
|
556 |
}catch(Exception e){
|
| 3354 |
chandransh |
557 |
logger.error("Error while updating item's risky flag on production", e);
|
| 2359 |
ankur.sing |
558 |
// If not able to change risky flag on production, revert on staging and return false (to show error to user).
|
|
|
559 |
catalogClient.changeItemRiskyFlag(itemId, !risky);
|
|
|
560 |
return false;
|
|
|
561 |
}
|
|
|
562 |
} catch (Exception e) {
|
| 3354 |
chandransh |
563 |
logger.error("Error while updating item's risky flag on staging", e);
|
| 2359 |
ankur.sing |
564 |
return false;
|
|
|
565 |
}
|
|
|
566 |
return true;
|
|
|
567 |
}
|
|
|
568 |
|
| 2427 |
ankur.sing |
569 |
|
|
|
570 |
/**
|
| 4762 |
phani.kuma |
571 |
* Retuns list of Items filtered by category (column is product_group in catalog.item table)
|
| 2427 |
ankur.sing |
572 |
* This list is used to generate master sheet (excel sheet)
|
|
|
573 |
* @param category
|
|
|
574 |
* @return
|
|
|
575 |
*/
|
| 4762 |
phani.kuma |
576 |
public List<Item> getItemsByCategory(String category) {
|
| 2359 |
ankur.sing |
577 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
578 |
try {
|
| 3129 |
rajveer |
579 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| 2359 |
ankur.sing |
580 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
581 |
|
| 4762 |
phani.kuma |
582 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByCategory(category);
|
| 2359 |
ankur.sing |
583 |
|
|
|
584 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
|
|
|
585 |
List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
|
|
|
586 |
List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
|
| 3558 |
rajveer |
587 |
List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
|
| 4423 |
phani.kuma |
588 |
itemList.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null));
|
| 2359 |
ankur.sing |
589 |
}
|
|
|
590 |
} catch (Exception e) {
|
| 4762 |
phani.kuma |
591 |
logger.error("Error while getting items by category: " + category, e);
|
| 2359 |
ankur.sing |
592 |
}
|
|
|
593 |
Collections.sort(itemList, new ItemsComparator());
|
|
|
594 |
return itemList;
|
|
|
595 |
}
|
|
|
596 |
|
|
|
597 |
@Override
|
| 2427 |
ankur.sing |
598 |
public String updateItemOnProduction(Item item) {
|
| 3354 |
chandransh |
599 |
logger.info("Update item on production call, Item Id: " + item.getId());
|
| 2427 |
ankur.sing |
600 |
|
| 3922 |
chandransh |
601 |
if(!canPushToProduction()) {
|
|
|
602 |
// If we can't push to production, then return that message to user
|
|
|
603 |
// else move forward with update.
|
|
|
604 |
return "Maximum push to production count reached for today";
|
| 2427 |
ankur.sing |
605 |
}
|
| 2359 |
ankur.sing |
606 |
try{
|
| 3165 |
chandransh |
607 |
CatalogClient catalogServiceClient_Prod = new CatalogClient(
|
| 2359 |
ankur.sing |
608 |
ConfigClientKeys.catalog_service_server_host_prod.toString(),
|
| 2498 |
ankur.sing |
609 |
ConfigClientKeys.catalog_service_server_port.toString());
|
| 2359 |
ankur.sing |
610 |
|
|
|
611 |
InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
|
|
|
612 |
|
|
|
613 |
in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(item.getId());
|
| 2427 |
ankur.sing |
614 |
|
| 2489 |
ankur.sing |
615 |
if(item.getMrp() != null) {
|
| 2359 |
ankur.sing |
616 |
tItem.setMrp(item.getMrp());
|
|
|
617 |
}
|
| 3354 |
chandransh |
618 |
|
| 2489 |
ankur.sing |
619 |
if(item.getSellingPrice() != null) {
|
| 2359 |
ankur.sing |
620 |
tItem.setSellingPrice(item.getSellingPrice());
|
|
|
621 |
}
|
| 3354 |
chandransh |
622 |
|
| 2359 |
ankur.sing |
623 |
long rItemId;
|
|
|
624 |
if((rItemId = catalogClient_Prod.updateItem(tItem)) != item.getId()) {
|
| 3354 |
chandransh |
625 |
logger.error("Error updating item on production, returned Item Id: " + rItemId);
|
| 2427 |
ankur.sing |
626 |
return "Error updating item prices on production";
|
| 2359 |
ankur.sing |
627 |
}
|
| 3354 |
chandransh |
628 |
logger.info("Successfully updated item: " + item.getId());
|
| 2359 |
ankur.sing |
629 |
|
| 3911 |
chandransh |
630 |
StringBuilder sb = new StringBuilder();
|
|
|
631 |
|
| 2359 |
ankur.sing |
632 |
Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
|
|
|
633 |
if(vendorPricings != null && !vendorPricings.isEmpty()) {
|
|
|
634 |
in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
|
|
|
635 |
for(VendorPricings v : vendorPricings.values()) {
|
|
|
636 |
tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();
|
|
|
637 |
tVendorPricing.setVendorId(v.getVendorId());
|
|
|
638 |
tVendorPricing.setItemId(item.getId());
|
|
|
639 |
tVendorPricing.setMop(v.getMop());
|
|
|
640 |
tVendorPricing.setTransferPrice(v.getTransferPrice());
|
|
|
641 |
tVendorPricing.setDealerPrice(v.getDealerPrice());
|
|
|
642 |
catalogClient_Prod.addVendorItemPricing(tVendorPricing);
|
| 3354 |
chandransh |
643 |
logger.info("VendorItemPricing updated. " + tVendorPricing.toString());
|
| 2489 |
ankur.sing |
644 |
sb.append("[VId:" + v.getVendorId() + ",MOP=" + v.getMop() + ",TP=" + v.getTransferPrice() + ",DP=" + v.getDealerPrice() + "], ");
|
| 2359 |
ankur.sing |
645 |
}
|
|
|
646 |
}
|
| 3911 |
chandransh |
647 |
|
|
|
648 |
Map<Long, SourcePricings> sourcePricings = item.getSourcePricesMap();
|
|
|
649 |
if(sourcePricings != null && !sourcePricings.isEmpty()){
|
|
|
650 |
in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricing;
|
|
|
651 |
for(SourcePricings s : sourcePricings.values()){
|
|
|
652 |
tSourcePricing = new in.shop2020.model.v1.catalog.SourceItemPricing();
|
|
|
653 |
tSourcePricing.setSourceId(s.getSourceId());
|
|
|
654 |
tSourcePricing.setItemId(item.getId());
|
|
|
655 |
tSourcePricing.setMrp(s.getMrp());
|
|
|
656 |
tSourcePricing.setSellingPrice(s.getSellingPrice());
|
|
|
657 |
catalogClient_Prod.addSourceItemPricing(tSourcePricing);
|
|
|
658 |
logger.info("SourceItemPricing updated. " + tSourcePricing.toString());
|
|
|
659 |
sb.append("[SId:" + s.getSourceId() + ",MRP=" + s.getMrp() + ",SP=" + s.getSellingPrice() + "], ");
|
|
|
660 |
}
|
|
|
661 |
}
|
|
|
662 |
|
| 3922 |
chandransh |
663 |
pushToProdLogger.info("Id=" + item.getId() + ",MRP=" + item.getMrp() + ",SP=" + " " + item.getSellingPrice() + sb.toString());
|
| 2359 |
ankur.sing |
664 |
} catch (Exception e) {
|
| 3354 |
chandransh |
665 |
logger.error("Error while updating prices on production", e);
|
| 2427 |
ankur.sing |
666 |
return "Error while updating all prices on production. Some of the prices may have been updated";
|
| 2359 |
ankur.sing |
667 |
}
|
| 2489 |
ankur.sing |
668 |
|
| 3907 |
chandransh |
669 |
try {
|
|
|
670 |
ContentClient contentServiceClient = new ContentClient();
|
|
|
671 |
ContentService.Client contentClient = contentServiceClient.getClient();
|
|
|
672 |
|
|
|
673 |
contentClient.pushContentToProduction(item.getCatalogItemId());
|
|
|
674 |
} catch (TTransportException e) {
|
|
|
675 |
logger.error("Error while establishing connection to the content server", e);
|
|
|
676 |
return "Error generating content. Prices updated successfully.";
|
|
|
677 |
} catch (TException e) {
|
|
|
678 |
logger.error("Error while pushing content to production", e);
|
|
|
679 |
return "Error generating content. Prices updated successfully.";
|
|
|
680 |
} catch (ContentServiceException e) {
|
|
|
681 |
logger.error("Error while pushing content to production", e);
|
|
|
682 |
return "Error generating content. Prices updated successfully.";
|
|
|
683 |
}
|
|
|
684 |
|
| 2427 |
ankur.sing |
685 |
return "Prices updated and content generated successfully";
|
| 2359 |
ankur.sing |
686 |
}
|
| 2427 |
ankur.sing |
687 |
|
| 2489 |
ankur.sing |
688 |
/**
|
| 3354 |
chandransh |
689 |
* Returns list of items with a particular status.
|
|
|
690 |
* @param st
|
|
|
691 |
* @return
|
|
|
692 |
*/
|
| 3850 |
chandransh |
693 |
private List<Item> getItemsByStatus(status st, int start, int limit) {
|
| 3354 |
chandransh |
694 |
List<Item> itemList = new ArrayList<Item>();
|
|
|
695 |
try {
|
|
|
696 |
CatalogClient catalogServiceClient = new CatalogClient();
|
|
|
697 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
698 |
|
| 3850 |
chandransh |
699 |
List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatusInRange(st, start, limit);
|
| 3354 |
chandransh |
700 |
|
|
|
701 |
for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {
|
| 4423 |
phani.kuma |
702 |
itemList.add(getItemFromThriftItem(thriftItem, null, null, null, null));
|
| 3354 |
chandransh |
703 |
}
|
|
|
704 |
} catch (Exception e) {
|
|
|
705 |
logger.error("Error while getting items by status: " + st, e);
|
|
|
706 |
}
|
|
|
707 |
return itemList;
|
|
|
708 |
}
|
|
|
709 |
|
|
|
710 |
/**
|
|
|
711 |
* Creates a new Item object and populates its attributes from thrift item passed as parameter.
|
| 4423 |
phani.kuma |
712 |
* Also creates a Map each for VendorItemPricing, VendorItemMapping, SourceItemPricing and SimilarItems and adds these maps to the
|
| 3354 |
chandransh |
713 |
* new Item object.
|
|
|
714 |
* @param thriftItem
|
|
|
715 |
* @param tVendorPricings
|
|
|
716 |
* @param tVendorMappings
|
| 4423 |
phani.kuma |
717 |
* @param tSourceMappings
|
|
|
718 |
* @param tSimilarItems
|
| 3354 |
chandransh |
719 |
* @return item object with attributes copied from thrift item object.
|
|
|
720 |
*/
|
|
|
721 |
private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem,
|
|
|
722 |
List<in.shop2020.model.v1.catalog.VendorItemPricing> tVendorPricings,
|
| 3558 |
rajveer |
723 |
List<in.shop2020.model.v1.catalog.VendorItemMapping> tVendorMappings,
|
| 4423 |
phani.kuma |
724 |
List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings,
|
|
|
725 |
List<in.shop2020.model.v1.catalog.Item> tSimilarItems){
|
| 3354 |
chandransh |
726 |
|
|
|
727 |
Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
|
|
|
728 |
VendorItemMapping vItemMapping;
|
|
|
729 |
if(tVendorMappings != null) {
|
|
|
730 |
for(in.shop2020.model.v1.catalog.VendorItemMapping vim : tVendorMappings) {
|
|
|
731 |
vItemMapping = new VendorItemMapping();
|
|
|
732 |
vItemMapping.setVendorId(vim.getVendorId());
|
|
|
733 |
vItemMapping.setItemKey(vim.getItemKey());
|
|
|
734 |
vItemMap.put(vItemMapping.getVendorId() + Item.KEY_SEPARATOR + vim.getItemKey(), vItemMapping);
|
|
|
735 |
}
|
|
|
736 |
}
|
|
|
737 |
|
|
|
738 |
Map<Long, VendorPricings> vendorPricingMap = new HashMap<Long, VendorPricings>();
|
|
|
739 |
VendorPricings vPricings;
|
|
|
740 |
if(tVendorPricings != null) {
|
|
|
741 |
for(in.shop2020.model.v1.catalog.VendorItemPricing vip : tVendorPricings) {
|
|
|
742 |
vPricings = new VendorPricings();
|
|
|
743 |
vPricings.setVendorId(vip.getVendorId());
|
|
|
744 |
vPricings.setMop(vip.getMop());
|
|
|
745 |
vPricings.setDealerPrice(vip.getDealerPrice());
|
|
|
746 |
vPricings.setTransferPrice(vip.getTransferPrice());
|
|
|
747 |
vendorPricingMap.put(vPricings.getVendorId(), vPricings);
|
|
|
748 |
}
|
|
|
749 |
}
|
|
|
750 |
|
| 3558 |
rajveer |
751 |
Map<Long, SourcePricings> sourcePricingMap = new HashMap<Long, SourcePricings>();
|
|
|
752 |
SourcePricings sPricings;
|
|
|
753 |
if(tSourceMappings != null) {
|
|
|
754 |
for(in.shop2020.model.v1.catalog.SourceItemPricing sip : tSourceMappings) {
|
|
|
755 |
sPricings = new SourcePricings();
|
|
|
756 |
sPricings.setSourceId(sip.getSourceId());
|
|
|
757 |
sPricings.setMrp(sip.getMrp());
|
|
|
758 |
sPricings.setSellingPrice(sip.getSellingPrice());
|
|
|
759 |
sourcePricingMap.put(sPricings.getSourceId(), sPricings);
|
|
|
760 |
}
|
|
|
761 |
}
|
| 4423 |
phani.kuma |
762 |
|
|
|
763 |
Map<Long, Item> SimilarItemslist = new HashMap<Long, Item>();
|
|
|
764 |
Item sItems;
|
|
|
765 |
if(tSimilarItems != null) {
|
|
|
766 |
for(in.shop2020.model.v1.catalog.Item sit : tSimilarItems) {
|
|
|
767 |
sItems = new Item();
|
|
|
768 |
sItems.setCatalogItemId(sit.getCatalogItemId());
|
|
|
769 |
sItems.setProductGroup(sit.getProductGroup());
|
|
|
770 |
sItems.setBrand(sit.getBrand());
|
|
|
771 |
sItems.setModelNumber(sit.getModelNumber());
|
|
|
772 |
sItems.setModelName(sit.getModelName());
|
|
|
773 |
sItems.setContentCategory(CategoryManager.getCategoryManager().getCategoryLabel(sit.getCategory()));
|
|
|
774 |
SimilarItemslist.put(sit.getCatalogItemId(), sItems);
|
|
|
775 |
}
|
|
|
776 |
}
|
| 3558 |
rajveer |
777 |
|
| 4431 |
phani.kuma |
778 |
Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
|
|
|
779 |
ItemInventory warehousedata;
|
|
|
780 |
if(thriftItem.getItemInventory() != null) {
|
|
|
781 |
Map<Long, Long> availabilityMap = thriftItem.getItemInventory().getAvailability();
|
|
|
782 |
Map<Long, Long> reservedMap = thriftItem.getItemInventory().getReserved();
|
|
|
783 |
for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
|
|
|
784 |
warehousedata = new ItemInventory();
|
|
|
785 |
warehousedata.setWarehouseId(availability.getKey());
|
|
|
786 |
warehousedata.setAvailability(availability.getValue());
|
|
|
787 |
warehousedata.setReserved(reservedMap.get(availability.getKey()));
|
|
|
788 |
itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
|
|
|
789 |
}
|
|
|
790 |
}
|
|
|
791 |
else {
|
|
|
792 |
itemInventoryMap = null;
|
|
|
793 |
}
|
|
|
794 |
|
| 3354 |
chandransh |
795 |
Item item = new Item(thriftItem.getId(),
|
|
|
796 |
thriftItem.getProductGroup(),
|
|
|
797 |
thriftItem.getBrand(),
|
|
|
798 |
thriftItem.getModelNumber(),
|
|
|
799 |
thriftItem.getModelName(),
|
|
|
800 |
thriftItem.getColor(),
|
|
|
801 |
CategoryManager.getCategoryManager().getCategoryLabel(thriftItem.getCategory()),
|
|
|
802 |
thriftItem.getCategory(),
|
|
|
803 |
thriftItem.getComments(),
|
|
|
804 |
thriftItem.getCatalogItemId(),
|
|
|
805 |
thriftItem.getFeatureId(),
|
|
|
806 |
thriftItem.getFeatureDescription(),
|
|
|
807 |
thriftItem.isSetMrp() ? thriftItem.getMrp() : null,
|
|
|
808 |
thriftItem.isSetSellingPrice() ? thriftItem.getSellingPrice() : null,
|
|
|
809 |
thriftItem.isSetWeight() ? thriftItem.getWeight() : null,
|
|
|
810 |
thriftItem.getAddedOn(),
|
|
|
811 |
thriftItem.getStartDate(),
|
|
|
812 |
thriftItem.getRetireDate(),
|
|
|
813 |
thriftItem.getUpdatedOn(),
|
|
|
814 |
thriftItem.getItemStatus().name(),
|
|
|
815 |
thriftItem.getItemStatus().getValue(),
|
|
|
816 |
thriftItem.getStatus_description(),
|
|
|
817 |
thriftItem.getOtherInfo(),
|
|
|
818 |
thriftItem.getBestDealText(),
|
|
|
819 |
thriftItem.isSetBestDealValue() ? thriftItem.getBestDealValue() : null,
|
|
|
820 |
thriftItem.isSetBestSellingRank() ? thriftItem.getBestSellingRank() : null,
|
|
|
821 |
thriftItem.isDefaultForEntity(),
|
|
|
822 |
thriftItem.isRisky(),
|
| 3359 |
chandransh |
823 |
thriftItem.isSetExpectedDelay() ? thriftItem.getExpectedDelay() : null,
|
|
|
824 |
thriftItem.isSetPreferredWarehouse() ? thriftItem.getPreferredWarehouse() : null,
|
| 4413 |
anupam.sin |
825 |
thriftItem.isSetDefaultWarehouse() ? thriftItem.getDefaultWarehouse() : null,
|
| 4506 |
phani.kuma |
826 |
thriftItem.isIsWarehousePreferenceSticky(),
|
|
|
827 |
thriftItem.isSetPreferredVendor() ? thriftItem.getPreferredVendor() : null,
|
| 4431 |
phani.kuma |
828 |
itemInventoryMap,
|
| 3354 |
chandransh |
829 |
vendorPricingMap,
|
| 3558 |
rajveer |
830 |
vItemMap,
|
| 4423 |
phani.kuma |
831 |
sourcePricingMap,
|
|
|
832 |
SimilarItemslist);
|
| 3354 |
chandransh |
833 |
return item;
|
|
|
834 |
}
|
|
|
835 |
|
|
|
836 |
/**
|
| 2489 |
ankur.sing |
837 |
*
|
| 3922 |
chandransh |
838 |
* @return True if push to production count is less than maximum allowed.
|
| 2489 |
ankur.sing |
839 |
*/
|
| 3922 |
chandransh |
840 |
private boolean canPushToProduction() {
|
|
|
841 |
int count = getPushToProdCount(logFile);
|
|
|
842 |
return count < maxCount;
|
| 2427 |
ankur.sing |
843 |
}
|
| 3922 |
chandransh |
844 |
|
| 2489 |
ankur.sing |
845 |
/**
|
|
|
846 |
* If this is the first attempt to push to production for current date, returns 0
|
|
|
847 |
* else reads number of lines from daily rolling log file to get the count.
|
|
|
848 |
* @return push to production count for current date
|
|
|
849 |
*/
|
| 2498 |
ankur.sing |
850 |
private int getPushToProdCount(String logfile) {
|
|
|
851 |
// logfile is "/var/log/services/pushToProductionCount/pushToProd.log"
|
|
|
852 |
// this should also be set in log4j.properties
|
| 2427 |
ankur.sing |
853 |
int lineCount = 0;
|
| 2498 |
ankur.sing |
854 |
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
| 2427 |
ankur.sing |
855 |
Date currentDate = Calendar.getInstance().getTime();
|
|
|
856 |
if(pushToProdDate == null || !dateFormat.format(pushToProdDate).equals(dateFormat.format(currentDate))) {
|
|
|
857 |
pushToProdDate = currentDate;
|
|
|
858 |
return lineCount;
|
|
|
859 |
}
|
|
|
860 |
try {
|
| 2498 |
ankur.sing |
861 |
BufferedReader br = new BufferedReader(new FileReader(logfile));
|
| 2427 |
ankur.sing |
862 |
while (br.readLine() != null) {
|
|
|
863 |
lineCount++;
|
|
|
864 |
}
|
|
|
865 |
} catch (IOException e) {
|
| 3354 |
chandransh |
866 |
logger.error("Error while reading the log file", e);
|
| 2427 |
ankur.sing |
867 |
}
|
|
|
868 |
return lineCount;
|
|
|
869 |
}
|
| 4423 |
phani.kuma |
870 |
|
|
|
871 |
@Override
|
|
|
872 |
public boolean deleteSimilarItem(long itemId, long catalogItemId) {
|
|
|
873 |
try{
|
|
|
874 |
CatalogClient catalogServiceClient = new CatalogClient();
|
|
|
875 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
876 |
|
|
|
877 |
return catalogClient.deleteSimilarItem(itemId, catalogItemId);
|
|
|
878 |
|
|
|
879 |
}catch(Exception e){
|
|
|
880 |
logger.error("Error while deleting the SimilarItems for: " + itemId, e);
|
|
|
881 |
}
|
|
|
882 |
return false;
|
|
|
883 |
}
|
|
|
884 |
|
|
|
885 |
@Override
|
|
|
886 |
public Item addSimilarItem(long itemId, long catalogItemId) {
|
|
|
887 |
try{
|
|
|
888 |
CatalogClient catalogServiceClient = new CatalogClient();
|
|
|
889 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
890 |
in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.addSimilarItem(itemId, catalogItemId);;
|
|
|
891 |
|
|
|
892 |
return getItemFromThriftItem(thriftItem, null, null, null, null);
|
|
|
893 |
}catch(Exception e){
|
|
|
894 |
logger.error("Error while adding the SimilarItems for: " + itemId, e);
|
|
|
895 |
}
|
|
|
896 |
return null;
|
|
|
897 |
}
|
| 4431 |
phani.kuma |
898 |
|
|
|
899 |
@Override
|
|
|
900 |
public Map<Long, ItemInventory> getProdItemInventory(long itemId) {
|
|
|
901 |
try {
|
|
|
902 |
// Initialize client for production server
|
|
|
903 |
CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),
|
|
|
904 |
ConfigClientKeys.catalog_service_server_port.toString());
|
|
|
905 |
InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
|
|
|
906 |
in.shop2020.model.v1.catalog.ItemInventory thriftItemInventory = catalogClient_Prod.getItemInventoryByItemId(itemId);
|
|
|
907 |
|
|
|
908 |
Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
|
|
|
909 |
ItemInventory warehousedata;
|
|
|
910 |
if(thriftItemInventory != null) {
|
|
|
911 |
Map<Long, Long> availabilityMap = thriftItemInventory.getAvailability();
|
|
|
912 |
Map<Long, Long> reservedMap = thriftItemInventory.getReserved();
|
|
|
913 |
for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
|
|
|
914 |
warehousedata = new ItemInventory();
|
|
|
915 |
warehousedata.setWarehouseId(availability.getKey());
|
|
|
916 |
warehousedata.setAvailability(availability.getValue());
|
|
|
917 |
warehousedata.setReserved(reservedMap.get(availability.getKey()));
|
|
|
918 |
itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
|
|
|
919 |
}
|
|
|
920 |
}
|
|
|
921 |
else {
|
|
|
922 |
itemInventoryMap = null;
|
|
|
923 |
}
|
|
|
924 |
return itemInventoryMap;
|
|
|
925 |
} catch (Exception e) {
|
|
|
926 |
logger.error("Error while updating item's risky flag on staging", e);
|
|
|
927 |
}
|
|
|
928 |
return null;
|
|
|
929 |
}
|
| 4649 |
phani.kuma |
930 |
|
|
|
931 |
@Override
|
|
|
932 |
public boolean addAuthorizationLog(long itemId, String username, String message) {
|
|
|
933 |
try{
|
|
|
934 |
CatalogClient catalogServiceClient = new CatalogClient();
|
|
|
935 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
936 |
|
|
|
937 |
return catalogClient.addAuthorizationLog(itemId, username, message);
|
|
|
938 |
|
|
|
939 |
}catch(Exception e){
|
|
|
940 |
logger.error("Error while adding the event for: " + itemId, e);
|
|
|
941 |
}
|
|
|
942 |
return false;
|
|
|
943 |
}
|
|
|
944 |
|
|
|
945 |
@Override
|
|
|
946 |
public Map<String, String> getConfigdataforPriceCompare() {
|
|
|
947 |
Map<String, String> ConfigMap = new HashMap<String, String>();
|
|
|
948 |
try {
|
|
|
949 |
ConfigMap.put("courier_cost_factor", ConfigClient.getClient().get(ConfigClientKeys.courier_cost_factor.toString()));
|
|
|
950 |
ConfigMap.put("courier_weight_factor", ConfigClient.getClient().get(ConfigClientKeys.courier_weight_factor.toString()));
|
|
|
951 |
ConfigMap.put("breakeven_divisor", ConfigClient.getClient().get(ConfigClientKeys.breakeven_divisor.toString()));
|
|
|
952 |
ConfigMap.put("breakeven_additon_factor", ConfigClient.getClient().get(ConfigClientKeys.breakeven_additon_factor.toString()));
|
|
|
953 |
ConfigMap.put("transfer_price_percentage", ConfigClient.getClient().get(ConfigClientKeys.transfer_price_percentage.toString()));
|
|
|
954 |
ConfigMap.put("transfer_price_factor", ConfigClient.getClient().get(ConfigClientKeys.transfer_price_factor.toString()));
|
|
|
955 |
} catch(ConfigException ce) {
|
|
|
956 |
logger.error("Unable to connect to the config server. Setting sensible defaults.", ce);
|
|
|
957 |
ConfigMap.put("courier_cost_factor", "60");
|
|
|
958 |
ConfigMap.put("courier_weight_factor", "500");
|
|
|
959 |
ConfigMap.put("breakeven_divisor", "0.98");
|
|
|
960 |
ConfigMap.put("breakeven_additon_factor", "50");
|
|
|
961 |
ConfigMap.put("transfer_price_percentage", "2");
|
|
|
962 |
ConfigMap.put("transfer_price_factor", "50");
|
|
|
963 |
}
|
|
|
964 |
return ConfigMap;
|
|
|
965 |
}
|
| 2427 |
ankur.sing |
966 |
}
|