| Line 11... |
Line 11... |
| 11 |
import in.shop2020.catalog.dashboard.shared.VoucherItemMapping;
|
11 |
import in.shop2020.catalog.dashboard.shared.VoucherItemMapping;
|
| 12 |
import in.shop2020.config.ConfigException;
|
12 |
import in.shop2020.config.ConfigException;
|
| 13 |
import in.shop2020.content.ContentService;
|
13 |
import in.shop2020.content.ContentService;
|
| 14 |
import in.shop2020.content.ContentServiceException;
|
14 |
import in.shop2020.content.ContentServiceException;
|
| 15 |
import in.shop2020.model.v1.catalog.InventoryService;
|
15 |
import in.shop2020.model.v1.catalog.InventoryService;
|
| - |
|
16 |
import in.shop2020.model.v1.catalog.ItemType;
|
| 16 |
import in.shop2020.model.v1.catalog.status;
|
17 |
import in.shop2020.model.v1.catalog.status;
|
| 17 |
import in.shop2020.model.v1.user.VoucherType;
|
18 |
import in.shop2020.model.v1.user.VoucherType;
|
| 18 |
import in.shop2020.model.v1.catalog.ItemType;
|
- |
|
| 19 |
import in.shop2020.thrift.clients.CatalogClient;
|
19 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 20 |
import in.shop2020.thrift.clients.ContentClient;
|
20 |
import in.shop2020.thrift.clients.ContentClient;
|
| 21 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
21 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 22 |
import in.shop2020.utils.CategoryManager;
|
22 |
import in.shop2020.utils.CategoryManager;
|
| 23 |
import in.shop2020.utils.ConfigClientKeys;
|
23 |
import in.shop2020.utils.ConfigClientKeys;
|
| Line 660... |
Line 660... |
| 660 |
return itemList;
|
660 |
return itemList;
|
| 661 |
}
|
661 |
}
|
| 662 |
|
662 |
|
| 663 |
@Override
|
663 |
@Override
|
| 664 |
public String updateItemOnProduction(Item item) {
|
664 |
public String updateItemOnProduction(Item item) {
|
| 665 |
logger.info("Update item on production call, Item Id: " + item.getId());
|
- |
|
| 666 |
|
- |
|
| 667 |
if(!canPushToProduction()) {
|
665 |
if(!canPushToProduction()) {
|
| 668 |
// If we can't push to production, then return that message to user
|
666 |
// If we can't push to production, then return that message to user
|
| 669 |
// else move forward with update.
|
667 |
// else move forward with update.
|
| 670 |
return "Maximum push to production count reached for today";
|
668 |
return "Maximum push to production count reached for today";
|
| - |
|
669 |
}
|
| - |
|
670 |
List<Long> itemIds = item.getSameItemsWithDifferentColors();
|
| - |
|
671 |
List<Item> items = new ArrayList<Item>();
|
| - |
|
672 |
items.add(item);
|
| - |
|
673 |
for(Long itemId : itemIds) {
|
| - |
|
674 |
try {
|
| - |
|
675 |
CatalogClient catalogServiceClient = new CatalogClient();
|
| - |
|
676 |
InventoryService.Client catalogClient = catalogServiceClient.getClient();
|
| - |
|
677 |
in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);
|
| - |
|
678 |
List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());
|
| - |
|
679 |
List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());
|
| - |
|
680 |
List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
|
| - |
|
681 |
items.add(getItemFromThriftItem(thriftItem, vip, vim, sip, null, null, null));
|
| - |
|
682 |
} catch (Exception e) {
|
| - |
|
683 |
logger.error("Could not fetch item for : " + itemId, e);
|
| - |
|
684 |
return "Could not push to production. No item got pushed.";
|
| - |
|
685 |
}
|
| - |
|
686 |
}
|
| - |
|
687 |
for (Item it : items) {
|
| - |
|
688 |
logger.info("Update item on production call, Item Id: " + it.getId());
|
| 671 |
}
|
689 |
|
| 672 |
try{
|
690 |
try{
|
| 673 |
CatalogClient catalogServiceClient_Prod = new CatalogClient(
|
691 |
CatalogClient catalogServiceClient_Prod = new CatalogClient(
|
| 674 |
ConfigClientKeys.catalog_service_server_host_prod.toString(),
|
692 |
ConfigClientKeys.catalog_service_server_host_prod.toString(),
|
| 675 |
ConfigClientKeys.catalog_service_server_port.toString());
|
693 |
ConfigClientKeys.catalog_service_server_port.toString());
|
| 676 |
|
694 |
|
| 677 |
InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
|
695 |
InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();
|
| 678 |
|
696 |
|
| 679 |
in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(item.getId());
|
697 |
in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(it.getId());
|
| 680 |
|
698 |
|
| 681 |
if(item.getMrp() != null) {
|
699 |
if(it.getMrp() != null) {
|
| 682 |
tItem.setMrp(item.getMrp());
|
700 |
tItem.setMrp(it.getMrp());
|
| 683 |
}
|
701 |
}
|
| 684 |
|
702 |
|
| 685 |
if(item.getSellingPrice() != null) {
|
703 |
if(it.getSellingPrice() != null) {
|
| 686 |
tItem.setSellingPrice(item.getSellingPrice());
|
704 |
tItem.setSellingPrice(it.getSellingPrice());
|
| 687 |
}
|
705 |
}
|
| 688 |
|
706 |
|
| 689 |
long rItemId;
|
707 |
long rItemId;
|
| 690 |
if((rItemId = catalogClient_Prod.updateItem(tItem)) != item.getId()) {
|
708 |
if((rItemId = catalogClient_Prod.updateItem(tItem)) != it.getId()) {
|
| 691 |
logger.error("Error updating item on production, returned Item Id: " + rItemId);
|
709 |
logger.error("Error updating item on production, returned Item Id: " + rItemId);
|
| 692 |
return "Error updating item prices on production";
|
710 |
return "Error updating item prices on production";
|
| 693 |
}
|
711 |
}
|
| 694 |
logger.info("Successfully updated item: " + item.getId());
|
712 |
logger.info("Successfully updated item: " + it.getId());
|
| 695 |
|
713 |
|
| 696 |
StringBuilder sb = new StringBuilder();
|
714 |
StringBuilder sb = new StringBuilder();
|
| 697 |
|
715 |
|
| 698 |
Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();
|
716 |
Map<Long, VendorPricings> vendorPricings = it.getVendorPricesMap();
|
| 699 |
if(vendorPricings != null && !vendorPricings.isEmpty()) {
|
717 |
if(vendorPricings != null && !vendorPricings.isEmpty()) {
|
| 700 |
in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
|
718 |
in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;
|
| 701 |
for(VendorPricings v : vendorPricings.values()) {
|
719 |
for(VendorPricings v : vendorPricings.values()) {
|
| 702 |
tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();
|
720 |
tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();
|
| 703 |
tVendorPricing.setVendorId(v.getVendorId());
|
721 |
tVendorPricing.setVendorId(v.getVendorId());
|
| 704 |
tVendorPricing.setItemId(item.getId());
|
722 |
tVendorPricing.setItemId(it.getId());
|
| 705 |
tVendorPricing.setMop(v.getMop());
|
723 |
tVendorPricing.setMop(v.getMop());
|
| 706 |
tVendorPricing.setTransferPrice(v.getTransferPrice());
|
724 |
tVendorPricing.setTransferPrice(v.getTransferPrice());
|
| 707 |
tVendorPricing.setDealerPrice(v.getDealerPrice());
|
725 |
tVendorPricing.setDealerPrice(v.getDealerPrice());
|
| 708 |
catalogClient_Prod.addVendorItemPricing(tVendorPricing);
|
726 |
catalogClient_Prod.addVendorItemPricing(tVendorPricing);
|
| 709 |
logger.info("VendorItemPricing updated. " + tVendorPricing.toString());
|
727 |
logger.info("VendorItemPricing updated. " + tVendorPricing.toString());
|
| 710 |
sb.append("[VId:" + v.getVendorId() + ",MOP=" + v.getMop() + ",TP=" + v.getTransferPrice() + ",DP=" + v.getDealerPrice() + "], ");
|
728 |
sb.append("[VId:" + v.getVendorId() + ",MOP=" + v.getMop() + ",TP=" + v.getTransferPrice() + ",DP=" + v.getDealerPrice() + "], ");
|
| 711 |
}
|
729 |
}
|
| 712 |
}
|
730 |
}
|
| 713 |
|
731 |
|
| 714 |
Map<String, VendorItemMapping> vendorMappings = item.getVendorKeysMap();
|
732 |
Map<String, VendorItemMapping> vendorMappings = it.getVendorKeysMap();
|
| 715 |
if(vendorMappings != null && !vendorMappings.isEmpty()) {
|
733 |
if(vendorMappings != null && !vendorMappings.isEmpty()) {
|
| 716 |
in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;
|
734 |
in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;
|
| 717 |
for(VendorItemMapping vendorItemMapping : vendorMappings.values()) {
|
735 |
for(VendorItemMapping vendorItemMapping : vendorMappings.values()) {
|
| 718 |
tVendorMapping = new in.shop2020.model.v1.catalog.VendorItemMapping();
|
736 |
tVendorMapping = new in.shop2020.model.v1.catalog.VendorItemMapping();
|
| 719 |
tVendorMapping.setVendorId(vendorItemMapping.getVendorId());
|
737 |
tVendorMapping.setVendorId(vendorItemMapping.getVendorId());
|
| 720 |
tVendorMapping.setItemId(item.getId());
|
738 |
tVendorMapping.setItemId(it.getId());
|
| 721 |
tVendorMapping.setItemKey(vendorItemMapping.getItemKey());
|
739 |
tVendorMapping.setItemKey(vendorItemMapping.getItemKey());
|
| 722 |
catalogClient_Prod.addVendorItemMapping(vendorItemMapping.getItemKey(), tVendorMapping);
|
740 |
catalogClient_Prod.addVendorItemMapping(vendorItemMapping.getItemKey(), tVendorMapping);
|
| 723 |
logger.info("VendorItemMapping updated. " + tVendorMapping.toString());
|
741 |
logger.info("VendorItemMapping updated. " + tVendorMapping.toString());
|
| 724 |
sb.append("[VId:" + vendorItemMapping.getVendorId() + ",ItemKey=" + vendorItemMapping.getItemKey() + "], ");
|
742 |
sb.append("[VId:" + vendorItemMapping.getVendorId() + ",ItemKey=" + vendorItemMapping.getItemKey() + "], ");
|
| 725 |
}
|
743 |
}
|
| 726 |
}
|
744 |
}
|
| 727 |
|
745 |
|
| 728 |
Map<Long, SourcePricings> sourcePricings = item.getSourcePricesMap();
|
746 |
Map<Long, SourcePricings> sourcePricings = it.getSourcePricesMap();
|
| 729 |
if(sourcePricings != null && !sourcePricings.isEmpty()){
|
747 |
if(sourcePricings != null && !sourcePricings.isEmpty()){
|
| 730 |
in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricing;
|
748 |
in.shop2020.model.v1.catalog.SourceItemPricing tSourcePricing;
|
| 731 |
for(SourcePricings s : sourcePricings.values()){
|
749 |
for(SourcePricings s : sourcePricings.values()){
|
| 732 |
tSourcePricing = new in.shop2020.model.v1.catalog.SourceItemPricing();
|
750 |
tSourcePricing = new in.shop2020.model.v1.catalog.SourceItemPricing();
|
| 733 |
tSourcePricing.setSourceId(s.getSourceId());
|
751 |
tSourcePricing.setSourceId(s.getSourceId());
|
| 734 |
tSourcePricing.setItemId(item.getId());
|
752 |
tSourcePricing.setItemId(it.getId());
|
| 735 |
tSourcePricing.setMrp(s.getMrp());
|
753 |
tSourcePricing.setMrp(s.getMrp());
|
| 736 |
tSourcePricing.setSellingPrice(s.getSellingPrice());
|
754 |
tSourcePricing.setSellingPrice(s.getSellingPrice());
|
| 737 |
catalogClient_Prod.addSourceItemPricing(tSourcePricing);
|
755 |
catalogClient_Prod.addSourceItemPricing(tSourcePricing);
|
| 738 |
logger.info("SourceItemPricing updated. " + tSourcePricing.toString());
|
756 |
logger.info("SourceItemPricing updated. " + tSourcePricing.toString());
|
| 739 |
sb.append("[SId:" + s.getSourceId() + ",MRP=" + s.getMrp() + ",SP=" + s.getSellingPrice() + "], ");
|
757 |
sb.append("[SId:" + s.getSourceId() + ",MRP=" + s.getMrp() + ",SP=" + s.getSellingPrice() + "], ");
|
| 740 |
}
|
758 |
}
|
| 741 |
}
|
759 |
}
|
| 742 |
|
760 |
|
| 743 |
pushToProdLogger.info("Id=" + item.getId() + ",MRP=" + item.getMrp() + ",SP=" + " " + item.getSellingPrice() + sb.toString());
|
761 |
pushToProdLogger.info("Id=" + it.getId() + ",MRP=" + it.getMrp() + ",SP=" + " " + it.getSellingPrice() + sb.toString());
|
| 744 |
} catch (Exception e) {
|
762 |
} catch (Exception e) {
|
| 745 |
logger.error("Error while updating prices on production", e);
|
763 |
logger.error("Error while updating prices on production", e);
|
| 746 |
return "Error while updating all prices on production. Some of the prices may have been updated";
|
764 |
return "Error while updating all prices on production. Some of the prices may not have been updated";
|
| 747 |
}
|
765 |
}
|
| - |
|
766 |
}
|
| 748 |
|
767 |
|
| 749 |
try {
|
768 |
try {
|
| 750 |
ContentClient contentServiceClient = new ContentClient();
|
769 |
ContentClient contentServiceClient = new ContentClient();
|
| 751 |
ContentService.Client contentClient = contentServiceClient.getClient();
|
770 |
ContentService.Client contentClient = contentServiceClient.getClient();
|
| 752 |
|
771 |
|
| 753 |
contentClient.pushContentToProduction(item.getCatalogItemId());
|
772 |
contentClient.pushContentToProduction(items.get(0).getCatalogItemId());
|
| 754 |
} catch (TTransportException e) {
|
773 |
} catch (TTransportException e) {
|
| 755 |
logger.error("Error while establishing connection to the content server", e);
|
774 |
logger.error("Error while establishing connection to the content server", e);
|
| 756 |
return "Error generating content. Prices updated successfully.";
|
775 |
return "Error generating content. Prices updated successfully.";
|
| 757 |
} catch (TException e) {
|
776 |
} catch (TException e) {
|
| 758 |
logger.error("Error while pushing content to production", e);
|
777 |
logger.error("Error while pushing content to production", e);
|