| Line 3... |
Line 3... |
| 3 |
import in.shop2020.logistics.DeliveryType;
|
3 |
import in.shop2020.logistics.DeliveryType;
|
| 4 |
import in.shop2020.logistics.LogisticsInfo;
|
4 |
import in.shop2020.logistics.LogisticsInfo;
|
| 5 |
import in.shop2020.logistics.LogisticsService;
|
5 |
import in.shop2020.logistics.LogisticsService;
|
| 6 |
import in.shop2020.metamodel.core.Entity;
|
6 |
import in.shop2020.metamodel.core.Entity;
|
| 7 |
import in.shop2020.metamodel.definitions.Catalog;
|
7 |
import in.shop2020.metamodel.definitions.Catalog;
|
| - |
|
8 |
import in.shop2020.metamodel.definitions.Category;
|
| 8 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
9 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
| 9 |
import in.shop2020.metamodel.util.CreationUtils;
|
10 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 10 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
11 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
| 11 |
import in.shop2020.model.v1.catalog.Item;
|
12 |
import in.shop2020.model.v1.catalog.Item;
|
| - |
|
13 |
import in.shop2020.model.v1.catalog.ItemShippingInfo;
|
| 12 |
import in.shop2020.model.v1.catalog.VoucherItemMapping;
|
14 |
import in.shop2020.model.v1.catalog.VoucherItemMapping;
|
| 13 |
import in.shop2020.model.v1.catalog.status;
|
15 |
import in.shop2020.model.v1.catalog.status;
|
| 14 |
import in.shop2020.model.v1.user.ItemCouponDiscount;
|
16 |
import in.shop2020.model.v1.user.ItemCouponDiscount;
|
| 15 |
import in.shop2020.thrift.clients.CatalogClient;
|
17 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 16 |
import in.shop2020.thrift.clients.LogisticsClient;
|
18 |
import in.shop2020.thrift.clients.LogisticsClient;
|
| Line 41... |
Line 43... |
| 41 |
*/
|
43 |
*/
|
| 42 |
public class ProductListGenerator {
|
44 |
public class ProductListGenerator {
|
| 43 |
|
45 |
|
| 44 |
private String[] xmlIndentation = {"", " ", " ", " "," "};
|
46 |
private String[] xmlIndentation = {"", " ", " ", " "," "};
|
| 45 |
private Client cc = null;
|
47 |
private Client cc = null;
|
| - |
|
48 |
List <Long> catalogItemIds = new ArrayList<Long>();
|
| 46 |
public Map<Long, List<Item>> entityIdItemMap;
|
49 |
public Map<Long, List<Item>> entityIdItemMap;
|
| 47 |
private static final String DEFAULT_PINCODE = "110001";
|
50 |
private static final String DEFAULT_PINCODE = "110001";
|
| 48 |
DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
|
51 |
DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
|
| 49 |
|
- |
|
| - |
|
52 |
private List<Long> validParentCategories = Arrays.asList((long)Utils.LAPTOPS_CATEGORY, (long)Utils.CAMERAS_CATEGORY, (long)Utils.MOBILE_PHONES_CATAGORY, (long)Utils.TABLETS_CATEGORY);
|
| 50 |
private List<Long> voucherEntities = new ArrayList<Long>();
|
53 |
private List<Long> voucherEntities = new ArrayList<Long>();
|
| 51 |
|
54 |
|
| 52 |
public ProductListGenerator(Map<Long, List<Item>> entityIdItemMap) throws Exception {
|
55 |
public ProductListGenerator(Map<Long, List<Item>> entityIdItemMap) throws Exception {
|
| 53 |
this.entityIdItemMap = entityIdItemMap;
|
56 |
this.entityIdItemMap = entityIdItemMap;
|
| 54 |
String vouchers = readFile(Utils.CONTENT_DB_PATH + "voucher-entities.txt");
|
57 |
String vouchers = readFile(Utils.CONTENT_DB_PATH + "voucher-entities.txt");
|
| Line 109... |
Line 112... |
| 109 |
if(minPrice > item.getSellingPrice()){
|
112 |
if(minPrice > item.getSellingPrice()){
|
| 110 |
minPrice = item.getSellingPrice();
|
113 |
minPrice = item.getSellingPrice();
|
| 111 |
it = item;
|
114 |
it = item;
|
| 112 |
}
|
115 |
}
|
| 113 |
}
|
116 |
}
|
| 114 |
if(Arrays.asList(1587l,2222l,2258l,2270l,5836l,6718l, 6719l).contains(it.getId())){
|
- |
|
| 115 |
System.out.println(it.getId());
|
- |
|
| 116 |
}
|
- |
|
| 117 |
if(it != null && voucherEntities.contains(it.getCatalogItemId())) {
|
117 |
if(it != null && voucherEntities.contains(it.getCatalogItemId())) {
|
| 118 |
try {
|
118 |
try {
|
| 119 |
cc = new CatalogClient().getClient();
|
119 |
cc = new CatalogClient().getClient();
|
| 120 |
List<VoucherItemMapping> mapping;
|
120 |
List<VoucherItemMapping> mapping;
|
| 121 |
mapping = cc.getAllItemVouchers(it.getId());
|
121 |
mapping = cc.getAllItemVouchers(it.getId());
|
| Line 243... |
Line 243... |
| 243 |
|
243 |
|
| 244 |
String imageUrl = "http://static" + ((entityId+1)%3) + ".saholic.com" + File.separator + "images" + File.separator +
|
244 |
String imageUrl = "http://static" + ((entityId+1)%3) + ".saholic.com" + File.separator + "images" + File.separator +
|
| 245 |
"website" + File.separator + entityId + File.separator + "icon.jpg";
|
245 |
"website" + File.separator + entityId + File.separator + "icon.jpg";
|
| 246 |
|
246 |
|
| 247 |
irDataXMLSnippets.add(this.xmlIndentation[2] + "<ProductURL>" + url + "</ProductURL>");
|
247 |
irDataXMLSnippets.add(this.xmlIndentation[2] + "<ProductURL>" + url + "</ProductURL>");
|
| 248 |
|
- |
|
| - |
|
248 |
irDataXMLSnippets.add(this.xmlIndentation[2] + "<Availability>" + (catalogItemIds.contains(entityId) ? "Y" : "N") + "</Availability>");
|
| 249 |
double minPrice = getMinPrice(items);
|
249 |
double minPrice = getMinPrice(items);
|
| 250 |
|
250 |
|
| 251 |
if(couponsAndDiscounts.containsKey(firstItem.getId())) {
|
251 |
if(couponsAndDiscounts.containsKey(firstItem.getId())) {
|
| 252 |
|
252 |
|
| 253 |
int discountedPrice = (int)(minPrice - couponsAndDiscounts.get(firstItem.getId()).getDiscount());
|
253 |
int discountedPrice = (int)(minPrice - couponsAndDiscounts.get(firstItem.getId()).getDiscount());
|
| Line 312... |
Line 312... |
| 312 |
|
312 |
|
| 313 |
} catch (Exception e) {
|
313 |
} catch (Exception e) {
|
| 314 |
prod_client = null;
|
314 |
prod_client = null;
|
| 315 |
Utils.info("Logistics estimations can't be fetched as Logistics Service is inaccessible" + e);
|
315 |
Utils.info("Logistics estimations can't be fetched as Logistics Service is inaccessible" + e);
|
| 316 |
}
|
316 |
}
|
| 317 |
List<Long> itemIds = new ArrayList<Long>();
|
- |
|
| 318 |
List<String> accessoriesXMLSnippets = new ArrayList<String>();
|
317 |
List<String> accessoriesXMLSnippets = new ArrayList<String>();
|
| 319 |
|
318 |
|
| 320 |
accessoriesXMLSnippets.add("<saholic.com>");
|
319 |
accessoriesXMLSnippets.add("<saholic.com>");
|
| 321 |
|
320 |
|
| 322 |
for(Long entityId: entityIdItemMap.keySet()) {
|
321 |
for(Long entityId: entityIdItemMap.keySet()) {
|
| Line 402... |
Line 401... |
| 402 |
camerasXMLSnippets.add(this.xmlIndentation[2] + "<ProductSKU>" + entityId + "</ProductSKU>");
|
401 |
camerasXMLSnippets.add(this.xmlIndentation[2] + "<ProductSKU>" + entityId + "</ProductSKU>");
|
| 403 |
camerasXMLSnippets.add(this.xmlIndentation[2] + "<ProductName>" + StringEscapeUtils.escapeXml(title) + "</ProductName>");
|
402 |
camerasXMLSnippets.add(this.xmlIndentation[2] + "<ProductName>" + StringEscapeUtils.escapeXml(title) + "</ProductName>");
|
| 404 |
camerasXMLSnippets.add(this.xmlIndentation[2] + "<ProductURL>" + StringEscapeUtils.escapeXml(url) + "</ProductURL>");
|
403 |
camerasXMLSnippets.add(this.xmlIndentation[2] + "<ProductURL>" + StringEscapeUtils.escapeXml(url) + "</ProductURL>");
|
| 405 |
camerasXMLSnippets.add(this.xmlIndentation[2] + "<ProductPrice>" + getMinPrice(items) + "</ProductPrice>");
|
404 |
camerasXMLSnippets.add(this.xmlIndentation[2] + "<ProductPrice>" + getMinPrice(items) + "</ProductPrice>");
|
| 406 |
camerasXMLSnippets.add(this.xmlIndentation[2] + "<ProductMRP>" + getMinMRP(items) + "</ProductMRP>");
|
405 |
camerasXMLSnippets.add(this.xmlIndentation[2] + "<ProductMRP>" + getMinMRP(items) + "</ProductMRP>");
|
| - |
|
406 |
camerasXMLSnippets.add(this.xmlIndentation[2] + "<Availability>" + (catalogItemIds.contains(entityId) ? "Y" : "N") + "</Availability>");
|
| 407 |
|
407 |
|
| 408 |
LogisticsInfo logisticsInfo = null;
|
408 |
LogisticsInfo logisticsInfo = null;
|
| 409 |
if(prod_client != null){
|
409 |
if(prod_client != null){
|
| 410 |
try {
|
410 |
try {
|
| 411 |
Long itemId = prod_client.getEntityLogisticsEstimation(entityId, DEFAULT_PINCODE, DeliveryType.PREPAID).get(0);
|
411 |
Long itemId = prod_client.getEntityLogisticsEstimation(entityId, DEFAULT_PINCODE, DeliveryType.PREPAID).get(0);
|
| Line 654... |
Line 654... |
| 654 |
|
654 |
|
| 655 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductMRP>" + firstItem.getMrp() + "</ProductMRP>");
|
655 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductMRP>" + firstItem.getMrp() + "</ProductMRP>");
|
| 656 |
|
656 |
|
| 657 |
double minPrice = getMinPrice(items);
|
657 |
double minPrice = getMinPrice(items);
|
| 658 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductSellingPrice>" + (int)minPrice + "</ProductSellingPrice>");
|
658 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductSellingPrice>" + (int)minPrice + "</ProductSellingPrice>");
|
| 659 |
|
- |
|
| - |
|
659 |
productXMLSnippets.add(this.xmlIndentation[2] + "<Availability>" + (catalogItemIds.contains(entityId) ? "Y" : "N") + "</Availability>");
|
| 660 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductDiscount>" + (int)((firstItem.getMrp()-minPrice)/firstItem.getMrp()*100) + "</ProductDiscount>");
|
660 |
productXMLSnippets.add(this.xmlIndentation[2] + "<ProductDiscount>" + (int)((firstItem.getMrp()-minPrice)/firstItem.getMrp()*100) + "</ProductDiscount>");
|
| 661 |
|
661 |
|
| 662 |
long itemId = firstItem.getId();
|
662 |
long itemId = firstItem.getId();
|
| 663 |
|
663 |
|
| 664 |
if(couponsAndDiscounts.containsKey(itemId)) {
|
664 |
if(couponsAndDiscounts.containsKey(itemId)) {
|
| Line 713... |
Line 713... |
| 713 |
//items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED));
|
713 |
//items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED));
|
| 714 |
// items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED_BY_RISK));
|
714 |
// items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED_BY_RISK));
|
| 715 |
|
715 |
|
| 716 |
Map<Long, List<Item>> entityIdItemMap1 = new HashMap<Long, List<Item>>();
|
716 |
Map<Long, List<Item>> entityIdItemMap1 = new HashMap<Long, List<Item>>();
|
| 717 |
ProductListGenerator pl = new ProductListGenerator(entityIdItemMap1);
|
717 |
ProductListGenerator pl = new ProductListGenerator(entityIdItemMap1);
|
| - |
|
718 |
//pl.generateThinkDigitFeed();
|
| 718 |
pl.populateEntityIdItemMap(items);
|
719 |
pl.populateEntityIdItemMap(items);
|
| 719 |
//pl.generateAccessoriesXML();
|
720 |
//pl.generateAccessoriesXML();
|
| 720 |
pl.generateXMLFeedForMobileSite();
|
721 |
//pl.generateXMLFeedForMobileSite();
|
| 721 |
}
|
722 |
}
|
| 722 |
|
723 |
|
| 723 |
private String readFile(String path) throws IOException {
|
724 |
private String readFile(String path) throws IOException {
|
| 724 |
FileInputStream stream = new FileInputStream(new File(path));
|
725 |
FileInputStream stream = new FileInputStream(new File(path));
|
| 725 |
try {
|
726 |
try {
|
| Line 730... |
Line 731... |
| 730 |
}
|
731 |
}
|
| 731 |
finally {
|
732 |
finally {
|
| 732 |
stream.close();
|
733 |
stream.close();
|
| 733 |
}
|
734 |
}
|
| 734 |
}
|
735 |
}
|
| - |
|
736 |
/**
|
| - |
|
737 |
* Feed generated for thinkdigit that only contains the live items
|
| - |
|
738 |
* feed should have s
|
| - |
|
739 |
*/
|
| - |
|
740 |
public void generateThinkDigitFeed() throws Exception{
|
| - |
|
741 |
|
| - |
|
742 |
List<String> productXMLSnippets = new ArrayList<String>();
|
| - |
|
743 |
productXMLSnippets.add("<root>");
|
| - |
|
744 |
String thinkDigitFeedFileName = Utils.EXPORT_PARTNERS_CONTENT_PATH + "all-categories.xml";
|
| - |
|
745 |
cc = new CatalogClient().getClient();
|
| - |
|
746 |
List<Item> items = cc.getAllItemsByStatus(status.ACTIVE);
|
| - |
|
747 |
Client catalogClientProd = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(), ConfigClientKeys.catalog_service_server_port.toString()).getClient();
|
| - |
|
748 |
for (Item item : items){
|
| - |
|
749 |
Category parentCategory = Catalog.getInstance().getDefinitionsContainer().getCategory(item.getCategory()).getParentCategory();
|
| - |
|
750 |
boolean isActive = true;
|
| - |
|
751 |
if(validParentCategories.contains(parentCategory.getID()) && !catalogItemIds.contains(item.getCatalogItemId())) {
|
| - |
|
752 |
if(item.isRisky()){
|
| - |
|
753 |
try {
|
| - |
|
754 |
ItemShippingInfo isi = catalogClientProd.isActive(item.getId());
|
| - |
|
755 |
isActive = isi.isIsActive();
|
| - |
|
756 |
} catch (Exception e) {
|
| - |
|
757 |
isActive = true;
|
| - |
|
758 |
}
|
| - |
|
759 |
}
|
| - |
|
760 |
if(isActive) {
|
| - |
|
761 |
productXMLSnippets.add(this.xmlIndentation[1] + "<products>");
|
| - |
|
762 |
productXMLSnippets.add(this.xmlIndentation[2] + "<id>" + item.getCatalogItemId() + "</id>");
|
| - |
|
763 |
productXMLSnippets.add(this.xmlIndentation[2] + "<product>" + getProductTitle(item) + "</product>");
|
| - |
|
764 |
productXMLSnippets.add(this.xmlIndentation[2] + "<Product_URL>" + getProductURL(item.getCatalogItemId(), item) + "</Product_URL>");
|
| - |
|
765 |
productXMLSnippets.add(this.xmlIndentation[2] + "<Product_Price>" + (int)item.getSellingPrice() + "</Product_Price>");
|
| - |
|
766 |
productXMLSnippets.add(this.xmlIndentation[2] + "<Merchant_Name>" + "saholic.com" + "</Merchant_Name>");
|
| - |
|
767 |
productXMLSnippets.add(this.xmlIndentation[2] + "<Category_Name>" + parentCategory.getLabel() + "</Category_Name>");
|
| - |
|
768 |
productXMLSnippets.add(this.xmlIndentation[1] + "</products>");
|
| - |
|
769 |
catalogItemIds.add(item.getCatalogItemId());
|
| - |
|
770 |
}
|
| - |
|
771 |
}
|
| - |
|
772 |
}
|
| - |
|
773 |
productXMLSnippets.add("</root>");
|
| - |
|
774 |
String productDataXML = StringUtils.join(productXMLSnippets, "\n");
|
| - |
|
775 |
DBUtils.store(productDataXML, thinkDigitFeedFileName);
|
| - |
|
776 |
|
| - |
|
777 |
}
|
| 735 |
}
|
778 |
}
|
| 736 |
|
779 |
|