Search in sources :

Example 96 with Statement

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

the class UpdateCreativeWrappers method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param creativeWrapperId the ID of the creative wrapper 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 creativeWrapperId) throws RemoteException {
    // Get the CreativeWrapperService.
    CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
    // Create a statement to only select a single creative wrapper by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", creativeWrapperId);
    // Get the creative wrapper.
    CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
    CreativeWrapper creativeWrapper = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Update the creative wrapper ordering.
    creativeWrapper.setOrdering(CreativeWrapperOrdering.OUTER);
    // Update the creative wrapper on the server.
    CreativeWrapper[] creativeWrappers = creativeWrapperService.updateCreativeWrappers(new CreativeWrapper[] { creativeWrapper });
    for (CreativeWrapper updatedCreativeWrapper : creativeWrappers) {
        System.out.printf("Creative wrapper with ID %d and wrapping order '%s' was updated.%n", updatedCreativeWrapper.getId(), updatedCreativeWrapper.getOrdering());
    }
}
Also used : CreativeWrapper(com.google.api.ads.admanager.axis.v202111.CreativeWrapper) CreativeWrapperPage(com.google.api.ads.admanager.axis.v202111.CreativeWrapperPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) CreativeWrapperServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeWrapperServiceInterface)

Example 97 with Statement

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

the class GetAllCustomFields 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 CustomFieldService.
    CustomFieldServiceInterface customFieldService = adManagerServices.get(session, CustomFieldServiceInterface.class);
    // Create a statement to get all custom fields.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get custom fields by statement.
        CustomFieldPage page = customFieldService.getCustomFieldsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CustomField customField : page.getResults()) {
                System.out.printf("%d) Custom field with ID %d and name '%s' was found.%n", i++, customField.getId(), customField.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : CustomFieldPage(com.google.api.ads.admanager.axis.v202111.CustomFieldPage) CustomFieldServiceInterface(com.google.api.ads.admanager.axis.v202111.CustomFieldServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) CustomField(com.google.api.ads.admanager.axis.v202111.CustomField)

Example 98 with Statement

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

the class GetCustomFieldsForLineItems 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 {
    CustomFieldServiceInterface customFieldService = adManagerServices.get(session, CustomFieldServiceInterface.class);
    // Create a statement to select custom fields.
    StatementBuilder statementBuilder = new StatementBuilder().where("entityType = :entityType").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("entityType", CustomFieldEntityType.LINE_ITEM.toString());
    // Retrieve a small amount of custom fields at a time, paging through
    // until all custom fields have been retrieved.
    int totalResultSetSize = 0;
    do {
        CustomFieldPage page = customFieldService.getCustomFieldsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each custom field.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CustomField customField : page.getResults()) {
                System.out.printf("%d) Custom field with ID %d and name '%s' was found.%n", i++, customField.getId(), customField.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : CustomFieldPage(com.google.api.ads.admanager.axis.v202111.CustomFieldPage) CustomFieldServiceInterface(com.google.api.ads.admanager.axis.v202111.CustomFieldServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) CustomField(com.google.api.ads.admanager.axis.v202111.CustomField)

Example 99 with Statement

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

the class DeleteCustomTargetingValues method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param customTargetingValueId the ID of the custom targeting value to delete.
 * @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 select custom targeting value.
    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();
            int i = page.getStartIndex();
            for (CustomTargetingValue customTargetingValue : page.getResults()) {
                System.out.printf("%d) Custom targeting value with ID %d" + " will be deleted.%n", i++, customTargetingValue.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of custom targeting values to be deleted: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202111.DeleteCustomTargetingValues action = new com.google.api.ads.admanager.axis.v202111.DeleteCustomTargetingValues();
        // Perform action.
        UpdateResult result = customTargetingService.performCustomTargetingValueAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of custom targeting values deleted: %d%n", result.getNumChanges());
        } else {
            System.out.println("No custom targeting values deleted.");
        }
    }
}
Also used : CustomTargetingServiceInterface(com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface) CustomTargetingValue(com.google.api.ads.admanager.axis.v202111.CustomTargetingValue) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) CustomTargetingValuePage(com.google.api.ads.admanager.axis.v202111.CustomTargetingValuePage) UpdateResult(com.google.api.ads.admanager.axis.v202111.UpdateResult)

Example 100 with Statement

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

the class UpdateCreatives method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param creativeId the ID of the creative 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 creativeId) throws RemoteException {
    // Get the CreativeService.
    CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
    // Create a statement to only select a single creative by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", creativeId);
    // Get the creative.
    CreativePage page = creativeService.getCreativesByStatement(statementBuilder.toStatement());
    Creative creative = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Only update the destination URL if it has one.
    if (creative instanceof HasDestinationUrlCreative) {
        HasDestinationUrlCreative hasDestinationUrlCreative = (HasDestinationUrlCreative) creative;
        // Update the destination URL of the creative.
        hasDestinationUrlCreative.setDestinationUrl("http://news.google.com");
        // Update the creative on the server.
        Creative[] creatives = creativeService.updateCreatives(new Creative[] { creative });
        for (Creative updatedCreative : creatives) {
            System.out.printf("Creative with ID %d and name '%s' was updated.%n", updatedCreative.getId(), updatedCreative.getName());
        }
    } else {
        System.out.println("No creatives were updated.");
    }
}
Also used : HasDestinationUrlCreative(com.google.api.ads.admanager.axis.v202111.HasDestinationUrlCreative) HasDestinationUrlCreative(com.google.api.ads.admanager.axis.v202111.HasDestinationUrlCreative) Creative(com.google.api.ads.admanager.axis.v202111.Creative) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) CreativePage(com.google.api.ads.admanager.axis.v202111.CreativePage)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)119 Test (org.junit.Test)77 UpdateResult (com.google.api.ads.admanager.axis.v202111.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 Statement (com.google.api.ads.admanager.axis.v202205.Statement)16 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202111.InventoryServiceInterface)8 AdUnit (com.google.api.ads.admanager.axis.v202111.AdUnit)7 AdUnitPage (com.google.api.ads.admanager.axis.v202111.AdUnitPage)7 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface)7 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)7 ArrayList (java.util.ArrayList)6 ProposalServiceInterface (com.google.api.ads.admanager.axis.v202111.ProposalServiceInterface)5 Statement (org.neo4j.driver.v1.Statement)5 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202105.String_ValueMapEntry)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202108.String_ValueMapEntry)4 LineItem (com.google.api.ads.admanager.axis.v202111.LineItem)4