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.CatalogServiceException;import in.shop2020.model.v1.catalog.Item;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;public String index() {return "index";}public String sendProductFeeds(){//boolean sendFeedsResult = false;Product insertedProduct = null;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(itemIdList!=null && itemIdList.size()>0){try {Item item = new CatalogClient().getClient().getItem(itemIdList.get(0));insertedProduct = sample.sendProductFeed(item);} catch (IOException e) {e.printStackTrace();} catch (TTransportException 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;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 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 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;}}