use of com.google.api.ads.adwords.lib.selectorfields.v201809.cm.AdGroupCriterionField in project googleads-java-lib by googleads.
the class ProductPartitionTreeImpl method createAdGroupTree.
/**
* Returns a new instance of this class by retrieving the product partitions of the
* specified ad group. All parameters are required.
*/
static ProductPartitionTreeImpl createAdGroupTree(AdWordsServicesInterface services, AdWordsSession session, Long adGroupId) throws ApiException, RemoteException {
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface criterionService = services.get(session, AdGroupCriterionServiceInterface.class);
SelectorBuilder selectorBuilder = new SelectorBuilder().fields(REQUIRED_SELECTOR_FIELD_ENUMS.toArray(new AdGroupCriterionField[REQUIRED_SELECTOR_FIELD_ENUMS.size()])).equals(AdGroupCriterionField.AdGroupId, adGroupId.toString()).equals(AdGroupCriterionField.CriteriaType, "PRODUCT_PARTITION").in(AdGroupCriterionField.Status, UserStatus.ENABLED.getValue(), UserStatus.PAUSED.getValue()).limit(PAGE_SIZE);
AdGroupCriterionPage adGroupCriterionPage;
// A multimap from each product partition ID to its direct children.
ListMultimap<Long, AdGroupCriterion> parentIdMap = LinkedListMultimap.create();
int offset = 0;
do {
// Get the next page of results.
adGroupCriterionPage = criterionService.get(selectorBuilder.build());
if (adGroupCriterionPage != null && adGroupCriterionPage.getEntries() != null) {
for (AdGroupCriterion adGroupCriterion : adGroupCriterionPage.getEntries()) {
ProductPartition partition = (ProductPartition) adGroupCriterion.getCriterion();
parentIdMap.put(partition.getParentCriterionId(), adGroupCriterion);
}
offset += adGroupCriterionPage.getEntries().length;
selectorBuilder.increaseOffsetBy(PAGE_SIZE);
}
} while (offset < adGroupCriterionPage.getTotalNumEntries());
// Construct the ProductPartitionTree from the parentIdMap.
if (!parentIdMap.containsKey(null)) {
Preconditions.checkState(parentIdMap.isEmpty(), "No root criterion found in the tree but the tree is not empty");
return createEmptyAdGroupTree(adGroupId, getAdGroupBiddingStrategyConfiguration(services, session, adGroupId));
}
return createNonEmptyAdGroupTree(adGroupId, parentIdMap);
}
Aggregations