use of com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion in project googleads-java-lib by googleads.
the class ProductPartitionTreeImpl method createNonEmptyAdGroupTree.
/**
* Returns a new tree based on a non-empty collection of ad group criteria. All parameters
* required.
*
* @param adGroupId the ID of the ad group
* @param parentIdMap the multimap from parent product partition ID to child criteria
* @return a new ProductPartitionTree
*/
private static ProductPartitionTreeImpl createNonEmptyAdGroupTree(Long adGroupId, ListMultimap<Long, AdGroupCriterion> parentIdMap) {
Preconditions.checkNotNull(adGroupId, "Null ad group ID");
Preconditions.checkArgument(!parentIdMap.isEmpty(), "parentIdMap passed for ad group ID %s is empty", adGroupId);
Preconditions.checkArgument(parentIdMap.containsKey(null), "No root criterion found in the list of ad group criteria for ad group ID %s", adGroupId);
AdGroupCriterion rootCriterion = Iterables.getOnlyElement(parentIdMap.get(null));
Preconditions.checkState(rootCriterion instanceof BiddableAdGroupCriterion, "Root criterion for ad group ID %s is not a BiddableAdGroupCriterion", adGroupId);
BiddableAdGroupCriterion biddableRootCriterion = (BiddableAdGroupCriterion) rootCriterion;
BiddingStrategyConfiguration biddingStrategyConfig = biddableRootCriterion.getBiddingStrategyConfiguration();
Preconditions.checkState(biddingStrategyConfig != null, "Null bidding strategy config on the root node of ad group ID %s", adGroupId);
ProductPartitionNode rootNode = new ProductPartitionNode(null, (ProductDimension) null, rootCriterion.getCriterion().getId(), new ProductDimensionComparator());
// Set the root's bid if a bid exists on the BiddableAdGroupCriterion.
Money rootNodeBid = getBid(biddableRootCriterion);
if (rootNodeBid != null) {
rootNode = rootNode.asBiddableUnit().setBid(rootNodeBid.getMicroAmount());
}
rootNode = rootNode.setTrackingUrlTemplate(biddableRootCriterion.getTrackingUrlTemplate());
rootNode = copyCustomParametersToNode(biddableRootCriterion, rootNode);
addChildNodes(rootNode, parentIdMap);
return new ProductPartitionTreeImpl(adGroupId, biddingStrategyConfig, rootNode);
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion in project googleads-java-lib by googleads.
the class JaxWsBatchJobResponseDeserializerTest method testDeserializeBatchJobMutateResponseWithErrors.
@Test
public void testDeserializeBatchJobMutateResponseWithErrors() throws Exception {
BatchJobMutateResponse response = deserializer.deserializeBatchJobMutateResults(BatchJobMutateResponse.class, JaxWsBatchJobResponseDeserializerTest.class.getResource("resources/BatchJobMutate.responseWithErrors.xml"));
assertNotNull("Null deserialized request returned", response);
// Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion,
// CriterionError, CriterionError, CriterionError
assertEquals(7, response.getMutateResults().length);
assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[2].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertThat(response.getMutateResults()[4].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
assertThat(response.getMutateResults()[5].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
assertThat(response.getMutateResults()[6].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion in project googleads-java-lib by googleads.
the class JaxWsDeserializationTest method testDeserializeBatchJobMutateRequest.
@Test
public void testDeserializeBatchJobMutateRequest() {
Source source = new StreamSource(JaxWsDeserializationTest.class.getResourceAsStream("resources/BatchJobMutate.responseWithErrors.xml"));
BatchJobMutateResponse response = deserializer.deserialize(source);
assertNotNull("Null deserialized request returned", response);
// Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion,
// CriterionError, CriterionError, CriterionError
assertEquals(7, response.getMutateResults().length);
assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[2].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertThat(response.getMutateResults()[4].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
assertThat(response.getMutateResults()[5].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
assertThat(response.getMutateResults()[6].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion in project googleads-java-lib by googleads.
the class JaxWsDeserializationTest method testDeserializeBatchJobResponseWithoutErrors.
/**
* Tests that a response without errors will be properly deserialized.
*/
@Test
public void testDeserializeBatchJobResponseWithoutErrors() throws Exception {
Source source = new StreamSource(JaxWsDeserializationTest.class.getResourceAsStream("resources/BatchJobMutate.responseWithoutErrors.xml"));
BatchJobMutateResponse response = deserializer.deserialize(source);
assertNotNull(response);
// Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion
assertEquals(4, response.getMutateResults().length);
assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion in project googleads-java-lib by googleads.
the class UpdateKeyword method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group for the criterion.
* @param keywordId the ID of the criterion to update.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long adGroupId, Long keywordId) throws RemoteException {
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
// Create ad group criterion with updated bid.
Criterion criterion = new Criterion();
criterion.setId(keywordId);
BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
biddableAdGroupCriterion.setAdGroupId(adGroupId);
biddableAdGroupCriterion.setCriterion(criterion);
// Create bids.
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
CpcBid bid = new CpcBid();
bid.setBid(new Money(null, 10000000L));
biddingStrategyConfiguration.setBids(new Bids[] { bid });
biddableAdGroupCriterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
// Create operations.
AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
operation.setOperand(biddableAdGroupCriterion);
operation.setOperator(Operator.SET);
AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] { operation };
// Update ad group criteria.
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
// Display ad group criteria.
for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
if (adGroupCriterionResult instanceof BiddableAdGroupCriterion) {
biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult;
CpcBid criterionCpcBid = null;
// Find the criterion-level CpcBid among the keyword's bids.
for (Bids bids : biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids()) {
if (bids instanceof CpcBid) {
CpcBid cpcBid = (CpcBid) bids;
if (BidSource.CRITERION.equals(cpcBid.getCpcBidSource())) {
criterionCpcBid = cpcBid;
}
}
}
System.out.printf("Ad group criterion with ad group ID %d, criterion ID %d, type " + "'%s', and bid %d was updated.%n", biddableAdGroupCriterion.getAdGroupId(), biddableAdGroupCriterion.getCriterion().getId(), biddableAdGroupCriterion.getCriterion().getCriterionType(), criterionCpcBid.getBid().getMicroAmount());
}
}
}
Aggregations