use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class ProductPartitionTreeImpl method createAdGroupTree.
/**
* Returns a new instance of this class based on the collection of ad group criteria provided.
* <p>NOTE: If retrieving existing criteria for use with this method, you must include all of the
* fields in {@link #REQUIRED_SELECTOR_FIELD_ENUMS} in your {@link Selector}.
*
* @param adGroupId the ID of the ad group
* @param biddingStrategyConfig the {@link BiddingStrategyConfiguration} for the ad group
* @param adGroupCriteria the non-null (but possibly empty) list of ad group criteria
*
* @throws NullPointerException if any argument is null, any element in {@code adGroupCriteria} is
* null, or any required field from {@link #REQUIRED_SELECTOR_FIELD_ENUMS} is missing from
* an element in {@code adGroupCriteria}
* @throws IllegalArgumentException if {@code adGroupCriteria} does not include the root criterion
* of the product partition tree
*/
static ProductPartitionTreeImpl createAdGroupTree(Long adGroupId, BiddingStrategyConfiguration biddingStrategyConfig, List<AdGroupCriterion> adGroupCriteria) {
Preconditions.checkNotNull(adGroupId, "Null ad group ID");
Preconditions.checkNotNull(biddingStrategyConfig, "Null bidding strategy configuration");
Preconditions.checkNotNull(adGroupCriteria, "Null criteria list");
if (adGroupCriteria.isEmpty()) {
return createEmptyAdGroupTree(adGroupId, biddingStrategyConfig);
}
ListMultimap<Long, AdGroupCriterion> parentIdMap = LinkedListMultimap.create();
for (AdGroupCriterion adGroupCriterion : adGroupCriteria) {
Preconditions.checkNotNull(adGroupCriterion.getCriterion(), "AdGroupCriterion has a null criterion");
if (adGroupCriterion instanceof BiddableAdGroupCriterion) {
BiddableAdGroupCriterion biddableCriterion = (BiddableAdGroupCriterion) adGroupCriterion;
Preconditions.checkNotNull(biddableCriterion.getUserStatus(), "User status is null for criterion ID %s", biddableCriterion.getCriterion().getId());
if (UserStatus.REMOVED.equals(biddableCriterion.getUserStatus())) {
// Skip REMOVED criteria.
continue;
}
}
if (adGroupCriterion.getCriterion() instanceof ProductPartition) {
ProductPartition partition = (ProductPartition) adGroupCriterion.getCriterion();
parentIdMap.put(partition.getParentCriterionId(), adGroupCriterion);
}
}
return createNonEmptyAdGroupTree(adGroupId, parentIdMap);
}
use of com.google.api.ads.adwords.axis.v201809.cm.Ad 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.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class AddAdCustomizer method createCustomizerFeed.
/**
* Creates a new AdCustomizerFeed.
*
* @param feedName the name of the new AdCustomizerFeed
* @return The new AdCustomizerFeed
*/
private static AdCustomizerFeed createCustomizerFeed(AdWordsServicesInterface adWordsServices, AdWordsSession session, String feedName) throws RemoteException {
// Get the AdCustomizerFeedService.
AdCustomizerFeedServiceInterface adCustomizerFeedService = adWordsServices.get(session, AdCustomizerFeedServiceInterface.class);
AdCustomizerFeed customizerFeed = new AdCustomizerFeed();
customizerFeed.setFeedName(feedName);
AdCustomizerFeedAttribute nameAttribute = new AdCustomizerFeedAttribute();
nameAttribute.setName("Name");
nameAttribute.setType(AdCustomizerFeedAttributeType.STRING);
AdCustomizerFeedAttribute priceAttribute = new AdCustomizerFeedAttribute();
priceAttribute.setName("Price");
priceAttribute.setType(AdCustomizerFeedAttributeType.STRING);
AdCustomizerFeedAttribute dateAttribute = new AdCustomizerFeedAttribute();
dateAttribute.setName("Date");
dateAttribute.setType(AdCustomizerFeedAttributeType.DATE_TIME);
customizerFeed.setFeedAttributes(new AdCustomizerFeedAttribute[] { nameAttribute, priceAttribute, dateAttribute });
AdCustomizerFeedOperation feedOperation = new AdCustomizerFeedOperation();
feedOperation.setOperand(customizerFeed);
feedOperation.setOperator(Operator.ADD);
AdCustomizerFeed addedFeed = adCustomizerFeedService.mutate(new AdCustomizerFeedOperation[] { feedOperation }).getValue()[0];
System.out.printf("Created ad customizer feed with ID %d, name '%s' and attributes:%n", addedFeed.getFeedId(), addedFeed.getFeedName());
for (AdCustomizerFeedAttribute feedAttribute : addedFeed.getFeedAttributes()) {
System.out.printf(" ID: %d, name: '%s', type: %s%n", feedAttribute.getId(), feedAttribute.getName(), feedAttribute.getType());
}
return addedFeed;
}
use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class AddAdCustomizer method restrictFeedItemToAdGroup.
/**
* Restricts the feed item to an ad group.
*/
private static void restrictFeedItemToAdGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, FeedItem feedItem, long adGroupId) throws RemoteException {
// Get the FeedItemTargetingService.
FeedItemTargetServiceInterface feedItemTargetService = adWordsServices.get(session, FeedItemTargetServiceInterface.class);
FeedItemAdGroupTarget adGroupTarget = new FeedItemAdGroupTarget();
adGroupTarget.setFeedId(feedItem.getFeedId());
adGroupTarget.setFeedItemId(feedItem.getFeedItemId());
adGroupTarget.setAdGroupId(adGroupId);
FeedItemTargetOperation operation = new FeedItemTargetOperation();
operation.setOperator(Operator.ADD);
operation.setOperand(adGroupTarget);
FeedItemTargetReturnValue returnValue = feedItemTargetService.mutate(new FeedItemTargetOperation[] { operation });
FeedItemAdGroupTarget addedAdGroupTarget = (FeedItemAdGroupTarget) returnValue.getValue(0);
System.out.printf("Feed item target for feed ID %d and feed item ID %d " + "was created to restrict serving to ad group ID %d.%n", addedAdGroupTarget.getFeedId(), addedAdGroupTarget.getFeedItemId(), addedAdGroupTarget.getAdGroupId());
}
use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class AddAdCustomizer method createFeedItemAddOperation.
/**
* Creates a FeedItemOperation that will create a FeedItem with the specified values and ad group
* target when sent to FeedItemService.mutate.
*
* @param name the value for the name attribute of the FeedItem
* @param price the value for the price attribute of the FeedItem
* @param date the value for the date attribute of the FeedItem
* @param adCustomizerFeed the customizer feed
* @return a new FeedItemOperation for adding a FeedItem
*/
private static FeedItemOperation createFeedItemAddOperation(String name, String price, String date, AdCustomizerFeed adCustomizerFeed) {
FeedItem feedItem = new FeedItem();
feedItem.setFeedId(adCustomizerFeed.getFeedId());
List<FeedItemAttributeValue> attributeValues = new ArrayList<>();
// FeedAttributes appear in the same order as they were created - Name, Price, Date.
// See the createCustomizerFeed method for details.
FeedItemAttributeValue nameAttributeValue = new FeedItemAttributeValue();
nameAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(0).getId());
nameAttributeValue.setStringValue(name);
attributeValues.add(nameAttributeValue);
FeedItemAttributeValue priceAttributeValue = new FeedItemAttributeValue();
priceAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(1).getId());
priceAttributeValue.setStringValue(price);
attributeValues.add(priceAttributeValue);
FeedItemAttributeValue dateAttributeValue = new FeedItemAttributeValue();
dateAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(2).getId());
dateAttributeValue.setStringValue(date);
attributeValues.add(dateAttributeValue);
feedItem.setAttributeValues(attributeValues.toArray(new FeedItemAttributeValue[attributeValues.size()]));
FeedItemOperation feedItemOperation = new FeedItemOperation();
feedItemOperation.setOperand(feedItem);
feedItemOperation.setOperator(Operator.ADD);
return feedItemOperation;
}
Aggregations