com.microsoft.bingads.v13.bulk.entities.BulkAd 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.campaignmanagement.Ad;
import com.microsoft.bingads.v13.campaignmanagement.AdEditorialStatus;
import com.microsoft.bingads.v13.campaignmanagement.AdStatus;
import com.microsoft.bingads.v13.campaignmanagement.ArrayOfstring;
import com.microsoft.bingads.v13.campaignmanagement.TextAd;
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;
/**
* This abstract base class provides properties that are shared by all bulk ad classes.
*
* @param the type of ad from the {@link com.microsoft.bingads.campaignmanagement} namespace, for example
* {@link TextAd} object.
*
* @see BulkProductAd
* @see BulkTextAd
* @see BulkAppInstallAd
* @see BulkExpandedTextAd
* @see BulkDynamicSearchAd
*/
class BulkAd extends SingleRecordBulkEntity {
private Long adGroupId;
private String campaignName;
private String adGroupName;
protected T ad;
private static final List> MAPPINGS;
static {
List> m = new ArrayList>();
m.add(new SimpleBulkMapping(StringTable.Status,
new Function() {
@Override
public String apply(BulkAd c) {
return c.getAd().getStatus() != null ? c.getAd().getStatus().value() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
c.getAd().setStatus(StringExtensions.parseOptional(v, new Function() {
@Override
public AdStatus apply(String value) {
return AdStatus.fromValue(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.Id,
new Function() {
@Override
public Long apply(BulkAd c) {
return c.getAd().getId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
c.getAd().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(BulkAd c) {
return c.getAdGroupId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
c.setAdGroupId(StringExtensions.parseOptional(v, new Function() {
@Override
public Long apply(String value) {
return Long.parseLong(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.Campaign,
new Function() {
@Override
public String apply(BulkAd c) {
return c.getCampaignName();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
c.setCampaignName(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.AdGroup,
new Function() {
@Override
public String apply(BulkAd c) {
return c.getAdGroupName();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
c.setAdGroupName(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.EditorialStatus,
new Function() {
@Override
public String apply(BulkAd t) {
return t.getAd().getEditorialStatus() != null ? t.getAd().getEditorialStatus().value() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
c.getAd().setEditorialStatus(StringExtensions.parseOptional(v, new Function() {
@Override
public AdEditorialStatus apply(String value) {
return AdEditorialStatus.fromValue(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.DevicePreference,
new Function() {
@Override
public String apply(BulkAd c) {
return StringExtensions.toDevicePreferenceBulkString(c.getAd().getDevicePreference());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
c.getAd().setDevicePreference(StringExtensions.parseDevicePreference(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.FinalUrl,
new Function() {
@Override
public String apply(BulkAd c) {
return StringExtensions.writeUrls("; ", c.getAd().getFinalUrls(), c.getAd().getId());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
ArrayOfstring urls = new ArrayOfstring();
List urlArray = StringExtensions.parseUrls(v);
if(urlArray == null) {
urls = null;
} else {
urls.getStrings().addAll(urlArray);
}
c.getAd().setFinalUrls(urls);
}
}
));
m.add(new SimpleBulkMapping(StringTable.FinalMobileUrl,
new Function() {
@Override
public String apply(BulkAd c) {
return StringExtensions.writeUrls("; ", c.getAd().getFinalMobileUrls(), c.getAd().getId());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
ArrayOfstring urls = new ArrayOfstring();
List urlArray = StringExtensions.parseUrls(v);
if(urlArray == null) {
urls = null;
} else {
urls.getStrings().addAll(urlArray);
}
c.getAd().setFinalMobileUrls(urls);
}
}
));
m.add(new SimpleBulkMapping(StringTable.TrackingTemplate,
new Function() {
@Override
public String apply(BulkAd c) {
return StringExtensions.toOptionalBulkString(c.getAd().getTrackingUrlTemplate(), c.getAd().getId());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
c.getAd().setTrackingUrlTemplate(StringExtensions.getValueOrEmptyString(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.CustomParameter,
new Function() {
@Override
public String apply(BulkAd c) {
return StringExtensions.toCustomParaBulkString(c.getAd().getUrlCustomParameters(), c.getAd().getId());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
try {
c.getAd().setUrlCustomParameters(StringExtensions.parseCustomParameters(v));
} catch (Exception e) {
e.printStackTrace();
}
}
}
));
m.add(new SimpleBulkMapping(StringTable.AdFormatPreference, new Function() {
@Override
public String apply(BulkAd c) {
return c.getAd().getAdFormatPreference();
}
}, new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
c.getAd().setAdFormatPreference(StringExtensions.getValueOrEmptyString(v));
}
}, true));
m.add(new SimpleBulkMapping(StringTable.FinalUrlSuffix,
new Function() {
@Override
public String apply(BulkAd c) {
return StringExtensions.toOptionalBulkString(c.getAd().getFinalUrlSuffix(), c.getAd().getId());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAd c) {
c.getAd().setFinalUrlSuffix(StringExtensions.getValueOrEmptyString(v));
}
}
));
MAPPINGS = Collections.unmodifiableList(m);
}
@Override
public void processMappingsToRowValues(RowValues values, boolean excludeReadonlyData) {
MappingHelpers.convertToValues(this, values, MAPPINGS);
}
@Override
public void processMappingsFromRowValues(RowValues values) {
MappingHelpers.convertToEntity(values, MAPPINGS, this);
}
/**
* Gets the identifier of the ad group that contains the ad.
*
*
* Corresponds to the 'Parent Id' field in the bulk file.
*
*/
public Long getAdGroupId() {
return adGroupId;
}
/**
* Gets the name of the campaign that contains the ad.
*
*
* Corresponds to the 'Campaign' field in the bulk file.
*
*/
public String getCampaignName() {
return campaignName;
}
/**
* Gets the name of the ad group that contains the ad.
*
*
* Corresponds to the 'Ad Group' field in the bulk file.
*
*/
public String getAdGroupName() {
return adGroupName;
}
/**
* Gets the ad from the {@link com.microsoft.bingads.campaignmanagement} namespace,
*/
public T getAd() {
return ad;
}
/**
* Sets the identifier of the ad group that contains the ad.
*
*
* Corresponds to the 'Parent Id' field in the bulk file.
*
*/
public void setAdGroupId(Long adGroupId) {
this.adGroupId = adGroupId;
}
/**
* Sets the ad from the {@link com.microsoft.bingads.campaignmanagement} namespace,
*/
public void setAd(T ad) {
this.ad = ad;
}
/**
* Sets the name of the campaign that contains the ad.
*
*
* Corresponds to the 'Campaign' field in the bulk file.
*
*/
public void setCampaignName(String campaignName) {
this.campaignName = campaignName;
}
/**
* Sets the name of the ad group that contains the ad.
*
*
* Corresponds to the 'Ad Group' field in the bulk file.
*
*/
public void setAdGroupName(String adGroupName) {
this.adGroupName = adGroupName;
}
}