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());
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations