com.microsoft.bingads.v13.bulk.entities.BulkNegativeSites 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.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.microsoft.bingads.internal.functionalinterfaces.Predicate;
import com.microsoft.bingads.v13.internal.bulk.BulkObjectWriter;
import com.microsoft.bingads.v13.internal.bulk.BulkRecordReader;
import com.microsoft.bingads.v13.internal.bulk.TryResult;
import com.microsoft.bingads.v13.internal.bulk.entities.BulkNegativeSiteIdentifier;
import com.microsoft.bingads.v13.internal.bulk.entities.MultiRecordBulkEntity;
/**
* This abstract base class for the bulk negative sites that assigned in sets to
* a campaign or ad group entity.
*
* @see BulkAdGroupNegativeSites
* @see BulkCampaignNegativeSites
*/
abstract class BulkNegativeSites, TIdentifier extends BulkNegativeSiteIdentifier> extends MultiRecordBulkEntity {
private final List bulkNegativeSites = new ArrayList();
private TIdentifier firstRowIdentifier;
private boolean hasDeleteAllRow;
/**
* The status of the negative site association. The value is Active if the
* negative site is assigned to the parent entity. The value is Deleted if
* the negative site is removed from the parent entity, or should be removed
* in a subsequent upload operation. Corresponds to the 'Status' field in
* the bulk file.
*/
private Status status;
private Class negativeSiteClass;
private Class identifierClass;
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public List getNegativeSites() {
return Collections.unmodifiableList(this.bulkNegativeSites);
}
@Override
public List extends BulkEntity> getChildEntities() {
return Collections.unmodifiableList(this.bulkNegativeSites);
}
/**
* Reserved for internal use.
*/
protected BulkNegativeSites() {
}
protected BulkNegativeSites(TNegativeSite site, Class negativeSiteClass, Class identifierClass) {
this(site.getIdentifier(), negativeSiteClass, identifierClass);
bulkNegativeSites.add(site);
}
protected BulkNegativeSites(TIdentifier identifier, Class negativeSiteClass, Class identifierClass) {
this.negativeSiteClass = negativeSiteClass;
this.identifierClass = identifierClass;
this.firstRowIdentifier = identifier;
this.hasDeleteAllRow = identifier.isDeleteRow();
}
/**
* Reserved for internal use.
*/
protected abstract TIdentifier createIdentifier();
protected abstract void validatePropertiesNotNull();
@Override
public void write(BulkObjectWriter rowWriter, boolean excludeReadonlyData) throws IOException {
validatePropertiesNotNull();
TIdentifier deleteRow = createIdentifier();
deleteRow.setStatus(Status.DELETED);
rowWriter.writeObjectRow(deleteRow, excludeReadonlyData);
if (status == Status.DELETED) {
return;
}
for (TNegativeSite site : convertApiToBulkNegativeSites()) {
site.write(rowWriter, excludeReadonlyData);
}
}
/**
* Reserved for internal use.
*/
protected abstract Iterable convertApiToBulkNegativeSites();
/**
* Reserved for internal use.
*/
protected abstract void reconstructApiObjects();
@Override
public void readRelatedData(BulkRecordReader reader) {
boolean hasMoreRows = true;
while (hasMoreRows) {
TryResult nextSiteResult = reader.tryRead(new Predicate() {
@Override
public boolean test(TNegativeSite x) {
return x.getIdentifier().equals(firstRowIdentifier);
}
}, this.negativeSiteClass);
if (nextSiteResult.isSuccessful()) {
this.bulkNegativeSites.add(nextSiteResult.getResult());
continue;
}
TryResult identifierResult = reader.tryRead(new Predicate() {
@Override
public boolean test(TIdentifier x) {
return x.equals(firstRowIdentifier);
}
}, this.identifierClass);
if (identifierResult.isSuccessful()) {
if (identifierResult.getResult().isDeleteRow()) {
this.hasDeleteAllRow = true;
}
} else {
hasMoreRows = false;
}
}
reconstructApiObjects();
this.status = bulkNegativeSites != null && bulkNegativeSites.size() > 0
? Status.ACTIVE
: Status.DELETED;
}
@Override
public boolean allChildrenPresent() {
return this.hasDeleteAllRow;
}
}