Search in sources :

Example 11 with Statement

use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.

the class StatementBuilder method toStatement.

/**
 * Gets the {@link Statement} representing the state of this statement builder.
 *
 * @return the {@link Statement}
 */
public Statement toStatement() {
    Statement statement = new Statement();
    statement.setQuery(queryBuilder.buildQuery());
    statement.getValues().addAll(Maps.toList(queryBuilder.getBindVariableMap(), StringValueMapEntry.class));
    return statement;
}
Also used : Statement(com.google.api.ads.admanager.jaxws.v202202.Statement) StringValueMapEntry(com.google.api.ads.admanager.jaxws.v202202.StringValueMapEntry)

Example 12 with Statement

use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.

the class UpdateCustomTargetingValues method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param customTargetingValueId the ID of the custom targeting value to update.
 * @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 customTargetingValueId) throws RemoteException {
    // Get the CustomTargetingService.
    CustomTargetingServiceInterface customTargetingService = adManagerServices.get(session, CustomTargetingServiceInterface.class);
    // Create a statement to get custom targeting values.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", customTargetingValueId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get custom targeting values by statement.
        CustomTargetingValuePage page = customTargetingService.getCustomTargetingValuesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            CustomTargetingValue[] customTargetingValues = page.getResults();
            // name.
            for (CustomTargetingValue customTargetingValue : customTargetingValues) {
                if (customTargetingValue.getDisplayName() == null) {
                    customTargetingValue.setDisplayName(customTargetingValue.getName());
                }
                customTargetingValue.setDisplayName(customTargetingValue.getDisplayName() + " (Deprecated)");
            }
            // Update the custom targeting values on the server.
            customTargetingValues = customTargetingService.updateCustomTargetingValues(customTargetingValues);
            for (CustomTargetingValue updatedCustomTargetingValue : customTargetingValues) {
                System.out.printf("Custom targeting value with ID %d, name '%s', and display name " + "'%s' was updated.%n", updatedCustomTargetingValue.getId(), updatedCustomTargetingValue.getName(), updatedCustomTargetingValue.getDisplayName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
}
Also used : CustomTargetingValue(com.google.api.ads.admanager.axis.v202202.CustomTargetingValue) CustomTargetingServiceInterface(com.google.api.ads.admanager.axis.v202202.CustomTargetingServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) CustomTargetingValuePage(com.google.api.ads.admanager.axis.v202202.CustomTargetingValuePage)

Example 13 with Statement

use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.

the class GetActiveLabels 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 {
    LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
    // Create a statement to select labels.
    StatementBuilder statementBuilder = new StatementBuilder().where("isActive = :isActive").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("isActive", true);
    // Retrieve a small amount of labels at a time, paging through
    // until all labels have been retrieved.
    int totalResultSetSize = 0;
    do {
        LabelPage page = labelService.getLabelsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each label.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Label label : page.getResults()) {
                System.out.printf("%d) Label with ID %d and name '%s' was found.%n", i++, label.getId(), label.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : LabelPage(com.google.api.ads.admanager.axis.v202202.LabelPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) LabelServiceInterface(com.google.api.ads.admanager.axis.v202202.LabelServiceInterface) Label(com.google.api.ads.admanager.axis.v202202.Label)

Example 14 with Statement

use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.

the class DeactivateLicas method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param lineItemId the ID of the line item to deactivate LICAs for.
 * @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 lineItemId) throws RemoteException {
    // Get the LineItemCreativeAssociationService.
    LineItemCreativeAssociationServiceInterface licaService = adManagerServices.get(session, LineItemCreativeAssociationServiceInterface.class);
    // Create a statement to select all LICAs for a line item.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE lineItemId = :lineItemId").orderBy("lineItemId ASC, creativeId ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("lineItemId", lineItemId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get LICAs by statement.
        LineItemCreativeAssociationPage page = licaService.getLineItemCreativeAssociationsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (LineItemCreativeAssociation lica : page.getResults()) {
                if (lica.getCreativeSetId() != null) {
                    System.out.printf("%d) LICA with line item ID %d and creative " + "set ID %d will be deactivated.%n", i++, lica.getLineItemId(), lica.getCreativeSetId());
                } else {
                    System.out.printf("%d) LICA with line item ID %d and creative ID %d will be deactivated.%n", i++, lica.getLineItemId(), lica.getCreativeId());
                }
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of LICAs to be deactivated: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        DeactivateLineItemCreativeAssociations action = new DeactivateLineItemCreativeAssociations();
        // Perform action.
        UpdateResult result = licaService.performLineItemCreativeAssociationAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of LICAs deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No LICAs were deactivated.");
        }
    }
}
Also used : LineItemCreativeAssociation(com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociation) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) LineItemCreativeAssociationPage(com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociationPage) DeactivateLineItemCreativeAssociations(com.google.api.ads.admanager.axis.v202202.DeactivateLineItemCreativeAssociations) LineItemCreativeAssociationServiceInterface(com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociationServiceInterface) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Example 15 with Statement

use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.

the class GetLicasForLineItem method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param lineItemId the ID of the line item.
 * @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 lineItemId) throws RemoteException {
    LineItemCreativeAssociationServiceInterface lineItemCreativeAssociationService = adManagerServices.get(session, LineItemCreativeAssociationServiceInterface.class);
    // Create a statement to select line item creative associations.
    StatementBuilder statementBuilder = new StatementBuilder().where("lineItemId = :lineItemId").orderBy("lineItemId ASC, creativeId ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("lineItemId", lineItemId);
    // Retrieve a small amount of line item creative associations at a time, paging through
    // until all line item creative associations have been retrieved.
    int totalResultSetSize = 0;
    do {
        LineItemCreativeAssociationPage page = lineItemCreativeAssociationService.getLineItemCreativeAssociationsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each line item creative association.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (LineItemCreativeAssociation lica : page.getResults()) {
                if (lica.getCreativeSetId() != null) {
                    System.out.printf("%d) LICA with line item ID %d and creative set ID %d was found.%n", i++, lica.getLineItemId(), lica.getCreativeSetId());
                } else {
                    System.out.printf("%d) LICA with line item ID %d and creative ID %d was found.%n", i++, lica.getLineItemId(), lica.getCreativeId());
                }
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : LineItemCreativeAssociation(com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociation) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) LineItemCreativeAssociationPage(com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociationPage) LineItemCreativeAssociationServiceInterface(com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociationServiceInterface)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)119 Test (org.junit.Test)61 UpdateResult (com.google.api.ads.admanager.axis.v202202.UpdateResult)18 Statement (com.google.api.ads.admanager.axis.v202105.Statement)16 Statement (com.google.api.ads.admanager.axis.v202108.Statement)16 Statement (com.google.api.ads.admanager.axis.v202111.Statement)16 Statement (com.google.api.ads.admanager.axis.v202202.Statement)16 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202202.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202202.InventoryServiceInterface)8 AdUnit (com.google.api.ads.admanager.axis.v202202.AdUnit)7 AdUnitPage (com.google.api.ads.admanager.axis.v202202.AdUnitPage)7 LineItem (com.google.api.ads.admanager.axis.v202202.LineItem)6 LineItemPage (com.google.api.ads.admanager.axis.v202202.LineItemPage)6 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface)6 LineItemCreativeAssociationServiceInterface (com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociationServiceInterface)5 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202202.PublisherQueryLanguageServiceInterface)5 ResultSet (com.google.api.ads.admanager.axis.v202202.ResultSet)5 CustomTargetingValue (com.google.api.ads.admanager.axis.v202202.CustomTargetingValue)4 CustomTargetingValuePage (com.google.api.ads.admanager.axis.v202202.CustomTargetingValuePage)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202202.String_ValueMapEntry)4