Subversion Repositories SmartDukaan

Rev

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