com.microsoft.bingads.v13.internal.bulk.SingleFieldBulkMapping 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.internal.bulk;
import com.microsoft.bingads.internal.functionalinterfaces.BiConsumer;
import com.microsoft.bingads.internal.functionalinterfaces.Function;
import com.microsoft.bingads.v13.bulk.entities.BulkEntity;
abstract class SingleFieldBulkMapping implements BulkMapping {
protected Function fieldToCsv;
protected BiConsumer csvToField;
protected Function bulkToString;
private boolean passNulls;
public SingleFieldBulkMapping(Function fieldToCsv,
BiConsumer csvToField) {
this(fieldToCsv, csvToField, false);
}
public SingleFieldBulkMapping(Function fieldToCsv,
BiConsumer csvToField, boolean passNulls) {
this.fieldToCsv = fieldToCsv;
this.csvToField = csvToField;
this.passNulls = passNulls;
}
@Override
public void convertToEntity(RowValues values, TEntity entity) {
String header = this.getHeader(entity);
if (values.containsHeader(header) && (values.get(header) != null || this.passNulls)) {
csvToField.accept(values.get(header), entity);
}
}
@Override
public void convertToCsv(TEntity entity, RowValues values) {
if (this.fieldToCsv == null) {
return; //This mapping is read only.
}
TProperty value = this.fieldToCsv.apply(entity);
values.put(this.getHeader(entity), StringExtensions.toBulkString(value));
}
/**
*
* @param value A {@link BulkEntity} containing data
* @return the header to store/read data from
*/
public abstract String getHeader(TEntity value);
}