com.microsoft.bingads.v13.bulk.entities.BulkCampaign Maven / Gradle / Ivy
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.AppSetting;
import com.microsoft.bingads.v13.campaignmanagement.AppStore;
import com.microsoft.bingads.v13.campaignmanagement.ArrayOfArrayOfKeyValuePairOfstringstring;
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.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.DisclaimerSetting;
import com.microsoft.bingads.v13.campaignmanagement.DynamicFeedSetting;
import com.microsoft.bingads.v13.campaignmanagement.DynamicSearchAdsSetting;
import com.microsoft.bingads.v13.campaignmanagement.DynamicSearchAdsSource;
import com.microsoft.bingads.v13.campaignmanagement.PerformanceMaxSetting;
import com.microsoft.bingads.v13.campaignmanagement.Setting;
import com.microsoft.bingads.v13.campaignmanagement.ShoppingSetting;
import com.microsoft.bingads.v13.campaignmanagement.TargetSetting;
import com.microsoft.bingads.v13.campaignmanagement.TargetSettingDetail;
import com.microsoft.bingads.v13.campaignmanagement.VerifiedTrackingSetting;
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 String BidStrategyName;
private String DestinationChannel;
private Boolean IsMultiChannelCampaign;
private Boolean ShouldServeOnMSAN;
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();
List settings = new ArrayList();
Setting setting = null;
switch (campaignType) {
case SEARCH:
case DYNAMIC_SEARCH_ADS:
setting = new DynamicSearchAdsSetting();
setting.setType(DynamicSearchAdsSetting.class.getSimpleName());
settings.add(setting);
setting = new DisclaimerSetting();
setting.setType(DisclaimerSetting.class.getSimpleName());
settings.add(setting);
break;
case AUDIENCE:
setting = new ShoppingSetting();
setting.setType(ShoppingSetting.class.getSimpleName());
settings.add(setting);
setting = new DynamicFeedSetting();
setting.setType(DynamicFeedSetting.class.getSimpleName());
settings.add(setting);
setting = new VerifiedTrackingSetting();
setting.setType(VerifiedTrackingSetting.class.getSimpleName());
settings.add(setting);
break;
case SHOPPING:
setting = new ShoppingSetting();
setting.setType(ShoppingSetting.class.getSimpleName());
settings.add(setting);
break;
case PERFORMANCE_MAX:
setting = new PerformanceMaxSetting();
setting.setType(PerformanceMaxSetting.class.getSimpleName());
settings.add(setting);
setting = new ShoppingSetting();
setting.setType(ShoppingSetting.class.getSimpleName());
settings.add(setting);
break;
case APP:
setting = new AppSetting();
setting.setType(AppSetting.class.getSimpleName());
settings.add(setting);
}
arrayOfSettings.getSettings().addAll(settings);
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 StringExtensions.fromValueOptional(value, BudgetLimitType.class);
}
});
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 StringExtensions.fromValueOptional(value, CampaignType.class);
}
});
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 StringExtensions.fromValueOptional(value, CampaignStatus.class);
}
}));
}
}
));
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 StringExtensions.fromValueOptional(value, BudgetLimitType.class);
}
}));
}
}
));
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 SimpleBulkMapping(StringTable.BidStrategyId,
new Function() {
@Override
public String apply(BulkCampaign c) {
return c.getCampaign().getBidStrategyId() != null ? c.getCampaign().getBidStrategyId().toString() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setBidStrategyId(StringExtensions.nullOrLong(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.BidStrategyName,
new Function() {
@Override
public String apply(BulkCampaign c) {
return c.getBidStrategyName();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.setBidStrategyName(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.FeedId,
new Function() {
@Override
public Long apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(DynamicFeedSetting.class, false);
return setting == null? null : ((DynamicFeedSetting)setting).getFeedId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(DynamicFeedSetting.class, true);
if (setting == null) {
return;
}
((DynamicFeedSetting)setting).setFeedId(StringExtensions.parseOptional(v, new Function() {
@Override
public Long apply(String s) {
return Long.parseLong(s);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.DisclaimerAdsEnabled,
new Function() {
@Override
public Boolean apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(DisclaimerSetting.class, false);
if (setting == null) {
return null;
}
return ((DisclaimerSetting)setting).getDisclaimerAdsEnabled();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(DisclaimerSetting.class, true);
if (setting == null) {
return;
}
((DisclaimerSetting)setting).setDisclaimerAdsEnabled(StringExtensions.parseOptional(v, new Function() {
@Override
public Boolean apply(String value) {
return Boolean.parseBoolean(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.FinalUrlExpansionOptOut,
new Function() {
@Override
public Boolean apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(PerformanceMaxSetting.class, false);
if (setting == null) {
return null;
}
return ((PerformanceMaxSetting)setting).getFinalUrlExpansionOptOut();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(PerformanceMaxSetting.class, true);
if (setting == null) {
return;
}
((PerformanceMaxSetting)setting).setFinalUrlExpansionOptOut(StringExtensions.parseOptional(v, new Function() {
@Override
public Boolean apply(String value) {
return Boolean.parseBoolean(value);
}
}));
}
}
));
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.MerchantCenterId,
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.ShoppableAdsEnabled,
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).getShoppableAdsEnabled());
}
},
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).setShoppableAdsEnabled(StringExtensions.parseOptional(v, new Function() {
@Override
public Boolean apply(String value) {
return Boolean.parseBoolean(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.FeedLabel,
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 ((ShoppingSetting)setting).getFeedLabel();
}
},
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).setFeedLabel(v);
}
}
));
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
StringExtensions.writeBiddingScheme(c.getCampaign().getBiddingScheme(), c.getCampaign().getId(), values);
}
},
new BiConsumer() {
@Override
public void accept(RowValues values, BulkCampaign c) {
BiddingScheme biddingScheme = StringExtensions.readBiddingScheme(values);
if (biddingScheme != null) {
c.getCampaign().setBiddingScheme(biddingScheme);
}
}
}
));
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.DynamicDescriptionEnabled,
new Function() {
@Override
public Boolean 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).getDynamicDescriptionEnabled();
}
},
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).setDynamicDescriptionEnabled(StringExtensions.parseOptional(v, new Function() {
@Override
public Boolean apply(String value) {
return Boolean.parseBoolean(value);
}
}));
}
}
));
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 StringExtensions.fromValueOptional(value, DynamicSearchAdsSource.class);
}
}
)
);
}
}
));
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) {
DynamicSearchAdsSetting dsaSetting = (DynamicSearchAdsSetting)setting;
if (dsaSetting.getPageFeedIds() == null
|| dsaSetting.getPageFeedIds().getLongs() == null
||dsaSetting.getPageFeedIds().getLongs().size() == 0)
{
return null;
}
return StringExtensions.toIdListBulkString(";", dsaSetting.getPageFeedIds());
} else {
setting = c.getCampaignSetting(PerformanceMaxSetting.class, false);
if (setting == null) {
return null;
}
PerformanceMaxSetting performMaxSetting = (PerformanceMaxSetting)setting;
if (performMaxSetting.getPageFeedIds() == null
|| performMaxSetting.getPageFeedIds().getLongs() == null
||performMaxSetting.getPageFeedIds().getLongs().size() == 0)
{
return null;
}
return StringExtensions.toIdListBulkString(";", performMaxSetting.getPageFeedIds());
}
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null || v == null) {
return;
}
Setting setting = c.getCampaignSetting(DynamicSearchAdsSetting.class, true);
ArrayOflong ids = new ArrayOflong();
List idArray = StringExtensions.parseIdList(v);
if (idArray == null) {
ids = null;
} else {
ids.getLongs().addAll(idArray);
}
if (setting != null) {
((DynamicSearchAdsSetting)setting).setPageFeedIds(ids);
} else {
setting = c.getCampaignSetting(PerformanceMaxSetting.class, true);
if (setting == null) {
return;
} else {
((PerformanceMaxSetting)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(), null);
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setAdScheduleUseSearcherTimeZone(StringExtensions.parseUseSearcherTimeZone(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.MultiMediaAdBidAdjustment,
new Function() {
@Override
public Integer apply(BulkCampaign c) {
return c.getCampaign().getMultimediaAdsBidAdjustment();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.getCampaign().setMultimediaAdsBidAdjustment(StringExtensions.parseOptionalInteger(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.DestinationChannel,
new Function() {
@Override
public String apply(BulkCampaign c) {
return c.getDestinationChannel();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.setDestinationChannel(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.IsMultiChannelCampaign,
new Function() {
@Override
public Boolean apply(BulkCampaign t) {
return t.getIsMultiChannelCampaign();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.setIsMultiChannelCampaign(v == null ? null : Boolean.parseBoolean(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.AutoGeneratedImageOptOut,
new Function() {
@Override
public Boolean apply(BulkCampaign t) {
Setting setting = t.getCampaignSetting(PerformanceMaxSetting.class, false);
if (setting == null) {
return null;
}
PerformanceMaxSetting performMaxSetting = (PerformanceMaxSetting)setting;
return performMaxSetting.getAutoGeneratedImageOptOut();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
Setting setting = c.getCampaignSetting(PerformanceMaxSetting.class, false);
if (setting == null) {
return;
}
((PerformanceMaxSetting)setting).setAutoGeneratedImageOptOut(v == null ? null : Boolean.parseBoolean(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.AutoGeneratedTextOptOut,
new Function() {
@Override
public Boolean apply(BulkCampaign t) {
Setting setting = t.getCampaignSetting(PerformanceMaxSetting.class, false);
if (setting == null) {
return null;
}
PerformanceMaxSetting performMaxSetting = (PerformanceMaxSetting)setting;
return performMaxSetting.getAutoGeneratedTextOptOut();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
Setting setting = c.getCampaignSetting(PerformanceMaxSetting.class, false);
if (setting == null) {
return;
}
((PerformanceMaxSetting)setting).setAutoGeneratedTextOptOut(v == null ? null : Boolean.parseBoolean(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.CostPerSaleOptOut,
new Function() {
@Override
public Boolean apply(BulkCampaign t) {
Setting setting = t.getCampaignSetting(PerformanceMaxSetting.class, false);
if (setting == null) {
return null;
}
PerformanceMaxSetting performMaxSetting = (PerformanceMaxSetting)setting;
return performMaxSetting.getCostPerSaleOptOut();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
Setting setting = c.getCampaignSetting(PerformanceMaxSetting.class, false);
if (setting == null) {
return;
}
((PerformanceMaxSetting)setting).setCostPerSaleOptOut(v == null ? null : Boolean.parseBoolean(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.ShouldServeOnMSAN,
new Function() {
@Override
public Boolean apply(BulkCampaign t) {
return t.getShouldServeOnMSAN();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
c.setShouldServeOnMSAN(v == null ? null : Boolean.parseBoolean(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.AppStoreId,
new Function() {
@Override
public String apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(AppSetting.class, false);
if (setting == null) {
return null;
}
return ((AppSetting)setting).getAppId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(AppSetting.class, true);
if (setting == null) {
return;
}
((AppSetting)setting).setAppId(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.AppStore,
new Function() {
@Override
public String apply(BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return null;
}
Setting setting = c.getCampaignSetting(AppSetting.class, false);
if (setting == null) {
return null;
}
if (((AppSetting)setting).getAppStore().size() != 1) {
throw new IllegalArgumentException("Only 1 App Store can be set in App Campaign");
}
Collection appStore = ((AppSetting)setting).getAppStore();
return (appStore.toArray(new AppStore[appStore.size()])[0]).value();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkCampaign c) {
if (c.getCampaign().getCampaignType() == null) {
return;
}
Setting setting = c.getCampaignSetting(AppSetting.class, true);
if (setting == null) {
return;
}
((AppSetting)setting).setAppStore(StringExtensions.parseOptional(v, new Function>() {
@Override
public Collection apply(String value) {
return Collections.singletonList(StringExtensions.fromValueOptional(v, AppStore.class));
}
}));
}
}
));
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;
}
/**
* Gets the Bid Strategy name for the campaign
* */
public String getBidStrategyName() {
return BidStrategyName;
}
/**
* Sets the Bid Strategy name for the campaign
* */
public void setBidStrategyName(String bidStrategyName) {
BidStrategyName = bidStrategyName;
}
public String getDestinationChannel() {
return DestinationChannel;
}
public void setDestinationChannel(String destinationChannel) {
DestinationChannel = destinationChannel;
}
public Boolean getIsMultiChannelCampaign() {
return IsMultiChannelCampaign;
}
public void setIsMultiChannelCampaign(Boolean isMultiChannelCampaign) {
IsMultiChannelCampaign = isMultiChannelCampaign;
}
public Boolean getShouldServeOnMSAN() {
return ShouldServeOnMSAN;
}
public void setShouldServeOnMSAN(Boolean ShouldServeOnMSAN) {
ShouldServeOnMSAN = ShouldServeOnMSAN;
}
@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);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy