Subversion Repositories SmartDukaan

Rev

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

Rev 9351 Rev 9435
Line 19... Line 19...
19
import in.shop2020.googleadwords.AdwordsCampaignStatus;
19
import in.shop2020.googleadwords.AdwordsCampaignStatus;
20
import in.shop2020.googleadwords.GoogleAdwordsService.Client;
20
import in.shop2020.googleadwords.GoogleAdwordsService.Client;
21
import in.shop2020.googleadwords.GoogleAdwordsServiceException;
21
import in.shop2020.googleadwords.GoogleAdwordsServiceException;
22
import in.shop2020.googleadwords.KeywordMatchType;
22
import in.shop2020.googleadwords.KeywordMatchType;
23
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;
-
 
29
import in.shop2020.model.v1.catalog.CatalogServiceException;
24
import in.shop2020.model.v1.catalog.CatalogServiceException;
30
import in.shop2020.model.v1.catalog.Item;
25
import in.shop2020.model.v1.catalog.Item;
31
import in.shop2020.model.v1.catalog.status;
26
import in.shop2020.model.v1.catalog.status;
32
import in.shop2020.support.utils.ReportsUtils;
27
import in.shop2020.support.utils.ReportsUtils;
33
import in.shop2020.thrift.clients.AdwordsClient;
28
import in.shop2020.thrift.clients.AdwordsClient;
Line 87... Line 82...
87
	private JSONObject jsonData = null;
82
	private JSONObject jsonData = null;
88
	private JSONObject jsonCampaignData = null;
83
	private JSONObject jsonCampaignData = null;
89
	private JSONObject jsonAdgroupData = null;
84
	private JSONObject jsonAdgroupData = null;
90
	private JSONObject jsonKeywordList = null;
85
	private JSONObject jsonKeywordList = null;
91
	private JSONObject jsonKeywordData = null;
86
	private JSONObject jsonKeywordData = null;
-
 
87
	private JSONObject jsonCampaignList = null;
92
	
88
	
93
	private AdwordsCampaignStatus campStatus;
89
	private AdwordsCampaignStatus campStatus;
94
	private AdwordsAdGroupStatus adgrpStatus;
90
	private AdwordsAdGroupStatus adgrpStatus;
95
	private KeywordMatchType keywordMatchType1;
91
	private KeywordMatchType keywordMatchType1;
96
	private KeywordMatchType keywordMatchType2;
92
	private KeywordMatchType keywordMatchType2;
Line 161... Line 157...
161
	private String adgroupListUpdate2;
157
	private String adgroupListUpdate2;
162
	private String keywordListUpdate1;
158
	private String keywordListUpdate1;
163
	private String keywordUpdate;
159
	private String keywordUpdate;
164
	private String bidUpdate;
160
	private String bidUpdate;
165
	private String matchTypeUpdate;
161
	private String matchTypeUpdate;
166
	
-
 
167
	private String cataLogItemId;
-
 
168
	private String sentFeedResult;
-
 
169
	
162
		
170
 
163
 
171
	public String index() {
164
	public String index() {
172
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath()))
165
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath()))
173
			return "authfail";
166
			return "authfail";
174
		checkForErrors();
167
		checkForErrors();
Line 288... Line 281...
288
		}
281
		}
289
 
282
 
290
		return index();
283
		return index();
291
	}
284
	}
292
	
285
	
293
	public String sendProductFeeds(){
286
	/*public String sendProductFeeds(){
294
		//boolean sendFeedsResult = false;
287
		//boolean sendFeedsResult = false;
295
		Product insertedProduct = null;
288
		Product insertedProduct = null;
296
		if(cataLogItemId!=null && !("").equalsIgnoreCase(cataLogItemId)){
289
		if(cataLogItemId!=null && !("").equalsIgnoreCase(cataLogItemId)){
297
			List<Long> itemIdList = getEntityLogisticsEstimation(Long.parseLong(cataLogItemId));
290
			List<Long> itemIdList = getEntityLogisticsEstimation(Long.parseLong(cataLogItemId));
298
			UserInformation userInformation = new UserInformation("8587366",
291
			UserInformation userInformation = new UserInformation("8587366",
Line 330... Line 323...
330
		}
323
		}
331
		else{
324
		else{
332
			sentFeedResult = "Some Error occured while sending feeds. Please contact concerned Team";
325
			sentFeedResult = "Some Error occured while sending feeds. Please contact concerned Team";
333
			return "output";
326
			return "output";
334
		}
327
		}
335
		/*if(sendFeedsResult){
328
		if(sendFeedsResult){
336
			successmsg = "Product Feeds are sent Successfully";
329
			successmsg = "Product Feeds are sent Successfully";
337
			return index();
330
			return index();
338
		}
331
		}
339
		else{
332
		else{
340
			errorMsg = "Some Error occured while sending feeds. Please contact concerned Team";
333
			errorMsg = "Some Error occured while sending feeds. Please contact concerned Team";
341
			return index();
334
			return index();
342
		}*/
335
		}
343
	}
336
	}*/
344
	
337
	/*
345
	public List<Long> getEntityLogisticsEstimation(long productId){
338
	public List<Long> getEntityLogisticsEstimation(long productId){
346
    	List<Long> items=null; 
339
    	List<Long> items=null; 
347
    	try {
340
    	try {
348
    		LogisticsClient cl = new LogisticsClient();
341
    		LogisticsClient cl = new LogisticsClient();
349
            LogisticsService.Client client = cl.getClient();
342
            LogisticsService.Client client = cl.getClient();
350
            items = client.getEntityLogisticsEstimation(productId, "110001", DeliveryType.PREPAID );
343
            items = client.getEntityLogisticsEstimation(productId, "110001", DeliveryType.PREPAID );
351
        } catch (Exception e1) {
344
        } catch (Exception e1) {
352
            System.out.println("Unable to get items by catalog item id"+e1.getMessage());
345
            System.out.println("Unable to get items by catalog item id"+e1.getMessage());
353
        }
346
        }
354
        return items;
347
        return items;
355
    }
348
    }*/
356
	
349
	
357
	public KeywordMatchType processAdKeywordMatchType(String value){
350
	public KeywordMatchType processAdKeywordMatchType(String value){
358
		return KeywordMatchType.findByValue(Integer.parseInt(value));
351
		return KeywordMatchType.findByValue(Integer.parseInt(value));
359
	}
352
	}
360
	
353
	
Line 379... Line 372...
379
		double bidamount = Double.parseDouble(bid);
372
		double bidamount = Double.parseDouble(bid);
380
		bidamount = bidamount * Math.pow(10, 6);
373
		bidamount = bidamount * Math.pow(10, 6);
381
		keywordMap.put("BidAmount", bidamount+"");
374
		keywordMap.put("BidAmount", bidamount+"");
382
		return keywordMap;
375
		return keywordMap;
383
	}
376
	}
-
 
377
	
384
	public void processAdGroupStatus(){
378
	public void processAdGroupStatus(){
385
		if(adgroupStatus!=null){
379
		if(adgroupStatus!=null){
386
			if("1".equalsIgnoreCase(adgroupStatus)){
380
			if("1".equalsIgnoreCase(adgroupStatus)){
387
				adgrpStatus = AdwordsAdGroupStatus.ENABLED;
381
				adgrpStatus = AdwordsAdGroupStatus.ENABLED;
388
			}
382
			}
Line 404... Line 398...
404
		} catch (ParseException e) {
398
		} catch (ParseException e) {
405
			e.printStackTrace();
399
			e.printStackTrace();
406
		}
400
		}
407
		return dateStr;
401
		return dateStr;
408
	}
402
	}
-
 
403
	
409
	public void processCampaignStatus(){
404
	public void processCampaignStatus(){
410
		if(campaignStatus!=null){
405
		if(campaignStatus!=null){
411
			if("1".equalsIgnoreCase(campaignStatus)){
406
			if("1".equalsIgnoreCase(campaignStatus)){
412
				campStatus = AdwordsCampaignStatus.ACTIVE;
407
				campStatus = AdwordsCampaignStatus.ACTIVE;
413
			}
408
			}
Line 689... Line 684...
689
						if(!campaign.getName().equalsIgnoreCase(campaignNameUpdate)){
684
						if(!campaign.getName().equalsIgnoreCase(campaignNameUpdate)){
690
							campaign.setName(campaignNameUpdate);
685
							campaign.setName(campaignNameUpdate);
691
							name = campaignNameUpdate;
686
							name = campaignNameUpdate;
692
						}
687
						}
693
					}
688
					}
694
					if(!campaign.getStatus().toString().equalsIgnoreCase(AdwordsCampaignStatus.valueOf(campaignStatusUpdate).toString())){
689
					if(campaign.getStatus().getValue()!=Integer.parseInt(campaignStatusUpdate)){
695
						campaign.setStatus(AdwordsCampaignStatus.valueOf(campaignStatusUpdate));
690
						campaign.setStatus(AdwordsCampaignStatus.findByValue(Integer.parseInt(campaignStatusUpdate)));
696
						status = AdwordsCampaignStatus.valueOf(campaignStatusUpdate).toString();
691
						status = AdwordsCampaignStatus.findByValue(Integer.parseInt(campaignStatusUpdate)).toString();
697
					}
692
					}
698
					if(campaignAmountUpdate!=null && !("").equalsIgnoreCase(campaignAmountUpdate)){
693
					if(campaignAmountUpdate!=null && !("").equalsIgnoreCase(campaignAmountUpdate)){
699
						if(campaign.getBudgetAmount()!=Double.parseDouble(campaignAmountUpdate)){
694
						if(campaign.getBudgetAmount()!=Double.parseDouble(campaignAmountUpdate)){
700
							campaign.setBudgetAmount(Double.parseDouble(campaignAmountUpdate));
695
							campaign.setBudgetAmount(Double.parseDouble(campaignAmountUpdate));
701
							amount = (long)(Double.parseDouble(campaignAmountUpdate) * Math.pow(10, 6));
696
							amount = (long)(Double.parseDouble(campaignAmountUpdate) * Math.pow(10, 6));
Line 765... Line 760...
765
						if(!adgroup.getName().equalsIgnoreCase(adgroupNameUpdate)){
760
						if(!adgroup.getName().equalsIgnoreCase(adgroupNameUpdate)){
766
							adgroup.setName(adgroupNameUpdate);
761
							adgroup.setName(adgroupNameUpdate);
767
							name = adgroupNameUpdate;
762
							name = adgroupNameUpdate;
768
						}			
763
						}			
769
					}
764
					}
770
					if(!adgroup.getStatus().toString().equalsIgnoreCase(AdwordsAdGroupStatus.valueOf(adgroupStatusUpdate).toString())){
765
					if(adgroup.getStatus().getValue()!=Integer.parseInt(adgroupStatusUpdate)){
771
						adgroup.setStatus(AdwordsAdGroupStatus.valueOf(adgroupStatusUpdate));
766
						adgroup.setStatus(AdwordsAdGroupStatus.findByValue(Integer.parseInt(adgroupStatusUpdate)));
772
						status = AdwordsAdGroupStatus.valueOf(adgroupStatusUpdate).toString();
767
						status = AdwordsAdGroupStatus.findByValue(Integer.parseInt(adgroupStatusUpdate)).toString();
773
					}
768
					}
774
					if(catalogItemIdUpdate!=null && !("").equalsIgnoreCase(catalogItemIdUpdate)){
769
					if(catalogItemIdUpdate!=null && !("").equalsIgnoreCase(catalogItemIdUpdate)){
775
						if(adgroup.getCatalogItemId()!= Long.parseLong(catalogItemIdUpdate)){
770
						if(adgroup.getCatalogItemId()!= Long.parseLong(catalogItemIdUpdate)){
776
							adgroup.setCatalogItemId(Long.parseLong(catalogItemIdUpdate));
771
							adgroup.setCatalogItemId(Long.parseLong(catalogItemIdUpdate));
777
						}
772
						}
Line 823... Line 818...
823
		} catch (TTransportException e) {
818
		} catch (TTransportException e) {
824
			e.printStackTrace();
819
			e.printStackTrace();
825
		}
820
		}
826
		if(adwordsServiceClient!=null){
821
		if(adwordsServiceClient!=null){
827
			Client client = adwordsServiceClient.getClient();
822
			Client client = adwordsServiceClient.getClient();
828
			if(adgroupListUpdate2!=null && !("-1").equalsIgnoreCase(adgroupListUpdate2) && keywordListUpdate1!=null && ("-1").equalsIgnoreCase(keywordListUpdate1)){
823
			if(adgroupListUpdate2!=null && !("-1").equalsIgnoreCase(adgroupListUpdate2) && keywordListUpdate1!=null && !("-1").equalsIgnoreCase(keywordListUpdate1)){
829
				String text = "";
824
				String text = "";
830
				String type = "";
825
				String type = "";
831
				long bidAmount = -1l;
826
				long bidAmount = -1l;
832
				
-
 
833
				AdwordsAdKeyword adkeyword = null;
827
				AdwordsAdKeyword adkeyword = null;
834
				try {
828
				try {
835
					adkeyword = client.getAdwordsAdKeywordByCriterionIdAndAdGroupId(Long.parseLong(keywordListUpdate1), Long.parseLong(adgroupListUpdate2));
829
					adkeyword = client.getAdwordsAdKeywordByCriterionIdAndAdGroupId(Long.parseLong(keywordListUpdate1), Long.parseLong(adgroupListUpdate2));
836
				} catch (NumberFormatException e) {
830
				} catch (NumberFormatException e) {
837
					addActionError("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2);
831
					addActionError("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2);
Line 855... Line 849...
855
						if(adkeyword.getBidAmount()!=Double.parseDouble(bidUpdate)){
849
						if(adkeyword.getBidAmount()!=Double.parseDouble(bidUpdate)){
856
							adkeyword.setBidAmount(Double.parseDouble(bidUpdate));
850
							adkeyword.setBidAmount(Double.parseDouble(bidUpdate));
857
							bidAmount = (long) (Double.parseDouble(bidUpdate) * Math.pow(10, 6));
851
							bidAmount = (long) (Double.parseDouble(bidUpdate) * Math.pow(10, 6));
858
						}
852
						}
859
					}
853
					}
860
					if(!adkeyword.getMatchType().toString().equalsIgnoreCase(KeywordMatchType.valueOf(matchTypeUpdate).toString())){
854
					if(adkeyword.getMatchType().getValue()!= Integer.parseInt(matchTypeUpdate)){
861
						adkeyword.setMatchType(KeywordMatchType.valueOf(matchTypeUpdate));
855
						adkeyword.setMatchType(KeywordMatchType.findByValue(Integer.parseInt(matchTypeUpdate)));
862
						type = KeywordMatchType.valueOf(matchTypeUpdate).toString();
856
						type = KeywordMatchType.findByValue(Integer.parseInt(matchTypeUpdate)).toString();
863
					}
857
					}
864
					
858
					
865
					Long updatedCriterionId = 0l;
859
					Long updatedCriterionId = 0l;
866
					try {
860
					try {
867
						updatedCriterionId = UpdateKeyword.runExample(Long.parseLong(adgroupListUpdate2), Long.parseLong(keywordListUpdate1), text, bidAmount, type);
861
						updatedCriterionId = UpdateKeyword.runExample(Long.parseLong(adgroupListUpdate2), Long.parseLong(keywordListUpdate1), text, bidAmount, type);
868
					} catch (NumberFormatException e) {
862
					} catch (NumberFormatException e) {
869
						addActionError("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2+ "(Google End)..");
863
						addActionError("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2+ "(Google End)..");
870
						logger.error("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2+ "(Google End)..", e);
864
						logger.error("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2+ "(Google End)..", e);
871
					} catch (Exception e) {
865
					} catch (Exception e) {
872
						addActionError("AdGroup Crierion Service Mutate Operation Exception ");
866
						addActionError("AdGroup Crierion Service Mutate Operation Exception ");
-
 
867
						e.printStackTrace();
873
						logger.error("Error while AdGroup Crierion Service Mutate Operation", e);
868
						logger.error("Error while AdGroup Crierion Service Mutate Operation", e);
874
					}
869
					}
875
					
870
					
876
					if(updatedCriterionId>0l){
871
					if(updatedCriterionId>0l){
877
						adkeyword.setCriterionId(updatedCriterionId);
872
						adkeyword.setCriterionId(updatedCriterionId);
Line 941... Line 936...
941
 
936
 
942
	public void setJsonAdgroupData(JSONObject jsonAdgroupData) {
937
	public void setJsonAdgroupData(JSONObject jsonAdgroupData) {
943
		this.jsonAdgroupData = jsonAdgroupData;
938
		this.jsonAdgroupData = jsonAdgroupData;
944
	}
939
	}
945
 
940
 
-
 
941
	public JSONObject getJsonCampaignList() {
-
 
942
		return jsonCampaignList;
-
 
943
	}
-
 
944
 
-
 
945
	public void setJsonCampaignList(JSONObject jsonCampaignList) {
-
 
946
		this.jsonCampaignList = jsonCampaignList;
-
 
947
	}
-
 
948
 
946
	public String getKeywordId() {
949
	public String getKeywordId() {
947
		return keywordId;
950
		return keywordId;
948
	}
951
	}
949
 
952
 
950
	public void setKeywordId(String keywordId) {
953
	public void setKeywordId(String keywordId) {
Line 1103... Line 1106...
1103
	
1106
	
1104
	public String getKeywordDetails(){
1107
	public String getKeywordDetails(){
1105
		Map<String, String> adkeywordUnitDataMap = new HashMap<String, String>();
1108
		Map<String, String> adkeywordUnitDataMap = new HashMap<String, String>();
1106
		AdwordsAdKeyword adKeyword = null;
1109
		AdwordsAdKeyword adKeyword = null;
1107
		try {
1110
		try {
1108
			System.out.println("keywordId" +keywordId);
-
 
1109
			System.out.println("adgroupId" +adgroupId);
-
 
1110
			adKeyword = new AdwordsClient().getClient().getAdwordsAdKeywordByCriterionIdAndAdGroupId(Long.parseLong(keywordId), Long.parseLong(adgroupId));
1111
			adKeyword = new AdwordsClient().getClient().getAdwordsAdKeywordByCriterionIdAndAdGroupId(Long.parseLong(keywordId), Long.parseLong(adgroupId));
1111
		} catch (NumberFormatException e) {
1112
		} catch (NumberFormatException e) {
1112
			e.printStackTrace();
1113
			e.printStackTrace();
1113
		} catch (TTransportException e) {
1114
		} catch (TTransportException e) {
1114
			e.printStackTrace();
1115
			e.printStackTrace();
Line 1125... Line 1126...
1125
		}
1126
		}
1126
		jsonKeywordData = new JSONObject(adkeywordUnitDataMap);
1127
		jsonKeywordData = new JSONObject(adkeywordUnitDataMap);
1127
		return "output";
1128
		return "output";
1128
	}
1129
	}
1129
 
1130
 
1130
	public List<AdwordsCampaign> getCampaigns(){
1131
	public String getCampaigns(){
-
 
1132
		
-
 
1133
		 List<Map<String,String>> campaignDataList = new ArrayList<Map<String,String>>();
-
 
1134
		Map<String, List<Map<String,String>>> mainMap = new HashMap<String, List<Map<String,String>>>();
1131
		List<AdwordsCampaign> campaignList =null;
1135
		List<AdwordsCampaign> campaignList =null;
1132
		try {
1136
		try {
1133
			campaignList = new AdwordsClient().getClient().getAllAdwordsCampaigns();
1137
			campaignList = new AdwordsClient().getClient().getAllAdwordsCampaigns();
1134
		} catch (TTransportException e) {
1138
		} catch (TTransportException e) {
1135
			e.printStackTrace();
1139
			e.printStackTrace();
1136
		} catch (GoogleAdwordsServiceException e) {
1140
		} catch (GoogleAdwordsServiceException e) {
1137
			e.printStackTrace();
1141
			e.printStackTrace();
1138
		} catch (TException e) {
1142
		} catch (TException e) {
1139
			e.printStackTrace();
1143
			e.printStackTrace();
1140
		}
1144
		}
-
 
1145
		for(int i=0 ; i<campaignList.size() ; i++){
-
 
1146
			AdwordsCampaign campaign = campaignList.get(i);
-
 
1147
			Map<String,String> campaignDataMap = new HashMap<String,String>();
-
 
1148
			campaignDataMap.put("CampaignId",campaign.getCampaignId()+"");
-
 
1149
			campaignDataMap.put("Name", campaign.getName());
-
 
1150
			campaignDataList.add(campaignDataMap);
-
 
1151
		}
-
 
1152
		mainMap.put("CampaignData", campaignDataList);
-
 
1153
		jsonCampaignList = new JSONObject(mainMap);
-
 
1154
		/*
-
 
1155
		List<AdwordsCampaign> campaignList =null;
-
 
1156
		try {
-
 
1157
			campaignList = new AdwordsClient().getClient().getAllAdwordsCampaigns();
-
 
1158
		} catch (TTransportException e) {
-
 
1159
			e.printStackTrace();
-
 
1160
		} catch (GoogleAdwordsServiceException e) {
-
 
1161
			e.printStackTrace();
-
 
1162
		} catch (TException e) {
-
 
1163
			e.printStackTrace();
-
 
1164
		} */
1141
		return campaignList;
1165
		return "output";
1142
	}
1166
	}
1143
 
1167
 
1144
	private boolean checkForErrors(){
1168
	private boolean checkForErrors(){
1145
		Collection<String> actionErrors = getActionErrors();
1169
		Collection<String> actionErrors = getActionErrors();
1146
		if(actionErrors != null && !actionErrors.isEmpty()){
1170
		if(actionErrors != null && !actionErrors.isEmpty()){
Line 1605... Line 1629...
1605
	}
1629
	}
1606
 
1630
 
1607
	public void setKeywordListUpdate1(String keywordListUpdate1) {
1631
	public void setKeywordListUpdate1(String keywordListUpdate1) {
1608
		this.keywordListUpdate1 = keywordListUpdate1;
1632
		this.keywordListUpdate1 = keywordListUpdate1;
1609
	}
1633
	}
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
	}
-
 
1626
 
1634
 
1627
}
1635
}