com.microsoft.bingads.v13.bulk.entities.BulkProductAudience 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 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.ProductAudience;
import com.microsoft.bingads.v13.campaignmanagement.ProductAudienceType;
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;
/**
* Represents a product audience that can be read or written in a bulk file.
*
* This class exposes the {@link BulkProductAudience#setProductAudience} and {@link BulkProductAudience#getProductAudience}
* methods that can be used to read and write fields of the Product Audience record in a bulk file.
*
*
* For more information, see Product Audience at
* https://go.microsoft.com/fwlink/?linkid=846127.
*
*
* @see BulkServiceManager
* @see BulkOperation
* @see BulkFileReader
* @see BulkFileWriter
*/
public class BulkProductAudience extends BulkAudience {
private static final List> MAPPINGS;
static {
List> m = new ArrayList>();
m.add(new SimpleBulkMapping(StringTable.TagId,
new Function() {
@Override
public Long apply(BulkProductAudience c) {
return c.getProductAudience().getTagId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkProductAudience c) {
c.getProductAudience().setTagId(StringExtensions.parseOptional(v, new Function() {
@Override
public Long apply(String value) {
return Long.parseLong(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.ProductAudienceType,
new Function() {
@Override
public String apply(BulkProductAudience c) {
Collection productAudienceTypes = c.getProductAudience().getProductAudienceType();
if (productAudienceTypes == null || productAudienceTypes.size() == 0) return null;
if (productAudienceTypes.size() != 1) {
throw new IllegalArgumentException("Only 1 Product Audience Type can be set in ProductAudience");
}
return (productAudienceTypes.toArray(new ProductAudienceType[productAudienceTypes.size()])[0]).value();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkProductAudience c) {
ProductAudienceType productAudienceType = StringExtensions.parseOptional(v, new Function() {
@Override
public ProductAudienceType apply(String value) {
return StringExtensions.fromValueOptional(value, ProductAudienceType.class);
}
});
if (productAudienceType != null) {
c.getProductAudience().setProductAudienceType(Collections.singleton(productAudienceType));
}
}
}
));
MAPPINGS = Collections.unmodifiableList(m);
}
@Override
public void processMappingsFromRowValues(RowValues values) {
super.processMappingsFromRowValues(values);
MappingHelpers.convertToEntity(values, MAPPINGS, this);
}
@Override
public void processMappingsToRowValues(RowValues values, boolean excludeReadonlyData) {
super.processMappingsToRowValues(values, excludeReadonlyData);
MappingHelpers.convertToValues(this, values, MAPPINGS);
}
/**
* Gets the product audience.
*/
public ProductAudience getProductAudience() {
return getAudience();
}
/**
* Sets the product audience.
*/
public void setProductAudience(ProductAudience productAudience) {
setAudience(productAudience);
}
@Override
public ProductAudience createAudience() {
return new ProductAudience();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy