Search in sources :

Example 16 with BiddableAdGroupCriterion

use of com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion in project googleads-java-lib by googleads.

the class ProductPartitionTreeImpl method addChildNodes.

/**
 * Using the criteria in {@code parentIdMap}, recursively adds all children under the partition ID
 * of {@code parentNode} to {@code parentNode}.
 *
 * @param parentNode required
 * @param parentIdMap the multimap from parent partition ID to list of child criteria
 */
private static void addChildNodes(ProductPartitionNode parentNode, ListMultimap<Long, AdGroupCriterion> parentIdMap) {
    if (parentIdMap.containsKey(parentNode.getProductPartitionId())) {
        parentNode = parentNode.asSubdivision();
    }
    for (AdGroupCriterion adGroupCriterion : parentIdMap.get(parentNode.getProductPartitionId())) {
        ProductPartition partition = (ProductPartition) adGroupCriterion.getCriterion();
        ProductPartitionNode childNode = parentNode.addChild(partition.getCaseValue());
        childNode = childNode.setProductPartitionId(partition.getId());
        if (ProductPartitionType.SUBDIVISION.equals(partition.getPartitionType())) {
            childNode = childNode.asSubdivision();
        } else {
            if (adGroupCriterion instanceof BiddableAdGroupCriterion) {
                childNode = childNode.asBiddableUnit();
                BiddableAdGroupCriterion biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterion;
                Money cpcBidAmount = getBid(biddableAdGroupCriterion);
                if (cpcBidAmount != null) {
                    childNode = childNode.setBid(cpcBidAmount.getMicroAmount());
                }
                childNode = childNode.setTrackingUrlTemplate(biddableAdGroupCriterion.getTrackingUrlTemplate());
                childNode = copyCustomParametersToNode(biddableAdGroupCriterion, childNode);
            } else {
                childNode = childNode.asExcludedUnit();
            }
        }
        addChildNodes(childNode, parentIdMap);
    }
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)

Example 17 with BiddableAdGroupCriterion

use of com.google.api.ads.adwords.axis.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);
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)

Example 18 with BiddableAdGroupCriterion

use of com.google.api.ads.adwords.axis.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));
}
Also used : BatchJobMutateResponse(com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse) BiddableAdGroupCriterion(com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion) CriterionError(com.google.api.ads.adwords.jaxws.v201809.cm.CriterionError) Test(org.junit.Test)

Example 19 with BiddableAdGroupCriterion

use of com.google.api.ads.adwords.axis.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));
}
Also used : BatchJobMutateResponse(com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse) BiddableAdGroupCriterion(com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion) StreamSource(javax.xml.transform.stream.StreamSource) CriterionError(com.google.api.ads.adwords.jaxws.v201809.cm.CriterionError) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 20 with BiddableAdGroupCriterion

use of com.google.api.ads.adwords.axis.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));
}
Also used : BatchJobMutateResponse(com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse) BiddableAdGroupCriterion(com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion) StreamSource(javax.xml.transform.stream.StreamSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Aggregations

BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)18 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)11 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)11 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)9 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)8 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)7 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)7 Test (org.junit.Test)7 NegativeAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)5 ProductPartition (com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)5 AdGroupCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue)4 Bids (com.google.api.ads.adwords.axis.v201809.cm.Bids)4 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)4 BatchJobMutateResponse (com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse)3 BiddableAdGroupCriterion (com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion)3 MockHttpIntegrationTest (com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)3 ArrayList (java.util.ArrayList)3 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)2 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)2 Webpage (com.google.api.ads.adwords.axis.v201809.cm.Webpage)2