com.microsoft.bingads.v13.bulk.entities.BulkAdGroupAudienceAssociation 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.Collections;
import java.util.List;
import com.microsoft.bingads.internal.functionalinterfaces.BiConsumer;
import com.microsoft.bingads.internal.functionalinterfaces.Function;
import com.microsoft.bingads.v13.campaignmanagement.AdGroupCriterionStatus;
import com.microsoft.bingads.v13.campaignmanagement.AudienceCriterion;
import com.microsoft.bingads.v13.campaignmanagement.BidMultiplier;
import com.microsoft.bingads.v13.campaignmanagement.BiddableAdGroupCriterion;
import com.microsoft.bingads.v13.campaignmanagement.CriterionBid;
import com.microsoft.bingads.v13.internal.bulk.BulkMapping;
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;
/**
* Base class for all Ad Group Audience Association subclasses that can be read
* or written in a bulk file.
*
* @see BulkAdGroupCustomAudienceAssociation
* @see BulkAdGroupInMarketAudienceAssociation
* @see BulkAdGroupProductAudienceAssociation
* @see BulkAdGroupRemarketingListAssociation
* @see BulkAdGroupSimilarRemarketingListAssociation
*/
public class BulkAdGroupAudienceAssociation extends SingleRecordBulkEntity {
private BiddableAdGroupCriterion biddableAdGroupCriterion;
private String campaignName;
private String adGroupName;
private String audienceName;
private static final List> MAPPINGS;
static {
List> m = new ArrayList>();
m.add(new SimpleBulkMapping(StringTable.Status,
new Function() {
@Override
public String apply(BulkAdGroupAudienceAssociation c) {
AdGroupCriterionStatus status = c.getBiddableAdGroupCriterion().getStatus();
return status == null ? null : status.value();
}
}, new BiConsumer() {
@Override
public void accept(String v, BulkAdGroupAudienceAssociation c) {
c.getBiddableAdGroupCriterion().setStatus(
StringExtensions.parseOptional(v, new Function() {
@Override
public AdGroupCriterionStatus apply(String s) {
return AdGroupCriterionStatus.fromValue(s);
}
}));
}
}));
m.add(new SimpleBulkMapping(StringTable.Id,
new Function() {
@Override
public Long apply(BulkAdGroupAudienceAssociation c) {
return c.getBiddableAdGroupCriterion().getId();
}
}, new BiConsumer() {
@Override
public void accept(String v, BulkAdGroupAudienceAssociation c) {
c.getBiddableAdGroupCriterion()
.setId(StringExtensions.parseOptional(v, new Function() {
@Override
public Long apply(String value) {
return Long.parseLong(value);
}
}));
}
}));
m.add(new SimpleBulkMapping(StringTable.ParentId,
new Function() {
@Override
public Long apply(BulkAdGroupAudienceAssociation c) {
return c.getBiddableAdGroupCriterion().getAdGroupId();
}
}, new BiConsumer() {
@Override
public void accept(String v, BulkAdGroupAudienceAssociation c) {
c.getBiddableAdGroupCriterion()
.setAdGroupId(StringExtensions.parseOptional(v, new Function() {
@Override
public Long apply(String value) {
return Long.parseLong(value);
}
}));
}
}));
m.add(new SimpleBulkMapping(StringTable.Campaign,
new Function() {
@Override
public String apply(BulkAdGroupAudienceAssociation c) {
return c.getCampaignName();
}
}, new BiConsumer() {
@Override
public void accept(String v, BulkAdGroupAudienceAssociation c) {
c.setCampaignName(v);
}
}));
m.add(new SimpleBulkMapping(StringTable.AdGroup,
new Function() {
@Override
public String apply(BulkAdGroupAudienceAssociation c) {
return c.getAdGroupName();
}
}, new BiConsumer() {
@Override
public void accept(String v, BulkAdGroupAudienceAssociation c) {
c.setAdGroupName(v);
}
}));
m.add(new SimpleBulkMapping(StringTable.Audience,
new Function() {
@Override
public String apply(BulkAdGroupAudienceAssociation c) {
return c.getAudienceName();
}
}, new BiConsumer() {
@Override
public void accept(String v, BulkAdGroupAudienceAssociation c) {
c.setAudienceName(v);
}
}));
m.add(new SimpleBulkMapping(StringTable.BidAdjustment,
new Function() {
@Override
public String apply(BulkAdGroupAudienceAssociation c) {
if (c.getBiddableAdGroupCriterion() instanceof BiddableAdGroupCriterion) {
CriterionBid bid = ((BiddableAdGroupCriterion) c.getBiddableAdGroupCriterion())
.getCriterionBid();
if (bid == null) {
return null;
} else {
return StringExtensions
.toCriterionBidMultiplierBulkString(((BidMultiplier) bid).getMultiplier());
}
} else {
return null;
}
}
}, new BiConsumer() {
@Override
public void accept(String v, BulkAdGroupAudienceAssociation c) {
if (c.getBiddableAdGroupCriterion() instanceof BiddableAdGroupCriterion) {
((BidMultiplier) ((BiddableAdGroupCriterion) c.getBiddableAdGroupCriterion())
.getCriterionBid()).setMultiplier(StringExtensions.nullOrDouble(v));
}
}
}));
m.add(new SimpleBulkMapping(StringTable.AudienceId,
new Function() {
@Override
public Long apply(BulkAdGroupAudienceAssociation c) {
if (c.getBiddableAdGroupCriterion() instanceof BiddableAdGroupCriterion) {
AudienceCriterion audienceCriterion = (AudienceCriterion) c.getBiddableAdGroupCriterion()
.getCriterion();
if (audienceCriterion == null) {
return null;
} else {
return audienceCriterion.getAudienceId();
}
} else {
return null;
}
}
}, new BiConsumer() {
@Override
public void accept(String v, BulkAdGroupAudienceAssociation c) {
AudienceCriterion audienceCriterion = (AudienceCriterion) c.getBiddableAdGroupCriterion()
.getCriterion();
if (audienceCriterion == null) {
return;
}
audienceCriterion
.setAudienceId(StringExtensions.parseOptional(v, new Function() {
@Override
public Long apply(String value) {
return Long.parseLong(value);
}
}));
}
}));
MAPPINGS = Collections.unmodifiableList(m);
}
@Override
public void processMappingsFromRowValues(RowValues values) {
BiddableAdGroupCriterion adGroupCriterion = new BiddableAdGroupCriterion();
adGroupCriterion.setType(BiddableAdGroupCriterion.class.getSimpleName());
BidMultiplier bidMultiplier = new BidMultiplier();
bidMultiplier.setType(BidMultiplier.class.getSimpleName());
AudienceCriterion audienceCriterion = new AudienceCriterion();
audienceCriterion.setType(AudienceCriterion.class.getSimpleName());
adGroupCriterion.setCriterion(audienceCriterion);
adGroupCriterion.setCriterionBid(bidMultiplier);
this.setBiddableAdGroupCriterion(adGroupCriterion);
MappingHelpers.convertToEntity(values, MAPPINGS, this);
}
@Override
public void processMappingsToRowValues(RowValues values, boolean excludeReadonlyData) {
validatePropertyNotNull(getBiddableAdGroupCriterion(), "AdGroupAudienceAssociation");
MappingHelpers.convertToValues(this, values, MAPPINGS);
}
/**
* Gets an AdGroup Criterion.
*/
public BiddableAdGroupCriterion getBiddableAdGroupCriterion() {
return this.biddableAdGroupCriterion;
}
/**
* Sets an AdGroup Criterion.
*/
public void setBiddableAdGroupCriterion(BiddableAdGroupCriterion adGroupCriterion) {
this.biddableAdGroupCriterion = adGroupCriterion;
}
/**
* Gets the name of the campaign. Corresponds to the 'Campaign' field in the
* bulk file.
*/
public String getCampaignName() {
return this.campaignName;
}
/**
* Sets the name of the campaign. Corresponds to the 'Campaign' field in the
* bulk file.
*/
public void setCampaignName(String campaignName) {
this.campaignName = campaignName;
}
/**
* Gets the name of the ad group.
*/
public String getAdGroupName() {
return this.adGroupName;
}
/**
* Sets the name of the ad group.
*/
public void setAdGroupName(String adGroupName) {
this.adGroupName = adGroupName;
}
/**
* Gets the name of the audience.
*/
public String getAudienceName() {
return this.audienceName;
}
/**
* Sets the name of the audience.
*/
public void setAudienceName(String audienceName) {
this.audienceName = audienceName;
}
}