Search in sources :

Example 1 with OrderBy

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

the class SelectorBuilderTest method testOrderBySubstitution.

/**
 * Tests that when a repeated ORDER BY clause is added to the selector, it is actually ignored.
 */
@Test
public void testOrderBySubstitution() {
    SelectorBuilder builder = new SelectorBuilder();
    builder = builder.orderAscBy(CampaignField.AdvertisingChannelType).orderDescBy(CampaignField.Amount);
    Selector selector = builder.build();
    assertNotNull(selector.getOrdering());
    assertEquals(2, selector.getOrdering().length);
    builder.orderAscBy(CampaignField.AdvertisingChannelType);
    selector = builder.build();
    assertNotNull(selector.getOrdering());
    assertEquals(2, selector.getOrdering().length);
    OrderBy orderBy = selector.getOrdering()[0];
    assertEquals("AdvertisingChannelType", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    orderBy = selector.getOrdering()[1];
    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.DESCENDING, orderBy.getSortOrder());
    checkUtilitiesState(true);
}
Also used : OrderBy(com.google.api.ads.adwords.axis.v201809.cm.OrderBy) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Test(org.junit.Test)

Example 2 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().length);
    OrderBy orderBy = selector.getOrdering()[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().length);
    orderBy = selector.getOrdering()[0];
    assertEquals("AdvertisingChannelType", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    orderBy = selector.getOrdering()[1];
    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    orderBy = selector.getOrdering()[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().length);
    orderBy = selector.getOrdering()[0];
    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    checkUtilitiesState(true);
}
Also used : OrderBy(com.google.api.ads.adwords.axis.v201809.cm.OrderBy) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Test(org.junit.Test)

Example 3 with OrderBy

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

the class SelectorBuilderImpl method orderDescBy.

@Override
public SelectorBuilderImpl orderDescBy(String field) {
    OrderBy orderBy = new OrderBy();
    orderBy.setField(field);
    orderBy.setSortOrder(SortOrder.DESCENDING);
    this.ordering.add(orderBy);
    return this;
}
Also used : OrderBy(com.google.api.ads.adwords.axis.v201809.cm.OrderBy)

Example 4 with OrderBy

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

the class SelectorBuilderImpl method copyOrderingSet.

/**
 * Copies the whole set of OrderBy objects, by creating new instances of each one in the given
 * set.
 *
 * @return the new set of OrderBy objects with different instance for each of the OrderBy
 */
private Set<OrderBy> copyOrderingSet() {
    Set<OrderBy> orderingCopy = Sets.newLinkedHashSet();
    for (OrderBy order : this.ordering) {
        OrderBy copyOrder = new OrderBy();
        copyOrder.setField(order.getField());
        copyOrder.setSortOrder(order.getSortOrder());
        orderingCopy.add(copyOrder);
    }
    return orderingCopy;
}
Also used : OrderBy(com.google.api.ads.adwords.axis.v201809.cm.OrderBy)

Example 5 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.setFields(this.fields.toArray(new String[this.fields.size()]));
    selectorCopy.setOrdering(orderingCopy.toArray(new OrderBy[this.ordering.size()]));
    selectorCopy.setPredicates(predicatesCopy.toArray(new Predicate[this.predicates.size()]));
    if (this.dateRange != null) {
        selectorCopy.setDateRange(new DateRange(this.dateRange.getMin(), this.dateRange.getMax()));
    }
    if (this.paging != null) {
        selectorCopy.setPaging(new Paging(this.paging.getStartIndex(), this.paging.getNumberResults()));
    }
    return selectorCopy;
}
Also used : OrderBy(com.google.api.ads.adwords.axis.v201809.cm.OrderBy) DateRange(com.google.api.ads.adwords.axis.v201809.cm.DateRange) Paging(com.google.api.ads.adwords.axis.v201809.cm.Paging) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.axis.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