com.microsoft.bingads.v13.bulk.entities.BulkCampaign Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of microsoft.bingads Show documentation
Show all versions of microsoft.bingads Show documentation
The Bing Ads Java SDK is a library improving developer experience when working with the Bing Ads services by providing high-level access to features such as Bulk API, OAuth Authorization and SOAP API.
package com.microsoft.bingads.v13.bulk.entities;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import com.microsoft.bingads.internal.functionalinterfaces.BiConsumer;
import com.microsoft.bingads.internal.functionalinterfaces.Function;
import com.microsoft.bingads.v13.bulk.BulkFileReader;
import com.microsoft.bingads.v13.bulk.BulkFileWriter;
import com.microsoft.bingads.v13.bulk.BulkOperation;
import com.microsoft.bingads.v13.bulk.BulkServiceManager;
import com.microsoft.bingads.v13.campaignmanagement.ArrayOfSetting;
import com.microsoft.bingads.v13.campaignmanagement.ArrayOfTargetSettingDetail;
import com.microsoft.bingads.v13.campaignmanagement.ArrayOflong;
import com.microsoft.bingads.v13.campaignmanagement.ArrayOfstring;
import com.microsoft.bingads.v13.campaignmanagement.Bid;
import com.microsoft.bingads.v13.campaignmanagement.BiddingScheme;
import com.microsoft.bingads.v13.campaignmanagement.BudgetLimitType;
import com.microsoft.bingads.v13.campaignmanagement.Campaign;
import com.microsoft.bingads.v13.campaignmanagement.CampaignStatus;
import com.microsoft.bingads.v13.campaignmanagement.CampaignType;
import com.microsoft.bingads.v13.campaignmanagement.DynamicSearchAdsSetting;
import com.microsoft.bingads.v13.campaignmanagement.DynamicSearchAdsSource;
import com.microsoft.bingads.v13.campaignmanagement.MaxClicksBiddingScheme;
import com.microsoft.bingads.v13.campaignmanagement.MaxConversionValueBiddingScheme;
import com.microsoft.bingads.v13.campaignmanagement.MaxConversionsBiddingScheme;
import com.microsoft.bingads.v13.campaignmanagement.Setting;
import com.microsoft.bingads.v13.campaignmanagement.ShoppingSetting;
import com.microsoft.bingads.v13.campaignmanagement.TargetCpaBiddingScheme;
import com.microsoft.bingads.v13.campaignmanagement.TargetImpressionShareBiddingScheme;
import com.microsoft.bingads.v13.campaignmanagement.TargetRoasBiddingScheme;
import com.microsoft.bingads.v13.campaignmanagement.TargetSetting;
import com.microsoft.bingads.v13.campaignmanagement.TargetSettingDetail;
import com.microsoft.bingads.v13.internal.bulk.BulkMapping;
import com.microsoft.bingads.v13.internal.bulk.ComplexBulkMapping;
import com.microsoft.bingads.v13.internal.bulk.MappingHelpers;
import com.microsoft.bingads.v13.internal.bulk.RowValues;
import com.microsoft.bingads.v13.internal.bulk.SimpleBulkMapping;
import com.microsoft.bingads.v13.internal.bulk.StringExtensions;
import com.microsoft.bingads.v13.internal.bulk.StringTable;
import com.microsoft.bingads.v13.internal.bulk.entities.SingleRecordBulkEntity;
/**
* Represents a campaign that can be read or written in a bulk file.
*
* This class exposes the {@link #setCampaign} and {@link #getCampaign} methods
* that can be used to read and write fields of the Campaign record in a bulk file.
*
*
* For more information, see Campaign at
* https://go.microsoft.com/fwlink/?linkid=846127.
*
*
* @see BulkServiceManager
* @see BulkOperation
* @see BulkFileReader
* @see BulkFileWriter
*/
public class BulkCampaign extends SingleRecordBulkEntity {
private Long accountId;
private Campaign campaign;
private QualityScoreData qualityScoreData;
private String budgetName;
private static final List> MAPPINGS;
private static BiConsumer budgetToCsv;
private static BiConsumer csvToBudget;
private Setting getCampaignSetting(Class extends Setting> settingClass, boolean addIfNotExist) {
if (campaign.getSettings() == null && addIfNotExist) {
tryAddCampaignSettings();
}
if (getCampaign().getSettings() == null) return null;
List settings = getCampaign().getSettings().getSettings().stream().filter(s -> s.getClass() == settingClass).collect(Collectors.toList());
if (settings.isEmpty()) return null;
if (settings.size() != 1) {
throw new IllegalArgumentException(String.format("Can only have 1 %s in Campaign Settings.", settingClass.getSimpleName()));
}
return settings.get(0);
}
private void tryAddCampaignSettings() {
Collection campaignTypes = campaign.getCampaignType();
if (campaignTypes.isEmpty()) return;
if (campaignTypes.size() > 1) {
throw new IllegalArgumentException("Can only have 1 campaign type in Campaign types.");
}
for (CampaignType type : campaignTypes) {
// in fact there is only one item in the list.
addCampaignSettings(type);
}
}
private void addCampaignSettings(CampaignType campaignType) {
ArrayOfSetting arrayOfSettings = new ArrayOfSetting();
Setting setting = null;
switch (campaignType) {
case SEARCH:
break;
case SHOPPING:
case AUDIENCE:
setting = new ShoppingSetting();
setting.setType(ShoppingSetting.class.getSimpleName());
break;
case DYNAMIC_SEARCH_ADS:
setting = new DynamicSearchAdsSetting();
setting.setType(DynamicSearchAdsSetting.class.getSimpleName());
break;
}
if (setting != null) {
arrayOfSettings.getSettings().add(setting);
}
setting = new TargetSetting();
setting.setType(TargetSetting.class.getSimpleName());
arrayOfSettings.getSettings().add(setting);
campaign.setSettings(arrayOfSettings);
}
static {
//Consumers to describe getting and setting Daily and Monthly budget fields based on the budget type and budget columns
budgetToCsv = new BiConsumer() {
@Override
public void accept(BulkCampaign c, RowValues values) {
BudgetLimitType budgetType = c.getCampaign().getBudgetType();
if (budgetType == null) {
return;
}
Double budget = null;
if (isDailyBudget(budgetType)) {
budget = c.getCampaign().getDailyBudget();
}
if (budget == null) {
return;
}
values.put(StringTable.Budget, budget.toString());
}
};
csvToBudget = new BiConsumer() {
@Override
public void accept(RowValues values, BulkCampaign c) {
String budgetTypeRowValue = values.get(StringTable.BudgetType);
BudgetLimitType budgetType = StringExtensions.parseOptional(budgetTypeRowValue, new Function() {
@Override
public BudgetLimitType apply(String value) {
return BudgetLimitType.fromValue(value);
}
});
if (budgetType == null) {
return;
}
String budgetRowValue = values.get(StringTable.Budget);
if (budgetRowValue == null) {
return;
}
Double budgetValue = StringExtensions.nullOrDouble(budgetRowValue);
c.getCampaign().setBudgetType(budgetType);
if (isDailyBudget(budgetType)) {
c.getCampaign().setDailyBudget(budgetValue);
}
}
};
List> m = new ArrayList>();
m.add(new SimpleBulkMapping(StringTable.CampaignType,
new Function() {
@Override
public String apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
if (c.getCampaign().getCampaignType().size() != 1) {
throw new IllegalArgumentException("Only 1 CampaignType can be set in Campaign");
}
Collection campaignTypes = c.getCampaign().getCampaignType();
return (campaignTypes.toArray(new CampaignType[campaignTypes.size()])[0]).value();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
CampaignType campaignType = StringExtensions.parseOptional(v, new Function() {
@Override
public CampaignType apply(String value) {
return CampaignType.fromValue(value);
}
});
if (campaignType != null) {
c.getCampaign().setCampaignType(Collections.singleton(campaignType));
c.addCampaignSettings(campaignType);
}
}
}
));
m.add(new SimpleBulkMapping(StringTable.Id,
new Function() {
@Override
public Long apply(BulkCampaign c) {
return c.getCampaign().getId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setId(StringExtensions.nullOrLong(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.Status,
new Function() {
@Override
public String apply(BulkCampaign c) {
return c.getCampaign().getStatus() != null ? c.getCampaign().getStatus().value() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setStatus(StringExtensions.parseOptional(v, new Function() {
@Override
public CampaignStatus apply(String value) {
return CampaignStatus.fromValue(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.ParentId,
new Function() {
@Override
public Long apply(BulkCampaign c) {
return c.getAccountId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.setAccountId(StringExtensions.nullOrLong(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.Campaign,
new Function() {
@Override
public String apply(BulkCampaign c) {
return c.getCampaign().getName();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setName(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.TimeZone,
new Function() {
@Override
public String apply(BulkCampaign c) {
return c.getCampaign().getTimeZone();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setTimeZone(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.Language,
new Function() {
@Override
public String apply(BulkCampaign c) {
return StringExtensions.writeCampaignLanguages(";", c.getCampaign().getLanguages(), c.getCampaign().getId());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
ArrayOfstring languages = new ArrayOfstring();
List languageArray = StringExtensions.parseCampaignLanguages(v);
if(languageArray == null) {
languages = null;
} else {
languages.getStrings().addAll(languageArray);
}
c.getCampaign().setLanguages(languages);
}
}
));
m.add(new SimpleBulkMapping(StringTable.BudgetType,
new Function() {
@Override
public String apply(BulkCampaign c) {
return c.getCampaign().getBudgetType() != null ? c.getCampaign().getBudgetType().value() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setBudgetType(StringExtensions.parseOptional(v, new Function() {
@Override
public BudgetLimitType apply(String value) {
return BudgetLimitType.fromValue(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.BudgetId,
new Function() {
@Override
public String apply(BulkCampaign c) {
return c.getCampaign().getBudgetId() != null ? c.getCampaign().getBudgetId().toString() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setBudgetId(StringExtensions.nullOrLong(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.BudgetName,
new Function() {
@Override
public String apply(BulkCampaign c) {
return c.getBudgetName();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.setBudgetName(v);
}
}
));
m.add(new ComplexBulkMapping(BulkCampaign.budgetToCsv, BulkCampaign.csvToBudget));
m.add(new SimpleBulkMapping(StringTable.BidAdjustment,
new Function() {
@Override
public Integer apply(BulkCampaign c) {
return c.getCampaign().getAudienceAdsBidAdjustment();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setAudienceAdsBidAdjustment(StringExtensions.parseOptionalInteger(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.BingMerchantCenterId,
new Function() {
@Override
public Long apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(ShoppingSetting.class, false);
return setting == null? null : ((ShoppingSetting)setting).getStoreId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(ShoppingSetting.class, true);
if (setting == null) {
return;
}
((ShoppingSetting)setting).setStoreId(StringExtensions.parseOptional(v, new Function() {
@Override
public Long apply(String s) {
return Long.parseLong(s);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.CampaignPriority,
new Function() {
@Override
public Integer apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(ShoppingSetting.class, false);
return setting == null? null : ((ShoppingSetting)setting).getPriority();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(ShoppingSetting.class, true);
if (setting == null) {
return;
}
((ShoppingSetting)setting).setPriority(StringExtensions.parseOptional(v, new Function() {
@Override
public Integer apply(String s) {
return Integer.parseInt(s);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.CountryCode,
new Function() {
@Override
public String apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(ShoppingSetting.class, false);
return setting == null? null : ((ShoppingSetting)setting).getSalesCountryCode();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(ShoppingSetting.class, true);
if (setting == null) {
return;
}
((ShoppingSetting)setting).setSalesCountryCode(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.LocalInventoryAdsEnabled,
new Function() {
@Override
public String apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(ShoppingSetting.class, false);
if (setting == null) {
return null;
}
return StringExtensions.toBooleanBulkString(((ShoppingSetting)setting).getLocalInventoryAdsEnabled());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(ShoppingSetting.class, true);
if (setting == null) {
return;
}
((ShoppingSetting)setting).setLocalInventoryAdsEnabled(StringExtensions.parseOptional(v, new Function() {
@Override
public Boolean apply(String value) {
return Boolean.parseBoolean(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.TargetSetting,
new Function() {
@Override
public String apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(TargetSetting.class, false);
return StringExtensions.toBulkString((TargetSetting)setting);
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(TargetSetting.class, true);
List details = StringExtensions.parseTargetSettingDetails(v);
if (setting == null || details == null) {
return;
}
TargetSetting targetSetting = new TargetSetting();
targetSetting.setType(TargetSetting.class.getSimpleName());
targetSetting.setDetails(new ArrayOfTargetSettingDetail());
targetSetting.getDetails().getTargetSettingDetails().addAll(details);
if (c.getCampaign().getSettings() == null) {
c.getCampaign().setSettings(new ArrayOfSetting());
}
c.getCampaign().getSettings().getSettings().add(setting);
}
}
));
m.add(new SimpleBulkMapping(StringTable.TrackingTemplate,
new Function() {
@Override
public String apply(BulkCampaign c) {
return StringExtensions.toOptionalBulkString(c.getCampaign().getTrackingUrlTemplate(), c.getCampaign().getId());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setTrackingUrlTemplate(StringExtensions.getValueOrEmptyString(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.CustomParameter,
new Function() {
@Override
public String apply(BulkCampaign c) {
return StringExtensions.toCustomParaBulkString(c.getCampaign().getUrlCustomParameters(), c.getCampaign().getId());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
try {
c.getCampaign().setUrlCustomParameters(StringExtensions.parseCustomParameters(v));
} catch (Exception e) {
e.printStackTrace();
}
}
}
));
m.add(new ComplexBulkMapping(
new BiConsumer() {
@Override
public void accept(BulkCampaign c, RowValues values) {
// BiddingScheme to Csv
try {
BiddingScheme biddingScheme = c.getCampaign().getBiddingScheme();
if (biddingScheme == null) {
return;
}
values.put(StringTable.BidStrategyType, StringExtensions.toBiddingSchemeBulkString(biddingScheme));
if (c.getCampaign().getBiddingScheme() instanceof MaxClicksBiddingScheme) {
Bid maxCpc = ((MaxClicksBiddingScheme)c.getCampaign().getBiddingScheme()).getMaxCpc();
values.put(StringTable.BidStrategyMaxCpc, StringExtensions.toBidBulkString(maxCpc, c.getCampaign().getId()));
}
else if (c.getCampaign().getBiddingScheme() instanceof MaxConversionsBiddingScheme) {
Bid maxCpc = ((MaxConversionsBiddingScheme)c.getCampaign().getBiddingScheme()).getMaxCpc();
values.put(StringTable.BidStrategyMaxCpc, StringExtensions.toBidBulkString(maxCpc, c.getCampaign().getId()));
}
else if (c.getCampaign().getBiddingScheme() instanceof TargetCpaBiddingScheme) {
Bid maxCpc = ((TargetCpaBiddingScheme)c.getCampaign().getBiddingScheme()).getMaxCpc();
values.put(StringTable.BidStrategyMaxCpc, StringExtensions.toBidBulkString(maxCpc, c.getCampaign().getId()));
Double targetCpa = ((TargetCpaBiddingScheme)c.getCampaign().getBiddingScheme()).getTargetCpa();
if (targetCpa != null) {
values.put(StringTable.BidStrategyTargetCpa, targetCpa.toString());
}
} else if (c.getCampaign().getBiddingScheme() instanceof MaxConversionValueBiddingScheme) {
Double targetRoas = ((MaxConversionValueBiddingScheme)c.getCampaign().getBiddingScheme()).getTargetRoas();
if (targetRoas != null) {
values.put(StringTable.BidStrategyTargetRoas, StringExtensions.toBulkString(targetRoas.toString()));
}
} else if (c.getCampaign().getBiddingScheme() instanceof TargetRoasBiddingScheme) {
TargetRoasBiddingScheme targetRoasBiddingScheme = (TargetRoasBiddingScheme)c.getCampaign().getBiddingScheme();
if (targetRoasBiddingScheme != null)
{
values.put(StringTable.BidStrategyMaxCpc, StringExtensions.toBidBulkString(targetRoasBiddingScheme.getMaxCpc(), c.getCampaign().getId()));
values.put(StringTable.BidStrategyTargetRoas, StringExtensions.toBulkString(targetRoasBiddingScheme.getTargetRoas()));
}
} else if (c.getCampaign().getBiddingScheme() instanceof TargetImpressionShareBiddingScheme) {
TargetImpressionShareBiddingScheme targetImpressionShareBiddingScheme = (TargetImpressionShareBiddingScheme)c.getCampaign().getBiddingScheme();
if (targetImpressionShareBiddingScheme != null)
{
values.put(StringTable.BidStrategyMaxCpc, StringExtensions.toBidBulkString(targetImpressionShareBiddingScheme.getMaxCpc(), c.getCampaign().getId()));
values.put(StringTable.BidStrategyTargetAdPosition, StringExtensions.toOptionalBulkString(targetImpressionShareBiddingScheme.getTargetAdPosition(), c.getCampaign().getId()));
values.put(StringTable.BidStrategyTargetImpressionShare, StringExtensions.toBulkString(targetImpressionShareBiddingScheme.getTargetImpressionShare()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
},
new BiConsumer() {
@Override
public void accept(RowValues values, BulkCampaign c) {
// Csv to BiddingScheme
try {
String bidStrategyTypeRowValue = values.get(StringTable.BidStrategyType);
BiddingScheme biddingScheme = StringExtensions.parseBiddingScheme(bidStrategyTypeRowValue);
if (biddingScheme == null) {
return;
}
String maxCpcRowValue = values.get(StringTable.BidStrategyMaxCpc);
String targetCpaRowValue = values.get(StringTable.BidStrategyTargetCpa);
String targetRoas = values.get(StringTable.BidStrategyTargetRoas);
String targetAdPositionValue = values.get(StringTable.BidStrategyTargetAdPosition);
String targetImpressionShareRowValue = values.get(StringTable.BidStrategyTargetImpressionShare);
Bid maxCpcValue = StringExtensions.parseBid(maxCpcRowValue);
Double targetCpaValue = StringExtensions.nullOrDouble(targetCpaRowValue);
Double targetRosValue = StringExtensions.nullOrDouble(targetRoas);
Double targetImpressionShareValue = StringExtensions.nullOrDouble(targetImpressionShareRowValue);
if (biddingScheme instanceof MaxClicksBiddingScheme) {
((MaxClicksBiddingScheme)biddingScheme).setMaxCpc(maxCpcValue);
}
else if (biddingScheme instanceof MaxConversionsBiddingScheme) {
((MaxConversionsBiddingScheme)biddingScheme).setMaxCpc(maxCpcValue);
} else if (biddingScheme instanceof TargetCpaBiddingScheme) {
((TargetCpaBiddingScheme)biddingScheme).setMaxCpc(maxCpcValue);
((TargetCpaBiddingScheme)biddingScheme).setTargetCpa(targetCpaValue);
} else if (biddingScheme instanceof MaxConversionValueBiddingScheme) {
((MaxConversionValueBiddingScheme)biddingScheme).setTargetRoas(targetRosValue);
} else if (biddingScheme instanceof TargetRoasBiddingScheme) {
((TargetRoasBiddingScheme)biddingScheme).setMaxCpc(maxCpcValue);
((TargetRoasBiddingScheme)biddingScheme).setTargetRoas(targetRosValue);
} else if (biddingScheme instanceof TargetImpressionShareBiddingScheme) {
((TargetImpressionShareBiddingScheme)biddingScheme).setType("TargetImpressionShare");
((TargetImpressionShareBiddingScheme)biddingScheme).setMaxCpc(maxCpcValue);
((TargetImpressionShareBiddingScheme)biddingScheme).setTargetImpressionShare(targetImpressionShareValue);
((TargetImpressionShareBiddingScheme)biddingScheme).setTargetAdPosition(targetAdPositionValue);
}
c.getCampaign().setBiddingScheme(biddingScheme);
} catch (Exception e) {
e.printStackTrace();
}
}
}
));
m.add(new SimpleBulkMapping(StringTable.Website,
new Function() {
@Override
public String apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(DynamicSearchAdsSetting.class, false);
if (setting == null) {
return null;
}
return ((DynamicSearchAdsSetting)setting).getDomainName();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(DynamicSearchAdsSetting.class, true);
if (setting == null) {
return;
}
((DynamicSearchAdsSetting)setting).setDomainName(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.DomainLanguage,
new Function() {
@Override
public String apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(DynamicSearchAdsSetting.class, false);
if (setting == null) {
return null;
}
return ((DynamicSearchAdsSetting)setting).getLanguage();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(DynamicSearchAdsSetting.class, true);
if (setting == null) {
return;
}
((DynamicSearchAdsSetting)setting).setLanguage(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.Source,
new Function() {
@Override
public String apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(DynamicSearchAdsSetting.class, false);
if (setting == null) {
return null;
}
DynamicSearchAdsSetting dsaSetting = (DynamicSearchAdsSetting)setting;
if (dsaSetting.getSource() == null) {
return null;
}
return dsaSetting.getSource().value();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(DynamicSearchAdsSetting.class, true);
if (setting == null) {
return;
}
((DynamicSearchAdsSetting)setting).setSource(
StringExtensions.parseOptional(v,
new Function() {
@Override
public DynamicSearchAdsSource apply(String value) {
return DynamicSearchAdsSource.fromValue(value);
}
}
)
);
}
}
));
m.add(new SimpleBulkMapping(StringTable.SubType,
new Function() {
@Override
public String apply(BulkCampaign c) {
return c.getCampaign().getSubType();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setSubType(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.ExperimentId,
new Function() {
@Override
public String apply(BulkCampaign c) {
return StringExtensions.toBulkString(c.getCampaign().getExperimentId());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setExperimentId(StringExtensions.nullOrLong(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.FinalUrlSuffix,
new Function() {
@Override
public String apply(BulkCampaign c) {
return StringExtensions.toOptionalBulkString(c.getCampaign().getFinalUrlSuffix(), c.getCampaign().getId());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setFinalUrlSuffix(StringExtensions.getValueOrEmptyString(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.PageFeedIds,
new Function() {
@Override
public String apply(BulkCampaign c) {
Setting setting = c.getCampaignSetting(DynamicSearchAdsSetting.class, false);
if (setting == null) {
return null;
}
DynamicSearchAdsSetting dsaSetting = (DynamicSearchAdsSetting)setting;
if (dsaSetting.getPageFeedIds() == null
|| dsaSetting.getPageFeedIds().getLongs() == null
||dsaSetting.getPageFeedIds().getLongs().size() == 0)
{
return null;
}
return StringExtensions.toIdListBulkString(";", dsaSetting.getPageFeedIds());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(DynamicSearchAdsSetting.class, true);
if (setting == null || v == null) {
return;
}
ArrayOflong ids = new ArrayOflong();
List idArray = StringExtensions.parseIdList(v);
if (idArray == null) {
ids = null;
} else {
ids.getLongs().addAll(idArray);
}
((DynamicSearchAdsSetting)setting).setPageFeedIds(ids);
}
}
));
m.add(new SimpleBulkMapping(StringTable.AdScheduleUseSearcherTimeZone,
new Function() {
@Override
public String apply(BulkCampaign t) {
if (t.getCampaign().getAdScheduleUseSearcherTimeZone()== null) {
return null;
}
return StringExtensions.toUseSearcherTimeZoneBulkString(t.getCampaign().getAdScheduleUseSearcherTimeZone(), t.getCampaign().getId());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setAdScheduleUseSearcherTimeZone(StringExtensions.parseUseSearcherTimeZone(v));
}
}
));
MAPPINGS = Collections.unmodifiableList(m);
}
/**
* Gets the identifier of the account that contains the campaign.
*
*
* Corresponds to the 'Parent Id' field in the bulk file.
*
*/
public Long getAccountId() {
return accountId;
}
/**
* Sets the identifier of the account that contains the campaign.
*
*
* Corresponds to the 'Parent Id' field in the bulk file.
*
*/
public void setAccountId(Long accountId) {
this.accountId = accountId;
}
/**
* Gets a campaign within an account.
*/
public Campaign getCampaign() {
return campaign;
}
/**
* Sets a campaign within an account.
*/
public void setCampaign(Campaign campaign) {
this.campaign = campaign;
}
/**
* Gets the quality score data for the campaign.
*/
public QualityScoreData getQualityScoreData() {
return qualityScoreData;
}
/**
* Gets the budget name for the campaign
* */
public String getBudgetName() {
return budgetName;
}
/**
* Sets the budget name for the campaign
* */
public void setBudgetName(String budgetName) {
this.budgetName = budgetName;
}
@Override
public void processMappingsFromRowValues(RowValues values) {
this.setCampaign(new Campaign());
MappingHelpers.convertToEntity(values, MAPPINGS, this);
qualityScoreData = QualityScoreData.readFromRowValuesOrNull(values);
}
@Override
public void processMappingsToRowValues(RowValues values, boolean excludeReadonlyData) {
validatePropertyNotNull(getCampaign(), "Campaign");
MappingHelpers.convertToValues(this, values, MAPPINGS);
if (!excludeReadonlyData) {
QualityScoreData.writeToRowValuesIfNotNull(qualityScoreData, values);
}
}
public static boolean isDailyBudget(BudgetLimitType budgetType) {
return BudgetLimitType.DAILY_BUDGET_ACCELERATED.equals(budgetType) || BudgetLimitType.DAILY_BUDGET_STANDARD.equals(budgetType);
}
}