| 9449 |
manish.sha |
1 |
package in.shop2020.inventory.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.googleadwords.feedshandler.ContentFeedsHandler;
|
|
|
4 |
import in.shop2020.googleadwords.model.Product;
|
|
|
5 |
import in.shop2020.googleadwords.util.UserInformation;
|
|
|
6 |
import in.shop2020.logistics.DeliveryType;
|
|
|
7 |
import in.shop2020.logistics.LogisticsService;
|
|
|
8 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
|
|
9 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
10 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
11 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
12 |
|
|
|
13 |
import java.io.IOException;
|
|
|
14 |
import java.util.List;
|
|
|
15 |
|
|
|
16 |
import org.apache.thrift.TException;
|
|
|
17 |
import org.apache.thrift.transport.TTransportException;
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
public class ProductFeedsController extends BaseController{
|
|
|
21 |
|
|
|
22 |
private String cataLogItemId;
|
|
|
23 |
private String sentFeedResult;
|
|
|
24 |
|
|
|
25 |
public String index() {
|
|
|
26 |
return "index";
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
public String sendProductFeeds(){
|
|
|
30 |
//boolean sendFeedsResult = false;
|
|
|
31 |
Product insertedProduct = null;
|
|
|
32 |
if(cataLogItemId!=null && !("").equalsIgnoreCase(cataLogItemId)){
|
|
|
33 |
List<Long> itemIdList = getEntityLogisticsEstimation(Long.parseLong(cataLogItemId));
|
|
|
34 |
UserInformation userInformation = new UserInformation("8587366",
|
|
|
35 |
"http://www.saholic.com",
|
|
|
36 |
"adwords@shop2020.in", "adwords_shop2020");
|
|
|
37 |
ContentFeedsHandler sample = new ContentFeedsHandler(userInformation,
|
|
|
38 |
"https://content.googleapis.com/content/v1/");
|
|
|
39 |
if(itemIdList!=null && itemIdList.size()>0){
|
|
|
40 |
try {
|
|
|
41 |
Item item = new CatalogClient().getClient().getItem(itemIdList.get(0));
|
|
|
42 |
insertedProduct = sample.sendProductFeed(item);
|
|
|
43 |
} catch (IOException e) {
|
|
|
44 |
e.printStackTrace();
|
|
|
45 |
} catch (TTransportException e) {
|
|
|
46 |
e.printStackTrace();
|
|
|
47 |
} catch (CatalogServiceException e) {
|
|
|
48 |
e.printStackTrace();
|
|
|
49 |
} catch (TException e) {
|
|
|
50 |
e.printStackTrace();
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
else{
|
|
|
54 |
sentFeedResult = "Error: There is No Product avaliable for given Catalog Item Id.";
|
|
|
55 |
return "output";
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
if(insertedProduct!=null){
|
|
|
59 |
if(insertedProduct.content!=null && insertedProduct.content.value.indexOf("Error:")>-1){
|
|
|
60 |
sentFeedResult = insertedProduct.content.value;
|
|
|
61 |
return "output";
|
|
|
62 |
}
|
|
|
63 |
sentFeedResult = "Product Feeds are sent Successfully and Product Details are Given Below:\nProduct Id- "
|
|
|
64 |
+insertedProduct.externalId+" Product Title- "+insertedProduct.title;
|
|
|
65 |
return "output";
|
|
|
66 |
}
|
|
|
67 |
else{
|
|
|
68 |
sentFeedResult = "Some Error occured while sending feeds. Please contact concerned Team";
|
|
|
69 |
return "output";
|
|
|
70 |
}
|
|
|
71 |
/*if(sendFeedsResult){
|
|
|
72 |
successmsg = "Product Feeds are sent Successfully";
|
|
|
73 |
return index();
|
|
|
74 |
}
|
|
|
75 |
else{
|
|
|
76 |
errorMsg = "Some Error occured while sending feeds. Please contact concerned Team";
|
|
|
77 |
return index();
|
|
|
78 |
}*/
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
public List<Long> getEntityLogisticsEstimation(long productId){
|
|
|
82 |
List<Long> items=null;
|
|
|
83 |
try {
|
|
|
84 |
LogisticsClient cl = new LogisticsClient();
|
|
|
85 |
LogisticsService.Client client = cl.getClient();
|
|
|
86 |
items = client.getEntityLogisticsEstimation(productId, "110001", DeliveryType.PREPAID );
|
|
|
87 |
} catch (Exception e1) {
|
|
|
88 |
System.out.println("Unable to get items by catalog item id"+e1.getMessage());
|
|
|
89 |
}
|
|
|
90 |
return items;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
public String getCataLogItemId() {
|
|
|
94 |
return cataLogItemId;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
public void setCataLogItemId(String cataLogItemId) {
|
|
|
98 |
this.cataLogItemId = cataLogItemId;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
public String getSentFeedResult() {
|
|
|
102 |
return sentFeedResult;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
public void setSentFeedResult(String sentFeedResult) {
|
|
|
106 |
this.sentFeedResult = sentFeedResult;
|
|
|
107 |
}
|
|
|
108 |
}
|