use of com.google.api.ads.adwords.axis.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);
}
use of com.google.api.ads.adwords.axis.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;
}
use of com.google.api.ads.adwords.axis.v201809.cm.OrderBy in project googleads-java-lib by googleads.
the class GetCampaignsWithAwql method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @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) throws RemoteException {
// Get the CampaignService.
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
ServiceQuery serviceQuery = new ServiceQuery.Builder().fields(CampaignField.Id, CampaignField.Name, CampaignField.Status).orderBy(CampaignField.Name).limit(0, PAGE_SIZE).build();
CampaignPage page = null;
do {
serviceQuery.nextPage(page);
// Get all campaigns.
page = campaignService.query(serviceQuery.toString());
// Display campaigns.
if (page.getEntries() != null) {
for (Campaign campaign : page.getEntries()) {
System.out.printf("Campaign with name '%s' and ID %d was found.%n", campaign.getName(), campaign.getId());
}
} else {
System.out.println("No campaigns were found.");
}
} while (serviceQuery.hasNext(page));
}
use of com.google.api.ads.adwords.axis.v201809.cm.OrderBy in project googleads-java-lib by googleads.
the class GetAllDisapprovedAdsWithAwql method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group to search for disapproved ads.
* @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, Long adGroupId) throws RemoteException {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
ServiceQuery serviceQuery = new ServiceQuery.Builder().fields(AdGroupAdField.Id, AdGroupAdField.PolicySummary).where(AdGroupAdField.AdGroupId).equalTo(adGroupId).where(AdGroupAdField.CombinedApprovalStatus).equalTo(PolicyApprovalStatus.DISAPPROVED.getValue()).orderBy(AdGroupAdField.Id, SortOrder.ASCENDING).limit(0, PAGE_SIZE).build();
// Get all disapproved ads.
AdGroupAdPage page = null;
int disapprovedAdsCount = 0;
do {
serviceQuery.nextPage(page);
page = adGroupAdService.query(serviceQuery.toString());
// Display ads.
for (AdGroupAd adGroupAd : page) {
disapprovedAdsCount++;
AdGroupAdPolicySummary policySummary = adGroupAd.getPolicySummary();
System.out.printf("Ad with ID %d and type '%s' was disapproved with the following " + "policy topic entries:%n", adGroupAd.getAd().getId(), adGroupAd.getAd().getAdType());
// Display the policy topic entries related to the ad disapproval.
for (PolicyTopicEntry policyTopicEntry : policySummary.getPolicyTopicEntries()) {
System.out.printf(" topic id: %s, topic name: '%s'%n", policyTopicEntry.getPolicyTopicId(), policyTopicEntry.getPolicyTopicName());
// Display the attributes and values that triggered the policy topic.
if (policyTopicEntry.getPolicyTopicEvidences() != null) {
for (PolicyTopicEvidence evidence : policyTopicEntry.getPolicyTopicEvidences()) {
System.out.printf(" evidence type: %s%n", evidence.getPolicyTopicEvidenceType());
if (evidence.getEvidenceTextList() != null) {
for (int i = 0; i < evidence.getEvidenceTextList().length; i++) {
System.out.printf(" evidence text[%d]: %s%n", i, evidence.getEvidenceTextList(i));
}
}
}
}
}
}
} while (serviceQuery.hasNext(page));
System.out.printf("%d disapproved ads were found.%n", disapprovedAdsCount);
}
Aggregations