static void addAndUpdateAdGroupCriterion(long adGroupId) throws RemoteException, Exception { // Add a biddable criterion as the root. AdGroupCriterion root = addPartition( adGroupId, null, new ProductCondition() { { setOperand("All"); setAttribute(null); } }, ProductPartitionType.UNIT, getFixedBid(0.35), false); outputStatusMessage("Applying a biddable criterion as the root...\n"); ApplyProductPartitionActionsResponse applyPartitionActionsResponse = applyPartitionActions(_partitionActions); printCriterionIds( applyPartitionActionsResponse.getAdGroupCriterionIds(), applyPartitionActionsResponse.getPartialErrors()); ArrayOfAdGroupCriterion adGroupCriterions = getAdGroupCriterionsByIds(AccountId, adGroupId, null, CriterionType.PRODUCT_PARTITION); outputStatusMessage( "Printing the ad group's product partition; contains only the tree root node\n"); printProductPartitions(adGroupCriterions); // Update the bid of the root node that we just added. BiddableAdGroupCriterion updatedRoot = new BiddableAdGroupCriterion(); updatedRoot.setId(applyPartitionActionsResponse.getAdGroupCriterionIds().getLongs().get(0)); updatedRoot.setAdGroupId(adGroupId); updatedRoot.setCriterionBid(getFixedBid(0.40)); _partitionActions.getAdGroupCriterionActions().clear(); addPartitionAction(updatedRoot, ItemAction.UPDATE); outputStatusMessage("Updating the bid for the tree root node...\n"); applyPartitionActionsResponse = applyPartitionActions(_partitionActions); adGroupCriterions = getAdGroupCriterionsByIds(AccountId, adGroupId, null, CriterionType.PRODUCT_PARTITION); outputStatusMessage("Updated the bid for the tree root node\n"); printProductPartitions(adGroupCriterions); }
static AdGroupCriterion addPartition( long adGroupId, AdGroupCriterion parent, ProductCondition condition, ProductPartitionType partitionType, FixedBid bid, Boolean isNegative) { AdGroupCriterion adGroupCriterion = null; if (isNegative) { adGroupCriterion = new NegativeAdGroupCriterion(); } else { adGroupCriterion = new BiddableAdGroupCriterion(); ((BiddableAdGroupCriterion) adGroupCriterion).setCriterionBid(bid); } adGroupCriterion.setAdGroupId(adGroupId); ProductPartition criterion = new ProductPartition(); criterion.setCondition(condition); criterion.setParentCriterionId((parent != null) ? parent.getId() : null); if (partitionType == ProductPartitionType.SUBDIVISION) { criterion.setPartitionType(ProductPartitionType.SUBDIVISION); // Branch adGroupCriterion.setId(_referenceId--); } else { criterion.setPartitionType(ProductPartitionType.UNIT); // Leaf } adGroupCriterion.setCriterion(criterion); addPartitionAction(adGroupCriterion, ItemAction.ADD); return adGroupCriterion; }
static void updateBranchAndLeafCriterion(long adGroupId, long rootId, long electronicsCriterionId) throws RemoteException, Exception { _partitionActions.getAdGroupCriterionActions().clear(); AdGroupCriterion electronics = new BiddableAdGroupCriterion(); electronics.setId(electronicsCriterionId); electronics.setAdGroupId(adGroupId); addPartitionAction(electronics, ItemAction.DELETE); BiddableAdGroupCriterion parent = new BiddableAdGroupCriterion(); parent.setId(rootId); AdGroupCriterion electronicsSubdivision = addPartition( adGroupId, parent, new ProductCondition() { { setOperand("CategoryL1"); setAttribute("Electronics"); } }, ProductPartitionType.SUBDIVISION, null, false); AdGroupCriterion brandC = addPartition( adGroupId, electronicsSubdivision, new ProductCondition() { { setOperand("Brand"); setAttribute("Brand C"); } }, ProductPartitionType.UNIT, getFixedBid(0.35), false); AdGroupCriterion brandD = addPartition( adGroupId, electronicsSubdivision, new ProductCondition() { { setOperand("Brand"); setAttribute("Brand D"); } }, ProductPartitionType.UNIT, getFixedBid(0.35), false); AdGroupCriterion otherElectronicBrands = addPartition( adGroupId, electronicsSubdivision, new ProductCondition() { { setOperand("Brand"); setAttribute(null); } }, ProductPartitionType.UNIT, getFixedBid(0.35), false); outputStatusMessage("Updating the electronics partition...\n"); ApplyProductPartitionActionsResponse applyPartitionActionsResponse = applyPartitionActions(_partitionActions); ArrayOfAdGroupCriterion adGroupCriterions = getAdGroupCriterionsByIds(AccountId, adGroupId, null, CriterionType.PRODUCT_PARTITION); outputStatusMessage("The product partition group tree now has 12 nodes\n"); printProductPartitions(adGroupCriterions); }