Subversion Repositories SmartDukaan

Rev

Rev 9449 | Rev 9855 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9449 Rev 9622
Line 3... Line 3...
3
import in.shop2020.googleadwords.feedshandler.ContentFeedsHandler;
3
import in.shop2020.googleadwords.feedshandler.ContentFeedsHandler;
4
import in.shop2020.googleadwords.model.Product;
4
import in.shop2020.googleadwords.model.Product;
5
import in.shop2020.googleadwords.util.UserInformation;
5
import in.shop2020.googleadwords.util.UserInformation;
6
import in.shop2020.logistics.DeliveryType;
6
import in.shop2020.logistics.DeliveryType;
7
import in.shop2020.logistics.LogisticsService;
7
import in.shop2020.logistics.LogisticsService;
-
 
8
import in.shop2020.model.v1.catalog.CatalogService;
8
import in.shop2020.model.v1.catalog.CatalogServiceException;
9
import in.shop2020.model.v1.catalog.CatalogServiceException;
9
import in.shop2020.model.v1.catalog.Item;
10
import in.shop2020.model.v1.catalog.Item;
-
 
11
import in.shop2020.model.v1.catalog.ProductFeedSubmit;
10
import in.shop2020.thrift.clients.CatalogClient;
12
import in.shop2020.thrift.clients.CatalogClient;
11
import in.shop2020.thrift.clients.LogisticsClient;
13
import in.shop2020.thrift.clients.LogisticsClient;
12
 
14
 
13
import java.io.IOException;
15
import java.io.IOException;
14
import java.util.List;
16
import java.util.List;
Line 19... Line 21...
19
 
21
 
20
public class ProductFeedsController extends BaseController{
22
public class ProductFeedsController extends BaseController{
21
	
23
	
22
	private String cataLogItemId;
24
	private String cataLogItemId;
23
	private String sentFeedResult;
25
	private String sentFeedResult;
-
 
26
	private String catalogItemIdDelete;
-
 
27
	private String deleteFeedResult;
-
 
28
	private String stockLinkFeed;
-
 
29
	private boolean stockLinkedFeed = false;
24
	
30
	
25
	public String index() {
31
	public String index() {
26
		return "index";
32
		return "index";
27
	}
33
	}
28
	
34
	
29
	public String sendProductFeeds(){
35
	public String sendProductFeeds(){
30
		//boolean sendFeedsResult = false;
36
		//boolean sendFeedsResult = false;
-
 
37
		processStockLinkFeed();
31
		Product insertedProduct = null;
38
		Product insertedProduct = null;
-
 
39
		CatalogClient catalogClient = null;
-
 
40
		try {
-
 
41
			catalogClient = new CatalogClient();
-
 
42
		} catch (TTransportException e1) {
-
 
43
			e1.printStackTrace();
-
 
44
		}
-
 
45
		
32
		if(cataLogItemId!=null && !("").equalsIgnoreCase(cataLogItemId)){
46
		if(cataLogItemId!=null && !("").equalsIgnoreCase(cataLogItemId)){
33
			List<Long> itemIdList = getEntityLogisticsEstimation(Long.parseLong(cataLogItemId));
47
			List<Long> itemIdList = getEntityLogisticsEstimation(Long.parseLong(cataLogItemId));
34
			UserInformation userInformation = new UserInformation("8587366",
48
			UserInformation userInformation = new UserInformation("8587366",
35
					"http://www.saholic.com",
49
					"http://www.saholic.com",
36
					"adwords@shop2020.in", "adwords_shop2020");
50
					"adwords@shop2020.in", "adwords_shop2020");
37
			ContentFeedsHandler sample = new ContentFeedsHandler(userInformation,
51
			ContentFeedsHandler sample = new ContentFeedsHandler(userInformation,
38
					"https://content.googleapis.com/content/v1/");
52
					"https://content.googleapis.com/content/v1/");
-
 
53
			
-
 
54
			if(catalogClient!= null){
39
			if(itemIdList!=null && itemIdList.size()>0){
55
				if(itemIdList!=null && itemIdList.size()>0){
40
				try {
56
					try {
41
					Item item = new CatalogClient().getClient().getItem(itemIdList.get(0));
57
						Item item = catalogClient.getClient().getItem(itemIdList.get(0));
42
					insertedProduct = sample.sendProductFeed(item);
58
						insertedProduct = sample.sendProductFeed(item);
43
				} catch (IOException e) {
59
					} catch (IOException e) {
44
					e.printStackTrace();
60
						e.printStackTrace();
45
				} catch (TTransportException e) {
61
					} catch (CatalogServiceException e) {
46
					e.printStackTrace();
62
						e.printStackTrace();
47
				} catch (CatalogServiceException e) {
63
					} catch (TException e) {
48
					e.printStackTrace();
64
						e.printStackTrace();
-
 
65
					}
-
 
66
				}
49
				} catch (TException e) {
67
				else{
-
 
68
					sentFeedResult = "Error: There is No Product avaliable for given Catalog Item Id.";
50
					e.printStackTrace();
69
					return "output";
51
				}
70
				}
52
			}
-
 
53
			else{
-
 
54
				sentFeedResult = "Error: There is No Product avaliable for given Catalog Item Id.";
-
 
55
				return "output";
-
 
56
			}
71
			}
57
		}
72
		}
58
		if(insertedProduct!=null){
73
		if(insertedProduct!=null){
59
			if(insertedProduct.content!=null && insertedProduct.content.value.indexOf("Error:")>-1){
74
			if(insertedProduct.content!=null && insertedProduct.content.value.indexOf("Error:")>-1){
60
				sentFeedResult = insertedProduct.content.value;
75
				sentFeedResult = insertedProduct.content.value;
61
				return "output";
76
				return "output";
62
			}
77
			}
-
 
78
			
63
			sentFeedResult = "Product Feeds are sent Successfully and Product Details are Given Below:\nProduct Id- "
79
			sentFeedResult = "Product Feeds are sent Successfully and Product Details are Given Below:\nProduct Id- "
64
				+insertedProduct.externalId+" Product Title- "+insertedProduct.title;
80
				+insertedProduct.externalId+" Product Title- "+insertedProduct.title;
-
 
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
			}
65
			return "output";
111
			return "output";
66
		}
112
		}
67
		else{
113
		else{
68
			sentFeedResult = "Some Error occured while sending feeds. Please contact concerned Team";
114
			sentFeedResult = "Some Error occured while sending feeds. Please contact concerned Team";
69
			return "output";
115
			return "output";
Line 76... Line 122...
76
			errorMsg = "Some Error occured while sending feeds. Please contact concerned Team";
122
			errorMsg = "Some Error occured while sending feeds. Please contact concerned Team";
77
			return index();
123
			return index();
78
		}*/
124
		}*/
79
	}
125
	}
80
	
126
	
-
 
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
	
81
	public List<Long> getEntityLogisticsEstimation(long productId){
166
	public List<Long> getEntityLogisticsEstimation(long productId){
82
    	List<Long> items=null; 
167
    	List<Long> items=null; 
83
    	try {
168
    	try {
84
    		LogisticsClient cl = new LogisticsClient();
169
    		LogisticsClient cl = new LogisticsClient();
85
            LogisticsService.Client client = cl.getClient();
170
            LogisticsService.Client client = cl.getClient();
Line 88... Line 173...
88
            System.out.println("Unable to get items by catalog item id"+e1.getMessage());
173
            System.out.println("Unable to get items by catalog item id"+e1.getMessage());
89
        }
174
        }
90
        return items;
175
        return items;
91
    }
176
    }
92
	
177
	
-
 
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
 
93
	public String getCataLogItemId() {
200
	public String getCataLogItemId() {
94
		return cataLogItemId;
201
		return cataLogItemId;
95
	}
202
	}
96
 
203
 
97
	public void setCataLogItemId(String cataLogItemId) {
204
	public void setCataLogItemId(String cataLogItemId) {
Line 103... Line 210...
103
	}
210
	}
104
 
211
 
105
	public void setSentFeedResult(String sentFeedResult) {
212
	public void setSentFeedResult(String sentFeedResult) {
106
		this.sentFeedResult = sentFeedResult;
213
		this.sentFeedResult = sentFeedResult;
107
	}
214
	}
-
 
215
 
-
 
216
	public String getStockLinkFeed() {
-
 
217
		return stockLinkFeed;
-
 
218
	}
-
 
219
 
-
 
220
	public void setStockLinkFeed(String stockLinkFeed) {
-
 
221
		this.stockLinkFeed = stockLinkFeed;
-
 
222
	}
108
}
223
}
109
224