Search in sources :

Example 1 with ProductCanonicalCondition

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

the class AddProductScope method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the shopping campaign.
 * @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 campaignId) throws RemoteException {
    // Get the campaign criterion service.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    ProductScope productScope = new ProductScope();
    // This set of dimensions is for demonstration purposes only. It would be
    // extremely unlikely that you want to include so many dimensions in your
    // product scope.
    ProductBrand productBrand = new ProductBrand();
    productBrand.setValue("Nexus");
    ProductCanonicalCondition productCanonicalCondition = new ProductCanonicalCondition();
    productCanonicalCondition.setCondition(ProductCanonicalConditionCondition.NEW);
    ProductCustomAttribute productCustomAttribute = new ProductCustomAttribute();
    productCustomAttribute.setType(ProductDimensionType.CUSTOM_ATTRIBUTE_0);
    productCustomAttribute.setValue("my attribute value");
    ProductOfferId productOfferId = new ProductOfferId();
    productOfferId.setValue("book1");
    ProductType productTypeLevel1Media = new ProductType();
    productTypeLevel1Media.setType(ProductDimensionType.PRODUCT_TYPE_L1);
    productTypeLevel1Media.setValue("Media");
    ProductType productTypeLevel2Books = new ProductType();
    productTypeLevel2Books.setType(ProductDimensionType.PRODUCT_TYPE_L2);
    productTypeLevel2Books.setValue("Books");
    // The value for the bidding category is a fixed ID for the 'Luggage & Bags'
    // category. You can retrieve IDs for categories from the ConstantDataService.
    // See the 'GetProductCategoryTaxonomy' example for more details.
    ProductBiddingCategory productBiddingCategory = new ProductBiddingCategory();
    productBiddingCategory.setType(ProductDimensionType.BIDDING_CATEGORY_L1);
    productBiddingCategory.setValue(-5914235892932915235L);
    productScope.setDimensions(new ProductDimension[] { productBrand, productCanonicalCondition, productCustomAttribute, productOfferId, productTypeLevel1Media, productTypeLevel2Books, productBiddingCategory });
    CampaignCriterion campaignCriterion = new CampaignCriterion();
    campaignCriterion.setCampaignId(campaignId);
    campaignCriterion.setCriterion(productScope);
    // Create operation.
    CampaignCriterionOperation criterionOperation = new CampaignCriterionOperation();
    criterionOperation.setOperand(campaignCriterion);
    criterionOperation.setOperator(Operator.ADD);
    // Make the mutate request.
    CampaignCriterionReturnValue result = campaignCriterionService.mutate(new CampaignCriterionOperation[] { criterionOperation });
    // Display the result.
    System.out.printf("Created a ProductScope criterion with ID %d.%n", result.getValue(0).getCriterion().getId());
}
Also used : CampaignCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue) ProductBrand(com.google.api.ads.adwords.axis.v201809.cm.ProductBrand) ProductOfferId(com.google.api.ads.adwords.axis.v201809.cm.ProductOfferId) CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) ProductCanonicalCondition(com.google.api.ads.adwords.axis.v201809.cm.ProductCanonicalCondition) ProductScope(com.google.api.ads.adwords.axis.v201809.cm.ProductScope) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) ProductCustomAttribute(com.google.api.ads.adwords.axis.v201809.cm.ProductCustomAttribute) ProductType(com.google.api.ads.adwords.axis.v201809.cm.ProductType) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) ProductBiddingCategory(com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategory)

Example 2 with ProductCanonicalCondition

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

the class ProductDimensionsTest method testCreateCanonicalCondition.

/**
 * Test method for createCanonicalCondition.
 */
@Test
public void testCreateCanonicalCondition() {
    ProductCanonicalCondition condition = ProductDimensions.createCanonicalCondition(ProductCanonicalConditionCondition.NEW);
    assertEquals(ProductCanonicalConditionCondition.NEW, condition.getCondition());
}
Also used : ProductCanonicalCondition(com.google.api.ads.adwords.axis.v201809.cm.ProductCanonicalCondition) Test(org.junit.Test)

Example 3 with ProductCanonicalCondition

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

the class ProductPartitionNodeTest method testNavigation.

@Test
public void testNavigation() {
    rootNode = rootNode.asSubdivision();
    ProductBrand brandGoogle = ProductDimensions.createBrand("google");
    ProductBrand brandOther = ProductDimensions.createBrand(null);
    ProductCanonicalCondition conditionNew = ProductDimensions.createCanonicalCondition(ProductCanonicalConditionCondition.NEW);
    ProductCanonicalCondition conditionUsed = ProductDimensions.createCanonicalCondition(ProductCanonicalConditionCondition.USED);
    ProductCanonicalCondition conditionOther = ProductDimensions.createCanonicalCondition(null);
    // Build up the brand = Google node under the root.
    ProductPartitionNode brandGoogleNode = rootNode.addChild(brandGoogle).asSubdivision();
    brandGoogleNode.addChild(conditionNew);
    brandGoogleNode.addChild(conditionUsed);
    brandGoogleNode.addChild(conditionOther);
    assertTrue("hasChild should return true for existing child dimension", brandGoogleNode.hasChild(conditionNew));
    assertSame("parent->getChild->getParent should return parent", brandGoogleNode, brandGoogleNode.getChild(conditionNew).getParent());
    assertTrue("hasChild should return true for existing child dimension", brandGoogleNode.hasChild(conditionUsed));
    assertSame("parent->getChild->getParent should return parent", brandGoogleNode, brandGoogleNode.getChild(conditionUsed).getParent());
    assertTrue("hasChild should return true for existing child dimension", brandGoogleNode.hasChild(conditionOther));
    assertSame("parent->getChild->getParent should return parent", brandGoogleNode, brandGoogleNode.getChild(conditionOther).getParent());
    // Build up the brand = null (other) node under the root.
    ProductPartitionNode brandOtherNode = rootNode.addChild(brandOther).asSubdivision();
    brandOtherNode.addChild(conditionNew);
    assertTrue("hasChild should return true for existing child dimension", brandOtherNode.hasChild(conditionNew));
    assertSame("parent->getChild->getParent should return parent", brandOtherNode, brandOtherNode.getChild(conditionNew).getParent());
    assertFalse("hasChild should return false for nonexistent child dimension", brandOtherNode.hasChild(conditionUsed));
    assertFalse("hasChild should return false for nonexistent child dimension", brandOtherNode.hasChild(conditionOther));
    brandOtherNode.addChild(conditionOther);
    assertTrue("hasChild should return true for existing child dimension", brandOtherNode.hasChild(conditionOther));
    assertSame("parent->getChild->getParent should return parent", brandOtherNode, brandOtherNode.getChild(conditionOther).getParent());
    // Remove one of the children of brand = null.
    brandOtherNode.removeChild(conditionOther);
    assertFalse("hasChild should return false for a removed child dimension", brandOtherNode.hasChild(conditionOther));
    // Remove the rest of the children of brand = null.
    brandOtherNode.removeAllChildren();
    assertFalse("hasChild should return false for any removed child dimension", brandOtherNode.hasChild(conditionNew));
    assertFalse("hasChild should return false for any removed child dimension", brandOtherNode.hasChild(conditionUsed));
}
Also used : ProductBrand(com.google.api.ads.adwords.axis.v201809.cm.ProductBrand) ProductCanonicalCondition(com.google.api.ads.adwords.axis.v201809.cm.ProductCanonicalCondition) Test(org.junit.Test)

Example 4 with ProductCanonicalCondition

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

the class ProductDimensions method createCanonicalCondition.

/**
 * Creates a new ProductCanonicalCondition.
 *
 * @param condition may be null if creating an "other" dimension
 */
public static ProductCanonicalCondition createCanonicalCondition(@Nullable ProductCanonicalConditionCondition condition) {
    ProductCanonicalCondition productCanonicalCondition = new ProductCanonicalCondition();
    productCanonicalCondition.setCondition(condition);
    return productCanonicalCondition;
}
Also used : ProductCanonicalCondition(com.google.api.ads.adwords.axis.v201809.cm.ProductCanonicalCondition)

Aggregations

ProductCanonicalCondition (com.google.api.ads.adwords.axis.v201809.cm.ProductCanonicalCondition)4 ProductBrand (com.google.api.ads.adwords.axis.v201809.cm.ProductBrand)2 Test (org.junit.Test)2 CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)1 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)1 CampaignCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue)1 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)1 ProductBiddingCategory (com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategory)1 ProductCustomAttribute (com.google.api.ads.adwords.axis.v201809.cm.ProductCustomAttribute)1 ProductOfferId (com.google.api.ads.adwords.axis.v201809.cm.ProductOfferId)1 ProductScope (com.google.api.ads.adwords.axis.v201809.cm.ProductScope)1 ProductType (com.google.api.ads.adwords.axis.v201809.cm.ProductType)1