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