Search in sources :

Example 36 with Selector

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

the class SelectorBuilderTest method testUniqueInternalDateRangeState.

/**
 * Tests that the built selectors don't share internal DateRange state.
 */
@Test
public void testUniqueInternalDateRangeState() {
    SelectorBuilder builder = new SelectorBuilder();
    DateFormat dateFormat = new SimpleDateFormat(SelectorBuilderImpl.DEFAULT_DATE_FORMAT);
    DateTime startOne = new DateTime(2013, 1, 1, 0, 0, 0, 0);
    DateTime endOne = new DateTime(2013, 1, 31, 0, 0, 0, 0);
    DateTime startTwo = new DateTime(2013, 2, 1, 0, 0, 0, 0);
    DateTime endTwo = new DateTime(2013, 2, 28, 0, 0, 0, 0);
    Selector selectorOne = builder.forDateRange(startOne, endOne).build();
    Selector selectorTwo = builder.forDateRange(startTwo, endTwo).build();
    assertEquals(dateFormat.format(startOne.toDate()), selectorOne.getDateRange().getMin());
    assertEquals(dateFormat.format(endOne.toDate()), selectorOne.getDateRange().getMax());
    assertEquals(dateFormat.format(startTwo.toDate()), selectorTwo.getDateRange().getMin());
    assertEquals(dateFormat.format(endTwo.toDate()), selectorTwo.getDateRange().getMax());
    checkUtilitiesState(false);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) DateTime(org.joda.time.DateTime) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Test(org.junit.Test)

Example 37 with Selector

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

the class ProductPartitionTreeImpl method getAdGroupBiddingStrategyConfiguration.

/**
 * Retrieves the {@link BiddingStrategyConfiguration} of an ad group.
 *
 * @param services the AdWordsServices
 * @param session the session to use for the request
 * @param adGroupId the ad group ID
 * @return the non-null BiddingStrategyConfiguration of the ad group
 */
private static BiddingStrategyConfiguration getAdGroupBiddingStrategyConfiguration(AdWordsServicesInterface services, AdWordsSession session, Long adGroupId) throws ApiException, RemoteException {
    AdGroupServiceInterface adGroupService = services.get(session, AdGroupServiceInterface.class);
    Selector selector = new SelectorBuilder().fields(AdGroupField.Id, AdGroupField.BiddingStrategyType, AdGroupField.BiddingStrategyId, AdGroupField.BiddingStrategyName).equalsId(adGroupId).build();
    AdGroupPage adGroupPage = adGroupService.get(selector);
    if (adGroupPage.getEntries() == null || adGroupPage.getEntries().length == 0) {
        throw new IllegalArgumentException("No ad group found with ID " + adGroupId);
    }
    AdGroup adGroup = adGroupPage.getEntries(0);
    Preconditions.checkState(adGroup.getBiddingStrategyConfiguration() != null, "Unexpected state - ad group ID %s has a null BiddingStrategyConfiguration", adGroupId);
    return adGroup.getBiddingStrategyConfiguration();
}
Also used : AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) AdGroupPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupPage) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 38 with Selector

use of com.google.api.ads.adwords.axis.v201809.cm.Selector 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);
}
Also used : BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)

Example 39 with Selector

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

the class AdvancedCreateCredentialFromScratch method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param reportFile the output file for the report contents.
 * @throws DetailedReportDownloadResponseException if the report request failed with a detailed
 *     error from the reporting service.
 * @throws ReportDownloadResponseException if the report request failed with a general error from
 *     the reporting service.
 * @throws ReportException if the report request failed due to a transport layer error.
 * @throws IOException if the report's contents could not be written to {@code reportFile}.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, String reportFile) throws ReportDownloadResponseException, ReportException, IOException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create selector to retrieve the first 100 campaigns.
    Selector selector = new Selector();
    selector.setFields(new String[] { "Id", "Name" });
    Paging paging = new Paging();
    paging.setStartIndex(0);
    paging.setNumberResults(100);
    // Get the first page of campaigns.
    CampaignPage page = campaignService.get(selector);
    System.out.printf("Found %d total campaigns.%n", page.getTotalNumEntries());
    // Display campaigns.
    if (page.getEntries() != null) {
        for (Campaign campaign : page.getEntries()) {
            System.out.printf("Campaign with name '%s' and ID %d was found.%n", campaign.getName(), campaign.getId());
        }
    } else {
        System.out.println("No campaigns were found.");
    }
    // Create selector.
    com.google.api.ads.adwords.lib.jaxb.v201809.Selector reportSelector = new com.google.api.ads.adwords.lib.jaxb.v201809.Selector();
    reportSelector.getFields().addAll(Arrays.asList("CampaignId", "AdGroupId", "Id", "CriteriaType", "Criteria", "Impressions", "Clicks", "Cost"));
    // Create report definition.
    ReportDefinition reportDefinition = new ReportDefinition();
    reportDefinition.setReportName("Criteria performance report #" + System.currentTimeMillis());
    reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.YESTERDAY);
    reportDefinition.setReportType(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT);
    reportDefinition.setDownloadFormat(DownloadFormat.CSV);
    reportDefinition.setSelector(reportSelector);
    ReportingConfiguration reportingConfig = new ReportingConfiguration.Builder().includeZeroImpressions(false).build();
    session.setReportingConfiguration(reportingConfig);
    ReportDownloadResponse response = new ReportDownloader(session).downloadReport(reportDefinition);
    FileOutputStream fos = new FileOutputStream(new File(reportFile));
    Streams.copy(response.getInputStream(), fos);
    fos.close();
    System.out.printf("Report successfully downloaded: %s%n", reportFile);
}
Also used : Paging(com.google.api.ads.adwords.axis.v201809.cm.Paging) CampaignPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignPage) CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) ReportDownloadResponse(com.google.api.ads.adwords.lib.utils.ReportDownloadResponse) ReportDownloader(com.google.api.ads.adwords.lib.utils.v201809.ReportDownloader) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ReportDefinition(com.google.api.ads.adwords.lib.jaxb.v201809.ReportDefinition) ReportingConfiguration(com.google.api.ads.adwords.lib.client.reporting.ReportingConfiguration) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 40 with Selector

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

the class SelectorBuilderTest method testDateRangeBuild.

/**
 * Tests the date range setting
 */
@Test
public void testDateRangeBuild() {
    DateFormat dateFormat = new SimpleDateFormat(SelectorBuilderImpl.DEFAULT_DATE_FORMAT);
    SelectorBuilder builder = new SelectorBuilder();
    DateTime start = new DateTime(2013, 3, 25, 0, 0, 0, 0);
    DateTime end = new DateTime(2013, 3, 26, 0, 0, 0, 0);
    String formatStart = dateFormat.format(start.toDate());
    String formatEnd = dateFormat.format(end.toDate());
    builder = builder.forDateRange(start, end);
    Selector selector = builder.build();
    assertEquals(formatStart, selector.getDateRange().getMin());
    assertEquals(formatEnd, selector.getDateRange().getMax());
    checkUtilitiesState(false);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) DateTime(org.joda.time.DateTime) Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Test(org.junit.Test)

Aggregations

Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)36 Test (org.junit.Test)27 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)22 Selector (com.google.api.ads.adwords.jaxws.v201809.cm.Selector)14 ArrayList (java.util.ArrayList)9 SimpleDateFormat (java.text.SimpleDateFormat)7 DateFormat (java.text.DateFormat)6 DateTime (org.joda.time.DateTime)6 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)5 CampaignPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignPage)5 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)5 OrderBy (com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy)4 Predicate (com.google.api.ads.adwords.jaxws.v201809.cm.Predicate)4 ConfigurationLoadException (com.google.api.ads.common.lib.conf.ConfigurationLoadException)4 OAuthException (com.google.api.ads.common.lib.exception.OAuthException)4 ValidationException (com.google.api.ads.common.lib.exception.ValidationException)4 RemoteException (java.rmi.RemoteException)4 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)3 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)3 AdGroupAdPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage)3