Search in sources :

Example 56 with UpdateResult

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

the class PopulateFirstPartyAudienceSegments method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param audienceSegmentId the ID of the first party audience segment to populate.
 * @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 audienceSegmentId) throws RemoteException {
    // Get the AudienceSegmentService.
    AudienceSegmentServiceInterface audienceSegmentService = adManagerServices.get(session, AudienceSegmentServiceInterface.class);
    // Create a statement to only select a specified first party audience
    // segment.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :audienceSegmentId and type = :type").orderBy("id ASC").limit(1).withBindVariableValue("audienceSegmentId", audienceSegmentId).withBindVariableValue("type", "FIRST_PARTY");
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get audience segments by statement.
        AudienceSegmentPage page = audienceSegmentService.getAudienceSegmentsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (AudienceSegment audienceSegment : page.getResults()) {
                System.out.printf("%d) Audience segment with ID %d and name '%s' will be populated.%n", i++, audienceSegment.getId(), audienceSegment.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of audience segments to be populated: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        PopulateAudienceSegments action = new PopulateAudienceSegments();
        // Perform action.
        UpdateResult result = audienceSegmentService.performAudienceSegmentAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of audience segments populated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No audience segments were populated.");
        }
    }
}
Also used : AudienceSegmentPage(com.google.api.ads.admanager.axis.v202202.AudienceSegmentPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) PopulateAudienceSegments(com.google.api.ads.admanager.axis.v202202.PopulateAudienceSegments) AudienceSegment(com.google.api.ads.admanager.axis.v202202.AudienceSegment) AudienceSegmentServiceInterface(com.google.api.ads.admanager.axis.v202202.AudienceSegmentServiceInterface) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Example 57 with UpdateResult

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

the class ActivateCmsMetadataValues method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param cmsMetadataKeyId the ID of the CMS Metadata Key to activate values 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 cmsMetadataKeyId) throws RemoteException {
    // Get the CmsMetadataService.
    CmsMetadataServiceInterface cmsMetadataService = adManagerServices.get(session, CmsMetadataServiceInterface.class);
    // Create a statement to select CMS Metadata Values.
    StatementBuilder statementBuilder = new StatementBuilder().where("cmsKeyId = :cmsKeyId AND status = :status").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("cmsKeyId", cmsMetadataKeyId).withBindVariableValue("status", CmsMetadataKeyStatus.INACTIVE.toString());
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get CMS Metadata Values by statement.
        CmsMetadataValuePage page = cmsMetadataService.getCmsMetadataValuesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CmsMetadataValue cmsMetadataValue : page.getResults()) {
                System.out.printf("%d) CMS Metadata Value with ID %d will be activated.%n", i++, cmsMetadataValue.getCmsMetadataValueId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of CMS Metadata Values to be activated: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement to activate all matching values.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202202.ActivateCmsMetadataValues action = new com.google.api.ads.admanager.axis.v202202.ActivateCmsMetadataValues();
        // Perform action.
        UpdateResult result = cmsMetadataService.performCmsMetadataValueAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of items activated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No CMS Metadata Values were activated.");
        }
    }
}
Also used : CmsMetadataValuePage(com.google.api.ads.admanager.axis.v202202.CmsMetadataValuePage) CmsMetadataServiceInterface(com.google.api.ads.admanager.axis.v202202.CmsMetadataServiceInterface) CmsMetadataValue(com.google.api.ads.admanager.axis.v202202.CmsMetadataValue) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Example 58 with UpdateResult

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

the class SubmitSiteForApproval method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param siteId the ID of the site to submit for approval.
 * @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 siteId) throws RemoteException {
    // Get the SiteService.
    SiteServiceInterface siteService = adManagerServices.get(session, SiteServiceInterface.class);
    // Create a statement to select a site.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", siteId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get sites by statement.
        SitePage page = siteService.getSitesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Site site : page.getResults()) {
                System.out.printf("%d) Site with ID %d will be submitted for approval.%n", i++, site.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of sites to be submitted: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202111.SubmitSiteForApproval action = new com.google.api.ads.admanager.axis.v202111.SubmitSiteForApproval();
        // Perform action.
        UpdateResult result = siteService.performSiteAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of sites submitted: %d%n", result.getNumChanges());
        } else {
            System.out.println("No sites were submitted.");
        }
    }
}
Also used : Site(com.google.api.ads.admanager.axis.v202111.Site) SitePage(com.google.api.ads.admanager.axis.v202111.SitePage) SiteServiceInterface(com.google.api.ads.admanager.axis.v202111.SiteServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202111.UpdateResult)

Example 59 with UpdateResult

use of com.google.api.ads.admanager.axis.v202108.UpdateResult 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.v202111.ArchiveProposalLineItems action = new com.google.api.ads.admanager.axis.v202111.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.");
        }
    }
}
Also used : ProposalLineItemPage(com.google.api.ads.admanager.axis.v202111.ProposalLineItemPage) ProposalLineItem(com.google.api.ads.admanager.axis.v202111.ProposalLineItem) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202111.UpdateResult) ProposalLineItemServiceInterface(com.google.api.ads.admanager.axis.v202111.ProposalLineItemServiceInterface)

Example 60 with UpdateResult

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

the class DeactivateUsers method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param userId the ID of the user 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 userId) throws RemoteException {
    // Get the UserService.
    UserServiceInterface userService = adManagerServices.get(session, UserServiceInterface.class);
    // Create a statement to select a user.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", userId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get users by statement.
        UserPage page = userService.getUsersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (User user : page.getResults()) {
                System.out.printf("%d) User with ID %d will be deactivated.%n", i++, user.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of users 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.v202111.DeactivateUsers action = new com.google.api.ads.admanager.axis.v202111.DeactivateUsers();
        // Perform action.
        UpdateResult result = userService.performUserAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of users deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No users were deactivated.");
        }
    }
}
Also used : UserServiceInterface(com.google.api.ads.admanager.axis.v202111.UserServiceInterface) User(com.google.api.ads.admanager.axis.v202111.User) UserPage(com.google.api.ads.admanager.axis.v202111.UserPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202111.UpdateResult)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)18 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)18 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)18 UpdateResult (com.google.api.ads.admanager.axis.v202108.UpdateResult)18 UpdateResult (com.google.api.ads.admanager.axis.v202111.UpdateResult)18 UpdateResult (com.google.api.ads.admanager.axis.v202202.UpdateResult)18 UpdateResult (org.apache.ignite.internal.processors.query.h2.UpdateResult)6 SQLException (java.sql.SQLException)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomTargetingServiceInterface)2 LineItemCreativeAssociationServiceInterface (com.google.api.ads.admanager.axis.v202108.LineItemCreativeAssociationServiceInterface)2 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202202.CustomTargetingServiceInterface)2 HashSet (java.util.HashSet)2 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)2 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)2 DmlStatementsProcessor (org.apache.ignite.internal.processors.query.h2.DmlStatementsProcessor)2 AdUnit (com.google.api.ads.admanager.axis.v202108.AdUnit)1 AdUnitPage (com.google.api.ads.admanager.axis.v202108.AdUnitPage)1 AudienceSegment (com.google.api.ads.admanager.axis.v202108.AudienceSegment)1 AudienceSegmentPage (com.google.api.ads.admanager.axis.v202108.AudienceSegmentPage)1