Search in sources :

Example 11 with OrderBy

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

the class SelectorBuilderTest method testOrderByBuild.

/**
 * Tests the order by criteria.
 */
@Test
public void testOrderByBuild() {
    SelectorBuilder builder = new SelectorBuilder();
    builder = builder.orderAscBy(CampaignField.AdvertisingChannelType);
    Selector selector = builder.build();
    assertNotNull(selector.getOrdering());
    assertEquals(1, selector.getOrdering().size());
    OrderBy orderBy = selector.getOrdering().get(0);
    assertEquals("AdvertisingChannelType", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    builder.orderAscBy(CampaignField.Amount).orderDescBy(CampaignField.AdvertisingChannelType);
    selector = builder.build();
    assertNotNull(selector.getOrdering());
    assertEquals(3, selector.getOrdering().size());
    orderBy = selector.getOrdering().get(0);
    assertEquals("AdvertisingChannelType", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    orderBy = selector.getOrdering().get(1);
    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    orderBy = selector.getOrdering().get(2);
    assertEquals("AdvertisingChannelType", orderBy.getField());
    assertEquals(SortOrder.DESCENDING, orderBy.getSortOrder());
    // Removing the OrderBy for AdvertisingChannelType
    selector = builder.removeOrderBy("AdvertisingChannelType").build();
    assertNotNull(selector.getOrdering());
    assertEquals(1, selector.getOrdering().size());
    orderBy = selector.getOrdering().get(0);
    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    checkUtilitiesState(true);
}
Also used : OrderBy(com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy) Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Test(org.junit.Test)

Example 12 with OrderBy

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

the class SelectorBuilderImpl method build.

@Override
public Selector build() {
    Selector selectorCopy = new Selector();
    Set<OrderBy> orderingCopy = this.copyOrderingSet();
    Set<Predicate> predicatesCopy = this.copyPredicatesSet();
    selectorCopy.getFields().addAll(Sets.newLinkedHashSet(this.fields));
    selectorCopy.getOrdering().addAll(orderingCopy);
    selectorCopy.getPredicates().addAll(predicatesCopy);
    if (this.dateRange != null) {
        DateRange newDateRange = new DateRange();
        newDateRange.setMin(this.dateRange.getMin());
        newDateRange.setMax(this.dateRange.getMax());
        selectorCopy.setDateRange(newDateRange);
    }
    if (this.paging != null) {
        Paging newPaging = new Paging();
        newPaging.setStartIndex(this.paging.getStartIndex());
        newPaging.setNumberResults(this.paging.getNumberResults());
        selectorCopy.setPaging(newPaging);
    }
    return selectorCopy;
}
Also used : OrderBy(com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy) DateRange(com.google.api.ads.adwords.jaxws.v201809.cm.DateRange) Paging(com.google.api.ads.adwords.jaxws.v201809.cm.Paging) Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.jaxws.v201809.cm.Predicate)

Example 13 with OrderBy

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

the class GetCampaignsWithAwql 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.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    ServiceQuery serviceQuery = new ServiceQuery.Builder().fields(CampaignField.Id, CampaignField.Name, CampaignField.Status).orderBy(CampaignField.Name).limit(0, PAGE_SIZE).build();
    CampaignPage page = null;
    do {
        serviceQuery.nextPage(page);
        // Get all campaigns.
        page = campaignService.query(serviceQuery.toString());
        // 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.");
        }
    } while (serviceQuery.hasNext(page));
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) CampaignPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignPage) ServiceQuery(com.google.api.ads.adwords.axis.utils.v201809.ServiceQuery)

Example 14 with OrderBy

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

the class GetAllDisapprovedAdsWithAwql method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group to search for disapproved ads.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long adGroupId) throws RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    ServiceQuery serviceQuery = new ServiceQuery.Builder().fields(AdGroupAdField.Id, AdGroupAdField.PolicySummary).where(AdGroupAdField.AdGroupId).equalTo(adGroupId).where(AdGroupAdField.CombinedApprovalStatus).equalTo(PolicyApprovalStatus.DISAPPROVED.getValue()).orderBy(AdGroupAdField.Id, SortOrder.ASCENDING).limit(0, PAGE_SIZE).build();
    // Get all disapproved ads.
    AdGroupAdPage page = null;
    int disapprovedAdsCount = 0;
    do {
        serviceQuery.nextPage(page);
        page = adGroupAdService.query(serviceQuery.toString());
        // Display ads.
        for (AdGroupAd adGroupAd : page) {
            disapprovedAdsCount++;
            AdGroupAdPolicySummary policySummary = adGroupAd.getPolicySummary();
            System.out.printf("Ad with ID %d and type '%s' was disapproved with the following " + "policy topic entries:%n", adGroupAd.getAd().getId(), adGroupAd.getAd().getAdType());
            // Display the policy topic entries related to the ad disapproval.
            for (PolicyTopicEntry policyTopicEntry : policySummary.getPolicyTopicEntries()) {
                System.out.printf("  topic id: %s, topic name: '%s'%n", policyTopicEntry.getPolicyTopicId(), policyTopicEntry.getPolicyTopicName());
                // Display the attributes and values that triggered the policy topic.
                if (policyTopicEntry.getPolicyTopicEvidences() != null) {
                    for (PolicyTopicEvidence evidence : policyTopicEntry.getPolicyTopicEvidences()) {
                        System.out.printf("    evidence type: %s%n", evidence.getPolicyTopicEvidenceType());
                        if (evidence.getEvidenceTextList() != null) {
                            for (int i = 0; i < evidence.getEvidenceTextList().length; i++) {
                                System.out.printf("      evidence text[%d]: %s%n", i, evidence.getEvidenceTextList(i));
                            }
                        }
                    }
                }
            }
        }
    } while (serviceQuery.hasNext(page));
    System.out.printf("%d disapproved ads were found.%n", disapprovedAdsCount);
}
Also used : AdGroupAdPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) PolicyTopicEvidence(com.google.api.ads.adwords.axis.v201809.cm.PolicyTopicEvidence) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) PolicyTopicEntry(com.google.api.ads.adwords.axis.v201809.cm.PolicyTopicEntry) AdGroupAdPolicySummary(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPolicySummary) ServiceQuery(com.google.api.ads.adwords.axis.utils.v201809.ServiceQuery)

Aggregations

OrderBy (com.google.api.ads.adwords.axis.v201809.cm.OrderBy)7 Test (org.junit.Test)6 OrderBy (com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy)5 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)4 Selector (com.google.api.ads.adwords.jaxws.v201809.cm.Selector)4 ServiceQuery (com.google.api.ads.adwords.axis.utils.v201809.ServiceQuery)2 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)1 AdGroupAdPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage)1 AdGroupAdPolicySummary (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPolicySummary)1 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)1 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)1 CampaignPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignPage)1 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)1 DateRange (com.google.api.ads.adwords.axis.v201809.cm.DateRange)1 Paging (com.google.api.ads.adwords.axis.v201809.cm.Paging)1 PolicyTopicEntry (com.google.api.ads.adwords.axis.v201809.cm.PolicyTopicEntry)1 PolicyTopicEvidence (com.google.api.ads.adwords.axis.v201809.cm.PolicyTopicEvidence)1 Predicate (com.google.api.ads.adwords.axis.v201809.cm.Predicate)1 DateRange (com.google.api.ads.adwords.jaxws.v201809.cm.DateRange)1 Paging (com.google.api.ads.adwords.jaxws.v201809.cm.Paging)1