Rev 3129 | Rev 3354 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.catalog.dashboard.server;import in.shop2020.catalog.dashboard.client.CatalogService;import in.shop2020.catalog.dashboard.shared.Item;import in.shop2020.catalog.dashboard.shared.ItemsComparator;import in.shop2020.catalog.dashboard.shared.VendorItemMapping;import in.shop2020.catalog.dashboard.shared.VendorPricings;import in.shop2020.config.ConfigException;import in.shop2020.model.v1.catalog.InventoryService;import in.shop2020.model.v1.catalog.status;import in.shop2020.thrift.clients.CatalogClient;import in.shop2020.thrift.clients.config.ConfigClient;import in.shop2020.utils.CategoryManager;import in.shop2020.utils.ConfigClientKeys;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Calendar;import java.util.Collections;import java.util.Date;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Map.Entry;import org.apache.log4j.Logger;import com.google.gwt.core.client.GWT;import com.google.gwt.user.server.rpc.RemoteServiceServlet;@SuppressWarnings("serial")public class CatalogServiceImpl extends RemoteServiceServlet implements CatalogService {private static Date pushToProdDate;public List<Item> getAllItems(){List<Item> itemList = new ArrayList<Item>();try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(false);for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {itemList.add(getItemFromThriftItem(thriftItem, null, null));}} catch (Exception e) {e.printStackTrace();}Collections.sort(itemList, new ItemsComparator());return itemList;}public List<Item> getAllActiveItems(){List<Item> itemList = new ArrayList<Item>();try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItems(true);for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {itemList.add(getItemFromThriftItem(thriftItem, null, null));}} catch (Exception e) {e.printStackTrace();}Collections.sort(itemList, new ItemsComparator());return itemList;}@Overridepublic List<Item> getAllPhasedOutItems(){return getItemsByStatus(status.PHASED_OUT);}@Overridepublic List<Item> getAllPausedItems(){return getItemsByStatus(status.PAUSED);}@Overridepublic List<Item> getAllInProcessItems() {return getItemsByStatus(status.IN_PROCESS);}@Overridepublic List<Item> getAllContentCompleteItems() {return getItemsByStatus(status.CONTENT_COMPLETE);}public List<Item> getBestDeals(){List<Item> itemList = new ArrayList<Item>();try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestDeals();for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {itemList.add(getItemFromThriftItem(thriftItem, null, null));}} catch(Exception e){e.printStackTrace();}//Collections.sort(itemList, new ItemsComparator());return itemList;}@Overridepublic List<Item> getRiskyItems() {List<Item> itemList = new ArrayList<Item>();try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByRiskyFlag();for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {itemList.add(getItemFromThriftItem(thriftItem, null, null));}} catch(Exception e){e.printStackTrace();}Collections.sort(itemList, new ItemsComparator());return itemList;}public List<Item> getBestSellers(){List<Item> itemList = new ArrayList<Item>();try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getBestSellers();for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {itemList.add(getItemFromThriftItem(thriftItem, null, null));}} catch(Exception e){e.printStackTrace();}//Collections.sort(itemList, new ItemsComparator());return itemList;}public List<Item> getLatestArrivals(){List<Item> itemList = new ArrayList<Item>();try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getLatestArrivals();for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {//List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());itemList.add(getItemFromThriftItem(thriftItem, null, null));}} catch(Exception e){e.printStackTrace();}//Collections.sort(itemList, new ItemsComparator());return itemList;}public Item getItem(long itemId){try{CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();in.shop2020.model.v1.catalog.Item thriftItem = catalogClient.getItem(itemId);List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());return getItemFromThriftItem(thriftItem, vip, vim);}catch(Exception e){e.printStackTrace();}return null;}/*** Creates a new Item object and populates its attributes from thrift item passed as parameter.* Also creates a Map each for VendorItemPricing and VendorItemMapping and adds these maps to the* new Item object.* @param thriftItem* @param tVendorPricings* @param tVendorMappings* @return item object with attributes copied from thrift item object.*/private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem,List<in.shop2020.model.v1.catalog.VendorItemPricing> tVendorPricings,List<in.shop2020.model.v1.catalog.VendorItemMapping> tVendorMappings){Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();VendorItemMapping vItemMapping;if(tVendorMappings != null) {for(in.shop2020.model.v1.catalog.VendorItemMapping vim : tVendorMappings) {vItemMapping = new VendorItemMapping();vItemMapping.setVendorId(vim.getVendorId());vItemMapping.setItemKey(vim.getItemKey());vItemMap.put(vItemMapping.getVendorId() + Item.KEY_SEPARATOR + vim.getItemKey(), vItemMapping);}}// TODO: For testing. Remove this code before moving to production./*Map<Long, VendorItemMapping> vItemMap = new HashMap<Long, VendorItemMapping>();vItemMap.put(1L, new VendorItemMapping(1, "Item Key Test 1"));vItemMap.put(1L, new VendorItemMapping(1, "Item Key Test 2"));*/Map<Long, VendorPricings> vendorPricingMap = new HashMap<Long, VendorPricings>();VendorPricings vPricings;if(tVendorPricings != null) {for(in.shop2020.model.v1.catalog.VendorItemPricing vip : tVendorPricings) {vPricings = new VendorPricings();vPricings.setVendorId(vip.getVendorId());vPricings.setMop(vip.getMop());vPricings.setDealerPrice(vip.getDealerPrice());vPricings.setTransferPrice(vip.getTransferPrice());vendorPricingMap.put(vPricings.getVendorId(), vPricings);}}Item item = new Item(thriftItem.getId(),thriftItem.getHotspotCategory(),thriftItem.getProductGroup(),thriftItem.getBrand(),thriftItem.getModelNumber(),thriftItem.getModelName(),thriftItem.getColor(),CategoryManager.getCategoryManager().getCategoryLabel(thriftItem.getCategory()),thriftItem.getCategory(),thriftItem.getComments(),thriftItem.getCatalogItemId(),thriftItem.getFeatureId(),thriftItem.getFeatureDescription(),thriftItem.isSetMrp() ? thriftItem.getMrp() : null,thriftItem.getMop(),thriftItem.isSetSellingPrice() ? thriftItem.getSellingPrice() : null,thriftItem.getDealerPrice(),thriftItem.isSetWeight() ? thriftItem.getWeight() : null,thriftItem.getAddedOn(),thriftItem.getStartDate(),thriftItem.getRetireDate(),thriftItem.getUpdatedOn(),thriftItem.getItemStatus().name(),thriftItem.getItemStatus().getValue(),thriftItem.getStatus_description(),thriftItem.getOtherInfo(),thriftItem.getBestDealText(),thriftItem.isSetBestDealValue() ? thriftItem.getBestDealValue() : null,thriftItem.isSetBestSellingRank() ? thriftItem.getBestSellingRank() : null,thriftItem.isDefaultForEntity(),thriftItem.isRisky(),(thriftItem.getItemInventory() != null ? thriftItem.getItemInventory().getAvailability() : null),vendorPricingMap,vItemMap);return item;}@Overridepublic boolean updateItem(Item item) {GWT.log("Got a call to update item, Item Id: " + item.getId());try{CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();in.shop2020.model.v1.catalog.Item tItem = catalogClient.getItem(item.getId());setThriftItemParams(tItem, item);long rItemId;if((rItemId = catalogClient.updateItem(tItem)) != item.getId()) {GWT.log("Error updating item, returned Item Id: " + rItemId);return false;}GWT.log("Item updated successfully, Item Id: " + item.getId());Map<String, VendorItemMapping> vendorMappings = item.getVendorKeysMap();if(vendorMappings != null && !vendorMappings.isEmpty()) {in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;for(Entry<String, VendorItemMapping> e : vendorMappings.entrySet()) {tVendorMapping = new in.shop2020.model.v1.catalog.VendorItemMapping();VendorItemMapping v = e.getValue();tVendorMapping.setVendorId(v.getVendorId());tVendorMapping.setItemKey(v.getItemKey());tVendorMapping.setItemId(item.getId());tVendorMapping.setVendorCategory(item.getVendorCategory());catalogClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);GWT.log("VendorItemMapping updated. " + tVendorMapping.getVendorId() + ", " + tVendorMapping.getItemId() + ", " +tVendorMapping.getItemKey() + ", " + tVendorMapping.getVendorCategory());}}Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();if(vendorPricings != null && !vendorPricings.isEmpty()) {in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;for(VendorPricings v : vendorPricings.values()) {tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();tVendorPricing.setVendorId(v.getVendorId());tVendorPricing.setItemId(item.getId());tVendorPricing.setMop(v.getMop());tVendorPricing.setTransferPrice(v.getTransferPrice());tVendorPricing.setDealerPrice(v.getDealerPrice());catalogClient.addVendorItemPricing(tVendorPricing);GWT.log("VendorItemPricing updated. " + tVendorPricing.getVendorId() + ", " + tVendorPricing.getItemId() + ", " +tVendorPricing.getMop() + ", " + tVendorPricing.getTransferPrice() + ", " + tVendorPricing.getDealerPrice());}}}catch(Exception e){e.printStackTrace();return false;}return true;}@Overridepublic Map<Long, String> getAllVendors() {Map<Long, String> vendorMap = new HashMap<Long, String>();try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();List<in.shop2020.model.v1.catalog.Vendor> vendors = catalogClient.getAllVendors();for(in.shop2020.model.v1.catalog.Vendor v : vendors) {vendorMap.put(v.getId(), v.getName());}} catch (Exception e) {e.printStackTrace();}return vendorMap;}@Overridepublic Map<Long, String> getAllWarehouses() {Map<Long, String> warehouseMap = new HashMap<Long, String>();try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();List<in.shop2020.model.v1.catalog.Warehouse> warehouses = catalogClient.getAllWarehouses(true);for(in.shop2020.model.v1.catalog.Warehouse w : warehouses) {warehouseMap.put(w.getId(), w.getDisplayName());}} catch (Exception e) {e.printStackTrace();}return warehouseMap;}@Overridepublic long addItem(Item item) {long itemId = 0;try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();in.shop2020.model.v1.catalog.Item tItem = new in.shop2020.model.v1.catalog.Item();setThriftItemParams(tItem, item);itemId = catalogClient.addItem(tItem);Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();if(vendorPricings != null && !vendorPricings.isEmpty()) {in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;for(VendorPricings v : vendorPricings.values()) {tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();tVendorPricing.setVendorId(v.getVendorId());tVendorPricing.setItemId(itemId);tVendorPricing.setMop(v.getMop());tVendorPricing.setTransferPrice(v.getTransferPrice());tVendorPricing.setDealerPrice(v.getDealerPrice());catalogClient.addVendorItemPricing(tVendorPricing);}}Map<String, VendorItemMapping> vendorKeysMap = item.getVendorKeysMap();if(vendorKeysMap != null && !vendorKeysMap.isEmpty()) {in.shop2020.model.v1.catalog.VendorItemMapping tVendorMapping;for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()) {tVendorMapping = new in.shop2020.model.v1.catalog.VendorItemMapping();VendorItemMapping v = e.getValue();tVendorMapping.setVendorId(v.getVendorId());tVendorMapping.setItemKey(v.getItemKey());tVendorMapping.setItemId(itemId);tVendorMapping.setVendorCategory(item.getVendorCategory());catalogClient.addVendorItemMapping(e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1), tVendorMapping);}}} catch (Exception e) {e.printStackTrace();}return itemId;}@Overridepublic long checkSimilarItem(String productGroup, String brand, String modelNumber, String color) {try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();return catalogClient.checkSimilarItem(productGroup, brand, modelNumber, color);} catch (Exception e) {e.printStackTrace();}return 0;}private void setThriftItemParams(in.shop2020.model.v1.catalog.Item tItem, Item item) {tItem.setId(tItem.getId());tItem.setProductGroup(item.getProductGroup());tItem.setBrand(item.getBrand());tItem.setModelName(item.getModelName());tItem.setModelNumber(item.getModelNumber());tItem.setColor(item.getColor());tItem.setStatus_description(item.getItemStatusDesc());tItem.setComments(item.getComments());if(item.getMrp() != null) {tItem.setMrp(item.getMrp());} else {tItem.setMrpIsSet(false);}if(item.getSellingPrice() != null) {tItem.setSellingPrice(item.getSellingPrice());} else {tItem.setSellingPriceIsSet(false);}if(item.getWeight() != null) {tItem.setWeight(item.getWeight());} else {tItem.setWeightIsSet(false);}if(item.getMop() != null) {tItem.setMop(item.getMop());} else {tItem.setMopIsSet(false);}if(item.getDealerPrice() != null) {tItem.setDealerPrice(item.getDealerPrice());} else {tItem.setTransferPriceIsSet(false);}if(item.getTransferPrice() != null) {tItem.setTransferPrice(item.getTransferPrice());} else {tItem.setTransferPriceIsSet(false);}tItem.setBestDealText(item.getBestDealsText());if(item.getBestDealsValue() != null) {tItem.setBestDealValue(item.getBestDealsValue());} else {tItem.setBestDealValueIsSet(false);}if(item.getBestSellingRank() != null) {tItem.setBestSellingRank(item.getBestSellingRank());} else {tItem.setBestSellingRankIsSet(false);}tItem.setDefaultForEntity(item.isDefaultForEntity());tItem.setRisky(item.isRisky());if(item.getStartDate() != null) {tItem.setStartDate(item.getStartDate());} else {tItem.setStartDateIsSet(false);}if(item.getRetireDate() != null) {tItem.setRetireDate(item.getRetireDate());} else {tItem.setRetireDateIsSet(false);}tItem.setUpdatedOn(Calendar.getInstance().getTimeInMillis());tItem.setHotspotCategory(item.getVendorCategory());}@Overridepublic void pauseItem(long itemId) {try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PAUSED);} catch (Exception e) {e.printStackTrace();}}@Overridepublic void markInProcess(long itemId) {try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.IN_PROCESS);} catch (Exception e) {e.printStackTrace();}}@Overridepublic void phaseoutItem(long itemId) {try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.PHASED_OUT);} catch (Exception e) {e.printStackTrace();}}@Overridepublic void activateItem(long itemId) {try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();catalogClient.changeItemStatus(itemId, Calendar.getInstance().getTimeInMillis(), status.ACTIVE);} catch (Exception e) {e.printStackTrace();}}@Overridepublic boolean changeItemRiskyFlag(long itemId, boolean risky) {try {// Initialize client for staging serverCatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();// Initialize client for production serverCatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),ConfigClientKeys.catalog_service_server_port.toString());InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();catalogClient.changeItemRiskyFlag(itemId, risky);try{catalogClient_Prod.changeItemRiskyFlag(itemId, risky);}catch(Exception e){e.printStackTrace();// If not able to change risky flag on production, revert on staging and return false (to show error to user).catalogClient.changeItemRiskyFlag(itemId, !risky);return false;}} catch (Exception e) {e.printStackTrace();return false;}return true;}/*** Retuns list of Items filtered by Vendor category (column is hotspotCategory in catalog.item table)* This list is used to generate master sheet (excel sheet)* @param category* @return*/List<Item> getItemsByVendorCategory(String category) {List<Item> itemList = new ArrayList<Item>();try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getItemsByVendorCategory(category);for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {List<in.shop2020.model.v1.catalog.VendorItemPricing> vip = catalogClient.getAllItemPricing(thriftItem.getId());List<in.shop2020.model.v1.catalog.VendorItemMapping> vim = catalogClient.getVendorItemMappings(thriftItem.getId());itemList.add(getItemFromThriftItem(thriftItem, vip, vim));}} catch (Exception e) {e.printStackTrace();}Collections.sort(itemList, new ItemsComparator());return itemList;}/*** Returns list of items with a particular status.* @param st* @return*/List<Item> getItemsByStatus(status st) {List<Item> itemList = new ArrayList<Item>();try {CatalogClient catalogServiceClient = new CatalogClient();InventoryService.Client catalogClient = catalogServiceClient.getClient();List<in.shop2020.model.v1.catalog.Item> thriftItems = catalogClient.getAllItemsByStatus(st);for(in.shop2020.model.v1.catalog.Item thriftItem : thriftItems) {itemList.add(getItemFromThriftItem(thriftItem, null, null));}} catch (Exception e) {e.printStackTrace();}Collections.sort(itemList, new ItemsComparator());return itemList;}@Overridepublic String updateItemOnProduction(Item item) {GWT.log("Update item on production call, Item Id: " + item.getId());String errMsg = checkPushToProdCount();// If errMsg is not null, then return that message to user// else move forward with update.if(errMsg != null) {return errMsg;}try{CatalogClient catalogServiceClient_Prod = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(),ConfigClientKeys.catalog_service_server_port.toString());//for testing, put catalog_service_server_port_test in shop2020.cfg/*CatalogServiceClient catalogServiceClient_Prod = new CatalogServiceClient(CatalogServiceClient.class.getSimpleName(),ConfigClientKeys.catalog_service_server_host.toString(), "catalog_service_server_port_test");*/InventoryService.Client catalogClient_Prod = catalogServiceClient_Prod.getClient();in.shop2020.model.v1.catalog.Item tItem = catalogClient_Prod.getItem(item.getId());if(item.getMrp() != null) {tItem.setMrp(item.getMrp());} else {tItem.setMrpIsSet(false);}if(item.getSellingPrice() != null) {tItem.setSellingPrice(item.getSellingPrice());} else {tItem.setSellingPriceIsSet(false);}if(item.getMop() != null) {tItem.setMop(item.getMop());} else {tItem.setMopIsSet(false);}if(item.getDealerPrice() != null) {tItem.setDealerPrice(item.getDealerPrice());} else {tItem.setDealerPriceIsSet(false);}if(item.getTransferPrice() != null) {tItem.setTransferPrice(item.getTransferPrice());} else {tItem.setTransferPriceIsSet(false);}long rItemId;if((rItemId = catalogClient_Prod.updateItem(tItem)) != item.getId()) {GWT.log("Error updating item, returned Item Id: " + rItemId);return "Error updating item prices on production";}GWT.log("Item updated successfully, Item Id: " + item.getId());Map<Long, VendorPricings> vendorPricings = item.getVendorPricesMap();StringBuilder sb = new StringBuilder();if(vendorPricings != null && !vendorPricings.isEmpty()) {in.shop2020.model.v1.catalog.VendorItemPricing tVendorPricing;for(VendorPricings v : vendorPricings.values()) {tVendorPricing = new in.shop2020.model.v1.catalog.VendorItemPricing();tVendorPricing.setVendorId(v.getVendorId());tVendorPricing.setItemId(item.getId());tVendorPricing.setMop(v.getMop());tVendorPricing.setTransferPrice(v.getTransferPrice());tVendorPricing.setDealerPrice(v.getDealerPrice());catalogClient_Prod.addVendorItemPricing(tVendorPricing);GWT.log("VendorItemPricing updated. " + tVendorPricing.getVendorId() + ", " + tVendorPricing.getItemId() + ", " +tVendorPricing.getMop() + ", " + tVendorPricing.getTransferPrice() + ", " + tVendorPricing.getDealerPrice());sb.append("[VId:" + v.getVendorId() + ",MOP=" + v.getMop() + ",TP=" + v.getTransferPrice() + ",DP=" + v.getDealerPrice() + "], ");}}logItemDetails("Id=" + item.getId() + ",MRP=" + item.getMrp() + ",SP=" + " " + item.getSellingPrice() + sb.toString());} catch (Exception e) {e.printStackTrace();return "Error while updating all prices on production. Some of the prices may have been updated";}/*// Push the content of one item to productionProcess p;try {String scriptPath = ConfigClient.getClient().get(ConfigClientKeys.PUSH_PRICES_TO_PROD_SCRIPT_PATH.toString());p = Runtime.getRuntime().exec(scriptPath + " " + item.getCatalogItemId());p.waitFor();} catch (IOException e) {GWT.log("Not able to update content on production");e.printStackTrace();return "Error generating content. Prices updated successfully.";} catch (InterruptedException e) {GWT.log("Not able to update content on production");e.printStackTrace();return "Error generating content. Prices updated successfully.";} catch (ConfigException e) {// TODO Auto-generated catch blocke.printStackTrace();return "Error getting content script path";}*/return "Prices updated and content generated successfully";}/**** @return null if push to production count is less than maximum allowed.* <br>otherwise error message to be passed to the client side for showing to the user*/private String checkPushToProdCount() {int count = 0, maxCount;try {String logfile = ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_log_file.toString());maxCount = Integer.parseInt(ConfigClient.getClient().get(ConfigClientKeys.push_prices_to_prod_max_count.toString()));count = getPushToProdCount(logfile);if(count >= maxCount) {return "Maximum push to production count reached for today";}} catch (ConfigException e1) {e1.printStackTrace();return "Error getting push to production parameters";}return null;}/*** Log push to production details* @param str*/private void logItemDetails(String str) {Logger log = Logger.getLogger(CatalogServiceImpl.class);log.info(str);}/*** If this is the first attempt to push to production for current date, returns 0* else reads number of lines from daily rolling log file to get the count.* @return push to production count for current date*/private int getPushToProdCount(String logfile) {// logfile is "/var/log/services/pushToProductionCount/pushToProd.log"// this should also be set in log4j.propertiesint lineCount = 0;DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");Date currentDate = Calendar.getInstance().getTime();if(pushToProdDate == null || !dateFormat.format(pushToProdDate).equals(dateFormat.format(currentDate))) {pushToProdDate = currentDate;return lineCount;}try {BufferedReader br = new BufferedReader(new FileReader(logfile));while (br.readLine() != null) {lineCount++;}} catch (IOException e) {e.printStackTrace();}return lineCount;}}