Subversion Repositories SmartDukaan

Rev

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