com.microsoft.bingads.v13.bulk.entities.BulkDataExclusion 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.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;
import com.microsoft.bingads.internal.UncheckedParseException;
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.DataExclusion;
import com.microsoft.bingads.v13.campaignmanagement.ArrayOfstring;
import com.microsoft.bingads.v13.campaignmanagement.BudgetLimitType;
import com.microsoft.bingads.v13.campaignmanagement.CallToAction;
import com.microsoft.bingads.v13.campaignmanagement.CampaignType;
import com.microsoft.bingads.v13.campaignmanagement.DeviceType;
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 Data Exclusion.
*
*
* This class exposes the {@link #setDataExclusion} and {@link #getDataExclusion} that can be used to read and write
* fields of the Asset Group record in a bulk file.
*
*
*
* For more information, see Data Exclusion at
* https://go.microsoft.com/fwlink/?linkid=846127.
*
*
* @see BulkServiceManager
* @see BulkOperation
* @see BulkFileReader
* @see BulkFileWriter
*/
public class BulkDataExclusion extends SingleRecordBulkEntity {
private DataExclusion DataExclusion;
private static final List> MAPPINGS;
static {
List> m = new ArrayList>();
m.add(new SimpleBulkMapping(StringTable.Id,
new Function() {
@Override
public Long apply(BulkDataExclusion c) {
return c.getDataExclusion().getId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkDataExclusion c) {
c.getDataExclusion().setId(StringExtensions.nullOrLong(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.DataExclusion,
new Function() {
@Override
public String apply(BulkDataExclusion c) {
return c.getDataExclusion().getName();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkDataExclusion c) {
c.getDataExclusion().setName(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.Description,
new Function() {
@Override
public String apply(BulkDataExclusion c) {
return c.getDataExclusion().getDescription();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkDataExclusion c) {
c.getDataExclusion().setDescription(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.StartDate,
new Function() {
@Override
public String apply(BulkDataExclusion t) {
if (t.getDataExclusion().getStartDate() == null) {
return null;
}
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format.format(t.getDataExclusion().getStartDate().getTime());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkDataExclusion c) {
c.getDataExclusion().setStartDate(StringExtensions.parseOptional(v, new Function() {
@Override
public Calendar apply(String t) {
Calendar c = new GregorianCalendar();
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
c.setTime(format.parse(t));
} catch (ParseException ex) {
throw new UncheckedParseException(ex);
}
return c;
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.EndDate,
new Function() {
@Override
public String apply(BulkDataExclusion t) {
if (t.getDataExclusion().getEndDate() == null) {
return null;
}
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format.format(t.getDataExclusion().getEndDate().getTime());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkDataExclusion c) {
c.getDataExclusion().setEndDate(StringExtensions.parseOptional(v, new Function() {
@Override
public Calendar apply(String t) {
Calendar c = new GregorianCalendar();
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
c.setTime(format.parse(t));
} catch (ParseException ex) {
throw new UncheckedParseException(ex);
}
return c;
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.CampaignType,
new Function() {
@Override
public String apply(BulkDataExclusion c) {
return StringExtensions.toCampaignTypeListBulkString(",", c.getDataExclusion().getCampaignTypeFilter());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkDataExclusion c) {
c.getDataExclusion().setCampaignTypeFilter(StringExtensions.parseCampaignTypeList(v, ","));
}
}
));
m.add(new SimpleBulkMapping(StringTable.DeviceType,
new Function() {
@Override
public String apply(BulkDataExclusion t) {
return t.getDataExclusion().getDeviceTypeFilter() != null ? t.getDataExclusion().getDeviceTypeFilter().value() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkDataExclusion c) {
c.getDataExclusion().setDeviceTypeFilter(StringExtensions.parseOptional(v, new Function() {
@Override
public DeviceType apply(String value) {
return DeviceType.fromValue(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.CampaignAssociations,
new Function() {
@Override
public String apply(BulkDataExclusion c) {
return StringExtensions.toCampaignAssociationsBulkString(";", c.getDataExclusion().getCampaignAssociations());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkDataExclusion c) {
c.getDataExclusion().setCampaignAssociations(StringExtensions.parseCampaignAssociations(v, ";"));
}
}
));
MAPPINGS = Collections.unmodifiableList(m);
}
@Override
public void processMappingsFromRowValues(RowValues values) {
this.setDataExclusion(new DataExclusion());
MappingHelpers.convertToEntity(values, MAPPINGS, this);
}
@Override
public void processMappingsToRowValues(RowValues values, boolean excludeReadonlyData) {
validatePropertyNotNull(getDataExclusion(), "DataExclusion");
MappingHelpers.convertToValues(this, values, MAPPINGS);
}
/**
* Gets the DataExclusion Data Object of the Campaign Management Service.
*
*
* A subset of DataExclusion properties are available in the Ad Group record.
* For more information, see Ad Group at
* https://go.microsoft.com/fwlink/?linkid=846127.
*
*/
public DataExclusion getDataExclusion() {
return DataExclusion;
}
/**
* Sets the DataExclusion Data Object of the Campaign Management Service.
*
*
* A subset of DataExclusion properties are available in the Ad Group record.
* For more information, see Ad Group at
* https://go.microsoft.com/fwlink/?linkid=846127.
*
*/
public void setDataExclusion(DataExclusion DataExclusion) {
this.DataExclusion = DataExclusion;
}
}