Search in sources :

Example 1 with Operand

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

the class ProductPartitionTreeTest method testCreateUltimatelyEmptyTree.

/**
 * Tests creating a tree that in its <em>final</em> state is just an empty tree.
 */
@Test
public void testCreateUltimatelyEmptyTree() {
    ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, Collections.<AdGroupCriterion>emptyList());
    ProductPartitionNode rootNode = tree.getRoot().asSubdivision();
    ProductPartitionNode brand1 = rootNode.addChild(ProductDimensions.createBrand("google")).asSubdivision();
    brand1.addChild(ProductDimensions.createOfferId("A")).asBiddableUnit().setBid(1000000L);
    brand1.addChild(ProductDimensions.createOfferId(null)).asExcludedUnit();
    ProductPartitionNode brand2 = rootNode.addChild(ProductDimensions.createBrand(null)).asExcludedUnit();
    // Now remove the two child nodes under the root and set the root back to a UNIT. This should
    // result in operations that simply create the root node.
    rootNode.removeChild(brand1.getDimension());
    rootNode.removeChild(brand2.getDimension());
    rootNode = rootNode.asBiddableUnit();
    List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
    assertEquals("Number of operations is incorrect", 1, mutateOperations.size());
    AdGroupCriterionOperation operation = mutateOperations.iterator().next();
    assertEquals("Should have a single operation to ADD the root node", Operator.ADD, operation.getOperator());
    BiddableAdGroupCriterion adGroupCriterion = (BiddableAdGroupCriterion) operation.getOperand();
    assertNull("Product dimension of operation's operand should be null", ((ProductPartition) adGroupCriterion.getCriterion()).getCaseValue());
    assertTrue("Partition ID of the operand should be negative", adGroupCriterion.getCriterion().getId().longValue() < 0L);
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest) Test(org.junit.Test)

Example 2 with Operand

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

the class ProductPartitionTreeTest method testCreateEmptyTree.

/**
 * Tests creating an empty ad group tree. In this case, all operations generated should be ADD
 * operations.
 */
@Test
public void testCreateEmptyTree() {
    ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, Collections.<AdGroupCriterion>emptyList());
    assertNotNull("Even an empty tree should automatically have a root node", tree.getRoot());
    assertTrue("The root node for an empty tree should have a negative (temporary) ID", tree.getRoot().getProductPartitionId().longValue() < 0L);
    assertTrue("The root node for an empty tree should be a UNIT", tree.getRoot().isUnit());
    List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
    assertEquals("Number of operations is incorrect", 1, mutateOperations.size());
    AdGroupCriterionOperation operation = mutateOperations.iterator().next();
    assertEquals("Should have a single operation to ADD the root node", Operator.ADD, operation.getOperator());
    BiddableAdGroupCriterion adGroupCriterion = (BiddableAdGroupCriterion) operation.getOperand();
    assertNull("Product dimension of operation's operand should be null", ((ProductPartition) adGroupCriterion.getCriterion()).getCaseValue());
    assertTrue("Partition ID of the operand should be negative", adGroupCriterion.getCriterion().getId().longValue() < 0L);
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest) Test(org.junit.Test)

Example 3 with Operand

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

the class MigrateToExtensionSettings method getFeedItemIdsForCampaign.

/**
 * Returns the list of feed item IDs that are used by a campaign through a given campaign feed.
 */
private static Set<Long> getFeedItemIdsForCampaign(CampaignFeed campaignFeed) throws RemoteException {
    Set<Long> feedItemIds = Sets.newHashSet();
    FunctionOperator functionOperator = campaignFeed.getMatchingFunction().getOperator();
    if (FunctionOperator.IN.equals(functionOperator)) {
        // Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
        // Extract feed items if applicable.
        feedItemIds.addAll(getFeedItemIdsFromArgument(campaignFeed.getMatchingFunction()));
    } else if (FunctionOperator.AND.equals(functionOperator)) {
        // Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
        // Extract feed items if applicable.
        Arrays.stream(campaignFeed.getMatchingFunction().getLhsOperand()).filter(FunctionOperand.class::isInstance).map(argument -> (FunctionOperand) argument).filter(operand -> FunctionOperator.IN.equals(operand.getValue().getOperator())).forEach(operand -> feedItemIds.addAll(getFeedItemIdsFromArgument(operand.getValue())));
    } else {
    // There are no other matching functions involving feed item IDs.
    }
    return feedItemIds;
}
Also used : Arrays(java.util.Arrays) UrlList(com.google.api.ads.adwords.axis.v201809.cm.UrlList) CampaignFeedOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation) CampaignExtensionSettingOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingOperation) CampaignFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface) HashMultimap(com.google.common.collect.HashMultimap) OfflineCredentials(com.google.api.ads.common.lib.auth.OfflineCredentials) Map(java.util.Map) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException) FeedItem(com.google.api.ads.adwords.axis.v201809.cm.FeedItem) FeedPage(com.google.api.ads.adwords.axis.v201809.cm.FeedPage) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) AdWordsServices(com.google.api.ads.adwords.axis.factory.AdWordsServices) Set(java.util.Set) Operator(com.google.api.ads.adwords.axis.v201809.cm.Operator) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RemoteException(java.rmi.RemoteException) CampaignExtensionSettingServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingServiceInterface) List(java.util.List) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) AdWordsServicesInterface(com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface) ApiError(com.google.api.ads.adwords.axis.v201809.cm.ApiError) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) FunctionOperand(com.google.api.ads.adwords.axis.v201809.cm.FunctionOperand) FunctionArgumentOperand(com.google.api.ads.adwords.axis.v201809.cm.FunctionArgumentOperand) ExtensionFeedItem(com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem) FunctionOperator(com.google.api.ads.adwords.axis.v201809.cm.FunctionOperator) FeedMapping(com.google.api.ads.adwords.axis.v201809.cm.FeedMapping) FeedItemAttributeValue(com.google.api.ads.adwords.axis.v201809.cm.FeedItemAttributeValue) AttributeFieldMapping(com.google.api.ads.adwords.axis.v201809.cm.AttributeFieldMapping) Multimap(com.google.common.collect.Multimap) FeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedServiceInterface) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FeedItemOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation) ExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.ExtensionSetting) CampaignExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSetting) Function(com.google.api.ads.adwords.axis.v201809.cm.Function) Credential(com.google.api.client.auth.oauth2.Credential) CampaignFeed(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeed) RequestContextOperandContextType(com.google.api.ads.adwords.axis.v201809.cm.RequestContextOperandContextType) FeedMappingServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface) CampaignFeedPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedPage) Feed(com.google.api.ads.adwords.axis.v201809.cm.Feed) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) ExtensionSettingPlatform(com.google.api.ads.adwords.axis.v201809.cm.ExtensionSettingPlatform) FeedMappingPage(com.google.api.ads.adwords.axis.v201809.cm.FeedMappingPage) SitelinkFeedItem(com.google.api.ads.adwords.axis.v201809.cm.SitelinkFeedItem) Maps(com.google.common.collect.Maps) DEFAULT_CONFIGURATION_FILENAME(com.google.api.ads.common.lib.utils.Builder.DEFAULT_CONFIGURATION_FILENAME) RequestContextOperand(com.google.api.ads.adwords.axis.v201809.cm.RequestContextOperand) FeedItemPage(com.google.api.ads.adwords.axis.v201809.cm.FeedItemPage) ConstantOperand(com.google.api.ads.adwords.axis.v201809.cm.ConstantOperand) FeedItemServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface) FeedType(com.google.api.ads.adwords.axis.v201809.cm.FeedType) Api(com.google.api.ads.common.lib.auth.OfflineCredentials.Api) FunctionOperand(com.google.api.ads.adwords.axis.v201809.cm.FunctionOperand) FunctionOperator(com.google.api.ads.adwords.axis.v201809.cm.FunctionOperator)

Example 4 with Operand

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

the class BatchJobHelperTest method assertDownloadResponse.

@Override
protected void assertDownloadResponse(BatchJobMutateResponse downloadResponse) {
    assertEquals("Wrong # of mutate results", 1, downloadResponse.getMutateResults().length);
    Operand operand = downloadResponse.getMutateResults()[0].getOperand();
    Campaign campaign = operand.getCampaign();
    assertEquals("ID is incorrect", Long.valueOf(12345L), campaign.getId());
    assertEquals("Status is incorrect", CampaignStatus.PAUSED, campaign.getStatus());
}
Also used : Campaign(com.google.api.ads.adwords.jaxws.v201809.cm.Campaign) Operand(com.google.api.ads.adwords.jaxws.v201809.cm.Operand)

Example 5 with Operand

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

the class AddCrmBasedUserList method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws UnsupportedEncodingException if encoding the hashed email failed.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException, UnsupportedEncodingException {
    // Get the UserListService.
    AdwordsUserListServiceInterface userListService = adWordsServices.get(session, AdwordsUserListServiceInterface.class);
    // Create a user list.
    CrmBasedUserList userList = new CrmBasedUserList();
    userList.setName("Customer relationship management list #" + System.currentTimeMillis());
    userList.setDescription("A list of customers that originated from email addresses");
    // CRM-based user lists can use a membershipLifeSpan of 10000 to indicate unlimited; otherwise
    // normal values apply.
    userList.setMembershipLifeSpan(30L);
    userList.setUploadKeyType(CustomerMatchUploadKeyType.CONTACT_INFO);
    // Create operation.
    UserListOperation operation = new UserListOperation();
    operation.setOperand(userList);
    operation.setOperator(Operator.ADD);
    // Add user list.
    UserListReturnValue result = userListService.mutate(new UserListOperation[] { operation });
    // Display user list.
    UserList userListAdded = result.getValue(0);
    System.out.printf("User list with name '%s' and ID %d was added.%n", userListAdded.getName(), userListAdded.getId());
    // Get user list ID.
    Long userListId = userListAdded.getId();
    // Create operation to add members to the user list based on email addresses.
    MutateMembersOperation mutateMembersOperation = new MutateMembersOperation();
    MutateMembersOperand operand = new MutateMembersOperand();
    operand.setUserListId(userListId);
    // Hash normalized email addresses based on SHA-256 hashing algorithm.
    List<Member> members = new ArrayList<>(EMAILS.size());
    for (String email : EMAILS) {
        String normalizedEmail = toNormalizedString(email);
        Member member = new Member();
        member.setHashedEmail(toSHA256String(normalizedEmail));
        members.add(member);
    }
    String firstName = "John";
    String lastName = "Doe";
    String countryCode = "US";
    String zipCode = "10011";
    AddressInfo addressInfo = new AddressInfo();
    // First and last name must be normalized and hashed.
    addressInfo.setHashedFirstName(toSHA256String(toNormalizedString(firstName)));
    addressInfo.setHashedLastName(toSHA256String(toNormalizedString(lastName)));
    // Country code and zip code are sent in plaintext.
    addressInfo.setCountryCode(countryCode);
    addressInfo.setZipCode(zipCode);
    Member memberByAddress = new Member();
    memberByAddress.setAddressInfo(addressInfo);
    members.add(memberByAddress);
    operand.setMembersList(members.toArray(new Member[members.size()]));
    mutateMembersOperation.setOperand(operand);
    mutateMembersOperation.setOperator(Operator.ADD);
    // Add members to the user list based on email addresses.
    MutateMembersReturnValue mutateMembersResult = userListService.mutateMembers(new MutateMembersOperation[] { mutateMembersOperation });
    // Reminder: it may take several hours for the list to be populated with members.
    for (UserList userListResult : mutateMembersResult.getUserLists()) {
        System.out.printf("%d email addresses were uploaded to user list with name '%s' and ID %d " + "and are scheduled for review.%n", EMAILS.size(), userListResult.getName(), userListResult.getId());
    }
}
Also used : AdwordsUserListServiceInterface(com.google.api.ads.adwords.axis.v201809.rm.AdwordsUserListServiceInterface) ArrayList(java.util.ArrayList) UserListOperation(com.google.api.ads.adwords.axis.v201809.rm.UserListOperation) UserListReturnValue(com.google.api.ads.adwords.axis.v201809.rm.UserListReturnValue) AddressInfo(com.google.api.ads.adwords.axis.v201809.rm.AddressInfo) CrmBasedUserList(com.google.api.ads.adwords.axis.v201809.rm.CrmBasedUserList) MutateMembersOperation(com.google.api.ads.adwords.axis.v201809.rm.MutateMembersOperation) MutateMembersOperand(com.google.api.ads.adwords.axis.v201809.rm.MutateMembersOperand) UserList(com.google.api.ads.adwords.axis.v201809.rm.UserList) CrmBasedUserList(com.google.api.ads.adwords.axis.v201809.rm.CrmBasedUserList) Member(com.google.api.ads.adwords.axis.v201809.rm.Member) MutateMembersReturnValue(com.google.api.ads.adwords.axis.v201809.rm.MutateMembersReturnValue)

Aggregations

AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)2 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)2 MockHttpIntegrationTest (com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)1 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)1 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)1 AttributeFieldMapping (com.google.api.ads.adwords.axis.v201809.cm.AttributeFieldMapping)1 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)1 CampaignExtensionSetting (com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSetting)1 CampaignExtensionSettingOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingOperation)1 CampaignExtensionSettingServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingServiceInterface)1 CampaignFeed (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeed)1 CampaignFeedOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation)1 CampaignFeedPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedPage)1 CampaignFeedServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface)1 ConstantOperand (com.google.api.ads.adwords.axis.v201809.cm.ConstantOperand)1 ExtensionFeedItem (com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem)1 ExtensionSetting (com.google.api.ads.adwords.axis.v201809.cm.ExtensionSetting)1