| 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;
|
| 9622 |
manish.sha |
8 |
import in.shop2020.model.v1.catalog.CatalogService;
|
| 9449 |
manish.sha |
9 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
|
|
10 |
import in.shop2020.model.v1.catalog.Item;
|
| 9622 |
manish.sha |
11 |
import in.shop2020.model.v1.catalog.ProductFeedSubmit;
|
| 9449 |
manish.sha |
12 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
13 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
14 |
|
|
|
15 |
import java.io.IOException;
|
|
|
16 |
import java.util.List;
|
|
|
17 |
|
|
|
18 |
import org.apache.thrift.TException;
|
|
|
19 |
import org.apache.thrift.transport.TTransportException;
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
public class ProductFeedsController extends BaseController{
|
|
|
23 |
|
|
|
24 |
private String cataLogItemId;
|
|
|
25 |
private String sentFeedResult;
|
| 9622 |
manish.sha |
26 |
private String catalogItemIdDelete;
|
|
|
27 |
private String deleteFeedResult;
|
|
|
28 |
private String stockLinkFeed;
|
|
|
29 |
private boolean stockLinkedFeed = false;
|
| 9449 |
manish.sha |
30 |
|
|
|
31 |
public String index() {
|
|
|
32 |
return "index";
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
public String sendProductFeeds(){
|
|
|
36 |
//boolean sendFeedsResult = false;
|
| 9622 |
manish.sha |
37 |
processStockLinkFeed();
|
| 9449 |
manish.sha |
38 |
Product insertedProduct = null;
|
| 9622 |
manish.sha |
39 |
CatalogClient catalogClient = null;
|
|
|
40 |
try {
|
|
|
41 |
catalogClient = new CatalogClient();
|
|
|
42 |
} catch (TTransportException e1) {
|
|
|
43 |
e1.printStackTrace();
|
|
|
44 |
}
|
|
|
45 |
|
| 9449 |
manish.sha |
46 |
if(cataLogItemId!=null && !("").equalsIgnoreCase(cataLogItemId)){
|
|
|
47 |
List<Long> itemIdList = getEntityLogisticsEstimation(Long.parseLong(cataLogItemId));
|
|
|
48 |
UserInformation userInformation = new UserInformation("8587366",
|
|
|
49 |
"http://www.saholic.com",
|
|
|
50 |
"adwords@shop2020.in", "adwords_shop2020");
|
|
|
51 |
ContentFeedsHandler sample = new ContentFeedsHandler(userInformation,
|
|
|
52 |
"https://content.googleapis.com/content/v1/");
|
| 9622 |
manish.sha |
53 |
|
|
|
54 |
if(catalogClient!= null){
|
|
|
55 |
if(itemIdList!=null && itemIdList.size()>0){
|
|
|
56 |
try {
|
|
|
57 |
Item item = catalogClient.getClient().getItem(itemIdList.get(0));
|
|
|
58 |
insertedProduct = sample.sendProductFeed(item);
|
|
|
59 |
} catch (IOException e) {
|
|
|
60 |
e.printStackTrace();
|
|
|
61 |
} catch (CatalogServiceException e) {
|
|
|
62 |
e.printStackTrace();
|
|
|
63 |
} catch (TException e) {
|
|
|
64 |
e.printStackTrace();
|
|
|
65 |
}
|
| 9449 |
manish.sha |
66 |
}
|
| 9622 |
manish.sha |
67 |
else{
|
|
|
68 |
sentFeedResult = "Error: There is No Product avaliable for given Catalog Item Id.";
|
|
|
69 |
return "output";
|
|
|
70 |
}
|
| 9449 |
manish.sha |
71 |
}
|
|
|
72 |
}
|
|
|
73 |
if(insertedProduct!=null){
|
|
|
74 |
if(insertedProduct.content!=null && insertedProduct.content.value.indexOf("Error:")>-1){
|
|
|
75 |
sentFeedResult = insertedProduct.content.value;
|
|
|
76 |
return "output";
|
|
|
77 |
}
|
| 9622 |
manish.sha |
78 |
|
| 9449 |
manish.sha |
79 |
sentFeedResult = "Product Feeds are sent Successfully and Product Details are Given Below:\nProduct Id- "
|
|
|
80 |
+insertedProduct.externalId+" Product Title- "+insertedProduct.title;
|
| 9622 |
manish.sha |
81 |
|
|
|
82 |
if(catalogClient!=null){
|
|
|
83 |
ProductFeedSubmit feedSubmit = null;
|
|
|
84 |
try {
|
|
|
85 |
feedSubmit= catalogClient.getClient().getProductFeedSubmit(Long.parseLong(cataLogItemId));
|
|
|
86 |
if(feedSubmit!=null && feedSubmit.getCatalogItemId() > 0l){
|
|
|
87 |
System.out.println("Comes into Update ");
|
|
|
88 |
feedSubmit.setCatalogItemId(Long.parseLong(cataLogItemId));
|
|
|
89 |
feedSubmit.setStockLinkedFeed(stockLinkedFeed);
|
|
|
90 |
boolean resultUpdate = catalogClient.getClient().updateProductFeedSubmit(feedSubmit);
|
|
|
91 |
if(resultUpdate){
|
|
|
92 |
sentFeedResult = sentFeedResult + "\n And Updated to Our System Successfully ";
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
else{
|
|
|
96 |
System.out.println("Comes into Add ");
|
|
|
97 |
feedSubmit = new ProductFeedSubmit();
|
|
|
98 |
feedSubmit.setCatalogItemId(Long.parseLong(cataLogItemId));
|
|
|
99 |
feedSubmit.setStockLinkedFeed(stockLinkedFeed);
|
|
|
100 |
boolean resultUpdate = catalogClient.getClient().addProductFeedSubmit(feedSubmit);
|
|
|
101 |
if(resultUpdate){
|
|
|
102 |
sentFeedResult = sentFeedResult + "\n And Added to Our System Successfully ";
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
} catch (CatalogServiceException e) {
|
|
|
106 |
e.printStackTrace();
|
|
|
107 |
} catch (TException e) {
|
|
|
108 |
e.printStackTrace();
|
|
|
109 |
}
|
|
|
110 |
}
|
| 9449 |
manish.sha |
111 |
return "output";
|
|
|
112 |
}
|
|
|
113 |
else{
|
|
|
114 |
sentFeedResult = "Some Error occured while sending feeds. Please contact concerned Team";
|
|
|
115 |
return "output";
|
|
|
116 |
}
|
|
|
117 |
/*if(sendFeedsResult){
|
|
|
118 |
successmsg = "Product Feeds are sent Successfully";
|
|
|
119 |
return index();
|
|
|
120 |
}
|
|
|
121 |
else{
|
|
|
122 |
errorMsg = "Some Error occured while sending feeds. Please contact concerned Team";
|
|
|
123 |
return index();
|
|
|
124 |
}*/
|
|
|
125 |
}
|
|
|
126 |
|
| 9622 |
manish.sha |
127 |
public String deleteProductFeeds(){
|
|
|
128 |
CatalogClient catalogClient = null;
|
|
|
129 |
try {
|
|
|
130 |
catalogClient = new CatalogClient();
|
|
|
131 |
} catch (TTransportException e1) {
|
|
|
132 |
e1.printStackTrace();
|
|
|
133 |
}
|
|
|
134 |
if(catalogClient!=null){
|
|
|
135 |
ProductFeedSubmit feedSubmit = null;
|
|
|
136 |
try {
|
|
|
137 |
feedSubmit= catalogClient.getClient().getProductFeedSubmit(Long.parseLong(catalogItemIdDelete));
|
|
|
138 |
if(feedSubmit!=null && feedSubmit.getCatalogItemId() > 0l){
|
|
|
139 |
UserInformation userInformation = new UserInformation("8587366",
|
|
|
140 |
"http://www.saholic.com",
|
|
|
141 |
"adwords@shop2020.in", "adwords_shop2020");
|
|
|
142 |
ContentFeedsHandler sample = new ContentFeedsHandler(userInformation,
|
|
|
143 |
"https://content.googleapis.com/content/v1/");
|
|
|
144 |
boolean deleteFeedResultBool = sample.deleteProduct(Long.parseLong(catalogItemIdDelete));
|
|
|
145 |
if(deleteFeedResultBool){
|
|
|
146 |
deleteFeedResult = "Product Feeds are deleted Successfully For Product Id "+ catalogItemIdDelete;
|
|
|
147 |
boolean deleteResult = catalogClient.getClient().deleteProductFeedSubmit(Long.parseLong(catalogItemIdDelete));
|
|
|
148 |
if(deleteResult){
|
|
|
149 |
deleteFeedResult = deleteFeedResult + "\n And Deleted from our System Successfully";
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
else{
|
|
|
153 |
deleteFeedResult = "Error Occurred: Product Feeds Deletion Unsuccessful";
|
|
|
154 |
}
|
|
|
155 |
}
|
|
|
156 |
} catch (CatalogServiceException e) {
|
|
|
157 |
e.printStackTrace();
|
|
|
158 |
} catch (TException e) {
|
|
|
159 |
e.printStackTrace();
|
|
|
160 |
}
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
return "output";
|
|
|
164 |
}
|
|
|
165 |
|
| 9449 |
manish.sha |
166 |
public List<Long> getEntityLogisticsEstimation(long productId){
|
|
|
167 |
List<Long> items=null;
|
|
|
168 |
try {
|
|
|
169 |
LogisticsClient cl = new LogisticsClient();
|
|
|
170 |
LogisticsService.Client client = cl.getClient();
|
|
|
171 |
items = client.getEntityLogisticsEstimation(productId, "110001", DeliveryType.PREPAID );
|
|
|
172 |
} catch (Exception e1) {
|
|
|
173 |
System.out.println("Unable to get items by catalog item id"+e1.getMessage());
|
|
|
174 |
}
|
|
|
175 |
return items;
|
|
|
176 |
}
|
|
|
177 |
|
| 9622 |
manish.sha |
178 |
public void processStockLinkFeed(){
|
|
|
179 |
if(stockLinkFeed!=null && ("on").equalsIgnoreCase(stockLinkFeed)){
|
|
|
180 |
stockLinkedFeed = true;
|
|
|
181 |
}
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
public String getCatalogItemIdDelete() {
|
|
|
185 |
return catalogItemIdDelete;
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
public void setCatalogItemIdDelete(String catalogItemIdDelete) {
|
|
|
189 |
this.catalogItemIdDelete = catalogItemIdDelete;
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
public String getDeleteFeedResult() {
|
|
|
193 |
return deleteFeedResult;
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
public void setDeleteFeedResult(String deleteFeedResult) {
|
|
|
197 |
this.deleteFeedResult = deleteFeedResult;
|
|
|
198 |
}
|
|
|
199 |
|
| 9449 |
manish.sha |
200 |
public String getCataLogItemId() {
|
|
|
201 |
return cataLogItemId;
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
public void setCataLogItemId(String cataLogItemId) {
|
|
|
205 |
this.cataLogItemId = cataLogItemId;
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
public String getSentFeedResult() {
|
|
|
209 |
return sentFeedResult;
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
public void setSentFeedResult(String sentFeedResult) {
|
|
|
213 |
this.sentFeedResult = sentFeedResult;
|
|
|
214 |
}
|
| 9622 |
manish.sha |
215 |
|
|
|
216 |
public String getStockLinkFeed() {
|
|
|
217 |
return stockLinkFeed;
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
public void setStockLinkFeed(String stockLinkFeed) {
|
|
|
221 |
this.stockLinkFeed = stockLinkFeed;
|
|
|
222 |
}
|
| 9449 |
manish.sha |
223 |
}
|