Search in sources :

Example 11 with OrderBy

use of com.google.api.ads.adwords.jaxws.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.jaxws.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)

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 DateRange (com.google.api.ads.adwords.axis.v201809.cm.DateRange)1 Paging (com.google.api.ads.adwords.axis.v201809.cm.Paging)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 Predicate (com.google.api.ads.adwords.jaxws.v201809.cm.Predicate)1