Search in sources :

Example 1 with Predicate

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

the class SelectorBuilderTest method testPredicatesInBuild.

/**
 * Tests the predicate with the IN clause.
 */
@Test
public void testPredicatesInBuild() {
    SelectorBuilder builder = new SelectorBuilder();
    builder = builder.in(CampaignField.Status, CampaignStatus.ENABLED.toString(), CampaignStatus.REMOVED.toString());
    Selector selector = builder.build();
    assertNotNull(selector.getPredicates());
    assertEquals(1, selector.getPredicates().length);
    Predicate predicate = selector.getPredicates()[0];
    assertEquals("Status", predicate.getField());
    assertEquals(PredicateOperator.IN, predicate.getOperator());
    assertNotNull(predicate.getValues());
    assertEquals(2, predicate.getValues().length);
    assertEquals(CampaignStatus.ENABLED.toString(), predicate.getValues()[0]);
    assertEquals(CampaignStatus.REMOVED.toString(), predicate.getValues()[1]);
    checkUtilitiesState(true);
}
Also used : Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.axis.v201809.cm.Predicate) Test(org.junit.Test)

Example 2 with Predicate

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

the class SelectorBuilderTest method testUniqueInternalPredicateState.

/**
 * Tests that the built selectors don't share internal Predicate state.
 */
@Test
public void testUniqueInternalPredicateState() {
    SelectorBuilder builder = new SelectorBuilder();
    Selector selectorOne = builder.equals("Id", "test").build();
    Selector selectorTwo = builder.build();
    Predicate predicateTwo = selectorTwo.getPredicates(0);
    predicateTwo.setField("Status");
    assertEquals("Id", selectorOne.getPredicates(0).getField());
    assertEquals("Status", selectorTwo.getPredicates(0).getField());
    checkUtilitiesState(false);
}
Also used : Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.axis.v201809.cm.Predicate) Test(org.junit.Test)

Example 3 with Predicate

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

the class SelectorBuilderImpl method multipleValuePredicate.

/**
 * Adds a predicate for the specified field, property values, and operator.
 */
private SelectorBuilderImpl multipleValuePredicate(String field, String[] propertyValues, PredicateOperator operator) {
    if (propertyValues == null) {
        return this;
    }
    Predicate predicate = new Predicate();
    predicate.setOperator(operator);
    predicate.setField(field);
    String[] values = Arrays.copyOf(propertyValues, propertyValues.length);
    predicate.setValues(values);
    this.predicates.add(predicate);
    return this;
}
Also used : Predicate(com.google.api.ads.adwords.axis.v201809.cm.Predicate)

Example 4 with Predicate

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

the class SelectorBuilderImpl method copyPredicatesSet.

/**
 * Copies the whole set of predicates, by creating new instances of each one in the given set.
 *
 * @return the new set of Predicate objects with different instance for each of the Predicate
 */
private Set<Predicate> copyPredicatesSet() {
    Set<Predicate> predicatesCopy = Sets.newLinkedHashSet();
    for (Predicate predicate : this.predicates) {
        Predicate copyPredicate = new Predicate();
        copyPredicate.setField(predicate.getField());
        copyPredicate.setOperator(predicate.getOperator());
        copyPredicate.setValues(Arrays.copyOf(predicate.getValues(), predicate.getValues().length));
        predicatesCopy.add(copyPredicate);
    }
    return predicatesCopy;
}
Also used : Predicate(com.google.api.ads.adwords.axis.v201809.cm.Predicate)

Example 5 with Predicate

use of com.google.api.ads.adwords.axis.v201809.cm.Predicate 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

Predicate (com.google.api.ads.adwords.axis.v201809.cm.Predicate)7 Predicate (com.google.api.ads.adwords.jaxws.v201809.cm.Predicate)7 Test (org.junit.Test)6 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)5 Selector (com.google.api.ads.adwords.jaxws.v201809.cm.Selector)4 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 AdWordsConversionTracker (com.google.api.ads.adwords.axis.v201809.cm.AdWordsConversionTracker)1 ConversionTracker (com.google.api.ads.adwords.axis.v201809.cm.ConversionTracker)1 ConversionTrackerPage (com.google.api.ads.adwords.axis.v201809.cm.ConversionTrackerPage)1 ConversionTrackerServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.ConversionTrackerServiceInterface)1 DateRange (com.google.api.ads.adwords.axis.v201809.cm.DateRange)1 OrderBy (com.google.api.ads.adwords.axis.v201809.cm.OrderBy)1 Paging (com.google.api.ads.adwords.axis.v201809.cm.Paging)1 AdwordsUserListServiceInterface (com.google.api.ads.adwords.axis.v201809.rm.AdwordsUserListServiceInterface)1 BasicUserList (com.google.api.ads.adwords.axis.v201809.rm.BasicUserList)1 UserList (com.google.api.ads.adwords.axis.v201809.rm.UserList)1 UserListConversionType (com.google.api.ads.adwords.axis.v201809.rm.UserListConversionType)1 UserListOperation (com.google.api.ads.adwords.axis.v201809.rm.UserListOperation)1 UserListReturnValue (com.google.api.ads.adwords.axis.v201809.rm.UserListReturnValue)1 DateRange (com.google.api.ads.adwords.jaxws.v201809.cm.DateRange)1