Subversion Repositories SmartDukaan

Rev

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

Rev 9284 Rev 9351
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
-
 
3
import java.io.IOException;
3
import java.text.ParseException;
4
import java.text.ParseException;
4
import java.text.SimpleDateFormat;
5
import java.text.SimpleDateFormat;
5
import java.util.ArrayList;
6
import java.util.ArrayList;
6
import java.util.Collection;
7
import java.util.Collection;
7
import java.util.Collections;
8
import java.util.Collections;
Line 18... Line 19...
18
import in.shop2020.googleadwords.AdwordsCampaignStatus;
19
import in.shop2020.googleadwords.AdwordsCampaignStatus;
19
import in.shop2020.googleadwords.GoogleAdwordsService.Client;
20
import in.shop2020.googleadwords.GoogleAdwordsService.Client;
20
import in.shop2020.googleadwords.GoogleAdwordsServiceException;
21
import in.shop2020.googleadwords.GoogleAdwordsServiceException;
21
import in.shop2020.googleadwords.KeywordMatchType;
22
import in.shop2020.googleadwords.KeywordMatchType;
22
import in.shop2020.googleadwords.NetworkSettingType;
23
import in.shop2020.googleadwords.NetworkSettingType;
-
 
24
import in.shop2020.googleadwords.feedshandler.ContentFeedsHandler;
-
 
25
import in.shop2020.googleadwords.model.Product;
-
 
26
import in.shop2020.googleadwords.util.UserInformation;
-
 
27
import in.shop2020.logistics.DeliveryType;
-
 
28
import in.shop2020.logistics.LogisticsService;
23
import in.shop2020.model.v1.catalog.CatalogServiceException;
29
import in.shop2020.model.v1.catalog.CatalogServiceException;
24
import in.shop2020.model.v1.catalog.Item;
30
import in.shop2020.model.v1.catalog.Item;
25
import in.shop2020.model.v1.catalog.status;
31
import in.shop2020.model.v1.catalog.status;
26
import in.shop2020.support.utils.ReportsUtils;
32
import in.shop2020.support.utils.ReportsUtils;
27
import in.shop2020.thrift.clients.AdwordsClient;
33
import in.shop2020.thrift.clients.AdwordsClient;
28
import in.shop2020.thrift.clients.CatalogClient;
34
import in.shop2020.thrift.clients.CatalogClient;
-
 
35
import in.shop2020.thrift.clients.LogisticsClient;
29
 
36
 
30
import javax.servlet.ServletContext;
37
import javax.servlet.ServletContext;
31
import javax.servlet.http.HttpServletRequest;
38
import javax.servlet.http.HttpServletRequest;
32
import javax.servlet.http.HttpSession;
39
import javax.servlet.http.HttpSession;
33
 
40
 
Line 155... Line 162...
155
	private String keywordListUpdate1;
162
	private String keywordListUpdate1;
156
	private String keywordUpdate;
163
	private String keywordUpdate;
157
	private String bidUpdate;
164
	private String bidUpdate;
158
	private String matchTypeUpdate;
165
	private String matchTypeUpdate;
159
	
166
	
-
 
167
	private String cataLogItemId;
-
 
168
	private String sentFeedResult;
-
 
169
	
160
 
170
 
161
	public String index() {
171
	public String index() {
162
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath()))
172
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath()))
163
			return "authfail";
173
			return "authfail";
164
		checkForErrors();
174
		checkForErrors();
Line 278... Line 288...
278
		}
288
		}
279
 
289
 
280
		return index();
290
		return index();
281
	}
291
	}
282
	
292
	
-
 
293
	public String sendProductFeeds(){
-
 
294
		//boolean sendFeedsResult = false;
-
 
295
		Product insertedProduct = null;
-
 
296
		if(cataLogItemId!=null && !("").equalsIgnoreCase(cataLogItemId)){
-
 
297
			List<Long> itemIdList = getEntityLogisticsEstimation(Long.parseLong(cataLogItemId));
-
 
298
			UserInformation userInformation = new UserInformation("8587366",
-
 
299
					"http://www.saholic.com",
-
 
300
					"adwords@shop2020.in", "adwords_shop2020");
-
 
301
			ContentFeedsHandler sample = new ContentFeedsHandler(userInformation,
-
 
302
					"https://content.googleapis.com/content/v1/");
-
 
303
			if(itemIdList!=null && itemIdList.size()>0){
-
 
304
				try {
-
 
305
					Item item = new CatalogClient().getClient().getItem(itemIdList.get(0));
-
 
306
					insertedProduct = sample.sendProductFeed(item);
-
 
307
				} catch (IOException e) {
-
 
308
					e.printStackTrace();
-
 
309
				} catch (TTransportException e) {
-
 
310
					e.printStackTrace();
-
 
311
				} catch (CatalogServiceException e) {
-
 
312
					e.printStackTrace();
-
 
313
				} catch (TException e) {
-
 
314
					e.printStackTrace();
-
 
315
				}
-
 
316
			}
-
 
317
			else{
-
 
318
				sentFeedResult = "Error: There is No Product avaliable for given Catalog Item Id.";
-
 
319
				return "output";
-
 
320
			}
-
 
321
		}
-
 
322
		if(insertedProduct!=null){
-
 
323
			if(insertedProduct.content!=null && insertedProduct.content.value.indexOf("Error:")>-1){
-
 
324
				sentFeedResult = insertedProduct.content.value;
-
 
325
				return "output";
-
 
326
			}
-
 
327
			sentFeedResult = "Product Feeds are sent Successfully and Product Details are Given Below:\nProduct Id- "
-
 
328
				+insertedProduct.externalId+" Product Title- "+insertedProduct.title;
-
 
329
			return "output";
-
 
330
		}
-
 
331
		else{
-
 
332
			sentFeedResult = "Some Error occured while sending feeds. Please contact concerned Team";
-
 
333
			return "output";
-
 
334
		}
-
 
335
		/*if(sendFeedsResult){
-
 
336
			successmsg = "Product Feeds are sent Successfully";
-
 
337
			return index();
-
 
338
		}
-
 
339
		else{
-
 
340
			errorMsg = "Some Error occured while sending feeds. Please contact concerned Team";
-
 
341
			return index();
-
 
342
		}*/
-
 
343
	}
-
 
344
	
-
 
345
	public List<Long> getEntityLogisticsEstimation(long productId){
-
 
346
    	List<Long> items=null; 
-
 
347
    	try {
-
 
348
    		LogisticsClient cl = new LogisticsClient();
-
 
349
            LogisticsService.Client client = cl.getClient();
-
 
350
            items = client.getEntityLogisticsEstimation(productId, "110001", DeliveryType.PREPAID );
-
 
351
        } catch (Exception e1) {
-
 
352
            System.out.println("Unable to get items by catalog item id"+e1.getMessage());
-
 
353
        }
-
 
354
        return items;
-
 
355
    }
-
 
356
	
283
	public KeywordMatchType processAdKeywordMatchType(String value){
357
	public KeywordMatchType processAdKeywordMatchType(String value){
284
		return KeywordMatchType.findByValue(Integer.parseInt(value));
358
		return KeywordMatchType.findByValue(Integer.parseInt(value));
285
	}
359
	}
286
	
360
	
287
	public AdwordsAdGroup getAdwordsAdgroup(long adgroupId){
361
	public AdwordsAdGroup getAdwordsAdgroup(long adgroupId){
Line 921... Line 995...
921
		}
995
		}
922
		if(itemPriceList!=null && itemPriceList.size()>0){
996
		if(itemPriceList!=null && itemPriceList.size()>0){
923
			Collections.sort(itemPriceList);
997
			Collections.sort(itemPriceList);
924
			itemPrice = itemPriceList.get(0).longValue()+"";
998
			itemPrice = itemPriceList.get(0).longValue()+"";
925
		}
999
		}
926
				
1000
		
927
		return itemPrice;
1001
		return itemPrice;
928
	}
1002
	}
929
	public String getAdgroupList(){
1003
	public String getAdgroupList(){
930
		List<Map<String,String>> adgroupDataList = new ArrayList<Map<String,String>>();
1004
		List<Map<String,String>> adgroupDataList = new ArrayList<Map<String,String>>();
931
		Map<String, List<Map<String,String>>> mainMap = new HashMap<String, List<Map<String,String>>>();
1005
		Map<String, List<Map<String,String>>> mainMap = new HashMap<String, List<Map<String,String>>>();
Line 946... Line 1020...
946
			adgroupDataMap.put("Name", adgroup.getName());
1020
			adgroupDataMap.put("Name", adgroup.getName());
947
			adgroupDataList.add(adgroupDataMap);
1021
			adgroupDataList.add(adgroupDataMap);
948
		}
1022
		}
949
		mainMap.put("AdGroupData", adgroupDataList);
1023
		mainMap.put("AdGroupData", adgroupDataList);
950
		jsonData = new JSONObject(mainMap);
1024
		jsonData = new JSONObject(mainMap);
-
 
1025
		
951
		return "output";
1026
		return "output";
952
	}
1027
	}
953
	
1028
	
954
	public String getKeywordList(){
1029
	public String getKeywordList(){
955
		List<Map<String,String>> adkeywordDataList = new ArrayList<Map<String,String>>();
1030
		List<Map<String,String>> adkeywordDataList = new ArrayList<Map<String,String>>();
Line 1530... Line 1605...
1530
	}
1605
	}
1531
 
1606
 
1532
	public void setKeywordListUpdate1(String keywordListUpdate1) {
1607
	public void setKeywordListUpdate1(String keywordListUpdate1) {
1533
		this.keywordListUpdate1 = keywordListUpdate1;
1608
		this.keywordListUpdate1 = keywordListUpdate1;
1534
	}
1609
	}
-
 
1610
	
-
 
1611
	public String getCataLogItemId() {
-
 
1612
		return cataLogItemId;
-
 
1613
	}
-
 
1614
 
-
 
1615
	public void setCataLogItemId(String cataLogItemId) {
-
 
1616
		this.cataLogItemId = cataLogItemId;
-
 
1617
	}
-
 
1618
 
-
 
1619
	public String getSentFeedResult() {
-
 
1620
		return sentFeedResult;
-
 
1621
	}
-
 
1622
 
-
 
1623
	public void setSentFeedResult(String sentFeedResult) {
-
 
1624
		this.sentFeedResult = sentFeedResult;
-
 
1625
	}
1535
 
1626
 
1536
}
1627
}