Subversion Repositories SmartDukaan

Rev

Rev 9461 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.support.controllers;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import in.shop2020.googleadwords.AdwordsAdGroup;
import in.shop2020.googleadwords.AdwordsAdGroupAd;
import in.shop2020.googleadwords.AdwordsAdGroupStatus;
import in.shop2020.googleadwords.AdwordsAdKeyword;
import in.shop2020.googleadwords.AdwordsCampaign;
import in.shop2020.googleadwords.AdwordsCampaignStatus;
import in.shop2020.googleadwords.GoogleAdwordsService.Client;
import in.shop2020.googleadwords.GoogleAdwordsServiceException;
import in.shop2020.googleadwords.KeywordMatchType;
import in.shop2020.googleadwords.NetworkSettingType;
import in.shop2020.model.v1.catalog.CatalogServiceException;
import in.shop2020.model.v1.catalog.Item;
import in.shop2020.model.v1.catalog.status;
import in.shop2020.support.utils.ReportsUtils;
import in.shop2020.thrift.clients.AdwordsClient;
import in.shop2020.thrift.clients.CatalogClient;
import in.shop2020.thrift.clients.LogisticsClient;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.util.ServletContextAware;
import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransportException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import adwords.axis.v201309.basicoperations.UpdateKeyword;
import adwords.axis.v201309.basicoperations.AddAdGroups;
import adwords.axis.v201309.basicoperations.AddCampaigns;
import adwords.axis.v201309.basicoperations.AddKeywords;
import adwords.axis.v201309.basicoperations.AddTextAds;
import adwords.axis.v201309.basicoperations.UpdateAdGroup;
import adwords.axis.v201309.basicoperations.UpdateCampaign;

import com.opensymphony.xwork2.ActionSupport;

@InterceptorRefs({
    @InterceptorRef("defaultStack"),
    @InterceptorRef("login")
})

@Results({
    @Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"}),
        @Result(name="redirect", type="redirectAction", location = "google-adwords",  params={"statusCode", "301"})
})
public class GoogleAdwordsController extends ActionSupport implements ServletRequestAware {
        /**
         * 
         */
        private static Logger logger = LoggerFactory.getLogger(GoogleAdwordsController.class);
        private static final long serialVersionUID = 5703456181320066690L;
        private HttpServletRequest request;
        private HttpSession session;
        private ServletContext context;
        
        private String errorMsg = "";
        private String successmsg = "";
        private String campaignId = "";
        private String adgroupId = "";
        private String keywordId = "";
        private JSONObject jsonData = null;
        private JSONObject jsonCampaignData = null;
        private JSONObject jsonAdgroupData = null;
        private JSONObject jsonKeywordList = null;
        private JSONObject jsonKeywordData = null;
        private JSONObject jsonCampaignList = null;
        
        private AdwordsCampaignStatus campStatus;
        private AdwordsAdGroupStatus adgrpStatus;
        private KeywordMatchType keywordMatchType1;
        private KeywordMatchType keywordMatchType2;
        private KeywordMatchType keywordMatchType3;
        private KeywordMatchType keywordMatchType4;
        private KeywordMatchType keywordMatchType5;
        
        private NetworkSettingType networkSettingType;

        private boolean googlesearchNetwork = false;
        private boolean displaynetwork = false;
        private boolean partnersearchNetwork = false;
        private int stocklinked = 0;
        private int stocklinkedUpdate = 0;

        private String adwordOpRadio;
        private String adwordAddRadio;
        private String campaignName;
        private String campaignStatus;
        private String startDate;
        private String endDate;
        private String campaignAmount;
        private String googleSearchNetwork;
        private String displayNetwork;
        private String partnerSearchNetwork;
        private String campaignList1;
        private String adgroupName;
        private String adgroupStatus;
        private String catalogItemId;
        private String bidAmount;
        private String stockLinked;
        private String campaignList2;
        private String adgroupList1;
        private String headline;
        private String description1;
        private String description2;
        private String url;
        private String displayUrl;
        private String campaignList3;
        private String adgroupList2;
        private String keyword1;
        private String keyword2;
        private String keyword3;
        private String keyword4;
        private String keyword5;
        private String bid1;
        private String bid2;
        private String bid3;
        private String bid4;
        private String bid5;
        private String matchType1;
        private String matchType2;
        private String matchType3;
        private String matchType4;
        private String matchType5;
        
        private String adwordUpdateRadio;
        private String campaignListUpdate1;
        private String campaignNameUpdate;
        private String campaignStatusUpdate;
        private String campaignAmountUpdate;
        private String campaignListUpdate2;
        private String adgroupListUpdate1;
        private String adgroupNameUpdate;
        private String adgroupStatusUpdate;
        private String catalogItemIdUpdate;
        private String bidAmountUpdate;
        private String stockLinkedUpdate;
        private String campaignListUpdate3;
        private String adgroupListUpdate2;
        private String keywordListUpdate1;
        private String keywordUpdate;
        private String bidUpdate;
        private String matchTypeUpdate;
                

        public String index() {
                if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath()))
                        return "authfail";
                checkForErrors();
                return "index";
        }

        public String create(){
                if(adwordOpRadio!=null && ("addOpRadio").equalsIgnoreCase(adwordOpRadio)){
                        if(adwordAddRadio!=null && ("campaignRdo").equalsIgnoreCase(adwordAddRadio)){
                                processCampaignStatus();
                                SimpleDateFormat timestmapFormatForGoogle = new SimpleDateFormat("yyyyMMdd");
                                String startdateStr = timestmapFormatForGoogle.format(new Date().getTime());
                                String enddateStr = "20371230";
                                if(startDate!=null && !startDate.isEmpty()){
                                        startdateStr = processedStartEndDate(startDate, timestmapFormatForGoogle);
                                }
                                if(endDate!=null && !endDate.isEmpty()){
                                         enddateStr = processedStartEndDate(endDate, timestmapFormatForGoogle);
                                }
                                processNetworkSetting();
                                Long budgetAmount = new Long(Long.parseLong(campaignAmount));
                                boolean addCampaignResult = addAdwordsCampaign(campaignName, startdateStr, enddateStr, (long)(budgetAmount * Math.pow(10, 6)), campStatus.toString(), googlesearchNetwork, displaynetwork, partnersearchNetwork, networkSettingType);
                                if(addCampaignResult){
                                        successmsg = "Adwords Campaign Added Successfully";
                                }
                        }
                        if(adwordAddRadio!=null && ("adgroupRdo").equalsIgnoreCase(adwordAddRadio)){
                                processAdGroupStatus();
                                if(catalogItemId==null || ("").equalsIgnoreCase(catalogItemId)){
                                        catalogItemId="0";
                                }
                                processStockLinked();
                                boolean addAdGroupResult = addAdwordsAdGroup(Long.parseLong(campaignList1), adgroupName, adgrpStatus.toString(), (long)(Double.parseDouble(bidAmount) * Math.pow(10, 6)), Long.parseLong(catalogItemId));
                                if(addAdGroupResult){
                                        successmsg = "Adwords AdGroup Added Successfully";
                                }
                        }
                        if(adwordAddRadio!=null && ("textAdRdo").equalsIgnoreCase(adwordAddRadio)){
                                boolean addAdgroupAdResult = addAdwordsAdGroupAd();
                                if(addAdgroupAdResult){
                                        successmsg = "Adwords AdGroup Text Ad Added Successfully";
                                }
                        }
                        if(adwordAddRadio!=null && ("keywordRdo").equalsIgnoreCase(adwordAddRadio)){
                                AdwordsAdGroup adgroup = getAdwordsAdgroup(Long.parseLong(adgroupList2));
                                List<Map<String, String>> keywordDataList = new ArrayList<Map<String, String>>();
                                if(keyword1 != null && !keyword1.isEmpty()){
                                        keywordMatchType1 = processAdKeywordMatchType(matchType1);
                                        if(bid1!=null && !bid1.isEmpty()){
                                                keywordDataList.add(getKeywordMap(keyword1,bid1,keywordMatchType1.toString()));
                                        }
                                        else{
                                                keywordDataList.add(getKeywordMap(keyword1,adgroup.getBidAmount()+"",keywordMatchType1.toString()));
                                        }
                                }
                                if(keyword2 != null && !keyword2.isEmpty()){
                                        keywordMatchType2 = processAdKeywordMatchType(matchType2);
                                        if(bid2!=null && !bid2.isEmpty()){
                                                keywordDataList.add(getKeywordMap(keyword2,bid2,keywordMatchType2.toString()));
                                        }
                                        else{
                                                keywordDataList.add(getKeywordMap(keyword2,adgroup.getBidAmount()+"",keywordMatchType2.toString()));
                                        }
                                }
                                if(keyword3 != null && !keyword3.isEmpty()){
                                        keywordMatchType3 = processAdKeywordMatchType(matchType3);
                                        if(bid3!=null && !bid3.isEmpty()){
                                                keywordDataList.add(getKeywordMap(keyword3,bid3,keywordMatchType3.toString()));
                                        }
                                        else{
                                                keywordDataList.add(getKeywordMap(keyword3,adgroup.getBidAmount()+"",keywordMatchType3.toString()));
                                        }
                                }
                                if(keyword4 != null && !keyword4.isEmpty()){
                                        keywordMatchType4 = processAdKeywordMatchType(matchType4);
                                        if(bid4!=null && !bid4.isEmpty()){
                                                keywordDataList.add(getKeywordMap(keyword4,bid4,keywordMatchType4.toString()));
                                        }
                                        else{
                                                keywordDataList.add(getKeywordMap(keyword4,adgroup.getBidAmount()+"",keywordMatchType4.toString()));
                                        }
                                }
                                if(keyword5 != null && !keyword5.isEmpty()){
                                        keywordMatchType5 = processAdKeywordMatchType(matchType5);
                                        if(bid5!=null && !bid5.isEmpty()){
                                                keywordDataList.add(getKeywordMap(keyword5,bid5,keywordMatchType5.toString()));
                                        }
                                        else{
                                                keywordDataList.add(getKeywordMap(keyword5,adgroup.getBidAmount()+"",keywordMatchType5.toString()));
                                        }
                                }
                                boolean addAdKeywordResult = addAdwordsAdKeyword(keywordDataList);
                                if(addAdKeywordResult){
                                        successmsg = "Adwords AdGroup Ad Keyword Added Successfully";
                                }
                        }
                }
                if(adwordOpRadio!=null && ("updateOpRadio").equalsIgnoreCase(adwordOpRadio)){
                        if(adwordUpdateRadio!=null && ("campaignRdoUpdate").equalsIgnoreCase(adwordUpdateRadio)){
                                boolean updateCamapaignResult = updateAdwordsCampaign();
                                if(updateCamapaignResult){
                                        successmsg = "Adwords Campaign Updated Successfully";
                                }
                        }
                        if(adwordUpdateRadio!=null && ("adgroupRdoUpdate").equalsIgnoreCase(adwordUpdateRadio)){
                                processStockLinkedUpdate();
                                boolean updateAdGroupResult = updateAdwordsAdGroup();
                                if(updateAdGroupResult){
                                        successmsg = "Adwords AdGroup Updated Successfully";
                                }
                        }
                        if(adwordUpdateRadio!=null && ("keywordRdoUpdate").equalsIgnoreCase(adwordUpdateRadio)){
                                boolean updateKeywordResult = updateAdwordsAdKeyword();
                                if(updateKeywordResult){
                                        successmsg = "Adwords AdKeyword Updated Successfully";
                                }
                        }
                }

                return index();
        }
        
        /*public String sendProductFeeds(){
                //boolean sendFeedsResult = false;
                Product insertedProduct = null;
                if(cataLogItemId!=null && !("").equalsIgnoreCase(cataLogItemId)){
                        List<Long> itemIdList = getEntityLogisticsEstimation(Long.parseLong(cataLogItemId));
                        UserInformation userInformation = new UserInformation("8587366",
                                        "http://www.saholic.com",
                                        "adwords@shop2020.in", "adwords_shop2020");
                        ContentFeedsHandler sample = new ContentFeedsHandler(userInformation,
                                        "https://content.googleapis.com/content/v1/");
                        if(itemIdList!=null && itemIdList.size()>0){
                                try {
                                        Item item = new CatalogClient().getClient().getItem(itemIdList.get(0));
                                        insertedProduct = sample.sendProductFeed(item);
                                } catch (IOException e) {
                                        e.printStackTrace();
                                } catch (TTransportException e) {
                                        e.printStackTrace();
                                } catch (CatalogServiceException e) {
                                        e.printStackTrace();
                                } catch (TException e) {
                                        e.printStackTrace();
                                }
                        }
                        else{
                                sentFeedResult = "Error: There is No Product avaliable for given Catalog Item Id.";
                                return "output";
                        }
                }
                if(insertedProduct!=null){
                        if(insertedProduct.content!=null && insertedProduct.content.value.indexOf("Error:")>-1){
                                sentFeedResult = insertedProduct.content.value;
                                return "output";
                        }
                        sentFeedResult = "Product Feeds are sent Successfully and Product Details are Given Below:\nProduct Id- "
                                +insertedProduct.externalId+" Product Title- "+insertedProduct.title;
                        return "output";
                }
                else{
                        sentFeedResult = "Some Error occured while sending feeds. Please contact concerned Team";
                        return "output";
                }
                if(sendFeedsResult){
                        successmsg = "Product Feeds are sent Successfully";
                        return index();
                }
                else{
                        errorMsg = "Some Error occured while sending feeds. Please contact concerned Team";
                        return index();
                }
        }*/
        /*
        public List<Long> getEntityLogisticsEstimation(long productId){
        List<Long> items=null; 
        try {
                LogisticsClient cl = new LogisticsClient();
            LogisticsService.Client client = cl.getClient();
            items = client.getEntityLogisticsEstimation(productId, "110001", DeliveryType.PREPAID );
        } catch (Exception e1) {
            System.out.println("Unable to get items by catalog item id"+e1.getMessage());
        }
        return items;
    }*/
        
        public KeywordMatchType processAdKeywordMatchType(String value){
                return KeywordMatchType.findByValue(Integer.parseInt(value));
        }
        
        public AdwordsAdGroup getAdwordsAdgroup(long adgroupId){
                AdwordsAdGroup adgroup = new AdwordsAdGroup();
                try {
                        adgroup = new AdwordsClient().getClient().getAdwordsAdGroupByAdGroupId(adgroupId);
                } catch (TTransportException e) {
                        e.printStackTrace();
                } catch (GoogleAdwordsServiceException e) {
                        e.printStackTrace();
                } catch (TException e) {
                        e.printStackTrace();
                }
                return adgroup;
        }
        
        public Map<String, String> getKeywordMap(String keyword, String bid, String type){
                Map<String, String> keywordMap = new HashMap<String, String>();
                keywordMap.put("Text", keyword1);
                keywordMap.put("Type", type);
                double bidamount = Double.parseDouble(bid);
                bidamount = bidamount * Math.pow(10, 6);
                keywordMap.put("BidAmount", bidamount+"");
                return keywordMap;
        }
        
        public void processAdGroupStatus(){
                if(adgroupStatus!=null){
                        if("1".equalsIgnoreCase(adgroupStatus)){
                                adgrpStatus = AdwordsAdGroupStatus.ENABLED;
                        }
                        else if("2".equalsIgnoreCase(campaignStatus)){
                                adgrpStatus = AdwordsAdGroupStatus.PAUSED;
                        }
                        else{
                                campStatus = AdwordsCampaignStatus.DELETED;
                        }
                }
        }

        public String processedStartEndDate(String dateString, SimpleDateFormat dateformat){
                SimpleDateFormat timestmapFormatRequest = new SimpleDateFormat("mm/dd/yyyy");
                String dateStr = "";
                try {
                        Date date = timestmapFormatRequest.parse(dateString);
                        dateStr = dateformat.format(date.getTime());
                } catch (ParseException e) {
                        e.printStackTrace();
                }
                return dateStr;
        }
        
        public void processCampaignStatus(){
                if(campaignStatus!=null){
                        if("1".equalsIgnoreCase(campaignStatus)){
                                campStatus = AdwordsCampaignStatus.ACTIVE;
                        }
                        else if("2".equalsIgnoreCase(campaignStatus)){
                                campStatus = AdwordsCampaignStatus.PAUSED;
                        }
                        else{
                                campStatus = AdwordsCampaignStatus.DELETED;
                        }
                }
        }

        public void processStockLinked(){
                if(stockLinked!=null && ("on").equalsIgnoreCase(stockLinked)){
                        stocklinked = 1;
                }
        }
        
        public void processStockLinkedUpdate(){
                if(stockLinkedUpdate!=null && ("on").equalsIgnoreCase(stockLinkedUpdate)){
                        stocklinkedUpdate = 1;
                }
        }
        
        public void processNetworkSetting(){
                if(googleSearchNetwork!=null && ("on").equalsIgnoreCase(googleSearchNetwork)){
                        googlesearchNetwork = true;
                }
                if(displayNetwork!=null && ("on").equalsIgnoreCase(displayNetwork)){
                        displaynetwork = true;
                }
                if(partnerSearchNetwork!=null && ("on").equalsIgnoreCase(partnerSearchNetwork)){
                        partnersearchNetwork = true;
                }

                if(googlesearchNetwork && !displaynetwork && !partnersearchNetwork){
                        networkSettingType = NetworkSettingType.GOOGLE_SEARCH_AND_SEARCH_NETWORK;
                }
                else if(googlesearchNetwork && displaynetwork && !partnersearchNetwork){
                        networkSettingType = NetworkSettingType.SEARCH_AND_DISPLAY_NETWORK;
                }
                else if(googlesearchNetwork && !displaynetwork && partnersearchNetwork){
                        networkSettingType = NetworkSettingType.SEARCH_AND_PARTNER_NETWORK;
                }
                else if(!googlesearchNetwork && displaynetwork && !partnersearchNetwork){
                        networkSettingType = NetworkSettingType.DISPLAY_NETWORK;
                }
                else if(!googlesearchNetwork && displaynetwork && partnersearchNetwork){
                        networkSettingType = NetworkSettingType.DISPLAY_AND_PARTNER_NETWORK;
                }
                else if(!googlesearchNetwork && !displaynetwork && partnersearchNetwork){
                        networkSettingType = NetworkSettingType.GOOGLE_PARTNER_SEARCH_NETWORK;
                }
                else if(googlesearchNetwork && displaynetwork && partnersearchNetwork){
                        networkSettingType = NetworkSettingType.ALL_AVALIABLE_SOURCES;
                }

        }

        public boolean addAdwordsCampaign(String name, String startDateStr, String endDateStr, 
                        Long amount, String status, boolean googlesrchNtwrk, boolean displayntwrk, 
                        boolean partnersrchNtwrk, NetworkSettingType networkType){
                Long campaignId = 0L;
                boolean retry = true;
                int attempt =0;
                while(retry && attempt<2){
                        try{
                                attempt = attempt+1;
                                campaignId = AddCampaigns.runExample(name, status, startDateStr, endDateStr, amount, googlesrchNtwrk, displayntwrk, partnersrchNtwrk);
                                retry = false;
                                System.out.println("@@@@@ CampaignId...... "+campaignId);
                        }
                        catch (Exception e) {
                                retry = true;
                                logger.error("Error while requesting Google Adwords Campaign Service", e);
                        }
                }
                if(campaignId==0L){
                        addActionError("Error while processing Add Request for Google Campaign Service");
                        return false;
                }
                try{
                        SimpleDateFormat timestmapFormatForGoogle = new SimpleDateFormat("yyyymmdd");
                        AdwordsCampaign campaign = new AdwordsCampaign();
                        campaign.setCampaignId(campaignId);
                        campaign.setName(name);
                        campaign.setBudgetAmount(amount * Math.pow(10, -6));
                        campaign.setNetworkType(networkType);
                        campaign.setStartDate(timestmapFormatForGoogle.parse(startDateStr).getTime());
                        campaign.setEndDate(timestmapFormatForGoogle.parse(endDateStr).getTime());
                        campaign.setStatus(campStatus);
                        new AdwordsClient().getClient().addAdwordsCampaign(campaign);
                        return true;
                }
                catch(ParseException pe){
                        addActionError("Unable to parse proper Data");
                        logger.error("Error while parsing proper Data", pe);
                } catch (TTransportException e) {
                        addActionError("Unable to get Connection with Saholic Google Adowrds Services in addAdwordsCampaign Method");
                        logger.error("Error while getting Connection with Saholic Google Adowrds Services in addAdwordsCampaign Method", e);
                } catch (GoogleAdwordsServiceException e) {
                        addActionError("Unable to perform operations with Saholic Google Adowrds Services in addAdwordsCampaign Method");
                        logger.error("Error while performing operations with Saholic Google Adowrds Services in addAdwordsCampaign Method", e);
                } catch (TException e) {
                        addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in addAdwordsCampaign Method");
                        logger.error("Error while performing operations with Saholic Google Adowrds Services Client in addAdwordsCampaign Method", e);
                }

                return false;
        }
        
        public boolean addAdwordsAdGroup(long campaignId, String name, String status, Long bidAmount, long catalogId){
                Long adGroupId = 0L;
                boolean retry = true;
                int attempt =0;
                while(retry && attempt < 2){
                        try{
                                attempt =attempt +1;
                                adGroupId = AddAdGroups.runExample(campaignId, name, status, bidAmount);
                                retry = false;
                        }
                        catch (Exception e) {
                                retry = true;
                                logger.error("Error while requesting Google Adwords AdGroup Service", e);
                        }
                }
                if(adGroupId == 0L){
                        addActionError("Error while processing Add Request for Google AdGroup Service");
                        return false;
                }
                try{
                        AdwordsAdGroup adgroup = new AdwordsAdGroup();
                        adgroup.setAdgroupId(adGroupId);
                        adgroup.setCampaignId(campaignId);
                        adgroup.setCatalogItemId(catalogId);
                        adgroup.setStatus(adgrpStatus);
                        adgroup.setName(name);
                        adgroup.setBidAmount(bidAmount * Math.pow(10, -6));
                        adgroup.setStockLinked(stocklinked);
                        new AdwordsClient().getClient().addAdwordsAdGroup(adgroup);
                        return true;
                }
                catch (TTransportException e) {
                        addActionError("Unable to get Connection with Saholic Google Adowrds Services in addAdwordsAdGroup Method");
                        logger.error("Error while getting Connection with Saholic Google Adowrds Services in addAdwordsAdGroup Method", e);
                } catch (GoogleAdwordsServiceException e) {
                        addActionError("Unable to perform operations with Saholic Google Adowrds Services in addAdwordsAdGroup Method");
                        logger.error("Error while performing operations with Saholic Google Adowrds Services in addAdwordsAdGroup Method", e);
                } catch (TException e) {
                        addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in addAdwordsAdGroup Method");
                        logger.error("Error while performing operations with Saholic Google Adowrds Services Client in addAdwordsAdGroup Method", e);
                }
                return false;
        }
        
        public boolean addAdwordsAdGroupAd(){
                Long adGroupAdId = 0L;
                int attempt =0;
                boolean retry = true;
                if(description1.contains("#price")){
                        description1 = description1.replace("#price", "Rs"+getTextAdItemPrice()+"#");
                }
                if(description1.length()>35){
                        addActionError("Description1 length is greater than 35. Final String is given as.... "+description1);
                        return false;
                }
                while(retry && attempt<2){
                        try{
                                attempt = attempt+1;
                                adGroupAdId = AddTextAds.runExample(Long.parseLong(adgroupList1), headline, description1, description2, url, displayUrl);
                                retry = false;
                        }
                        catch (Exception e) {
                                retry = true;
                                logger.error("Error while requesting Google Adwords AdGroupAd Service", e);
                        }
                }
                if(adGroupAdId == 0L){
                        addActionError("Error while processing Add Request for Google AdGroupAd Service");
                        return false;
                }
                try{
                        AdwordsAdGroupAd adgroupad = new AdwordsAdGroupAd();
                        adgroupad.setAdgroupadId(adGroupAdId);
                        adgroupad.setCampaignId(Long.parseLong(campaignList2));
                        adgroupad.setAdgroupId(Long.parseLong(adgroupList1));
                        adgroupad.setDescription1(description1);
                        adgroupad.setDescription2(description2);
                        adgroupad.setHeadline(headline);
                        adgroupad.setDisplayUrl(displayUrl);
                        adgroupad.setUrl(url);
                        new AdwordsClient().getClient().addAdwordsAdGroupAd(adgroupad);
                        return true;
                }
                catch (TTransportException e) {
                        addActionError("Unable to get Connection with Saholic Google Adowrds Services in addAdwordsAdGroupAd Method");
                        logger.error("Error while getting Connection with Saholic Google Adowrds Services in addAdwordsAdGroupAd Method", e);
                } catch (GoogleAdwordsServiceException e) {
                        addActionError("Unable to perform operations with Saholic Google Adowrds Services in addAdwordsAdGroupAd Method");
                        logger.error("Error while performing operations with Saholic Google Adowrds Services in addAdwordsAdGroupAd Method", e);
                } catch (TException e) {
                        addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in addAdwordsAdGroupAd Method");
                        logger.error("Error while performing operations with Saholic Google Adowrds Services Client in addAdwordsAdGroupAd Method", e);
                }
                
                return false;
        }
        
        public boolean addAdwordsAdKeyword(List<Map<String,String>> keywordDataList){
                List<Map<String,String>> adgroupDataList = new ArrayList<Map<String,String>>();
                int attempt =0;
                boolean retry = true;
                while(retry && attempt<2){
                        try{
                                attempt = attempt+1;
                                adgroupDataList = AddKeywords.runExample(Long.parseLong(adgroupList2), keywordDataList);
                                retry = false;
                        }
                        catch (Exception e) {
                                retry = true;
                                logger.error("Error while requesting Google Adwords AdGroup Criterion Service", e);
                        }
                }
                if(adgroupDataList!=null && adgroupDataList.size()>0){
                        try{
                                AdwordsClient adwordsServiceClient = new AdwordsClient();
                                Client client = adwordsServiceClient.getClient();
                                for(Map<String,String> keywordMap : adgroupDataList){
                                        AdwordsAdKeyword adkeyword = new AdwordsAdKeyword();
                                        adkeyword.setAdgroupId(Long.parseLong(adgroupList2));
                                        adkeyword.setCampaignId(Long.parseLong(campaignList3));
                                        adkeyword.setCriterionId(Long.parseLong(keywordMap.get("CriterionId")));
                                        adkeyword.setText(keywordMap.get("Text"));
                                        adkeyword.setMatchType(KeywordMatchType.valueOf(keywordMap.get("Type")));
                                        adkeyword.setBidAmount( (Double.parseDouble(keywordMap.get("BidAmount"))) * (Math.pow(10, -6) ));
                                        client.addAdwordsAdKeyword(adkeyword);
                                }
                                return true;
                        }
                        catch (TTransportException e) {
                                addActionError("Unable to get Connection with Saholic Google Adowrds Services in addAdwordsAdKeyword Method");
                                logger.error("Error while getting Connection with Saholic Google Adowrds Services in addAdwordsAdKeyword Method", e);
                        } catch (GoogleAdwordsServiceException e) {
                                addActionError("Unable to perform operations with Saholic Google Adowrds Services in addAdwordsAdKeyword Method");
                                logger.error("Error while performing operations with Saholic Google Adowrds Services in addAdwordsAdKeyword Method", e);
                        } catch (TException e) {
                                addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in addAdwordsAdKeyword Method");
                                logger.error("Error while performing operations with Saholic Google Adowrds Services Client in addAdwordsAdKeyword Method", e);
                        }
                }
                else{
                        addActionError("Error while processing Add Request for Google AdGroupCriterion Service");
                }
                return false;
        }
        
        public boolean updateAdwordsCampaign(){
                AdwordsClient adwordsServiceClient = null;
                try {
                        adwordsServiceClient = new AdwordsClient();
                } catch (TTransportException e) {
                        addActionError("Unable to get Connection with Saholic Google Adowrds Services in updateAdwordsCampaign Method");
                        logger.error("Error while getting Connection with Saholic Google Adowrds Services in updateAdwordsCampaign Method", e); 
                }
                if(adwordsServiceClient!=null){
                        Client client = adwordsServiceClient.getClient();
                        if(campaignListUpdate1!=null && !("-1").equalsIgnoreCase(campaignListUpdate1)){
                                long amount= -1l;
                                String status = "";
                                String name = "";
                                AdwordsCampaign campaign = null;
                                try {
                                        campaign = client.getAdwordsCampaignByCampaignId(Long.parseLong(campaignListUpdate1));
                                } catch (NumberFormatException e) {
                                        addActionError("Number Format Exception for CampaignId.."+campaignListUpdate1);
                                        logger.error("Number Format Exception for CampaignId.."+campaignListUpdate1, e);
                                } catch (GoogleAdwordsServiceException e) {
                                        addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsCampaign Method while getting Data");
                                        logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsCampaign Method while getting Data", e);
                                } catch (TException e) {
                                        addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsCampaign Method while getting Data");
                                        logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsCampaign Method while getting Data", e);
                                }
                                if(campaign!=null){
                                        if(campaignNameUpdate!=null && !("").equalsIgnoreCase(campaignNameUpdate)){
                                                if(!campaign.getName().equalsIgnoreCase(campaignNameUpdate)){
                                                        campaign.setName(campaignNameUpdate);
                                                        name = campaignNameUpdate;
                                                }
                                        }
                                        if(campaign.getStatus().getValue()!=Integer.parseInt(campaignStatusUpdate)){
                                                campaign.setStatus(AdwordsCampaignStatus.findByValue(Integer.parseInt(campaignStatusUpdate)));
                                                status = AdwordsCampaignStatus.findByValue(Integer.parseInt(campaignStatusUpdate)).toString();
                                        }
                                        if(campaignAmountUpdate!=null && !("").equalsIgnoreCase(campaignAmountUpdate)){
                                                if(campaign.getBudgetAmount()!=Double.parseDouble(campaignAmountUpdate)){
                                                        campaign.setBudgetAmount(Double.parseDouble(campaignAmountUpdate));
                                                        amount = (long)(Double.parseDouble(campaignAmountUpdate) * Math.pow(10, 6));
                                                }
                                        }
                                        Long updatedCampaignId = 0l;
                                        if(!("").equalsIgnoreCase(name) || !("").equalsIgnoreCase(name) || amount!=-1l){
                                                try {
                                                        updatedCampaignId = UpdateCampaign.runExample(Long.parseLong(campaignListUpdate1), status, name, amount);
                                                } catch (NumberFormatException e) {
                                                        addActionError("Number Format Exception for CampaignId (Google End).."+campaignListUpdate1);
                                                        logger.error("Number Format Exception for CampaignId (Google End).."+campaignListUpdate1, e);
                                                } catch (Exception e) {
                                                        addActionError("Campaign Service Mutate Operation Exception ");
                                                        logger.error("Error while Campaign Service Mutate Operation", e);
                                                }
                                        }
                                        if(updatedCampaignId > 0l){
                                                campaign.setCampaignId(updatedCampaignId);
                                                try {
                                                        client.updateAdwordsCampaign(campaign);
                                                        return true;
                                                } catch (GoogleAdwordsServiceException e) {
                                                        addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsCampaign Method while updating Data");
                                                        logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsCampaign Method while updating Data", e); 
                                                } catch (TException e) {
                                                        addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsCampaign Method while updating Data");
                                                        logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsCampaign Method while updating Data", e);
                                                }
                                        }
                                        else{
                                                addActionError("Either There is Nothing to Update for Campaign Or Some Error Occured");
                                        }
                                }
                        }
                }
                
                return false;
        }
        
        public boolean updateAdwordsAdGroup(){
                AdwordsClient adwordsServiceClient = null;
                try {
                        adwordsServiceClient = new AdwordsClient();
                } catch (TTransportException e) {
                        e.printStackTrace();
                }
                if(adwordsServiceClient!=null){
                        Client client = adwordsServiceClient.getClient();
                        if(adgroupListUpdate1!=null && !("-1").equalsIgnoreCase(adgroupListUpdate1)){
                                String name="";
                                String status ="";
                                long bidAmount = -1L;
                                boolean catalogItemIdChanged = false;
                                boolean stockLinkedChanged = false;
                                AdwordsAdGroup adgroup = null;
                                try {
                                        adgroup = client.getAdwordsAdGroupByAdGroupId(Long.parseLong(adgroupListUpdate1));
                                } catch (NumberFormatException e) {
                                        addActionError("Number Format Exception for AdGroupId.."+adgroupListUpdate1);
                                        logger.error("Number Format Exception for AdGroupId.."+adgroupListUpdate1, e);
                                } catch (GoogleAdwordsServiceException e) {
                                        addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsAdGroup Method while getting Data");
                                        logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsAdGroup Method while getting Data", e);
                                } catch (TException e) {
                                        addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsAdGroup Method while getting Data");
                                        logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsAdGroup Method while getting Data", e);
                                }
                                if(adgroup!=null){
                                        if(adgroupNameUpdate!=null && !("").equalsIgnoreCase(adgroupNameUpdate)){
                                                if(!adgroup.getName().equalsIgnoreCase(adgroupNameUpdate)){
                                                        adgroup.setName(adgroupNameUpdate);
                                                        name = adgroupNameUpdate;
                                                }                       
                                        }
                                        if(adgroup.getStatus().getValue()!=Integer.parseInt(adgroupStatusUpdate)){
                                                adgroup.setStatus(AdwordsAdGroupStatus.findByValue(Integer.parseInt(adgroupStatusUpdate)));
                                                status = AdwordsAdGroupStatus.findByValue(Integer.parseInt(adgroupStatusUpdate)).toString();
                                        }
                                        if(catalogItemIdUpdate!=null && !("").equalsIgnoreCase(catalogItemIdUpdate)){
                                                if(adgroup.getCatalogItemId()!= Long.parseLong(catalogItemIdUpdate)){
                                                        adgroup.setCatalogItemId(Long.parseLong(catalogItemIdUpdate));
                                                        catalogItemIdChanged = true;
                                                }
                                        }
                                        if(bidAmountUpdate!=null && !("").equalsIgnoreCase(bidAmountUpdate)){
                                                if(adgroup.getBidAmount()!=Double.parseDouble(bidAmountUpdate)){
                                                        adgroup.setBidAmount(Double.parseDouble(bidAmountUpdate));
                                                        bidAmount = (long) (Double.parseDouble(bidAmountUpdate) * Math.pow(10, 6));
                                                }
                                        }
                                        if(stocklinkedUpdate!=adgroup.getStockLinked()){
                                                adgroup.setStockLinked(stocklinkedUpdate);
                                                stockLinkedChanged = true;
                                        }
                                        
                                        Long updatedAdgroupId = 0l;
                                        if(!("").equalsIgnoreCase(name) || !("").equalsIgnoreCase(name) || bidAmount != -1l){
                                                try {
                                                        updatedAdgroupId = UpdateAdGroup.runExample(name, status, bidAmount, Long.parseLong(adgroupListUpdate1));
                                                } catch (NumberFormatException e) {
                                                        addActionError("Number Format Exception for AdGroupId (Google End).."+adgroupListUpdate1);
                                                        logger.error("Number Format Exception for AdGroupId (Google End).."+adgroupListUpdate1, e);
                                                } catch (Exception e) {
                                                        addActionError("AdGroup Service Mutate Operation Exception ");
                                                        logger.error("Error while AdGroup Service Mutate Operation", e);
                                                }
                                        }
                                        if(updatedAdgroupId>0l){
                                                adgroup.setAdgroupId(updatedAdgroupId);
                                                try {
                                                        client.updateAdwordsAdGroup(adgroup);
                                                        return true;
                                                } catch (GoogleAdwordsServiceException e) {
                                                        addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsAdGroup Method while updating Data");
                                                        logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsAdGroup Method while updating Data", e); 
                                                } catch (TException e) {
                                                        addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsAdGroup Method while updating Data");
                                                        logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsAdGroup Method while updating Data", e);
                                                }
                                        }
                                        else{
                                                if(catalogItemIdChanged || stockLinkedChanged){
                                                        try {
                                                                client.updateAdwordsAdGroup(adgroup);
                                                                return true;
                                                        } catch (GoogleAdwordsServiceException e) {
                                                                addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsAdGroup Method while updating Data");
                                                                logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsAdGroup Method while updating Data", e); 
                                                        } catch (TException e) {
                                                                addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsAdGroup Method while updating Data");
                                                                logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsAdGroup Method while updating Data", e);
                                                        }
                                                }
                                                else{
                                                        addActionError("There is Nothing to Update for AdGroup at Google End(Local System Also) or Some Error Occured");
                                                }
                                        }
                                }
                                
                        }
                }
                return false;
        }
        
        public boolean updateAdwordsAdKeyword(){
                AdwordsClient adwordsServiceClient = null;
                try {
                        adwordsServiceClient = new AdwordsClient();
                } catch (TTransportException e) {
                        e.printStackTrace();
                }
                if(adwordsServiceClient!=null){
                        Client client = adwordsServiceClient.getClient();
                        if(adgroupListUpdate2!=null && !("-1").equalsIgnoreCase(adgroupListUpdate2) && keywordListUpdate1!=null && !("-1").equalsIgnoreCase(keywordListUpdate1)){
                                String text = "";
                                String type = "";
                                long bidAmount = -1l;
                                AdwordsAdKeyword adkeyword = null;
                                try {
                                        adkeyword = client.getAdwordsAdKeywordByCriterionIdAndAdGroupId(Long.parseLong(keywordListUpdate1), Long.parseLong(adgroupListUpdate2));
                                } catch (NumberFormatException e) {
                                        addActionError("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2);
                                        logger.error("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2, e);
                                } catch (GoogleAdwordsServiceException e) {
                                        addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsAdKeyword Method while getting Data");
                                        logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsAdKeyword Method while getting Data", e);
                                } catch (TException e) {
                                        addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsAdKeyword Method while getting Data");
                                        logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsAdKeyword Method while getting Data", e);
                                }
                                
                                if(adkeyword!=null){
                                        if(keywordUpdate!=null && !("").equalsIgnoreCase(keywordUpdate)){
                                                if(!adkeyword.getText().equalsIgnoreCase(keywordUpdate)){
                                                        adkeyword.setText(keywordUpdate);
                                                        text = keywordUpdate;
                                                }
                                        }
                                        if(bidUpdate!=null && !("").equalsIgnoreCase(bidUpdate)){
                                                if(adkeyword.getBidAmount()!=Double.parseDouble(bidUpdate)){
                                                        adkeyword.setBidAmount(Double.parseDouble(bidUpdate));
                                                        bidAmount = (long) (Double.parseDouble(bidUpdate) * Math.pow(10, 6));
                                                }
                                        }
                                        if(adkeyword.getMatchType().getValue()!= Integer.parseInt(matchTypeUpdate)){
                                                adkeyword.setMatchType(KeywordMatchType.findByValue(Integer.parseInt(matchTypeUpdate)));
                                                type = KeywordMatchType.findByValue(Integer.parseInt(matchTypeUpdate)).toString();
                                        }
                                        
                                        Long updatedCriterionId = 0l;
                                        if(!("").equalsIgnoreCase(text) || !("").equalsIgnoreCase(type) || bidAmount != -1l){
                                                try {
                                                        updatedCriterionId = UpdateKeyword.runExample(Long.parseLong(adgroupListUpdate2), Long.parseLong(keywordListUpdate1), text, bidAmount, type);
                                                } catch (NumberFormatException e) {
                                                        addActionError("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2+ "(Google End)..");
                                                        logger.error("Number Format Exception for AdGroupCriterionId.."+keywordListUpdate1+"..AdGroupId.."+adgroupListUpdate2+ "(Google End)..", e);
                                                } catch (Exception e) {
                                                        addActionError("AdGroup Crierion Service Mutate Operation Exception ");
                                                        e.printStackTrace();
                                                        logger.error("Error while AdGroup Crierion Service Mutate Operation", e);
                                                }
                                        }
                                        
                                        if(updatedCriterionId>0l){
                                                adkeyword.setCriterionId(updatedCriterionId);
                                                try {
                                                        client.updateAdwordsAdKeyword(adkeyword);
                                                        return true;
                                                } catch (GoogleAdwordsServiceException e) {
                                                        addActionError("Unable to perform operations with Saholic Google Adowrds Services in updateAdwordsAdKeyword Method while updating Data");
                                                        logger.error("Error while performing operations with Saholic Google Adowrds Services in updateAdwordsAdKeyword Method while updating Data", e); 
                                                } catch (TException e) {
                                                        addActionError("Unable to perform operations with Saholic Google Adowrds Services Client in updateAdwordsAdKeyword Method while updating Data");
                                                        logger.error("Error while performing operations with Saholic Google Adowrds Services Client in updateAdwordsAdKeyword Method while updating Data", e);
                                                }
                                        }
                                        else{
                                                addActionError("Either There is Nothing to Update for Keyword Or Some Error Occured");
                                        }
                                        
                                }
                                
                        }
                }
                return false;
        }
        
        @Override
        public void setServletRequest(HttpServletRequest request) {
                this.request = request;
                this.session = request.getSession();
        }
        
        public String getCampaignId() {
                return campaignId;
        }

        public void setCampaignId(String campaignId) {
                this.campaignId = campaignId;
        }

        public String getErrorMsg(){
                return this.errorMsg;
        }

        public String getSuccessMessage(){
                return this.successmsg ;
        }

        public JSONObject getJsonData() {
                return jsonData;
        }

        public void setJsonData(JSONObject jsonData) {
                this.jsonData = jsonData;
        }
        
        public JSONObject getJsonCampaignData() {
                return jsonCampaignData;
        }

        public void setJsonCampaignData(JSONObject jsonCampaignData) {
                this.jsonCampaignData = jsonCampaignData;
        }

        public JSONObject getJsonAdgroupData() {
                return jsonAdgroupData;
        }

        public void setJsonAdgroupData(JSONObject jsonAdgroupData) {
                this.jsonAdgroupData = jsonAdgroupData;
        }

        public JSONObject getJsonCampaignList() {
                return jsonCampaignList;
        }

        public void setJsonCampaignList(JSONObject jsonCampaignList) {
                this.jsonCampaignList = jsonCampaignList;
        }

        public String getKeywordId() {
                return keywordId;
        }

        public void setKeywordId(String keywordId) {
                this.keywordId = keywordId;
        }

        public String getAdgroupId() {
                return adgroupId;
        }

        public void setAdgroupId(String adgroupId) {
                this.adgroupId = adgroupId;
        }

        public JSONObject getJsonKeywordList() {
                return jsonKeywordList;
        }

        public void setJsonKeywordList(JSONObject jsonKeywordList) {
                this.jsonKeywordList = jsonKeywordList;
        }

        public JSONObject getJsonKeywordData() {
                return jsonKeywordData;
        }

        public void setJsonKeywordData(JSONObject jsonKeywordData) {
                this.jsonKeywordData = jsonKeywordData;
        }

        public String getTextAdItemPrice(){
                String itemPrice = "";
                List<Item> itemList = new ArrayList<Item>();
                try {
                        itemList = new CatalogClient().getClient().getItemsByCatalogId(Long.parseLong(catalogItemId));
                } catch (NumberFormatException e) {
                        e.printStackTrace();
                } catch (TTransportException e) {
                        e.printStackTrace();
                } catch (CatalogServiceException e) {
                        e.printStackTrace();
                } catch (TException e) {
                        e.printStackTrace();
                }
                List<Long> itemPriceList = new ArrayList<Long>();
                for(Item item : itemList){
                        itemPriceList.add((long)item.getSellingPrice());
                }
                if(itemPriceList!=null && itemPriceList.size()>0){
                        Collections.sort(itemPriceList);
                        itemPrice = itemPriceList.get(0).longValue()+"";
                }
                
                return itemPrice;
        }
        public String getAdgroupList(){
                List<Map<String,String>> adgroupDataList = new ArrayList<Map<String,String>>();
                Map<String, List<Map<String,String>>> mainMap = new HashMap<String, List<Map<String,String>>>();
                List<AdwordsAdGroup> adgroupList =null;
                try {
                        adgroupList = new AdwordsClient().getClient().getAdwordsAdGroupsByCampaignId(Long.parseLong(campaignId));
                } catch (TTransportException e) {
                        e.printStackTrace();
                } catch (GoogleAdwordsServiceException e) {
                        e.printStackTrace();
                } catch (TException e) {
                        e.printStackTrace();
                }
                for(int i=0 ; i<adgroupList.size() ; i++){
                        AdwordsAdGroup adgroup = adgroupList.get(i);
                        Map<String,String> adgroupDataMap = new HashMap<String,String>();
                        adgroupDataMap.put("AdgroupId",adgroup.getAdgroupId()+"");
                        adgroupDataMap.put("Name", adgroup.getName());
                        adgroupDataList.add(adgroupDataMap);
                }
                mainMap.put("AdGroupData", adgroupDataList);
                jsonData = new JSONObject(mainMap);
                
                return "output";
        }
        
        public String getKeywordList(){
                List<Map<String,String>> adkeywordDataList = new ArrayList<Map<String,String>>();
                Map<String, List<Map<String,String>>> mainMap = new HashMap<String, List<Map<String,String>>>();
                List<AdwordsAdKeyword> adkeywordList = null;
                try {
                        adkeywordList = new AdwordsClient().getClient().getAdwordsAdKeywordsByAdgroupId(Long.parseLong(adgroupId));
                }
                catch (TTransportException e) {
                        e.printStackTrace();
                } catch (GoogleAdwordsServiceException e) {
                        e.printStackTrace();
                } catch (TException e) {
                        e.printStackTrace();
                }
                
                for(AdwordsAdKeyword adkeyword : adkeywordList){
                        Map<String,String> adkeywordDataMap = new HashMap<String,String>();
                        adkeywordDataMap.put("KeywordId", adkeyword.getCriterionId()+"");
                        adkeywordDataMap.put("Text", adkeyword.getText());
                        adkeywordDataList.add(adkeywordDataMap);
                }
                mainMap.put("AdKeywordData", adkeywordDataList);
                jsonKeywordList = new JSONObject(mainMap);
                return "output";
        }
        
        public String getCampaignDetails(){
                Map<String, String> campaignUnitDataMap = new HashMap<String, String>();
                AdwordsCampaign campaign = null;
                try {
                        campaign = new AdwordsClient().getClient().getAdwordsCampaignByCampaignId(Long.parseLong(campaignId));
                } catch (NumberFormatException e) {
                        e.printStackTrace();
                } catch (TTransportException e) {
                        e.printStackTrace();
                } catch (GoogleAdwordsServiceException e) {
                        e.printStackTrace();
                } catch (TException e) {
                        e.printStackTrace();
                }
                
                if(campaign!=null){
                        campaignUnitDataMap.put("Name", campaign.getName());
                        campaignUnitDataMap.put("BudgetAmount", campaign.getBudgetAmount()+"");
                        campaignUnitDataMap.put("Status", campaign.getStatus().getValue()+"");
                }
                jsonCampaignData = new JSONObject(campaignUnitDataMap);
                return "output";
        }
        
        public String getAdGroupDetails(){
                Map<String, String> adgroupUnitDataMap = new HashMap<String, String>();
                AdwordsAdGroup adGroup = null;
                try {
                        adGroup = new AdwordsClient().getClient().getAdwordsAdGroupByAdGroupId(Long.parseLong(adgroupId));
                } catch (NumberFormatException e) {
                        e.printStackTrace();
                } catch (TTransportException e) {
                        e.printStackTrace();
                } catch (GoogleAdwordsServiceException e) {
                        e.printStackTrace();
                } catch (TException e) {
                        e.printStackTrace();
                }
                
                if(adGroup!=null){
                        adgroupUnitDataMap.put("Name", adGroup.getName());
                        adgroupUnitDataMap.put("BidAmount", adGroup.getBidAmount()+"");
                        adgroupUnitDataMap.put("Status", adGroup.getStatus().getValue()+"");
                        adgroupUnitDataMap.put("CatalogItemId", adGroup.getCatalogItemId()+"");
                        adgroupUnitDataMap.put("StockLinked",adGroup.getStockLinked()+"");
                }
                jsonAdgroupData = new JSONObject(adgroupUnitDataMap);
                return "output";
        }
        
        public String getKeywordDetails(){
                Map<String, String> adkeywordUnitDataMap = new HashMap<String, String>();
                AdwordsAdKeyword adKeyword = null;
                try {
                        adKeyword = new AdwordsClient().getClient().getAdwordsAdKeywordByCriterionIdAndAdGroupId(Long.parseLong(keywordId), Long.parseLong(adgroupId));
                } catch (NumberFormatException e) {
                        e.printStackTrace();
                } catch (TTransportException e) {
                        e.printStackTrace();
                } catch (GoogleAdwordsServiceException e) {
                        e.printStackTrace();
                } catch (TException e) {
                        e.printStackTrace();
                }
                
                if(adKeyword!=null){
                        adkeywordUnitDataMap.put("Text", adKeyword.getText());
                        adkeywordUnitDataMap.put("Bid", adKeyword.getBidAmount()+"");
                        adkeywordUnitDataMap.put("MatchType", adKeyword.getMatchType().getValue()+"");
                }
                jsonKeywordData = new JSONObject(adkeywordUnitDataMap);
                return "output";
        }

        public String getCampaigns(){
                
                 List<Map<String,String>> campaignDataList = new ArrayList<Map<String,String>>();
                Map<String, List<Map<String,String>>> mainMap = new HashMap<String, List<Map<String,String>>>();
                List<AdwordsCampaign> campaignList =null;
                try {
                        campaignList = new AdwordsClient().getClient().getAllAdwordsCampaigns();
                } catch (TTransportException e) {
                        e.printStackTrace();
                } catch (GoogleAdwordsServiceException e) {
                        e.printStackTrace();
                } catch (TException e) {
                        e.printStackTrace();
                }
                for(int i=0 ; i<campaignList.size() ; i++){
                        AdwordsCampaign campaign = campaignList.get(i);
                        Map<String,String> campaignDataMap = new HashMap<String,String>();
                        campaignDataMap.put("CampaignId",campaign.getCampaignId()+"");
                        campaignDataMap.put("Name", campaign.getName());
                        campaignDataList.add(campaignDataMap);
                }
                mainMap.put("CampaignData", campaignDataList);
                jsonCampaignList = new JSONObject(mainMap);
                /*
                List<AdwordsCampaign> campaignList =null;
                try {
                        campaignList = new AdwordsClient().getClient().getAllAdwordsCampaigns();
                } catch (TTransportException e) {
                        e.printStackTrace();
                } catch (GoogleAdwordsServiceException e) {
                        e.printStackTrace();
                } catch (TException e) {
                        e.printStackTrace();
                } */
                return "output";
        }

        private boolean checkForErrors(){
                Collection<String> actionErrors = getActionErrors();
                if(actionErrors != null && !actionErrors.isEmpty()){
                        for (String str : actionErrors) {
                                errorMsg += "<BR/>" + str;
                        }
                        return true;
                }
                return false;
        }

        public String getAdwordOpRadio() {
                return adwordOpRadio;
        }

        public void setAdwordOpRadio(String adwordOpRadio) {
                this.adwordOpRadio = adwordOpRadio;
        }

        public String getAdwordAddRadio() {
                return adwordAddRadio;
        }

        public void setAdwordAddRadio(String adwordAddRadio) {
                this.adwordAddRadio = adwordAddRadio;
        }

        public String getCampaignName() {
                return campaignName;
        }

        public void setCampaignName(String campaignName) {
                this.campaignName = campaignName;
        }

        public String getCampaignStatus() {
                return campaignStatus;
        }

        public void setCampaignStatus(String campaignStatus) {
                this.campaignStatus = campaignStatus;
        }

        public String getStartDate() {
                return startDate;
        }

        public void setStartDate(String startDate) {
                this.startDate = startDate;
        }

        public String getEndDate() {
                return endDate;
        }

        public void setEndDate(String endDate) {
                this.endDate = endDate;
        }

        public String getCampaignAmount() {
                return campaignAmount;
        }

        public void setCampaignAmount(String campaignAmount) {
                this.campaignAmount = campaignAmount;
        }

        public String getGoogleSearchNetwork() {
                return googleSearchNetwork;
        }

        public void setGoogleSearchNetwork(String googleSearchNetwork) {
                this.googleSearchNetwork = googleSearchNetwork;
        }

        public String getDisplayNetwork() {
                return displayNetwork;
        }

        public void setDisplayNetwork(String displayNetwork) {
                this.displayNetwork = displayNetwork;
        }

        public String getPartnerSearchNetwork() {
                return partnerSearchNetwork;
        }

        public void setPartnerSearchNetwork(String partnerSearchNetwork) {
                this.partnerSearchNetwork = partnerSearchNetwork;
        }

        public String getCampaignList1() {
                return campaignList1;
        }

        public void setCampaignList1(String campaignList1) {
                this.campaignList1 = campaignList1;
        }

        public String getAdgroupName() {
                return adgroupName;
        }

        public void setAdgroupName(String adgroupName) {
                this.adgroupName = adgroupName;
        }

        public String getAdgroupStatus() {
                return adgroupStatus;
        }

        public void setAdgroupStatus(String adgroupStatus) {
                this.adgroupStatus = adgroupStatus;
        }

        public String getCatalogItemId() {
                return catalogItemId;
        }

        public void setCatalogItemId(String catalogItemId) {
                this.catalogItemId = catalogItemId;
        }

        public String getBidAmount() {
                return bidAmount;
        }

        public void setBidAmount(String bidAmount) {
                this.bidAmount = bidAmount;
        }

        public String getCampaignList2() {
                return campaignList2;
        }

        public void setCampaignList2(String campaignList2) {
                this.campaignList2 = campaignList2;
        }

        public String getAdgroupList1() {
                return adgroupList1;
        }

        public void setAdgroupList1(String adgroupList1) {
                this.adgroupList1 = adgroupList1;
        }

        public String getHeadline() {
                return headline;
        }

        public void setHeadline(String headline) {
                this.headline = headline;
        }

        public String getDescription1() {
                return description1;
        }

        public void setDescription1(String description1) {
                this.description1 = description1;
        }

        public String getDescription2() {
                return description2;
        }

        public void setDescription2(String description2) {
                this.description2 = description2;
        }

        public String getUrl() {
                return url;
        }

        public void setUrl(String url) {
                this.url = url;
        }

        public String getDisplayUrl() {
                return displayUrl;
        }

        public void setDisplayUrl(String displayUrl) {
                this.displayUrl = displayUrl;
        }

        public String getCampaignList3() {
                return campaignList3;
        }

        public void setCampaignList3(String campaignList3) {
                this.campaignList3 = campaignList3;
        }

        public String getAdgroupList2() {
                return adgroupList2;
        }

        public void setAdgroupList2(String adgroupList2) {
                this.adgroupList2 = adgroupList2;
        }

        public String getKeyword1() {
                return keyword1;
        }

        public void setKeyword1(String keyword1) {
                this.keyword1 = keyword1;
        }

        public String getKeyword2() {
                return keyword2;
        }

        public void setKeyword2(String keyword2) {
                this.keyword2 = keyword2;
        }

        public String getKeyword3() {
                return keyword3;
        }

        public void setKeyword3(String keyword3) {
                this.keyword3 = keyword3;
        }

        public String getKeyword4() {
                return keyword4;
        }

        public void setKeyword4(String keyword4) {
                this.keyword4 = keyword4;
        }

        public String getKeyword5() {
                return keyword5;
        }

        public void setKeyword5(String keyword5) {
                this.keyword5 = keyword5;
        }

        public String getBid1() {
                return bid1;
        }

        public void setBid1(String bid1) {
                this.bid1 = bid1;
        }

        public String getBid2() {
                return bid2;
        }

        public void setBid2(String bid2) {
                this.bid2 = bid2;
        }

        public String getBid3() {
                return bid3;
        }

        public void setBid3(String bid3) {
                this.bid3 = bid3;
        }

        public String getBid4() {
                return bid4;
        }

        public void setBid4(String bid4) {
                this.bid4 = bid4;
        }

        public String getBid5() {
                return bid5;
        }

        public void setBid5(String bid5) {
                this.bid5 = bid5;
        }

        public String getMatchType1() {
                return matchType1;
        }

        public void setMatchType1(String matchType1) {
                this.matchType1 = matchType1;
        }

        public String getMatchType2() {
                return matchType2;
        }

        public void setMatchType2(String matchType2) {
                this.matchType2 = matchType2;
        }

        public String getMatchType3() {
                return matchType3;
        }

        public void setMatchType3(String matchType3) {
                this.matchType3 = matchType3;
        }

        public String getMatchType4() {
                return matchType4;
        }

        public void setMatchType4(String matchType4) {
                this.matchType4 = matchType4;
        }

        public String getMatchType5() {
                return matchType5;
        }

        public void setMatchType5(String matchType5) {
                this.matchType5 = matchType5;
        }

        public String getStockLinked() {
                return stockLinked;
        }

        public void setStockLinked(String stockLinked) {
                this.stockLinked = stockLinked;
        }

        public String getAdwordUpdateRadio() {
                return adwordUpdateRadio;
        }

        public void setAdwordUpdateRadio(String adwordUpdateRadio) {
                this.adwordUpdateRadio = adwordUpdateRadio;
        }

        public String getCampaignListUpdate1() {
                return campaignListUpdate1;
        }

        public void setCampaignListUpdate1(String campaignListUpdate1) {
                this.campaignListUpdate1 = campaignListUpdate1;
        }

        public String getCampaignNameUpdate() {
                return campaignNameUpdate;
        }

        public void setCampaignNameUpdate(String campaignNameUpdate) {
                this.campaignNameUpdate = campaignNameUpdate;
        }

        public String getCampaignStatusUpdate() {
                return campaignStatusUpdate;
        }

        public void setCampaignStatusUpdate(String campaignStatusUpdate) {
                this.campaignStatusUpdate = campaignStatusUpdate;
        }

        public String getCampaignAmountUpdate() {
                return campaignAmountUpdate;
        }

        public void setCampaignAmountUpdate(String campaignAmountUpdate) {
                this.campaignAmountUpdate = campaignAmountUpdate;
        }

        public String getCampaignListUpdate2() {
                return campaignListUpdate2;
        }

        public void setCampaignListUpdate2(String campaignListUpdate2) {
                this.campaignListUpdate2 = campaignListUpdate2;
        }

        public String getAdgroupListUpdate1() {
                return adgroupListUpdate1;
        }

        public void setAdgroupListUpdate1(String adgroupListUpdate1) {
                this.adgroupListUpdate1 = adgroupListUpdate1;
        }

        public String getAdgroupNameUpdate() {
                return adgroupNameUpdate;
        }

        public void setAdgroupNameUpdate(String adgroupNameUpdate) {
                this.adgroupNameUpdate = adgroupNameUpdate;
        }

        public String getAdgroupStatusUpdate() {
                return adgroupStatusUpdate;
        }

        public void setAdgroupStatusUpdate(String adgroupStatusUpdate) {
                this.adgroupStatusUpdate = adgroupStatusUpdate;
        }

        public String getCatalogItemIdUpdate() {
                return catalogItemIdUpdate;
        }

        public void setCatalogItemIdUpdate(String catalogItemIdUpdate) {
                this.catalogItemIdUpdate = catalogItemIdUpdate;
        }

        public String getBidAmountUpdate() {
                return bidAmountUpdate;
        }

        public void setBidAmountUpdate(String bidAmountUpdate) {
                this.bidAmountUpdate = bidAmountUpdate;
        }

        public String getStockLinkedUpdate() {
                return stockLinkedUpdate;
        }

        public void setStockLinkedUpdate(String stockLinkedUpdate) {
                this.stockLinkedUpdate = stockLinkedUpdate;
        }

        public String getCampaignListUpdate3() {
                return campaignListUpdate3;
        }

        public void setCampaignListUpdate3(String campaignListUpdate3) {
                this.campaignListUpdate3 = campaignListUpdate3;
        }

        public String getAdgroupListUpdate2() {
                return adgroupListUpdate2;
        }

        public void setAdgroupListUpdate2(String adgroupListUpdate2) {
                this.adgroupListUpdate2 = adgroupListUpdate2;
        }

        public String getKeywordUpdate() {
                return keywordUpdate;
        }

        public void setKeywordUpdate(String keywordUpdate) {
                this.keywordUpdate = keywordUpdate;
        }

        public String getBidUpdate() {
                return bidUpdate;
        }

        public void setBidUpdate(String bidUpdate) {
                this.bidUpdate = bidUpdate;
        }

        public String getMatchTypeUpdate() {
                return matchTypeUpdate;
        }

        public void setMatchTypeUpdate(String matchTypeUpdate) {
                this.matchTypeUpdate = matchTypeUpdate;
        }

        public String getKeywordListUpdate1() {
                return keywordListUpdate1;
        }

        public void setKeywordListUpdate1(String keywordListUpdate1) {
                this.keywordListUpdate1 = keywordListUpdate1;
        }

}