All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.bingads.v13.internal.bulk.SingleFieldBulkMapping Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 13.0.22.1
Show newest version
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);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy