com.microsoft.bingads.v13.bulk.entities.BulkAudience 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.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.Audience;
import com.microsoft.bingads.v13.campaignmanagement.EntityScope;
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;
/**
* Represents a basic audience that can be read or written in a bulk file.
*
* This class exposes the {@link BulkAudience#setAudience} and {@link BulkAudience#getAudience}
* methods that can be used to read and write fields of the Audience record in a bulk file.
*
*
* For more information, see Audience at
* https://go.microsoft.com/fwlink/?linkid=846127.
*
*
* @see BulkServiceManager
* @see BulkOperation
* @see BulkFileReader
* @see BulkFileWriter
*/
public abstract class BulkAudience extends SingleRecordBulkEntity {
private T audience;
private Status status;
private static final List> MAPPINGS;
static {
List> m = new ArrayList>();
m.add(new SimpleBulkMapping(StringTable.Status,
new Function() {
@Override
public String apply(BulkAudience c) {
return c.getStatus() != null ? c.getStatus().value() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAudience c) {
c.setStatus(StringExtensions.parseOptional(v, new Function() {
@Override
public Status apply(String value) {
return Status.fromValue(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.Id,
new Function() {
@Override
public Long apply(BulkAudience c) {
return c.getAudience().getId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAudience c) {
c.getAudience().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(BulkAudience c) {
return c.getAudience().getParentId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAudience c) {
c.getAudience().setParentId(StringExtensions.parseOptional(v, new Function() {
@Override
public Long apply(String value) {
return Long.parseLong(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.Audience,
new Function() {
@Override
public String apply(BulkAudience c) {
return c.getAudience().getName();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAudience c) {
c.getAudience().setName(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.AudienceSearchSize,
new Function() {
@Override
public Long apply(BulkAudience c) {
return c.getAudience().getSearchSize();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAudience c) {
c.getAudience().setSearchSize(StringExtensions.parseOptional(v, new Function() {
@Override
public Long apply(String value) {
return Long.parseLong(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.Description,
new Function() {
@Override
public String apply(BulkAudience c) {
return c.getAudience().getDescription();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAudience c) {
c.getAudience().setDescription(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.MembershipDuration,
new Function() {
@Override
public Integer apply(BulkAudience c) {
return c.getAudience().getMembershipDuration();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAudience c) {
c.getAudience().setMembershipDuration(StringExtensions.parseOptional(v, new Function() {
@Override
public Integer apply(String value) {
return Integer.parseInt(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.Scope,
new Function() {
@Override
public String apply(BulkAudience c) {
return c.getAudience().getScope() != null ? c.getAudience().getScope().value() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAudience c) {
c.getAudience().setScope(StringExtensions.parseOptional(v, new Function() {
@Override
public EntityScope apply(String value) {
return EntityScope.fromValue(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.AudienceNetworkSize,
new Function() {
@Override
public Long apply(BulkAudience c) {
return c.getAudience().getAudienceNetworkSize();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAudience c) {
c.getAudience().setAudienceNetworkSize(StringExtensions.parseOptional(v, new Function() {
@Override
public Long apply(String value) {
return Long.parseLong(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.SupportedCampaignTypes,
new Function() {
@Override
public String apply(BulkAudience c) {
return StringExtensions.writeArrayOfstring(c.getAudience().getSupportedCampaignTypes(), ";");
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAudience c) {
c.getAudience().setSupportedCampaignTypes(StringExtensions.parseArrayOfString(v));
}
}
));
MAPPINGS = Collections.unmodifiableList(m);
}
@Override
public void processMappingsFromRowValues(RowValues values) {
this.setAudience(createAudience());
MappingHelpers.convertToEntity(values, MAPPINGS, this);
}
@Override
public void processMappingsToRowValues(RowValues values, boolean excludeReadonlyData) {
validatePropertyNotNull(getAudience(), "Audience");
MappingHelpers.convertToValues(this, values, MAPPINGS);
}
public abstract T createAudience();
/**
* Gets the audience.
*/
public T getAudience() {
return audience;
}
/**
* Sets the audience.
*/
public void setAudience(T audience) {
this.audience = audience;
}
/**
* Gets the status of the audience.
*
*
* The value is Active if the audience is available in the account's shared library.
* The value is Deleted if the audience is deleted from the library,
* or should be deleted in a subsequent upload operation.
* Corresponds to the 'Status' field in the bulk file.
*
*/
public Status getStatus() {
return status;
}
/**
* Sets the status of the audience.
*
*
* The value is Active if the audience is available to be associated with an ad group.
* The value is Deleted if the audience is deleted, or should be deleted
* in a subsequent upload operation.
* Corresponds to the 'Status' field in the bulk file.
*
*/
public void setStatus(Status status) {
this.status = status;
}
}