com.microsoft.bingads.v10.bulk.entities.BulkAdGroup Maven / Gradle / Ivy
Show all versions of microsoft.bingads Show documentation
package com.microsoft.bingads.v10.bulk.entities;
import com.microsoft.bingads.v10.bulk.BulkFileReader;
import com.microsoft.bingads.v10.bulk.BulkFileWriter;
import com.microsoft.bingads.v10.bulk.BulkOperation;
import com.microsoft.bingads.v10.bulk.BulkServiceManager;
import com.microsoft.bingads.v10.campaignmanagement.*;
import com.microsoft.bingads.v10.internal.bulk.StringExtensions;
import com.microsoft.bingads.v10.internal.bulk.StringTable;
import com.microsoft.bingads.internal.UncheckedParseException;
import com.microsoft.bingads.v10.internal.bulk.BulkMapping;
import com.microsoft.bingads.v10.internal.bulk.MappingHelpers;
import com.microsoft.bingads.v10.internal.bulk.RowValues;
import com.microsoft.bingads.v10.internal.bulk.SimpleBulkMapping;
import com.microsoft.bingads.v10.internal.bulk.entities.SingleRecordBulkEntity;
import com.microsoft.bingads.internal.functionalinterfaces.BiConsumer;
import com.microsoft.bingads.internal.functionalinterfaces.Function;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Represents an Ad Group.
*
*
* This class exposes the {@link #setAdGroup} and {@link #getAdGroup} that can be used to read and write
* fields of the Ad Group record in a bulk file.
*
*
*
* For more information, see Ad Group at
* http://go.microsoft.com/fwlink/?LinkID=620252.
*
*
* @see BulkServiceManager
* @see BulkOperation
* @see BulkFileReader
* @see BulkFileWriter
*/
public class BulkAdGroup extends SingleRecordBulkEntity {
private Long campaignId;
private String campaignName;
private AdGroup adGroup;
private QualityScoreData qualityScoreData;
private PerformanceData performanceData;
private boolean isExpired;
private static final List> MAPPINGS;
private static final BiConsumer orSearchAdDistribution = new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
if (StringTable.On.equals(v)) {
c.getAdGroup().getAdDistribution().add(AdDistribution.SEARCH);
}
}
};
private static final BiConsumer orContentAdDistribution = new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
if (StringTable.On.equals(v)) {
c.getAdGroup().getAdDistribution().add(AdDistribution.CONTENT);
}
}
};
static {
List> m = new ArrayList>();
m.add(new SimpleBulkMapping(StringTable.Id,
new Function() {
@Override
public Long apply(BulkAdGroup c) {
return c.getAdGroup().getId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.getAdGroup().setId(StringExtensions.nullOrLong(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.Status,
new Function() {
@Override
public String apply(BulkAdGroup c) {
if (c.getIsExpired()) {
return "Expired";
}
return c.getAdGroup().getStatus() != null ? c.getAdGroup().getStatus().value() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
if (v.equals("Expired")) {
c.getAdGroup().setStatus(AdGroupStatus.EXPIRED);
c.setIsExpired(true);
} else {
c.getAdGroup().setStatus(StringExtensions.parseOptional(v, new Function() {
@Override
public AdGroupStatus apply(String value) {
return AdGroupStatus.fromValue(value);
}
}));
}
}
}
));
m.add(new SimpleBulkMapping(StringTable.ParentId,
new Function() {
@Override
public Long apply(BulkAdGroup c) {
return c.getCampaignId();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.setCampaignId(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(BulkAdGroup c) {
return c.getCampaignName();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.setCampaignName(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.AdGroup,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return c.getAdGroup().getName();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.getAdGroup().setName(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.StartDate,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return StringExtensions.toDateBulkString(c.getAdGroup().getStartDate());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
try {
c.getAdGroup().setStartDate(StringExtensions.parseDate(v));
} catch (ParseException ex) {
throw new UncheckedParseException(ex);
}
}
}
));
m.add(new SimpleBulkMapping(StringTable.EndDate,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return StringExtensions.toDateBulkString(c.getAdGroup().getEndDate());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
try {
c.getAdGroup().setEndDate(StringExtensions.parseDate(v));
} catch (ParseException ex) {
throw new UncheckedParseException(ex);
}
}
}
));
m.add(new SimpleBulkMapping(StringTable.NetworkDistribution,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return c.getAdGroup().getNetwork() != null ? c.getAdGroup().getNetwork().value() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.getAdGroup().setNetwork(StringExtensions.parseOptional(v, new Function() {
@Override
public Network apply(String value) {
return Network.fromValue(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.PricingModel,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return c.getAdGroup().getPricingModel() != null ? c.getAdGroup().getPricingModel().value() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.getAdGroup().setPricingModel(StringExtensions.parseOptionalUpperCase(v, new Function() {
@Override
public PricingModel apply(String value) {
return PricingModel.fromValue(value);
}
}));
}
}
));
m.add(new SimpleBulkMapping(StringTable.AdRotation,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return StringExtensions.toAdRotationBulkString(c.getAdGroup().getAdRotation());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.getAdGroup().setAdRotation(StringExtensions.parseAdRotation(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.SearchNetwork,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return StringExtensions.isOnOrOff(c.getAdGroup().getAdDistribution(), AdDistribution.SEARCH);
}
},
orSearchAdDistribution
));
m.add(new SimpleBulkMapping(StringTable.ContentNetwork,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return StringExtensions.isOnOrOff(c.getAdGroup().getAdDistribution(), AdDistribution.CONTENT);
}
},
orContentAdDistribution
));
m.add(new SimpleBulkMapping(StringTable.SearchBid,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return StringExtensions.toAdGroupBidBulkString(c.getAdGroup().getSearchBid());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.getAdGroup().setSearchBid(StringExtensions.parseAdGroupBid(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.ContentBid,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return StringExtensions.toAdGroupBidBulkString(c.getAdGroup().getContentMatchBid());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.getAdGroup().setContentMatchBid(StringExtensions.parseAdGroupBid(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.Language,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return c.getAdGroup().getLanguage();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.getAdGroup().setLanguage(v);
}
}
));
m.add(new SimpleBulkMapping(StringTable.BidAdjustment,
new Function() {
@Override
public Integer apply(BulkAdGroup c) {
return c.getAdGroup().getNativeBidAdjustment();
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.getAdGroup().setNativeBidAdjustment(StringExtensions.parseOptionalInteger(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.TrackingTemplate,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return StringExtensions.toOptionalBulkString(c.getAdGroup().getTrackingUrlTemplate());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.getAdGroup().setTrackingUrlTemplate(StringExtensions.getValueOrEmptyString(v));
}
}
));
m.add(new SimpleBulkMapping(StringTable.CustomParameter,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return StringExtensions.toCustomParaBulkString(c.getAdGroup().getUrlCustomParameters());
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
try {
c.getAdGroup().setUrlCustomParameters(StringExtensions.parseCustomParameters(v));
} catch (Exception e) {
e.printStackTrace();
}
}
}
));
m.add(new SimpleBulkMapping(StringTable.BidStrategyType,
new Function() {
@Override
public String apply(BulkAdGroup c) {
try {
return StringExtensions.toBiddingSchemeBulkString(c.getAdGroup().getBiddingScheme());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
try {
c.getAdGroup().setBiddingScheme(StringExtensions.parseBiddingScheme(v));
} catch (Exception e) {
e.printStackTrace();
}
}
}
));
m.add(new SimpleBulkMapping(StringTable.RemarketingTargetingSetting,
new Function() {
@Override
public String apply(BulkAdGroup c) {
return c.getAdGroup().getRemarketingTargetingSetting() != null ? c.getAdGroup().getRemarketingTargetingSetting().value() : null;
}
},
new BiConsumer() {
@Override
public void accept(String v, BulkAdGroup c) {
c.getAdGroup().setRemarketingTargetingSetting(StringExtensions.parseOptional(v, new Function() {
@Override
public RemarketingTargetingSetting apply(String value) {
return RemarketingTargetingSetting.fromValue(value);
}
}));
}
}
));
MAPPINGS = Collections.unmodifiableList(m);
}
@Override
public void processMappingsFromRowValues(RowValues values) {
this.setAdGroup(new AdGroup());
getAdGroup().setAdDistribution(new ArrayList(2));
MappingHelpers.convertToEntity(values, MAPPINGS, this);
qualityScoreData = QualityScoreData.readFromRowValuesOrNull(values);
performanceData = PerformanceData.readFromRowValuesOrNull(values);
}
@Override
public void processMappingsToRowValues(RowValues values, boolean excludeReadonlyData) {
validatePropertyNotNull(getAdGroup(), "AdGroup");
MappingHelpers.convertToValues(this, values, MAPPINGS);
if (!excludeReadonlyData) {
QualityScoreData.writeToRowValuesIfNotNull(qualityScoreData, values);
PerformanceData.writeToRowValuesIfNotNull(performanceData, values);
}
}
/**
* Gets the identifier of the campaign that contains the ad group.
*
*
* Corresponds to the 'Parent Id' field in the bulk file.
*
*/
public Long getCampaignId() {
return campaignId;
}
/**
* Sets the identifier of the campaign that contains the ad group.
*
*
* Corresponds to the 'Parent Id' field in the bulk file.
*
*/
public void setCampaignId(Long campaignId) {
this.campaignId = campaignId;
}
/**
* Gets the name of the campaign that contains the ad group.
*
*
* Corresponds to the 'Campaign' field in the bulk file.
*
*/
public String getCampaignName() {
return campaignName;
}
/**
* Sets the name of the campaign that contains the ad group.
*
*
* Corresponds to the 'Campaign' field in the bulk file.
*
*/
public void setCampaignName(String campaignName) {
this.campaignName = campaignName;
}
/**
* Gets the AdGroup Data Object of the Campaign Management Service.
*
*
* A subset of AdGroup properties are available in the Ad Group record.
* For more information, see Ad Group at
* http://go.microsoft.com/fwlink/?LinkID=620252.
*
*/
public AdGroup getAdGroup() {
return adGroup;
}
/**
* Sets the AdGroup Data Object of the Campaign Management Service.
*
*
* A subset of AdGroup properties are available in the Ad Group record.
* For more information, see Ad Group at
* http://go.microsoft.com/fwlink/?LinkID=620252.
*
*/
public void setAdGroup(AdGroup adGroup) {
this.adGroup = adGroup;
}
/**
* Gets the quality score data for the ad group.
*/
public QualityScoreData getQualityScoreData() {
return qualityScoreData;
}
/**
* Gets the historical performance data for the ad group.
*/
public PerformanceData getPerformanceData() {
return performanceData;
}
/**
* Gets whether the AdGroup is expired.
*/
public boolean getIsExpired() {
return isExpired;
}
/**
* Sets whether the AdGroup is expired.
*/
private void setIsExpired(boolean isExpired) {
this.isExpired = isExpired;
}
}