Subversion Repositories SmartDukaan

Rev

Rev 9067 | Rev 9284 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9067 manish.sha 1
package in.shop2020.support.controllers;
2
 
3
import java.text.ParseException;
4
import java.text.SimpleDateFormat;
5
import java.util.ArrayList;
6
import java.util.Collection;
7
import java.util.Date;
8
import java.util.HashMap;
9
import java.util.List;
10
import java.util.Map;
11
 
12
import in.shop2020.googleadwords.AdwordsAdGroup;
13
import in.shop2020.googleadwords.AdwordsAdGroupAd;
14
import in.shop2020.googleadwords.AdwordsAdGroupStatus;
15
import in.shop2020.googleadwords.AdwordsAdKeyword;
16
import in.shop2020.googleadwords.AdwordsCampaign;
17
import in.shop2020.googleadwords.AdwordsCampaignStatus;
18
import in.shop2020.googleadwords.GoogleAdwordsService.Client;
19
import in.shop2020.googleadwords.GoogleAdwordsServiceException;
20
import in.shop2020.googleadwords.KeywordMatchType;
21
import in.shop2020.googleadwords.NetworkSettingType;
9230 manish.sha 22
import in.shop2020.model.v1.catalog.CatalogServiceException;
23
import in.shop2020.model.v1.catalog.Item;
24
import in.shop2020.model.v1.catalog.status;
9067 manish.sha 25
import in.shop2020.support.utils.ReportsUtils;
26
import in.shop2020.thrift.clients.AdwordsClient;
9230 manish.sha 27
import in.shop2020.thrift.clients.CatalogClient;
9067 manish.sha 28
 
29
import javax.servlet.ServletContext;
30
import javax.servlet.http.HttpServletRequest;
31
import javax.servlet.http.HttpSession;
32
 
33
import org.apache.struts2.convention.annotation.InterceptorRef;
34
import org.apache.struts2.convention.annotation.InterceptorRefs;
35
import org.apache.struts2.convention.annotation.Result;
36
import org.apache.struts2.convention.annotation.Results;
37
import org.apache.struts2.interceptor.ServletRequestAware;
38
import org.apache.struts2.util.ServletContextAware;
39
import org.apache.thrift.TException;
40
import org.apache.thrift.transport.TTransportException;
41
import org.json.JSONObject;
42
import org.slf4j.Logger;
43
import org.slf4j.LoggerFactory;
44
 
9230 manish.sha 45
import adwords.axis.v201309.basicoperations.UpdateKeyword;
9067 manish.sha 46
import adwords.axis.v201309.basicoperations.AddAdGroups;
47
import adwords.axis.v201309.basicoperations.AddCampaigns;
48
import adwords.axis.v201309.basicoperations.AddKeywords;
49
import adwords.axis.v201309.basicoperations.AddTextAds;
9230 manish.sha 50
import adwords.axis.v201309.basicoperations.UpdateAdGroup;
51
import adwords.axis.v201309.basicoperations.UpdateCampaign;
9067 manish.sha 52
 
53
import com.opensymphony.xwork2.ActionSupport;
54
 
55
@InterceptorRefs({
56
    @InterceptorRef("defaultStack"),
57
    @InterceptorRef("login")
58
})
59
 
60
@Results({
61
    @Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"}),
62
	@Result(name="redirect", type="redirectAction", location = "google-adwords",  params={"statusCode", "301"})
63
})
64
public class GoogleAdwordsController extends ActionSupport implements ServletRequestAware {
65
	/**
66
	 * 
67
	 */
68
	private static Logger logger = LoggerFactory.getLogger(GoogleAdwordsController.class);
69
	private static final long serialVersionUID = 5703456181320066690L;
70
	private HttpServletRequest request;
71
	private HttpSession session;
72
	private ServletContext context;
73
 
74
	private String errorMsg = "";
75
	private String successmsg = "";
76
	private String campaignId = "";
9230 manish.sha 77
	private String adgroupId = "";
78
	private String keywordId = "";
9067 manish.sha 79
	private JSONObject jsonData = null;
9230 manish.sha 80
	private JSONObject jsonCampaignData = null;
81
	private JSONObject jsonAdgroupData = null;
82
	private JSONObject jsonKeywordList = null;
83
	private JSONObject jsonKeywordData = null;
84
 
9067 manish.sha 85
	private AdwordsCampaignStatus campStatus;
86
	private AdwordsAdGroupStatus adgrpStatus;
87
	private KeywordMatchType keywordMatchType1;
88
	private KeywordMatchType keywordMatchType2;
89
	private KeywordMatchType keywordMatchType3;
90
	private KeywordMatchType keywordMatchType4;
91
	private KeywordMatchType keywordMatchType5;
92
 
93
	private NetworkSettingType networkSettingType;
94
 
95
	private boolean googlesearchNetwork = false;
96
	private boolean displaynetwork = false;
97
	private boolean partnersearchNetwork = false;
98
	private int stocklinked = 0;
99
 
100
	private String adwordOpRadio;
101
	private String adwordAddRadio;
102
	private String campaignName;
103
	private String campaignStatus;
104
	private String startDate;
105
	private String endDate;
106
	private String campaignAmount;
107
	private String googleSearchNetwork;
108
	private String displayNetwork;
109
	private String partnerSearchNetwork;
110
	private String campaignList1;
111
	private String adgroupName;
112
	private String adgroupStatus;
113
	private String catalogItemId;
114
	private String bidAmount;
115
	private String stockLinked;
116
	private String campaignList2;
117
	private String adgroupList1;
118
	private String headline;
119
	private String description1;
120
	private String description2;
121
	private String url;
122
	private String displayUrl;
123
	private String campaignList3;
124
	private String adgroupList2;
125
	private String keyword1;
126
	private String keyword2;
127
	private String keyword3;
128
	private String keyword4;
129
	private String keyword5;
130
	private String bid1;
131
	private String bid2;
132
	private String bid3;
133
	private String bid4;
134
	private String bid5;
135
	private String matchType1;
136
	private String matchType2;
137
	private String matchType3;
138
	private String matchType4;
139
	private String matchType5;
9230 manish.sha 140
 
141
	private String adwordUpdateRadio;
142
	private String campaignListUpdate1;
143
	private String campaignNameUpdate;
144
	private String campaignStatusUpdate;
145
	private String campaignAmountUpdate;
146
	private String campaignListUpdate2;
147
	private String adgroupListUpdate1;
148
	private String adgroupNameUpdate;
149
	private String adgroupStatusUpdate;
150
	private String catalogItemIdUpdate;
151
	private String bidAmountUpdate;
152
	private String campaignListUpdate3;
153
	private String adgroupListUpdate2;
154
	private String keywordListUpdate1;
155
	private String keywordUpdate;
156
	private String bidUpdate;
157
	private String matchTypeUpdate;
158
 
9067 manish.sha 159
 
160
	public String index() {
161
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath()))
162
			return "authfail";
163
		checkForErrors();
164
		return "index";
165
	}
166
 
167
	public String create(){
168
		if(adwordOpRadio!=null && ("addOpRadio").equalsIgnoreCase(adwordOpRadio)){
169
			if(adwordAddRadio!=null && ("campaignRdo").equalsIgnoreCase(adwordAddRadio)){
170
				processCampaignStatus();
171
				SimpleDateFormat timestmapFormatForGoogle = new SimpleDateFormat("yyyyMMdd");
172
				String startdateStr = timestmapFormatForGoogle.format(new Date().getTime());
173
				String enddateStr = "20371230";
174
				if(startDate!=null && !startDate.isEmpty()){
175
					startdateStr = processedStartEndDate(startDate, timestmapFormatForGoogle);
176
				}
177
				if(endDate!=null && !endDate.isEmpty()){
178
					 enddateStr = processedStartEndDate(endDate, timestmapFormatForGoogle);
179
				}
180
				processNetworkSetting();
181
				Long budgetAmount = new Long(Long.parseLong(campaignAmount));
182
				boolean addCampaignResult = addAdwordsCampaign(campaignName, startdateStr, enddateStr, (long)(budgetAmount * Math.pow(10, 6)), campStatus.toString(), googlesearchNetwork, displaynetwork, partnersearchNetwork, networkSettingType);
183
				if(addCampaignResult){
184
					successmsg = "Adwords Campaign Added Successfully";
185
				}
186
			}
187
			if(adwordAddRadio!=null && ("adgroupRdo").equalsIgnoreCase(adwordAddRadio)){
188
				processAdGroupStatus();
189
				if(catalogItemId==null || ("").equalsIgnoreCase(catalogItemId)){
190
					catalogItemId="0";
191
				}
192
				processStockLinked();
193
				boolean addAdGroupResult = addAdwordsAdGroup(Long.parseLong(campaignList1), adgroupName, adgrpStatus.toString(), (long)(Double.parseDouble(bidAmount) * Math.pow(10, 6)), Long.parseLong(catalogItemId));
194
				if(addAdGroupResult){
195
					successmsg = "Adwords AdGroup Added Successfully";
196
				}
197
			}
198
			if(adwordAddRadio!=null && ("textAdRdo").equalsIgnoreCase(adwordAddRadio)){
199
				boolean addAdgroupAdResult = addAdwordsAdGroupAd();
200
				if(addAdgroupAdResult){
201
					successmsg = "Adwords AdGroup Text Ad Added Successfully";
202
				}
203
			}
204
			if(adwordAddRadio!=null && ("keywordRdo").equalsIgnoreCase(adwordAddRadio)){
205
				AdwordsAdGroup adgroup = getAdwordsAdgroup(Long.parseLong(adgroupList2));
206
				List<Map<String, String>> keywordDataList = new ArrayList<Map<String, String>>();
207
				if(keyword1 != null && !keyword1.isEmpty()){
208
					keywordMatchType1 = processAdKeywordMatchType(matchType1);
209
					if(bid1!=null && !bid1.isEmpty()){
210
						keywordDataList.add(getKeywordMap(keyword1,bid1,keywordMatchType1.toString()));
211
					}
212
					else{
213
						keywordDataList.add(getKeywordMap(keyword1,adgroup.getBidAmount()+"",keywordMatchType1.toString()));
214
					}
215
				}
216
				if(keyword2 != null && !keyword2.isEmpty()){
217
					keywordMatchType2 = processAdKeywordMatchType(matchType2);
218
					if(bid2!=null && !bid2.isEmpty()){
219
						keywordDataList.add(getKeywordMap(keyword2,bid2,keywordMatchType2.toString()));
220
					}
221
					else{
222
						keywordDataList.add(getKeywordMap(keyword2,adgroup.getBidAmount()+"",keywordMatchType2.toString()));
223
					}
224
				}
225
				if(keyword3 != null && !keyword3.isEmpty()){
226
					keywordMatchType3 = processAdKeywordMatchType(matchType3);
227
					if(bid3!=null && !bid3.isEmpty()){
228
						keywordDataList.add(getKeywordMap(keyword3,bid3,keywordMatchType3.toString()));
229
					}
230
					else{
231
						keywordDataList.add(getKeywordMap(keyword3,adgroup.getBidAmount()+"",keywordMatchType3.toString()));
232
					}
233
				}
234
				if(keyword4 != null && !keyword4.isEmpty()){
235
					keywordMatchType4 = processAdKeywordMatchType(matchType4);
236
					if(bid4!=null && !bid4.isEmpty()){
237
						keywordDataList.add(getKeywordMap(keyword4,bid4,keywordMatchType4.toString()));
238
					}
239
					else{
240
						keywordDataList.add(getKeywordMap(keyword4,adgroup.getBidAmount()+"",keywordMatchType4.toString()));
241
					}
242
				}
243
				if(keyword5 != null && !keyword5.isEmpty()){
244
					keywordMatchType5 = processAdKeywordMatchType(matchType5);
245
					if(bid5!=null && !bid5.isEmpty()){
246
						keywordDataList.add(getKeywordMap(keyword5,bid5,keywordMatchType5.toString()));
247
					}
248
					else{
249
						keywordDataList.add(getKeywordMap(keyword5,adgroup.getBidAmount()+"",keywordMatchType5.toString()));
250
					}
251
				}
252
				boolean addAdKeywordResult = addAdwordsAdKeyword(keywordDataList);
253
				if(addAdKeywordResult){
254
					successmsg = "Adwords AdGroup Ad Keyword Added Successfully";
255
				}
256
			}
257
		}
9230 manish.sha 258
		if(adwordOpRadio!=null && ("updateOpRadio").equalsIgnoreCase(adwordOpRadio)){
259
			if(adwordUpdateRadio!=null && ("campaignRdoUpdate").equalsIgnoreCase(adwordUpdateRadio)){
260
				boolean updateCamapaignResult = updateAdwordsCampaign();
261
				if(updateCamapaignResult){
262
					successmsg = "Adwords Campaign Updated Successfully";
263
				}
264
			}
265
			if(adwordUpdateRadio!=null && ("adgroupRdoUpdate").equalsIgnoreCase(adwordUpdateRadio)){
266
				boolean updateAdGroupResult = updateAdwordsAdGroup();
267
				if(updateAdGroupResult){
268
					successmsg = "Adwords AdGroup Updated Successfully";
269
				}
270
			}
271
			if(adwordUpdateRadio!=null && ("keywordRdoUpdate").equalsIgnoreCase(adwordUpdateRadio)){
272
				boolean updateKeywordResult = updateAdwordsAdKeyword();
273
				if(updateKeywordResult){
274
					successmsg = "Adwords AdKeyword Updated Successfully";
275
				}
276
			}
277
		}
9067 manish.sha 278
 
279
		return index();
280
	}
281
 
282
	public KeywordMatchType processAdKeywordMatchType(String value){
283
		return KeywordMatchType.findByValue(Integer.parseInt(value));
284
	}
285
 
286
	public AdwordsAdGroup getAdwordsAdgroup(long adgroupId){
287
		AdwordsAdGroup adgroup = new AdwordsAdGroup();
288
		try {
289
			adgroup = new AdwordsClient().getClient().getAdwordsAdGroupByAdGroupId(adgroupId);
290
		} catch (TTransportException e) {
291
			e.printStackTrace();
292
		} catch (GoogleAdwordsServiceException e) {
293
			e.printStackTrace();
294
		} catch (TException e) {
295
			e.printStackTrace();
296
		}
297
		return adgroup;
298
	}
299
 
300
	public Map<String, String> getKeywordMap(String keyword, String bid, String type){
301
		Map<String, String> keywordMap = new HashMap<String, String>();
302
		keywordMap.put("Text", keyword1);
303
		keywordMap.put("Type", type);
304
		double bidamount = Double.parseDouble(bid);
305
		bidamount = bidamount * Math.pow(10, 6);
306
		keywordMap.put("BidAmount", bidamount+"");
307
		return keywordMap;
308
	}
309
	public void processAdGroupStatus(){
310
		if(adgroupStatus!=null){
311
			if("1".equalsIgnoreCase(adgroupStatus)){
312
				adgrpStatus = AdwordsAdGroupStatus.ENABLED;
313
			}
314
			else if("2".equalsIgnoreCase(campaignStatus)){
315
				adgrpStatus = AdwordsAdGroupStatus.PAUSED;
316
			}
317
			else{
318
				campStatus = AdwordsCampaignStatus.DELETED;
319
			}
320
		}
321
	}
322
 
323
	public String processedStartEndDate(String dateString, SimpleDateFormat dateformat){
324
		SimpleDateFormat timestmapFormatRequest = new SimpleDateFormat("mm/dd/yyyy");
325
		String dateStr = "";
326
		try {
327
			Date date = timestmapFormatRequest.parse(dateString);
328
			dateStr = dateformat.format(date.getTime());
329
		} catch (ParseException e) {
330
			e.printStackTrace();
331
		}
332
		return dateStr;
333
	}
334
	public void processCampaignStatus(){
335
		if(campaignStatus!=null){
336
			if("1".equalsIgnoreCase(campaignStatus)){
337
				campStatus = AdwordsCampaignStatus.ACTIVE;
338
			}
339
			else if("2".equalsIgnoreCase(campaignStatus)){
340
				campStatus = AdwordsCampaignStatus.PAUSED;
341
			}
342
			else{
343
				campStatus = AdwordsCampaignStatus.DELETED;
344
			}
345
		}
346
	}
347
 
348
	public void processStockLinked(){
349
		if(stockLinked!=null && ("on").equalsIgnoreCase(stockLinked)){
350
			stocklinked = 1;
351
		}
352
	}
353
	public void processNetworkSetting(){
354
		if(googleSearchNetwork!=null && ("on").equalsIgnoreCase(googleSearchNetwork)){
355
			googlesearchNetwork = true;
356
		}
357
		if(displayNetwork!=null && ("on").equalsIgnoreCase(displayNetwork)){
358
			displaynetwork = true;
359
		}
360
		if(partnerSearchNetwork!=null && ("on").equalsIgnoreCase(partnerSearchNetwork)){
361
			partnersearchNetwork = true;
362
		}
363
 
364
		if(googlesearchNetwork && !displaynetwork && !partnersearchNetwork){
365
			networkSettingType = NetworkSettingType.GOOGLE_SEARCH_AND_SEARCH_NETWORK;
366
		}
367
		else if(googlesearchNetwork && displaynetwork && !partnersearchNetwork){
368
			networkSettingType = NetworkSettingType.SEARCH_AND_DISPLAY_NETWORK;
369
		}
370
		else if(googlesearchNetwork && !displaynetwork && partnersearchNetwork){
371
			networkSettingType = NetworkSettingType.SEARCH_AND_PARTNER_NETWORK;
372
		}
373
		else if(!googlesearchNetwork && displaynetwork && !partnersearchNetwork){
374
			networkSettingType = NetworkSettingType.DISPLAY_NETWORK;
375
		}
376
		else if(!googlesearchNetwork && displaynetwork && partnersearchNetwork){
377
			networkSettingType = NetworkSettingType.DISPLAY_AND_PARTNER_NETWORK;
378
		}
379
		else if(!googlesearchNetwork && !displaynetwork && partnersearchNetwork){
380
			networkSettingType = NetworkSettingType.GOOGLE_PARTNER_SEARCH_NETWORK;
381
		}
382
		else if(googlesearchNetwork && displaynetwork && partnersearchNetwork){
383
			networkSettingType = NetworkSettingType.ALL_AVALIABLE_SOURCES;
384
		}
385
 
386
	}
387
 
388
	public boolean addAdwordsCampaign(String name, String startDateStr, String endDateStr, 
389
			Long amount, String status, boolean googlesrchNtwrk, boolean displayntwrk, 
390
			boolean partnersrchNtwrk, NetworkSettingType networkType){
391
		Long campaignId = 0L;
392
		boolean retry = true;
393
		int attempt =0;
394
		while(retry && attempt<2){
395
			try{
396
				attempt = attempt+1;
397
				campaignId = AddCampaigns.runExample(name, status, startDateStr, endDateStr, amount, googlesrchNtwrk, displayntwrk, partnersrchNtwrk);
398
				retry = false;
399
				System.out.println("@@@@@ CampaignId...... "+campaignId);
400
			}
401
			catch (Exception e) {
402
				retry = true;
403
				logger.error("Error while requesting Google Adwords Campaign Service", e);
404
			}
405
		}
406
		if(campaignId==0L){
407
			addActionError("Error while processing Add Request for Google Campaign Service");
408
			return false;
409
		}
410
		try{
411
			SimpleDateFormat timestmapFormatForGoogle = new SimpleDateFormat("yyyymmdd");
412
			AdwordsCampaign campaign = new AdwordsCampaign();
413
			campaign.setCampaignId(campaignId);
414
			campaign.setName(name);
415
			campaign.setBudgetAmount(amount * Math.pow(10, -6));
416
			campaign.setNetworkType(networkType);
417
			campaign.setStartDate(timestmapFormatForGoogle.parse(startDateStr).getTime());
418
			campaign.setEndDate(timestmapFormatForGoogle.parse(endDateStr).getTime());
419
			campaign.setStatus(campStatus);
420
			new AdwordsClient().getClient().addAdwordsCampaign(campaign);
421
			return true;
422
		}
423
		catch(ParseException pe){
424
			addActionError("Unable to parse proper Data");
425
			logger.error("Error while parsing proper Data", pe);
426
		} catch (TTransportException e) {
9230 manish.sha 427
			addActionError("Unable to get Connection with Saholic Google Adowrds Services in addAdwordsCampaign Method");
428
			logger.error("Error while getting Connection with Saholic Google Adowrds Services in addAdwordsCampaign Method", e);
9067 manish.sha 429
		} catch (GoogleAdwordsServiceException e) {
9230 manish.sha 430
			addActionError("Unable to perform operations with Saholic Google Adowrds Services in addAdwordsCampaign Method");
431
			logger.error("Error while performing operations with Saholic Google Adowrds Services in addAdwordsCampaign Method", e);
9067 manish.sha 432
		} catch (TException e) {
9230 manish.sha 433
			addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in addAdwordsCampaign Method");
434
			logger.error("Error while performing operations with Saholic Google Adowrds Services Client in addAdwordsCampaign Method", e);
9067 manish.sha 435
		}
436
 
437
		return false;
438
	}
439
 
440
	public boolean addAdwordsAdGroup(long campaignId, String name, String status, Long bidAmount, long catalogId){
441
		Long adGroupId = 0L;
442
		boolean retry = true;
443
		int attempt =0;
444
		while(retry && attempt < 2){
445
			try{
446
				attempt =attempt +1;
447
				adGroupId = AddAdGroups.runExample(campaignId, name, status, bidAmount);
448
				retry = false;
449
			}
450
			catch (Exception e) {
451
				retry = true;
452
				logger.error("Error while requesting Google Adwords AdGroup Service", e);
453
			}
454
		}
455
		if(adGroupId == 0L){
456
			addActionError("Error while processing Add Request for Google AdGroup Service");
457
			return false;
458
		}
459
		try{
460
			AdwordsAdGroup adgroup = new AdwordsAdGroup();
461
			adgroup.setAdgroupId(adGroupId);
462
			adgroup.setCampaignId(campaignId);
463
			adgroup.setCatalogItemId(catalogId);
464
			adgroup.setStatus(adgrpStatus);
465
			adgroup.setName(name);
466
			adgroup.setBidAmount(bidAmount * Math.pow(10, -6));
467
			adgroup.setStockLinked(stocklinked);
468
			new AdwordsClient().getClient().addAdwordsAdGroup(adgroup);
469
			return true;
470
		}
471
		catch (TTransportException e) {
9230 manish.sha 472
			addActionError("Unable to get Connection with Saholic Google Adowrds Services in addAdwordsAdGroup Method");
473
			logger.error("Error while getting Connection with Saholic Google Adowrds Services in addAdwordsAdGroup Method", e);
9067 manish.sha 474
		} catch (GoogleAdwordsServiceException e) {
9230 manish.sha 475
			addActionError("Unable to perform operations with Saholic Google Adowrds Services in addAdwordsAdGroup Method");
476
			logger.error("Error while performing operations with Saholic Google Adowrds Services in addAdwordsAdGroup Method", e);
9067 manish.sha 477
		} catch (TException e) {
9230 manish.sha 478
			addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in addAdwordsAdGroup Method");
479
			logger.error("Error while performing operations with Saholic Google Adowrds Services Client in addAdwordsAdGroup Method", e);
9067 manish.sha 480
		}
481
		return false;
482
	}
483
 
484
	public boolean addAdwordsAdGroupAd(){
485
		Long adGroupAdId = 0L;
486
		int attempt =0;
487
		boolean retry = true;
9230 manish.sha 488
		if(description1.contains("#price")){
489
			description1 = description1.replace("#price", "Rs"+getTextAdItemPrice()+"#");
490
		}
491
		if(description1.length()>35){
492
			addActionError("Description1 length is greater than 35. Final String is given as.... "+description1);
493
			return false;
494
		}
9067 manish.sha 495
		while(retry && attempt<2){
496
			try{
497
				attempt = attempt+1;
498
				adGroupAdId = AddTextAds.runExample(Long.parseLong(adgroupList1), headline, description1, description2, url, displayUrl);
499
				retry = false;
500
			}
501
			catch (Exception e) {
502
				retry = true;
503
				logger.error("Error while requesting Google Adwords AdGroupAd Service", e);
504
			}
505
		}
506
		if(adGroupAdId == 0L){
507
			addActionError("Error while processing Add Request for Google AdGroupAd Service");
508
			return false;
509
		}
510
		try{
511
			AdwordsAdGroupAd adgroupad = new AdwordsAdGroupAd();
512
			adgroupad.setAdgroupadId(adGroupAdId);
513
			adgroupad.setCampaignId(Long.parseLong(campaignList2));
514
			adgroupad.setAdgroupId(Long.parseLong(adgroupList1));
515
			adgroupad.setDescription1(description1);
516
			adgroupad.setDescription2(description2);
517
			adgroupad.setHeadline(headline);
518
			adgroupad.setDisplayUrl(displayUrl);
519
			adgroupad.setUrl(url);
520
			new AdwordsClient().getClient().addAdwordsAdGroupAd(adgroupad);
521
			return true;
522
		}
523
		catch (TTransportException e) {
9230 manish.sha 524
			addActionError("Unable to get Connection with Saholic Google Adowrds Services in addAdwordsAdGroupAd Method");
525
			logger.error("Error while getting Connection with Saholic Google Adowrds Services in addAdwordsAdGroupAd Method", e);
9067 manish.sha 526
		} catch (GoogleAdwordsServiceException e) {
9230 manish.sha 527
			addActionError("Unable to perform operations with Saholic Google Adowrds Services in addAdwordsAdGroupAd Method");
528
			logger.error("Error while performing operations with Saholic Google Adowrds Services in addAdwordsAdGroupAd Method", e);
9067 manish.sha 529
		} catch (TException e) {
9230 manish.sha 530
			addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in addAdwordsAdGroupAd Method");
531
			logger.error("Error while performing operations with Saholic Google Adowrds Services Client in addAdwordsAdGroupAd Method", e);
9067 manish.sha 532
		}
533
 
534
		return false;
535
	}
536
 
537
	public boolean addAdwordsAdKeyword(List<Map<String,String>> keywordDataList){
538
		List<Map<String,String>> adgroupDataList = new ArrayList<Map<String,String>>();
539
		int attempt =0;
540
		boolean retry = true;
541
		while(retry && attempt<2){
542
			try{
543
				attempt = attempt+1;
544
				adgroupDataList = AddKeywords.runExample(Long.parseLong(adgroupList2), keywordDataList);
545
				retry = false;
546
			}
547
			catch (Exception e) {
548
				retry = true;
549
				logger.error("Error while requesting Google Adwords AdGroup Criterion Service", e);
550
			}
551
		}
552
		if(adgroupDataList!=null && adgroupDataList.size()>0){
553
			try{
554
				AdwordsClient adwordsServiceClient = new AdwordsClient();
555
				Client client = adwordsServiceClient.getClient();
556
				for(Map<String,String> keywordMap : adgroupDataList){
557
					AdwordsAdKeyword adkeyword = new AdwordsAdKeyword();
558
					adkeyword.setAdgroupId(Long.parseLong(adgroupList2));
559
					adkeyword.setCampaignId(Long.parseLong(campaignList3));
560
					adkeyword.setCriterionId(Long.parseLong(keywordMap.get("CriterionId")));
561
					adkeyword.setText(keywordMap.get("Text"));
562
					adkeyword.setMatchType(KeywordMatchType.valueOf(keywordMap.get("Type")));
563
					adkeyword.setBidAmount( (Double.parseDouble(keywordMap.get("BidAmount"))) * (Math.pow(10, -6) ));
564
					client.addAdwordsAdKeyword(adkeyword);
565
				}
566
				return true;
567
			}
568
			catch (TTransportException e) {
9230 manish.sha 569
				addActionError("Unable to get Connection with Saholic Google Adowrds Services in addAdwordsAdKeyword Method");
570
				logger.error("Error while getting Connection with Saholic Google Adowrds Services in addAdwordsAdKeyword Method", e);
9067 manish.sha 571
			} catch (GoogleAdwordsServiceException e) {
9230 manish.sha 572
				addActionError("Unable to perform operations with Saholic Google Adowrds Services in addAdwordsAdKeyword Method");
573
				logger.error("Error while performing operations with Saholic Google Adowrds Services in addAdwordsAdKeyword Method", e);
9067 manish.sha 574
			} catch (TException e) {
9230 manish.sha 575
				addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in addAdwordsAdKeyword Method");
576
				logger.error("Error while performing operations with Saholic Google Adowrds Services Client in addAdwordsAdKeyword Method", e);
9067 manish.sha 577
			}
578
		}
9230 manish.sha 579
		else{
580
			addActionError("Error while processing Add Request for Google AdGroupCriterion Service");
581
		}
9067 manish.sha 582
		return false;
583
	}
584
 
9230 manish.sha 585
	public boolean updateAdwordsCampaign(){
586
		AdwordsClient adwordsServiceClient = null;
587
		try {
588
			adwordsServiceClient = new AdwordsClient();
589
		} catch (TTransportException e) {
590
			addActionError("Unable to get Connection with Saholic Google Adowrds Services in updateAdwordsCampaign Method");
591
			logger.error("Error while getting Connection with Saholic Google Adowrds Services in updateAdwordsCampaign Method", e); 
592
		}
593
		if(adwordsServiceClient!=null){
594
			Client client = adwordsServiceClient.getClient();
595
			if(campaignListUpdate1!=null && !("-1").equalsIgnoreCase(campaignListUpdate1)){
596
				long amount= -1l;
597
				String status = "";
598
				String name = "";
599
				AdwordsCampaign campaign = null;
600
				try {
601
					campaign = client.getAdwordsCampaignByCampaignId(Long.parseLong(campaignListUpdate1));
602
				} catch (NumberFormatException e) {
603
					addActionError("Number Format Exception for CampaignId.."+campaignListUpdate1);
604
					logger.error("Number Format Exception for CampaignId.."+campaignListUpdate1, e);
605
				} catch (GoogleAdwordsServiceException e) {
606
					addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsCampaign Method while getting Data");
607
					logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsCampaign Method while getting Data", e);
608
				} catch (TException e) {
609
					addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsCampaign Method while getting Data");
610
					logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsCampaign Method while getting Data", e);
611
				}
612
				if(campaign!=null){
613
					if(campaignNameUpdate!=null && !("").equalsIgnoreCase(campaignNameUpdate)){
614
						if(!campaign.getName().equalsIgnoreCase(campaignNameUpdate)){
615
							campaign.setName(campaignNameUpdate);
616
							name = campaignNameUpdate;
617
						}
618
					}
619
					if(!campaign.getStatus().toString().equalsIgnoreCase(AdwordsCampaignStatus.valueOf(campaignStatusUpdate).toString())){
620
						campaign.setStatus(AdwordsCampaignStatus.valueOf(campaignStatusUpdate));
621
						status = AdwordsCampaignStatus.valueOf(campaignStatusUpdate).toString();
622
					}
623
					if(campaignAmountUpdate!=null && !("").equalsIgnoreCase(campaignAmountUpdate)){
624
						if(campaign.getBudgetAmount()!=Double.parseDouble(campaignAmountUpdate)){
625
							campaign.setBudgetAmount(Double.parseDouble(campaignAmountUpdate));
626
							amount = (long)(Double.parseDouble(campaignAmountUpdate) * Math.pow(10, 6));
627
						}
628
					}
629
					Long updatedCampaignId = 0l;
630
					try {
631
						updatedCampaignId = UpdateCampaign.runExample(Long.parseLong(campaignListUpdate1), status, name, amount);
632
					} catch (NumberFormatException e) {
633
						addActionError("Number Format Exception for CampaignId (Google End).."+campaignListUpdate1);
634
						logger.error("Number Format Exception for CampaignId (Google End).."+campaignListUpdate1, e);
635
					} catch (Exception e) {
636
						addActionError("Campaign Service Mutate Operation Exception ");
637
						logger.error("Error while Campaign Service Mutate Operation", e);
638
					}
639
					if(updatedCampaignId > 0l){
640
						campaign.setCampaignId(updatedCampaignId);
641
						try {
642
							client.updateAdwordsCampaign(campaign);
643
							return true;
644
						} catch (GoogleAdwordsServiceException e) {
645
							addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsCampaign Method while updating Data");
646
							logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsCampaign Method while updating Data", e); 
647
						} catch (TException e) {
648
							addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsCampaign Method while updating Data");
649
							logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsCampaign Method while updating Data", e);
650
						}
651
					}
652
					else{
653
						addActionError("Error while processing Update Request for Google Campaign Service");
654
					}
655
				}
656
			}
657
		}
658
 
659
		return false;
660
	}
661
 
662
	public boolean updateAdwordsAdGroup(){
663
		AdwordsClient adwordsServiceClient = null;
664
		try {
665
			adwordsServiceClient = new AdwordsClient();
666
		} catch (TTransportException e) {
667
			e.printStackTrace();
668
		}
669
		if(adwordsServiceClient!=null){
670
			Client client = adwordsServiceClient.getClient();
671
			if(adgroupListUpdate1!=null && !("-1").equalsIgnoreCase(adgroupListUpdate1)){
672
				String name="";
673
				String status ="";
674
				long bidAmount = -1L;
675
				AdwordsAdGroup adgroup = null;
676
				try {
677
					adgroup = client.getAdwordsAdGroupByAdGroupId(Long.parseLong(adgroupListUpdate1));
678
				} catch (NumberFormatException e) {
679
					addActionError("Number Format Exception for AdGroupId.."+adgroupListUpdate1);
680
					logger.error("Number Format Exception for AdGroupId.."+adgroupListUpdate1, e);
681
				} catch (GoogleAdwordsServiceException e) {
682
					addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsAdGroup Method while getting Data");
683
					logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsAdGroup Method while getting Data", e);
684
				} catch (TException e) {
685
					addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsAdGroup Method while getting Data");
686
					logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsAdGroup Method while getting Data", e);
687
				}
688
				if(adgroup!=null){
689
					if(adgroupNameUpdate!=null && !("").equalsIgnoreCase(adgroupNameUpdate)){
690
						if(!adgroup.getName().equalsIgnoreCase(adgroupNameUpdate)){
691
							adgroup.setName(adgroupNameUpdate);
692
							name = adgroupNameUpdate;
693
						}			
694
					}
695
					if(!adgroup.getStatus().toString().equalsIgnoreCase(AdwordsAdGroupStatus.valueOf(adgroupStatusUpdate).toString())){
696
						adgroup.setStatus(AdwordsAdGroupStatus.valueOf(adgroupStatusUpdate));
697
						status = AdwordsAdGroupStatus.valueOf(adgroupStatusUpdate).toString();
698
					}
699
					if(catalogItemIdUpdate!=null && !("").equalsIgnoreCase(catalogItemIdUpdate)){
700
						if(adgroup.getCatalogItemId()!= Long.parseLong(catalogItemIdUpdate)){
701
							adgroup.setCatalogItemId(Long.parseLong(catalogItemIdUpdate));
702
						}
703
					}
704
					if(bidAmountUpdate!=null && !("").equalsIgnoreCase(bidAmountUpdate)){
705
						if(adgroup.getBidAmount()!=Double.parseDouble(bidAmountUpdate)){
706
							adgroup.setBidAmount(Double.parseDouble(bidAmountUpdate));
707
							bidAmount = (long) (Double.parseDouble(bidAmountUpdate) * Math.pow(10, 6));
708
						}
709
					}
710
 
711
					Long updatedAdgroupId = 0l;
712
					try {
713
						updatedAdgroupId = UpdateAdGroup.runExample(name, status, bidAmount, Long.parseLong(adgroupListUpdate1));
714
					} catch (NumberFormatException e) {
715
						addActionError("Number Format Exception for AdGroupId (Google End).."+adgroupListUpdate1);
716
						logger.error("Number Format Exception for AdGroupId (Google End).."+adgroupListUpdate1, e);
717
					} catch (Exception e) {
718
						addActionError("AdGroup Service Mutate Operation Exception ");
719
						logger.error("Error while AdGroup Service Mutate Operation", e);
720
					}
721
					if(updatedAdgroupId>0l){
722
						adgroup.setAdgroupId(updatedAdgroupId);
723
						try {
724
							client.updateAdwordsAdGroup(adgroup);
725
							return true;
726
						} catch (GoogleAdwordsServiceException e) {
727
							addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsAdGroup Method while updating Data");
728
							logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsAdGroup Method while updating Data", e); 
729
						} catch (TException e) {
730
							addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsAdGroup Method while updating Data");
731
							logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsAdGroup Method while updating Data", e);
732
						}
733
					}
734
					else{
735
						addActionError("Error while processing Update Request for Google AdGroup Service");
736
					}
737
				}
738
 
739
			}
740
		}
741
		return false;
742
	}
743
 
744
	public boolean updateAdwordsAdKeyword(){
745
		AdwordsClient adwordsServiceClient = null;
746
		try {
747
			adwordsServiceClient = new AdwordsClient();
748
		} catch (TTransportException e) {
749
			e.printStackTrace();
750
		}
751
		if(adwordsServiceClient!=null){
752
			Client client = adwordsServiceClient.getClient();
753
			if(adgroupListUpdate2!=null && !("-1").equalsIgnoreCase(adgroupListUpdate2) && keywordListUpdate1!=null && ("-1").equalsIgnoreCase(keywordListUpdate1)){
754
				String text = "";
755
				String type = "";
756
				long bidAmount = -1l;
757
 
758
				AdwordsAdKeyword adkeyword = null;
759
				try {
760
					adkeyword = client.getAdwordsAdKeywordByCriterionIdAndAdGroupId(Long.parseLong(keywordListUpdate1), Long.parseLong(adgroupListUpdate2));
761
				} catch (NumberFormatException e) {
762
					addActionError("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2);
763
					logger.error("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2, e);
764
				} catch (GoogleAdwordsServiceException e) {
765
					addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsAdKeyword Method while getting Data");
766
					logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsAdKeyword Method while getting Data", e);
767
				} catch (TException e) {
768
					addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsAdKeyword Method while getting Data");
769
					logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsAdKeyword Method while getting Data", e);
770
				}
771
 
772
				if(adkeyword!=null){
773
					if(keywordUpdate!=null && !("").equalsIgnoreCase(keywordUpdate)){
774
						if(!adkeyword.getText().equalsIgnoreCase(keywordUpdate)){
775
							adkeyword.setText(keywordUpdate);
776
							text = keywordUpdate;
777
						}
778
					}
779
					if(bidUpdate!=null && !("").equalsIgnoreCase(bidUpdate)){
780
						if(adkeyword.getBidAmount()!=Double.parseDouble(bidUpdate)){
781
							adkeyword.setBidAmount(Double.parseDouble(bidUpdate));
782
							bidAmount = (long) (Double.parseDouble(bidUpdate) * Math.pow(10, 6));
783
						}
784
					}
785
					if(!adkeyword.getMatchType().toString().equalsIgnoreCase(KeywordMatchType.valueOf(matchTypeUpdate).toString())){
786
						adkeyword.setMatchType(KeywordMatchType.valueOf(matchTypeUpdate));
787
						type = KeywordMatchType.valueOf(matchTypeUpdate).toString();
788
					}
789
 
790
					Long updatedCriterionId = 0l;
791
					try {
792
						updatedCriterionId = UpdateKeyword.runExample(Long.parseLong(adgroupListUpdate2), Long.parseLong(keywordListUpdate1), text, bidAmount, type);
793
					} catch (NumberFormatException e) {
794
						addActionError("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2+ "(Google End)..");
795
						logger.error("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2+ "(Google End)..", e);
796
					} catch (Exception e) {
797
						addActionError("AdGroup Crierion Service Mutate Operation Exception ");
798
						logger.error("Error while AdGroup Crierion Service Mutate Operation", e);
799
					}
800
 
801
					if(updatedCriterionId>0l){
802
						adkeyword.setCriterionId(updatedCriterionId);
803
						try {
804
							client.updateAdwordsAdKeyword(adkeyword);
805
							return true;
806
						} catch (GoogleAdwordsServiceException e) {
807
							addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsAdKeyword Method while updating Data");
808
							logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsAdKeyword Method while updating Data", e); 
809
						} catch (TException e) {
810
							addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsAdKeyword Method while updating Data");
811
							logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsAdKeyword Method while updating Data", e);
812
						}
813
					}
814
					else{
815
						addActionError("Error while processing Update Request for Google AdGroupCriterion Service");
816
					}
817
 
818
				}
819
 
820
			}
821
		}
822
		return false;
823
	}
824
 
9067 manish.sha 825
	@Override
826
	public void setServletRequest(HttpServletRequest request) {
827
		this.request = request;
828
		this.session = request.getSession();
829
	}
830
 
831
	public String getCampaignId() {
832
		return campaignId;
833
	}
834
 
835
	public void setCampaignId(String campaignId) {
836
		this.campaignId = campaignId;
837
	}
838
 
839
	public String getErrorMsg(){
840
		return this.errorMsg;
841
	}
842
 
843
	public String getSuccessMessage(){
844
		return this.successmsg ;
845
	}
846
 
847
	public JSONObject getJsonData() {
848
		return jsonData;
849
	}
850
 
851
	public void setJsonData(JSONObject jsonData) {
852
		this.jsonData = jsonData;
853
	}
9230 manish.sha 854
 
855
	public JSONObject getJsonCampaignData() {
856
		return jsonCampaignData;
857
	}
9067 manish.sha 858
 
9230 manish.sha 859
	public void setJsonCampaignData(JSONObject jsonCampaignData) {
860
		this.jsonCampaignData = jsonCampaignData;
861
	}
862
 
863
	public JSONObject getJsonAdgroupData() {
864
		return jsonAdgroupData;
865
	}
866
 
867
	public void setJsonAdgroupData(JSONObject jsonAdgroupData) {
868
		this.jsonAdgroupData = jsonAdgroupData;
869
	}
870
 
871
	public String getKeywordId() {
872
		return keywordId;
873
	}
874
 
875
	public void setKeywordId(String keywordId) {
876
		this.keywordId = keywordId;
877
	}
878
 
879
	public String getAdgroupId() {
880
		return adgroupId;
881
	}
882
 
883
	public void setAdgroupId(String adgroupId) {
884
		this.adgroupId = adgroupId;
885
	}
886
 
887
	public JSONObject getJsonKeywordList() {
888
		return jsonKeywordList;
889
	}
890
 
891
	public void setJsonKeywordList(JSONObject jsonKeywordList) {
892
		this.jsonKeywordList = jsonKeywordList;
893
	}
894
 
895
	public JSONObject getJsonKeywordData() {
896
		return jsonKeywordData;
897
	}
898
 
899
	public void setJsonKeywordData(JSONObject jsonKeywordData) {
900
		this.jsonKeywordData = jsonKeywordData;
901
	}
902
 
903
	public String getTextAdItemPrice(){
904
		String itemPrice = "";
905
		List<Item> itemList = new ArrayList<Item>();
906
		try {
907
			itemList = new CatalogClient().getClient().getItemsByCatalogId(Long.parseLong(catalogItemId));
908
		} catch (NumberFormatException e) {
909
			e.printStackTrace();
910
		} catch (TTransportException e) {
911
			e.printStackTrace();
912
		} catch (CatalogServiceException e) {
913
			e.printStackTrace();
914
		} catch (TException e) {
915
			e.printStackTrace();
916
		}
917
 
918
		for(Item item : itemList){
919
			if(status.ACTIVE==item.getItemStatus()){
920
				itemPrice = ((long)item.getSellingPrice()) + "";
921
				break;
922
			}
923
		}
924
 
925
		return itemPrice;
926
	}
9067 manish.sha 927
	public String getAdgroupList(){
928
		List<Map<String,String>> adgroupDataList = new ArrayList<Map<String,String>>();
929
		Map<String, List<Map<String,String>>> mainMap = new HashMap<String, List<Map<String,String>>>();
930
		List<AdwordsAdGroup> adgroupList =null;
931
		try {
932
			adgroupList = new AdwordsClient().getClient().getAdwordsAdGroupsByCampaignId(Long.parseLong(campaignId));
933
		} catch (TTransportException e) {
934
			e.printStackTrace();
935
		} catch (GoogleAdwordsServiceException e) {
936
			e.printStackTrace();
937
		} catch (TException e) {
938
			e.printStackTrace();
939
		}
940
		for(int i=0 ; i<adgroupList.size() ; i++){
941
			AdwordsAdGroup adgroup = adgroupList.get(i);
942
			Map<String,String> adgroupDataMap = new HashMap<String,String>();
943
			adgroupDataMap.put("AdgroupId",adgroup.getAdgroupId()+"");
944
			adgroupDataMap.put("Name", adgroup.getName());
945
			adgroupDataList.add(adgroupDataMap);
946
		}
947
		mainMap.put("AdGroupData", adgroupDataList);
948
		jsonData = new JSONObject(mainMap);
949
		return "output";
950
	}
9230 manish.sha 951
 
952
	public String getKeywordList(){
953
		List<Map<String,String>> adkeywordDataList = new ArrayList<Map<String,String>>();
954
		Map<String, List<Map<String,String>>> mainMap = new HashMap<String, List<Map<String,String>>>();
955
		List<AdwordsAdKeyword> adkeywordList = null;
956
		try {
957
			adkeywordList = new AdwordsClient().getClient().getAdwordsAdKeywordsByAdgroupId(Long.parseLong(adgroupId));
958
		}
959
		catch (TTransportException e) {
960
			e.printStackTrace();
961
		} catch (GoogleAdwordsServiceException e) {
962
			e.printStackTrace();
963
		} catch (TException e) {
964
			e.printStackTrace();
965
		}
966
 
967
		for(AdwordsAdKeyword adkeyword : adkeywordList){
968
			Map<String,String> adkeywordDataMap = new HashMap<String,String>();
969
			adkeywordDataMap.put("KeywordId", adkeyword.getCriterionId()+"");
970
			adkeywordDataMap.put("Text", adkeyword.getText());
971
			adkeywordDataList.add(adkeywordDataMap);
972
		}
973
		mainMap.put("AdKeywordData", adkeywordDataList);
974
		jsonKeywordList = new JSONObject(mainMap);
975
		return "output";
976
	}
977
 
978
	public String getCampaignDetails(){
979
		Map<String, String> campaignUnitDataMap = new HashMap<String, String>();
980
		AdwordsCampaign campaign = null;
981
		try {
982
			campaign = new AdwordsClient().getClient().getAdwordsCampaignByCampaignId(Long.parseLong(campaignId));
983
		} catch (NumberFormatException e) {
984
			e.printStackTrace();
985
		} catch (TTransportException e) {
986
			e.printStackTrace();
987
		} catch (GoogleAdwordsServiceException e) {
988
			e.printStackTrace();
989
		} catch (TException e) {
990
			e.printStackTrace();
991
		}
992
 
993
		if(campaign!=null){
994
			campaignUnitDataMap.put("Name", campaign.getName());
995
			campaignUnitDataMap.put("BudgetAmount", campaign.getBudgetAmount()+"");
996
			campaignUnitDataMap.put("Status", campaign.getStatus().getValue()+"");
997
		}
998
		jsonCampaignData = new JSONObject(campaignUnitDataMap);
999
		return "output";
1000
	}
1001
 
1002
	public String getAdGroupDetails(){
1003
		Map<String, String> adgroupUnitDataMap = new HashMap<String, String>();
1004
		AdwordsAdGroup adGroup = null;
1005
		try {
1006
			adGroup = new AdwordsClient().getClient().getAdwordsAdGroupByAdGroupId(Long.parseLong(adgroupId));
1007
		} catch (NumberFormatException e) {
1008
			e.printStackTrace();
1009
		} catch (TTransportException e) {
1010
			e.printStackTrace();
1011
		} catch (GoogleAdwordsServiceException e) {
1012
			e.printStackTrace();
1013
		} catch (TException e) {
1014
			e.printStackTrace();
1015
		}
1016
 
1017
		if(adGroup!=null){
1018
			adgroupUnitDataMap.put("Name", adGroup.getName());
1019
			adgroupUnitDataMap.put("BidAmount", adGroup.getBidAmount()+"");
1020
			adgroupUnitDataMap.put("Status", adGroup.getStatus().getValue()+"");
1021
			adgroupUnitDataMap.put("CatalogItemId", adGroup.getCatalogItemId()+"");
1022
		}
1023
		jsonAdgroupData = new JSONObject(adgroupUnitDataMap);
1024
		return "output";
1025
	}
1026
 
1027
	public String getKeywordDetails(){
1028
		Map<String, String> adkeywordUnitDataMap = new HashMap<String, String>();
1029
		AdwordsAdKeyword adKeyword = null;
1030
		try {
1031
			System.out.println("keywordId" +keywordId);
1032
			System.out.println("adgroupId" +adgroupId);
1033
			adKeyword = new AdwordsClient().getClient().getAdwordsAdKeywordByCriterionIdAndAdGroupId(Long.parseLong(keywordId), Long.parseLong(adgroupId));
1034
		} catch (NumberFormatException e) {
1035
			e.printStackTrace();
1036
		} catch (TTransportException e) {
1037
			e.printStackTrace();
1038
		} catch (GoogleAdwordsServiceException e) {
1039
			e.printStackTrace();
1040
		} catch (TException e) {
1041
			e.printStackTrace();
1042
		}
1043
 
1044
		if(adKeyword!=null){
1045
			adkeywordUnitDataMap.put("Text", adKeyword.getText());
1046
			adkeywordUnitDataMap.put("Bid", adKeyword.getBidAmount()+"");
1047
			adkeywordUnitDataMap.put("MatchType", adKeyword.getMatchType().getValue()+"");
1048
		}
1049
		jsonKeywordData = new JSONObject(adkeywordUnitDataMap);
1050
		return "output";
1051
	}
9067 manish.sha 1052
 
1053
	public List<AdwordsCampaign> getCampaigns(){
1054
		List<AdwordsCampaign> campaignList =null;
1055
		try {
1056
			campaignList = new AdwordsClient().getClient().getAllAdwordsCampaigns();
1057
		} catch (TTransportException e) {
1058
			e.printStackTrace();
1059
		} catch (GoogleAdwordsServiceException e) {
1060
			e.printStackTrace();
1061
		} catch (TException e) {
1062
			e.printStackTrace();
1063
		}
1064
		return campaignList;
1065
	}
1066
 
1067
	private boolean checkForErrors(){
1068
		Collection<String> actionErrors = getActionErrors();
1069
		if(actionErrors != null && !actionErrors.isEmpty()){
1070
			for (String str : actionErrors) {
1071
				errorMsg += "<BR/>" + str;
1072
			}
1073
			return true;
1074
		}
1075
		return false;
1076
	}
1077
 
1078
	public String getAdwordOpRadio() {
1079
		return adwordOpRadio;
1080
	}
1081
 
1082
	public void setAdwordOpRadio(String adwordOpRadio) {
1083
		this.adwordOpRadio = adwordOpRadio;
1084
	}
1085
 
1086
	public String getAdwordAddRadio() {
1087
		return adwordAddRadio;
1088
	}
1089
 
1090
	public void setAdwordAddRadio(String adwordAddRadio) {
1091
		this.adwordAddRadio = adwordAddRadio;
1092
	}
1093
 
1094
	public String getCampaignName() {
1095
		return campaignName;
1096
	}
1097
 
1098
	public void setCampaignName(String campaignName) {
1099
		this.campaignName = campaignName;
1100
	}
1101
 
1102
	public String getCampaignStatus() {
1103
		return campaignStatus;
1104
	}
1105
 
1106
	public void setCampaignStatus(String campaignStatus) {
1107
		this.campaignStatus = campaignStatus;
1108
	}
1109
 
1110
	public String getStartDate() {
1111
		return startDate;
1112
	}
1113
 
1114
	public void setStartDate(String startDate) {
1115
		this.startDate = startDate;
1116
	}
1117
 
1118
	public String getEndDate() {
1119
		return endDate;
1120
	}
1121
 
1122
	public void setEndDate(String endDate) {
1123
		this.endDate = endDate;
1124
	}
1125
 
1126
	public String getCampaignAmount() {
1127
		return campaignAmount;
1128
	}
1129
 
1130
	public void setCampaignAmount(String campaignAmount) {
1131
		this.campaignAmount = campaignAmount;
1132
	}
1133
 
1134
	public String getGoogleSearchNetwork() {
1135
		return googleSearchNetwork;
1136
	}
1137
 
1138
	public void setGoogleSearchNetwork(String googleSearchNetwork) {
1139
		this.googleSearchNetwork = googleSearchNetwork;
1140
	}
1141
 
1142
	public String getDisplayNetwork() {
1143
		return displayNetwork;
1144
	}
1145
 
1146
	public void setDisplayNetwork(String displayNetwork) {
1147
		this.displayNetwork = displayNetwork;
1148
	}
1149
 
1150
	public String getPartnerSearchNetwork() {
1151
		return partnerSearchNetwork;
1152
	}
1153
 
1154
	public void setPartnerSearchNetwork(String partnerSearchNetwork) {
1155
		this.partnerSearchNetwork = partnerSearchNetwork;
1156
	}
1157
 
1158
	public String getCampaignList1() {
1159
		return campaignList1;
1160
	}
1161
 
1162
	public void setCampaignList1(String campaignList1) {
1163
		this.campaignList1 = campaignList1;
1164
	}
1165
 
1166
	public String getAdgroupName() {
1167
		return adgroupName;
1168
	}
1169
 
1170
	public void setAdgroupName(String adgroupName) {
1171
		this.adgroupName = adgroupName;
1172
	}
1173
 
1174
	public String getAdgroupStatus() {
1175
		return adgroupStatus;
1176
	}
1177
 
1178
	public void setAdgroupStatus(String adgroupStatus) {
1179
		this.adgroupStatus = adgroupStatus;
1180
	}
1181
 
1182
	public String getCatalogItemId() {
1183
		return catalogItemId;
1184
	}
1185
 
1186
	public void setCatalogItemId(String catalogItemId) {
1187
		this.catalogItemId = catalogItemId;
1188
	}
1189
 
1190
	public String getBidAmount() {
1191
		return bidAmount;
1192
	}
1193
 
1194
	public void setBidAmount(String bidAmount) {
1195
		this.bidAmount = bidAmount;
1196
	}
1197
 
1198
	public String getCampaignList2() {
1199
		return campaignList2;
1200
	}
1201
 
1202
	public void setCampaignList2(String campaignList2) {
1203
		this.campaignList2 = campaignList2;
1204
	}
1205
 
1206
	public String getAdgroupList1() {
1207
		return adgroupList1;
1208
	}
1209
 
1210
	public void setAdgroupList1(String adgroupList1) {
1211
		this.adgroupList1 = adgroupList1;
1212
	}
1213
 
1214
	public String getHeadline() {
1215
		return headline;
1216
	}
1217
 
1218
	public void setHeadline(String headline) {
1219
		this.headline = headline;
1220
	}
1221
 
1222
	public String getDescription1() {
1223
		return description1;
1224
	}
1225
 
1226
	public void setDescription1(String description1) {
1227
		this.description1 = description1;
1228
	}
1229
 
1230
	public String getDescription2() {
1231
		return description2;
1232
	}
1233
 
1234
	public void setDescription2(String description2) {
1235
		this.description2 = description2;
1236
	}
1237
 
1238
	public String getUrl() {
1239
		return url;
1240
	}
1241
 
1242
	public void setUrl(String url) {
1243
		this.url = url;
1244
	}
1245
 
1246
	public String getDisplayUrl() {
1247
		return displayUrl;
1248
	}
1249
 
1250
	public void setDisplayUrl(String displayUrl) {
1251
		this.displayUrl = displayUrl;
1252
	}
1253
 
1254
	public String getCampaignList3() {
1255
		return campaignList3;
1256
	}
1257
 
1258
	public void setCampaignList3(String campaignList3) {
1259
		this.campaignList3 = campaignList3;
1260
	}
1261
 
1262
	public String getAdgroupList2() {
1263
		return adgroupList2;
1264
	}
1265
 
1266
	public void setAdgroupList2(String adgroupList2) {
1267
		this.adgroupList2 = adgroupList2;
1268
	}
1269
 
1270
	public String getKeyword1() {
1271
		return keyword1;
1272
	}
1273
 
1274
	public void setKeyword1(String keyword1) {
1275
		this.keyword1 = keyword1;
1276
	}
1277
 
1278
	public String getKeyword2() {
1279
		return keyword2;
1280
	}
1281
 
1282
	public void setKeyword2(String keyword2) {
1283
		this.keyword2 = keyword2;
1284
	}
1285
 
1286
	public String getKeyword3() {
1287
		return keyword3;
1288
	}
1289
 
1290
	public void setKeyword3(String keyword3) {
1291
		this.keyword3 = keyword3;
1292
	}
1293
 
1294
	public String getKeyword4() {
1295
		return keyword4;
1296
	}
1297
 
1298
	public void setKeyword4(String keyword4) {
1299
		this.keyword4 = keyword4;
1300
	}
1301
 
1302
	public String getKeyword5() {
1303
		return keyword5;
1304
	}
1305
 
1306
	public void setKeyword5(String keyword5) {
1307
		this.keyword5 = keyword5;
1308
	}
1309
 
1310
	public String getBid1() {
1311
		return bid1;
1312
	}
1313
 
1314
	public void setBid1(String bid1) {
1315
		this.bid1 = bid1;
1316
	}
1317
 
1318
	public String getBid2() {
1319
		return bid2;
1320
	}
1321
 
1322
	public void setBid2(String bid2) {
1323
		this.bid2 = bid2;
1324
	}
1325
 
1326
	public String getBid3() {
1327
		return bid3;
1328
	}
1329
 
1330
	public void setBid3(String bid3) {
1331
		this.bid3 = bid3;
1332
	}
1333
 
1334
	public String getBid4() {
1335
		return bid4;
1336
	}
1337
 
1338
	public void setBid4(String bid4) {
1339
		this.bid4 = bid4;
1340
	}
1341
 
1342
	public String getBid5() {
1343
		return bid5;
1344
	}
1345
 
1346
	public void setBid5(String bid5) {
1347
		this.bid5 = bid5;
1348
	}
1349
 
1350
	public String getMatchType1() {
1351
		return matchType1;
1352
	}
1353
 
1354
	public void setMatchType1(String matchType1) {
1355
		this.matchType1 = matchType1;
1356
	}
1357
 
1358
	public String getMatchType2() {
1359
		return matchType2;
1360
	}
1361
 
1362
	public void setMatchType2(String matchType2) {
1363
		this.matchType2 = matchType2;
1364
	}
1365
 
1366
	public String getMatchType3() {
1367
		return matchType3;
1368
	}
1369
 
1370
	public void setMatchType3(String matchType3) {
1371
		this.matchType3 = matchType3;
1372
	}
1373
 
1374
	public String getMatchType4() {
1375
		return matchType4;
1376
	}
1377
 
1378
	public void setMatchType4(String matchType4) {
1379
		this.matchType4 = matchType4;
1380
	}
1381
 
1382
	public String getMatchType5() {
1383
		return matchType5;
1384
	}
1385
 
1386
	public void setMatchType5(String matchType5) {
1387
		this.matchType5 = matchType5;
1388
	}
1389
 
1390
	public String getStockLinked() {
1391
		return stockLinked;
1392
	}
1393
 
1394
	public void setStockLinked(String stockLinked) {
1395
		this.stockLinked = stockLinked;
1396
	}
1397
 
9230 manish.sha 1398
	public String getAdwordUpdateRadio() {
1399
		return adwordUpdateRadio;
1400
	}
1401
 
1402
	public void setAdwordUpdateRadio(String adwordUpdateRadio) {
1403
		this.adwordUpdateRadio = adwordUpdateRadio;
1404
	}
1405
 
1406
	public String getCampaignListUpdate1() {
1407
		return campaignListUpdate1;
1408
	}
1409
 
1410
	public void setCampaignListUpdate1(String campaignListUpdate1) {
1411
		this.campaignListUpdate1 = campaignListUpdate1;
1412
	}
1413
 
1414
	public String getCampaignNameUpdate() {
1415
		return campaignNameUpdate;
1416
	}
1417
 
1418
	public void setCampaignNameUpdate(String campaignNameUpdate) {
1419
		this.campaignNameUpdate = campaignNameUpdate;
1420
	}
1421
 
1422
	public String getCampaignStatusUpdate() {
1423
		return campaignStatusUpdate;
1424
	}
1425
 
1426
	public void setCampaignStatusUpdate(String campaignStatusUpdate) {
1427
		this.campaignStatusUpdate = campaignStatusUpdate;
1428
	}
1429
 
1430
	public String getCampaignAmountUpdate() {
1431
		return campaignAmountUpdate;
1432
	}
1433
 
1434
	public void setCampaignAmountUpdate(String campaignAmountUpdate) {
1435
		this.campaignAmountUpdate = campaignAmountUpdate;
1436
	}
1437
 
1438
	public String getCampaignListUpdate2() {
1439
		return campaignListUpdate2;
1440
	}
1441
 
1442
	public void setCampaignListUpdate2(String campaignListUpdate2) {
1443
		this.campaignListUpdate2 = campaignListUpdate2;
1444
	}
1445
 
1446
	public String getAdgroupListUpdate1() {
1447
		return adgroupListUpdate1;
1448
	}
1449
 
1450
	public void setAdgroupListUpdate1(String adgroupListUpdate1) {
1451
		this.adgroupListUpdate1 = adgroupListUpdate1;
1452
	}
1453
 
1454
	public String getAdgroupNameUpdate() {
1455
		return adgroupNameUpdate;
1456
	}
1457
 
1458
	public void setAdgroupNameUpdate(String adgroupNameUpdate) {
1459
		this.adgroupNameUpdate = adgroupNameUpdate;
1460
	}
1461
 
1462
	public String getAdgroupStatusUpdate() {
1463
		return adgroupStatusUpdate;
1464
	}
1465
 
1466
	public void setAdgroupStatusUpdate(String adgroupStatusUpdate) {
1467
		this.adgroupStatusUpdate = adgroupStatusUpdate;
1468
	}
1469
 
1470
	public String getCatalogItemIdUpdate() {
1471
		return catalogItemIdUpdate;
1472
	}
1473
 
1474
	public void setCatalogItemIdUpdate(String catalogItemIdUpdate) {
1475
		this.catalogItemIdUpdate = catalogItemIdUpdate;
1476
	}
1477
 
1478
	public String getBidAmountUpdate() {
1479
		return bidAmountUpdate;
1480
	}
1481
 
1482
	public void setBidAmountUpdate(String bidAmountUpdate) {
1483
		this.bidAmountUpdate = bidAmountUpdate;
1484
	}
1485
 
1486
	public String getCampaignListUpdate3() {
1487
		return campaignListUpdate3;
1488
	}
1489
 
1490
	public void setCampaignListUpdate3(String campaignListUpdate3) {
1491
		this.campaignListUpdate3 = campaignListUpdate3;
1492
	}
1493
 
1494
	public String getAdgroupListUpdate2() {
1495
		return adgroupListUpdate2;
1496
	}
1497
 
1498
	public void setAdgroupListUpdate2(String adgroupListUpdate2) {
1499
		this.adgroupListUpdate2 = adgroupListUpdate2;
1500
	}
1501
 
1502
	public String getKeywordUpdate() {
1503
		return keywordUpdate;
1504
	}
1505
 
1506
	public void setKeywordUpdate(String keywordUpdate) {
1507
		this.keywordUpdate = keywordUpdate;
1508
	}
1509
 
1510
	public String getBidUpdate() {
1511
		return bidUpdate;
1512
	}
1513
 
1514
	public void setBidUpdate(String bidUpdate) {
1515
		this.bidUpdate = bidUpdate;
1516
	}
1517
 
1518
	public String getMatchTypeUpdate() {
1519
		return matchTypeUpdate;
1520
	}
1521
 
1522
	public void setMatchTypeUpdate(String matchTypeUpdate) {
1523
		this.matchTypeUpdate = matchTypeUpdate;
1524
	}
1525
 
1526
	public String getKeywordListUpdate1() {
1527
		return keywordListUpdate1;
1528
	}
1529
 
1530
	public void setKeywordListUpdate1(String keywordListUpdate1) {
1531
		this.keywordListUpdate1 = keywordListUpdate1;
1532
	}
1533
 
9067 manish.sha 1534
}