use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class DeactivatePlacements method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param placementId the ID of the placement to deactivate.
* @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(AdManagerServices adManagerServices, AdManagerSession session, long placementId) throws RemoteException {
// Get the PlacementService.
PlacementServiceInterface placementService = adManagerServices.get(session, PlacementServiceInterface.class);
// Create a statement to select a placement.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", placementId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get placements by statement.
PlacementPage page = placementService.getPlacementsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Placement placement : page.getResults()) {
System.out.printf("%d) Placement with ID %d will be deactivated.%n", i++, placement.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of placements to be deactivated: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.admanager.axis.v202202.DeactivatePlacements action = new com.google.api.ads.admanager.axis.v202202.DeactivatePlacements();
// Perform action.
UpdateResult result = placementService.performPlacementAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of placements deactivated: %d%n", result.getNumChanges());
} else {
System.out.println("No placements were deactivated.");
}
}
}
use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class GetAllPlacements method runExample.
/**
* Runs the example.
*
* @param adManagerServices 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(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
// Get the PlacementService.
PlacementServiceInterface placementService = adManagerServices.get(session, PlacementServiceInterface.class);
// Create a statement to get all placements.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get placements by statement.
PlacementPage page = placementService.getPlacementsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Placement placement : page.getResults()) {
System.out.printf("%d) Placement with ID %d and name '%s' was found.%n", i++, placement.getId(), placement.getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class ArchiveProposalLineItems method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param proposalLineItemId the ID of the proposal line item to archive.
* @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(AdManagerServices adManagerServices, AdManagerSession session, long proposalLineItemId) throws RemoteException {
// Get the ProposalLineItemService.
ProposalLineItemServiceInterface proposalLineItemService = adManagerServices.get(session, ProposalLineItemServiceInterface.class);
// Create a statement to select a proposal line item.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", proposalLineItemId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get proposal line items by statement.
ProposalLineItemPage page = proposalLineItemService.getProposalLineItemsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (ProposalLineItem proposalLineItem : page.getResults()) {
System.out.printf("%d) Proposal line item with ID %d will be archived.%n", i++, proposalLineItem.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of proposal line items to be archived: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.admanager.axis.v202202.ArchiveProposalLineItems action = new com.google.api.ads.admanager.axis.v202202.ArchiveProposalLineItems();
// Perform action.
UpdateResult result = proposalLineItemService.performProposalLineItemAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of proposal line items archived: %d%n", result.getNumChanges());
} else {
System.out.println("No proposal line items were archived.");
}
}
}
use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class GetAllProposalLineItems method runExample.
/**
* Runs the example.
*
* @param adManagerServices 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(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
// Get the ProposalLineItemService.
ProposalLineItemServiceInterface proposalLineItemService = adManagerServices.get(session, ProposalLineItemServiceInterface.class);
// Create a statement to select all proposal line items.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get proposal line items by statement.
ProposalLineItemPage page = proposalLineItemService.getProposalLineItemsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (ProposalLineItem proposalLineItem : page.getResults()) {
System.out.printf("%d) Proposal line item with ID %d and name '%s' was found.%n", i++, proposalLineItem.getId(), proposalLineItem.getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.
the class GetProposalLineItemsForProposal method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param proposalId the ID of the proposal.
* @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(AdManagerServices adManagerServices, AdManagerSession session, long proposalId) throws RemoteException {
ProposalLineItemServiceInterface proposalLineItemService = adManagerServices.get(session, ProposalLineItemServiceInterface.class);
// Create a statement to select proposal line items.
StatementBuilder statementBuilder = new StatementBuilder().where("proposalId = :proposalId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("proposalId", proposalId);
// Retrieve a small amount of proposal line items at a time, paging through
// until all proposal line items have been retrieved.
int totalResultSetSize = 0;
do {
ProposalLineItemPage page = proposalLineItemService.getProposalLineItemsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
// Print out some information for each proposal line item.
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (ProposalLineItem proposalLineItem : page.getResults()) {
System.out.printf("%d) Proposal line item with ID %d and name '%s' was found.%n", i++, proposalLineItem.getId(), proposalLineItem.getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Aggregations