Subversion Repositories SmartDukaan

Rev

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