| Line 1... |
Line 1... |
| 1 |
package in.shop2020.util;
|
1 |
package in.shop2020.util;
|
| 2 |
|
2 |
|
| - |
|
3 |
import in.shop2020.metamodel.core.Entity;
|
| - |
|
4 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 3 |
import in.shop2020.model.v1.catalog.Category;
|
5 |
import in.shop2020.model.v1.catalog.Category;
|
| 4 |
import in.shop2020.model.v1.catalog.Item;
|
6 |
import in.shop2020.model.v1.catalog.Item;
|
| 5 |
import in.shop2020.utils.CategoryManager;
|
7 |
import in.shop2020.utils.CategoryManager;
|
| - |
|
8 |
import in.shop2020.model.v1.catalog.status;
|
| - |
|
9 |
import in.shop2020.model.v1.user.ItemCouponDiscount;
|
| - |
|
10 |
|
| - |
|
11 |
import in.shop2020.thrift.clients.CatalogClient;
|
| - |
|
12 |
import in.shop2020.thrift.clients.PromotionClient;
|
| 6 |
|
13 |
|
| 7 |
import java.io.File;
|
14 |
import java.io.File;
|
| 8 |
import java.util.ArrayList;
|
15 |
import java.util.ArrayList;
|
| - |
|
16 |
import java.util.Date;
|
| 9 |
import java.util.HashMap;
|
17 |
import java.util.HashMap;
|
| 10 |
import java.util.List;
|
18 |
import java.util.List;
|
| 11 |
import java.util.Map;
|
19 |
import java.util.Map;
|
| 12 |
|
20 |
|
| 13 |
import org.apache.commons.lang.StringUtils;
|
21 |
import org.apache.commons.lang.StringUtils;
|
| Line 227... |
Line 235... |
| 227 |
|
235 |
|
| 228 |
// Write it to file
|
236 |
// Write it to file
|
| 229 |
String productXMLFilename = Utils.EXPORT_JAVASCRIPT_CONTENT_PATH + "saholicmobilephones.js";
|
237 |
String productXMLFilename = Utils.EXPORT_JAVASCRIPT_CONTENT_PATH + "saholicmobilephones.js";
|
| 230 |
DBUtils.store(productsJavascript.toString(), productXMLFilename);
|
238 |
DBUtils.store(productsJavascript.toString(), productXMLFilename);
|
| 231 |
}
|
239 |
}
|
| - |
|
240 |
|
| - |
|
241 |
public static void main(String[] args) throws Exception {
|
| - |
|
242 |
CatalogClient cl = new CatalogClient();
|
| - |
|
243 |
in.shop2020.model.v1.catalog.InventoryService.Client client = cl.getClient();
|
| - |
|
244 |
|
| - |
|
245 |
List<Item> items = cl.getClient().getAllItemsByStatus(status.ACTIVE);
|
| - |
|
246 |
items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED));
|
| - |
|
247 |
items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED_BY_RISK));
|
| - |
|
248 |
|
| - |
|
249 |
Map<Long, List<Item>> entityIdItemMap1 = new HashMap<Long, List<Item>>();
|
| - |
|
250 |
ProductListGenerator pl = new ProductListGenerator(entityIdItemMap1);
|
| - |
|
251 |
pl.populateEntityIdItemMap(items);
|
| - |
|
252 |
pl.generateProductXMLForDisplayAds();
|
| - |
|
253 |
}
|
| - |
|
254 |
|
| - |
|
255 |
private void populateEntityIdItemMap(List<Item> items){
|
| - |
|
256 |
Date toDate = new Date();
|
| - |
|
257 |
for(Item item: items){
|
| - |
|
258 |
//TODO Can be removed as we are checking in calling function
|
| - |
|
259 |
if(!(item.getItemStatus()==status.ACTIVE || item.getItemStatus()==status.CONTENT_COMPLETE || item.getItemStatus() == status.PAUSED)){
|
| - |
|
260 |
continue;
|
| - |
|
261 |
}
|
| - |
|
262 |
if(toDate.getTime() < item.getStartDate() || item.getSellingPrice() == 0){
|
| - |
|
263 |
continue;
|
| - |
|
264 |
}
|
| - |
|
265 |
List<Item> itemList = entityIdItemMap.get(item.getCatalogItemId());
|
| - |
|
266 |
if(itemList == null){
|
| - |
|
267 |
itemList = new ArrayList<Item>();
|
| - |
|
268 |
}
|
| - |
|
269 |
itemList.add(item);
|
| - |
|
270 |
entityIdItemMap.put(item.getCatalogItemId(), itemList);
|
| - |
|
271 |
}
|
| - |
|
272 |
|
| - |
|
273 |
//Remove all items which have not been updated since last content generation.
|
| - |
|
274 |
List<Long> removeEntities = new ArrayList<Long>();
|
| - |
|
275 |
for(Long entityId:entityIdItemMap.keySet()){
|
| - |
|
276 |
boolean isValidEntity = false;
|
| - |
|
277 |
//If any one of the items has been updated before current timestamp, than we generate content for whole entity
|
| - |
|
278 |
for(Item item: entityIdItemMap.get(entityId)){
|
| - |
|
279 |
if(item.getUpdatedOn() > 0){
|
| - |
|
280 |
isValidEntity = true;
|
| - |
|
281 |
}
|
| - |
|
282 |
}
|
| - |
|
283 |
if(!isValidEntity){
|
| - |
|
284 |
removeEntities.add(entityId);
|
| - |
|
285 |
}
|
| - |
|
286 |
}
|
| - |
|
287 |
for(Long entityId: removeEntities){
|
| - |
|
288 |
entityIdItemMap.remove(entityId);
|
| - |
|
289 |
}
|
| - |
|
290 |
}
|
| - |
|
291 |
|
| - |
|
292 |
|
| - |
|
293 |
/**
|
| - |
|
294 |
* Generate the xml list of all the active phones and store in a file
|
| - |
|
295 |
* @throws Exception
|
| - |
|
296 |
*/
|
| - |
|
297 |
public void generateProductXMLForDisplayAds() throws Exception {
|
| - |
|
298 |
|
| - |
|
299 |
List<String> productXMLSnippets = new ArrayList<String>();
|
| - |
|
300 |
productXMLSnippets.add("<saholic.com>");
|
| - |
|
301 |
List<Long> itemIds = new ArrayList<Long>();
|
| - |
|
302 |
|
| - |
|
303 |
for(Long entityId: entityIdItemMap.keySet()){
|
| - |
|
304 |
List<Item> items = entityIdItemMap.get(entityId);
|
| - |
|
305 |
Item firstItem = items.get(0);
|
| - |
|
306 |
if(isMobile(firstItem)) {
|
| - |
|
307 |
itemIds.add(firstItem.getId());
|
| - |
|
308 |
}
|
| - |
|
309 |
}
|
| - |
|
310 |
|
| - |
|
311 |
PromotionClient promotionClient = new PromotionClient();
|
| - |
|
312 |
in.shop2020.model.v1.user.PromotionService.Client promotionServiceClient = promotionClient.getClient();
|
| - |
|
313 |
|
| - |
|
314 |
List<ItemCouponDiscount> itemsCouponsAndDiscounts = promotionServiceClient.getItemDiscountMap(itemIds);
|
| - |
|
315 |
|
| - |
|
316 |
Map<Long, ItemCouponDiscount> couponsAndDiscounts = new HashMap<Long, ItemCouponDiscount>();
|
| - |
|
317 |
|
| - |
|
318 |
for (ItemCouponDiscount itemCouponDiscount: itemsCouponsAndDiscounts) {
|
| - |
|
319 |
couponsAndDiscounts.put(itemCouponDiscount.getItemId(), itemCouponDiscount);
|
| - |
|
320 |
}
|
| - |
|
321 |
|
| - |
|
322 |
for(Long entityId: entityIdItemMap.keySet()) {
|
| - |
|
323 |
List<Item> items = entityIdItemMap.get(entityId);
|
| - |
|
324 |
Item firstItem = items.get(0);
|
| - |
|
325 |
if(!isMobile(firstItem)){
|
| - |
|
326 |
continue;
|
| - |
|
327 |
}
|
| - |
|
328 |
|
| - |
|
329 |
productXMLSnippets.add(this.xmlIndentation[1] + "<products>");
|
| - |
|
330 |
|
| - |
|
331 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductSKU>" + entityId + "</ProductSKU>");
|
| - |
|
332 |
|
| - |
|
333 |
String title = getProductTitle(firstItem);
|
| - |
|
334 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductName>" + title + "</ProductName>");
|
| - |
|
335 |
|
| - |
|
336 |
String url = getProductURL(entityId, firstItem);
|
| - |
|
337 |
|
| - |
|
338 |
String imageUrl = "http://static" + ((entityId+1)%3) + ".saholic.com" + File.separator + "images" + File.separator + entityId + File.separator + "icon.jpg";
|
| - |
|
339 |
|
| - |
|
340 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductURL>" + url + "</ProductURL>");
|
| - |
|
341 |
|
| - |
|
342 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductImageURL>" + imageUrl + "</ProductImageURL>");
|
| - |
|
343 |
|
| - |
|
344 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductMRP>" + firstItem.getMrp() + "</ProductMRP>");
|
| - |
|
345 |
|
| - |
|
346 |
double minPrice = getMinPrice(items);
|
| - |
|
347 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductSellingPrice>" + (int)minPrice + "</ProductSellingPrice>");
|
| - |
|
348 |
|
| - |
|
349 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductDiscount>" + (int)((firstItem.getMrp()-minPrice)/firstItem.getMrp()*100) + "</ProductDiscount>");
|
| - |
|
350 |
|
| - |
|
351 |
long itemId = firstItem.getId();
|
| - |
|
352 |
|
| - |
|
353 |
if(couponsAndDiscounts.containsKey(itemId)) {
|
| - |
|
354 |
|
| - |
|
355 |
ItemCouponDiscount itemCouponDiscount = couponsAndDiscounts.get(itemId);
|
| - |
|
356 |
|
| - |
|
357 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductCoupons>");
|
| - |
|
358 |
productXMLSnippets.add(this.xmlIndentation[3] + "<Coupon>");
|
| - |
|
359 |
productXMLSnippets.add(this.xmlIndentation[4] + "<CouponCode>" + itemCouponDiscount.getCouponCode() + "</CouponCode>");
|
| - |
|
360 |
productXMLSnippets.add(this.xmlIndentation[4] + "<PriceAfterCoupon>" + (int)(minPrice - itemCouponDiscount.getDiscount()) + "</PriceAfterCoupon>");
|
| - |
|
361 |
productXMLSnippets.add(this.xmlIndentation[3] + "</Coupon>");
|
| - |
|
362 |
productXMLSnippets.add(this.xmlIndentation[2] + "</ProductCoupons>");
|
| - |
|
363 |
|
| - |
|
364 |
} else {
|
| - |
|
365 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductCoupons />");
|
| - |
|
366 |
}
|
| - |
|
367 |
|
| - |
|
368 |
String description = "";
|
| - |
|
369 |
Entity entity = CreationUtils.getEntity(entityId);
|
| - |
|
370 |
if(entity!=null){
|
| - |
|
371 |
if(entity.getSlide(130001) !=null){
|
| - |
|
372 |
description = entity.getSlide(130001).getFreeformContent().getFreeformText();
|
| - |
|
373 |
|
| - |
|
374 |
}
|
| - |
|
375 |
}
|
| - |
|
376 |
|
| - |
|
377 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductDescription>" + description + "</ProductDescription>");
|
| - |
|
378 |
|
| - |
|
379 |
productXMLSnippets.add(this.xmlIndentation[1] + "</products>");
|
| - |
|
380 |
}
|
| - |
|
381 |
|
| - |
|
382 |
productXMLSnippets.add("</saholic.com>");
|
| - |
|
383 |
|
| - |
|
384 |
String productDataXML = StringUtils.join(productXMLSnippets, "\n");
|
| - |
|
385 |
|
| - |
|
386 |
Utils.info(productDataXML);
|
| - |
|
387 |
|
| - |
|
388 |
// Write it to file
|
| - |
|
389 |
String productXMLFilename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "advertismentapi.xml";
|
| - |
|
390 |
DBUtils.store(productDataXML, productXMLFilename);
|
| - |
|
391 |
}
|
| 232 |
}
|
392 |
}
|
| 233 |
|
393 |
|