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);
}
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);
}
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;
}
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());
}
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());
}
}
Aggregations