Search in sources :

Example 6 with CustomFieldServiceInterface

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

the class DeactivateCustomFields method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param customFieldId the ID of the custom field 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 customFieldId) throws RemoteException {
    // Get the CustomFieldService.
    CustomFieldServiceInterface customFieldService = adManagerServices.get(session, CustomFieldServiceInterface.class);
    // Create a statement to select a custom field.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", customFieldId);
    // 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 will be deactivated.%n", i++, customField.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of custom fields 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.DeactivateCustomFields action = new com.google.api.ads.admanager.axis.v202202.DeactivateCustomFields();
        // Perform action.
        UpdateResult result = customFieldService.performCustomFieldAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of custom fields deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No custom fields were deactivated.");
        }
    }
}
Also used : CustomFieldServiceInterface(com.google.api.ads.admanager.axis.v202202.CustomFieldServiceInterface) CustomFieldPage(com.google.api.ads.admanager.axis.v202202.CustomFieldPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) CustomField(com.google.api.ads.admanager.axis.v202202.CustomField) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Example 7 with CustomFieldServiceInterface

use of com.google.api.ads.admanager.axis.v202202.CustomFieldServiceInterface 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.v202202.CustomFieldPage) CustomFieldServiceInterface(com.google.api.ads.admanager.axis.v202202.CustomFieldServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) CustomField(com.google.api.ads.admanager.axis.v202202.CustomField)

Example 8 with CustomFieldServiceInterface

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

the class CreateCustomFieldsAndOptions 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 number custom field that can be used for an external ID in the
    // API.
    CustomField numberCustomField = new CustomField();
    numberCustomField.setName("External ID #" + new Random().nextInt(Integer.MAX_VALUE));
    numberCustomField.setEntityType(CustomFieldEntityType.LINE_ITEM);
    numberCustomField.setDataType(CustomFieldDataType.NUMBER);
    numberCustomField.setVisibility(CustomFieldVisibility.API_ONLY);
    // Create a drop-down custom field that can be used in the UI.
    CustomField dropDownCustomField = new CustomField();
    dropDownCustomField.setName("Internal approval status #" + new Random().nextInt(Integer.MAX_VALUE));
    dropDownCustomField.setEntityType(CustomFieldEntityType.LINE_ITEM);
    dropDownCustomField.setDataType(CustomFieldDataType.DROP_DOWN);
    dropDownCustomField.setVisibility(CustomFieldVisibility.FULL);
    // Create the custom fields on the server.
    CustomField[] customFields = customFieldService.createCustomFields(new CustomField[] { numberCustomField, dropDownCustomField });
    for (CustomField createdCustomField : customFields) {
        System.out.printf("A custom field with ID %d and name '%s' was created.%n", createdCustomField.getId(), createdCustomField.getName());
    }
    // Set the created drop-down custom field.
    dropDownCustomField = customFields[1];
    // Create approved custom field option.
    CustomFieldOption approvedCustomFieldOption = new CustomFieldOption();
    approvedCustomFieldOption.setDisplayName("APPROVED");
    approvedCustomFieldOption.setCustomFieldId(dropDownCustomField.getId());
    // Create unapproved custom field option.
    CustomFieldOption unapprovedCustomFieldOption = new CustomFieldOption();
    unapprovedCustomFieldOption.setDisplayName("UNAPPROVED");
    unapprovedCustomFieldOption.setCustomFieldId(dropDownCustomField.getId());
    // Create the custom field options on the server.
    CustomFieldOption[] customFieldOptions = customFieldService.createCustomFieldOptions(new CustomFieldOption[] { approvedCustomFieldOption, unapprovedCustomFieldOption });
    for (CustomFieldOption createdCustomFieldOption : customFieldOptions) {
        System.out.printf("A custom field option with ID %d and display name '%s' was created.%n", createdCustomFieldOption.getId(), createdCustomFieldOption.getDisplayName());
    }
}
Also used : Random(java.util.Random) CustomFieldOption(com.google.api.ads.admanager.axis.v202108.CustomFieldOption) CustomFieldServiceInterface(com.google.api.ads.admanager.axis.v202108.CustomFieldServiceInterface) CustomField(com.google.api.ads.admanager.axis.v202108.CustomField)

Example 9 with CustomFieldServiceInterface

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

the class DeactivateCustomFields method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param customFieldId the ID of the custom field 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 customFieldId) throws RemoteException {
    // Get the CustomFieldService.
    CustomFieldServiceInterface customFieldService = adManagerServices.get(session, CustomFieldServiceInterface.class);
    // Create a statement to select a custom field.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", customFieldId);
    // 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 will be deactivated.%n", i++, customField.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of custom fields 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.v202108.DeactivateCustomFields action = new com.google.api.ads.admanager.axis.v202108.DeactivateCustomFields();
        // Perform action.
        UpdateResult result = customFieldService.performCustomFieldAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of custom fields deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No custom fields were deactivated.");
        }
    }
}
Also used : CustomFieldServiceInterface(com.google.api.ads.admanager.axis.v202108.CustomFieldServiceInterface) CustomFieldPage(com.google.api.ads.admanager.axis.v202108.CustomFieldPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) CustomField(com.google.api.ads.admanager.axis.v202108.CustomField) UpdateResult(com.google.api.ads.admanager.axis.v202108.UpdateResult)

Example 10 with CustomFieldServiceInterface

use of com.google.api.ads.admanager.axis.v202202.CustomFieldServiceInterface 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.v202108.CustomFieldPage) CustomFieldServiceInterface(com.google.api.ads.admanager.axis.v202108.CustomFieldServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) CustomField(com.google.api.ads.admanager.axis.v202108.CustomField)

Aggregations

CustomFieldServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomFieldServiceInterface)6 CustomFieldServiceInterface (com.google.api.ads.admanager.axis.v202111.CustomFieldServiceInterface)6 CustomFieldServiceInterface (com.google.api.ads.admanager.axis.v202202.CustomFieldServiceInterface)6 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)5 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)5 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)5 CustomField (com.google.api.ads.admanager.axis.v202108.CustomField)5 CustomField (com.google.api.ads.admanager.axis.v202111.CustomField)5 CustomField (com.google.api.ads.admanager.axis.v202202.CustomField)5 CustomFieldPage (com.google.api.ads.admanager.axis.v202108.CustomFieldPage)4 CustomFieldPage (com.google.api.ads.admanager.axis.v202111.CustomFieldPage)4 CustomFieldPage (com.google.api.ads.admanager.axis.v202202.CustomFieldPage)4 ArrayList (java.util.ArrayList)3 Random (java.util.Random)3 BaseCustomFieldValue (com.google.api.ads.admanager.axis.v202108.BaseCustomFieldValue)1 CustomFieldOption (com.google.api.ads.admanager.axis.v202108.CustomFieldOption)1 CustomFieldValue (com.google.api.ads.admanager.axis.v202108.CustomFieldValue)1 DropDownCustomFieldValue (com.google.api.ads.admanager.axis.v202108.DropDownCustomFieldValue)1 LineItem (com.google.api.ads.admanager.axis.v202108.LineItem)1 LineItemPage (com.google.api.ads.admanager.axis.v202108.LineItemPage)1