Rev 9449 | Rev 9855 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.inventory.controllers;import in.shop2020.googleadwords.feedshandler.ContentFeedsHandler;import in.shop2020.googleadwords.model.Product;import in.shop2020.googleadwords.util.UserInformation;import in.shop2020.logistics.DeliveryType;import in.shop2020.logistics.LogisticsService;import in.shop2020.model.v1.catalog.CatalogService;import in.shop2020.model.v1.catalog.CatalogServiceException;import in.shop2020.model.v1.catalog.Item;import in.shop2020.model.v1.catalog.ProductFeedSubmit;import in.shop2020.thrift.clients.CatalogClient;import in.shop2020.thrift.clients.LogisticsClient;import java.io.IOException;import java.util.List;import org.apache.thrift.TException;import org.apache.thrift.transport.TTransportException;public class ProductFeedsController extends BaseController{private String cataLogItemId;private String sentFeedResult;private String catalogItemIdDelete;private String deleteFeedResult;private String stockLinkFeed;private boolean stockLinkedFeed = false;public String index() {return "index";}public String sendProductFeeds(){//boolean sendFeedsResult = false;processStockLinkFeed();Product insertedProduct = null;CatalogClient catalogClient = null;try {catalogClient = new CatalogClient();} catch (TTransportException e1) {e1.printStackTrace();}if(cataLogItemId!=null && !("").equalsIgnoreCase(cataLogItemId)){List<Long> itemIdList = getEntityLogisticsEstimation(Long.parseLong(cataLogItemId));UserInformation userInformation = new UserInformation("8587366","http://www.saholic.com","adwords@shop2020.in", "adwords_shop2020");ContentFeedsHandler sample = new ContentFeedsHandler(userInformation,"https://content.googleapis.com/content/v1/");if(catalogClient!= null){if(itemIdList!=null && itemIdList.size()>0){try {Item item = catalogClient.getClient().getItem(itemIdList.get(0));insertedProduct = sample.sendProductFeed(item);} catch (IOException e) {e.printStackTrace();} catch (CatalogServiceException e) {e.printStackTrace();} catch (TException e) {e.printStackTrace();}}else{sentFeedResult = "Error: There is No Product avaliable for given Catalog Item Id.";return "output";}}}if(insertedProduct!=null){if(insertedProduct.content!=null && insertedProduct.content.value.indexOf("Error:")>-1){sentFeedResult = insertedProduct.content.value;return "output";}sentFeedResult = "Product Feeds are sent Successfully and Product Details are Given Below:\nProduct Id- "+insertedProduct.externalId+" Product Title- "+insertedProduct.title;if(catalogClient!=null){ProductFeedSubmit feedSubmit = null;try {feedSubmit= catalogClient.getClient().getProductFeedSubmit(Long.parseLong(cataLogItemId));if(feedSubmit!=null && feedSubmit.getCatalogItemId() > 0l){System.out.println("Comes into Update ");feedSubmit.setCatalogItemId(Long.parseLong(cataLogItemId));feedSubmit.setStockLinkedFeed(stockLinkedFeed);boolean resultUpdate = catalogClient.getClient().updateProductFeedSubmit(feedSubmit);if(resultUpdate){sentFeedResult = sentFeedResult + "\n And Updated to Our System Successfully ";}}else{System.out.println("Comes into Add ");feedSubmit = new ProductFeedSubmit();feedSubmit.setCatalogItemId(Long.parseLong(cataLogItemId));feedSubmit.setStockLinkedFeed(stockLinkedFeed);boolean resultUpdate = catalogClient.getClient().addProductFeedSubmit(feedSubmit);if(resultUpdate){sentFeedResult = sentFeedResult + "\n And Added to Our System Successfully ";}}} catch (CatalogServiceException e) {e.printStackTrace();} catch (TException e) {e.printStackTrace();}}return "output";}else{sentFeedResult = "Some Error occured while sending feeds. Please contact concerned Team";return "output";}/*if(sendFeedsResult){successmsg = "Product Feeds are sent Successfully";return index();}else{errorMsg = "Some Error occured while sending feeds. Please contact concerned Team";return index();}*/}public String deleteProductFeeds(){CatalogClient catalogClient = null;try {catalogClient = new CatalogClient();} catch (TTransportException e1) {e1.printStackTrace();}if(catalogClient!=null){ProductFeedSubmit feedSubmit = null;try {feedSubmit= catalogClient.getClient().getProductFeedSubmit(Long.parseLong(catalogItemIdDelete));if(feedSubmit!=null && feedSubmit.getCatalogItemId() > 0l){UserInformation userInformation = new UserInformation("8587366","http://www.saholic.com","adwords@shop2020.in", "adwords_shop2020");ContentFeedsHandler sample = new ContentFeedsHandler(userInformation,"https://content.googleapis.com/content/v1/");boolean deleteFeedResultBool = sample.deleteProduct(Long.parseLong(catalogItemIdDelete));if(deleteFeedResultBool){deleteFeedResult = "Product Feeds are deleted Successfully For Product Id "+ catalogItemIdDelete;boolean deleteResult = catalogClient.getClient().deleteProductFeedSubmit(Long.parseLong(catalogItemIdDelete));if(deleteResult){deleteFeedResult = deleteFeedResult + "\n And Deleted from our System Successfully";}}else{deleteFeedResult = "Error Occurred: Product Feeds Deletion Unsuccessful";}}} catch (CatalogServiceException e) {e.printStackTrace();} catch (TException e) {e.printStackTrace();}}return "output";}public List<Long> getEntityLogisticsEstimation(long productId){List<Long> items=null;try {LogisticsClient cl = new LogisticsClient();LogisticsService.Client client = cl.getClient();items = client.getEntityLogisticsEstimation(productId, "110001", DeliveryType.PREPAID );} catch (Exception e1) {System.out.println("Unable to get items by catalog item id"+e1.getMessage());}return items;}public void processStockLinkFeed(){if(stockLinkFeed!=null && ("on").equalsIgnoreCase(stockLinkFeed)){stockLinkedFeed = true;}}public String getCatalogItemIdDelete() {return catalogItemIdDelete;}public void setCatalogItemIdDelete(String catalogItemIdDelete) {this.catalogItemIdDelete = catalogItemIdDelete;}public String getDeleteFeedResult() {return deleteFeedResult;}public void setDeleteFeedResult(String deleteFeedResult) {this.deleteFeedResult = deleteFeedResult;}public String getCataLogItemId() {return cataLogItemId;}public void setCataLogItemId(String cataLogItemId) {this.cataLogItemId = cataLogItemId;}public String getSentFeedResult() {return sentFeedResult;}public void setSentFeedResult(String sentFeedResult) {this.sentFeedResult = sentFeedResult;}public String getStockLinkFeed() {return stockLinkFeed;}public void setStockLinkFeed(String stockLinkFeed) {this.stockLinkFeed = stockLinkFeed;}}