private static ProductPartitionTree createProductPartitions ( AdWordsServicesInterface adWordsServices , AdWordsSession session , Long adGroupId ) throws RemoteException { AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices . get ( session , AdGroupCriterionServiceInterface . class ) ; ProductPartitionTree partitionTree = ProductPartitionTree . createAdGroupTree ( adWordsServices , session , adGroupId ) ; System . out . printf ( "Original tree: %s%n" , partitionTree ) ; // Clear out any existing criteria. ProductPartitionNode rootNode = partitionTree . getRoot ( ) . removeAllChildren ( ) ; // Make the root node a subdivision. rootNode = rootNode . asSubdivision ( ) ; // Add a unit node for condition = NEW to include it. rootNode . addChild ( ProductDimensions . createCanonicalCondition ( ProductCanonicalConditionCondition . NEW ) ) . asBiddableUnit ( ) ; // Add a unit node for condition = USED to include it. rootNode . addChild ( ProductDimensions . createCanonicalCondition ( ProductCanonicalConditionCondition . USED ) ) . asBiddableUnit ( ) ; // Exclude everything else. rootNode . addChild ( ProductDimensions . createCanonicalCondition ( null ) ) . asExcludedUnit ( ) ; // Make the mutate request, using the operations returned by the ProductPartitionTree. List < AdGroupCriterionOperation > mutateOperations = partitionTree . getMutateOperations ( ) ; if ( mutateOperations . isEmpty ( ) ) { System . out . println ( "Skipping the mutate call because the original tree and the current " + "tree are logically identical." ) ; } else { adGroupCriterionService . mutate ( mutateOperations . toArray ( new AdGroupCriterionOperation [ mutateOperations . size ( ) ] ) ) ; } // The request was successful, so create a new ProductPartitionTree based on the updated // state of the ad group. return ProductPartitionTree . createAdGroupTree ( adWordsServices , session , adGroupId ) ; }
Creates the product partition tree for the ad group .