Search in sources :

Example 21 with Selector

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

the class LookupLocation method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param locationNames the location names to use for the lookup.
 * @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, String[] locationNames) throws RemoteException {
    // Get the LocationCriterionService.
    LocationCriterionServiceInterface locationCriterionService = adWordsServices.get(session, LocationCriterionServiceInterface.class);
    Selector selector = new SelectorBuilder().fields("Id", "LocationName", "CanonicalName", "DisplayType", "ParentLocations", "Reach", "TargetingStatus").in("LocationName", locationNames).equals("Locale", "en").build();
    // Make the get request.
    LocationCriterion[] locationCriteria = locationCriterionService.get(selector);
    // Display the resulting location criteria.
    for (LocationCriterion locationCriterion : locationCriteria) {
        String parentString = getParentLocationString(locationCriterion.getLocation().getParentLocations());
        System.out.printf("The search term '%s' returned the location '%s (%d)' of type '%s' " + "with parent locations '%s' and reach %d (%s).%n", locationCriterion.getSearchTerm(), locationCriterion.getLocation().getLocationName(), locationCriterion.getLocation().getId(), locationCriterion.getLocation().getDisplayType(), parentString, locationCriterion.getReach(), locationCriterion.getLocation().getTargetingStatus());
    }
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) LocationCriterion(com.google.api.ads.adwords.axis.v201809.cm.LocationCriterion) LocationCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.LocationCriterionServiceInterface) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 22 with Selector

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

Example 23 with Selector

use of com.google.api.ads.adwords.axis.v201809.cm.Selector 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().get(0);
    predicateTwo.setField("Status");
    assertEquals("Id", selectorOne.getPredicates().get(0).getField());
    assertEquals("Status", selectorTwo.getPredicates().get(0).getField());
    checkUtilitiesState(false);
}
Also used : Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.jaxws.v201809.cm.Predicate) Test(org.junit.Test)

Example 24 with Selector

use of com.google.api.ads.adwords.axis.v201809.cm.Selector 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("Status", CampaignStatus.ENABLED.toString(), CampaignStatus.REMOVED.toString());
    Selector selector = builder.build();
    assertNotNull(selector.getPredicates());
    assertEquals(1, selector.getPredicates().size());
    Predicate predicate = selector.getPredicates().get(0);
    assertEquals("Status", predicate.getField());
    assertEquals(PredicateOperator.IN, predicate.getOperator());
    assertNotNull(predicate.getValues());
    assertEquals(2, predicate.getValues().size());
    assertEquals(CampaignStatus.ENABLED.toString(), predicate.getValues().get(0));
    assertEquals(CampaignStatus.REMOVED.toString(), predicate.getValues().get(1));
    checkUtilitiesState(false);
}
Also used : Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.jaxws.v201809.cm.Predicate) Test(org.junit.Test)

Example 25 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.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