Search in sources :

Example 56 with StatementBuilder

use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.

the class GetActiveActivities 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 {
    ActivityServiceInterface activityService = adManagerServices.get(session, ActivityServiceInterface.class);
    // Create a statement to select activities.
    StatementBuilder statementBuilder = new StatementBuilder().where("status = :status").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", ActivityStatus.ACTIVE.toString());
    // Retrieve a small amount of activities at a time, paging through
    // until all activities have been retrieved.
    int totalResultSetSize = 0;
    do {
        ActivityPage page = activityService.getActivitiesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each activity.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Activity activity : page.getResults()) {
                System.out.printf("%d) Activity with ID %d, name '%s', and type '%s' was found.%n", i++, activity.getId(), activity.getName(), activity.getType());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : ActivityPage(com.google.api.ads.admanager.axis.v202111.ActivityPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) ActivityServiceInterface(com.google.api.ads.admanager.axis.v202111.ActivityServiceInterface) Activity(com.google.api.ads.admanager.axis.v202111.Activity)

Example 57 with StatementBuilder

use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.

the class UpdateActivities method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param activityId the ID of the activity 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 activityId) throws RemoteException {
    // Get the ActivityService.
    ActivityServiceInterface activityService = adManagerServices.get(session, ActivityServiceInterface.class);
    // Create a statement to only select a single activity by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", activityId);
    // Get the activity.
    ActivityPage page = activityService.getActivitiesByStatement(statementBuilder.toStatement());
    // Get the activity.
    Activity activity = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Update the expected URL.
    activity.setExpectedURL("http://google.com");
    // Update the activity on the server.
    Activity[] activities = activityService.updateActivities(new Activity[] { activity });
    for (Activity updatedActivity : activities) {
        System.out.printf("Activity with ID %d and name '%s' was updated.%n", updatedActivity.getId(), updatedActivity.getName());
    }
}
Also used : ActivityPage(com.google.api.ads.admanager.axis.v202111.ActivityPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) ActivityServiceInterface(com.google.api.ads.admanager.axis.v202111.ActivityServiceInterface) Activity(com.google.api.ads.admanager.axis.v202111.Activity)

Example 58 with StatementBuilder

use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.

the class GetAllForecastAdjustments 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 AdjustmentService.
    AdjustmentServiceInterface adjustmentService = adManagerServices.get(session, AdjustmentServiceInterface.class);
    // Create a statement to get all forecast adjustments.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get forecast adjustments by statement.
        ForecastAdjustmentPage page = adjustmentService.getForecastAdjustmentsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (ForecastAdjustment adjustment : page.getResults()) {
                System.out.printf("%d) Forecast adjustment with ID %d and name '%s' belonging to ForecastSegment %d" + " was found.%n", i++, adjustment.getId(), adjustment.getName(), adjustment.getTrafficForecastSegmentId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) ForecastAdjustmentPage(com.google.api.ads.admanager.axis.v202111.ForecastAdjustmentPage) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202111.AdjustmentServiceInterface) ForecastAdjustment(com.google.api.ads.admanager.axis.v202111.ForecastAdjustment)

Example 59 with StatementBuilder

use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.

the class GetAllTrafficForecastSegments 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 AdjustmentService.
    AdjustmentServiceInterface adjustmentService = adManagerServices.get(session, AdjustmentServiceInterface.class);
    // Create a statement to get all traffic forecast segments.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get traffic forecast segments by statement.
        TrafficForecastSegmentPage page = adjustmentService.getTrafficForecastSegmentsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (TrafficForecastSegment trafficForecastSegment : page.getResults()) {
                System.out.printf("%d) Traffic forecast segment with ID %d and name '%s' was found.%n", i++, trafficForecastSegment.getId(), trafficForecastSegment.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : TrafficForecastSegment(com.google.api.ads.admanager.axis.v202111.TrafficForecastSegment) TrafficForecastSegmentPage(com.google.api.ads.admanager.axis.v202111.TrafficForecastSegmentPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202111.AdjustmentServiceInterface)

Example 60 with StatementBuilder

use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder in project googleads-java-lib by googleads.

the class DeleteUserTeamAssociations method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param userId the ID of the user to delete user team associations 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 userId) throws RemoteException {
    // Get the UserTeamAssociationService.
    UserTeamAssociationServiceInterface userTeamAssociationService = adManagerServices.get(session, UserTeamAssociationServiceInterface.class);
    // Create a statement to get all user team associations for a user.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE userId = :userId ").orderBy("userId ASC, teamid ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("userId", userId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get user team associations by statement.
        UserTeamAssociationPage page = userTeamAssociationService.getUserTeamAssociationsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (UserTeamAssociation userTeamAssociation : page.getResults()) {
                System.out.printf("%d) User team association with user ID %d and " + "team ID %d will be deleted.%n", i++, userTeamAssociation.getUserId(), userTeamAssociation.getTeamId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of user team associations 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.v202205.DeleteUserTeamAssociations action = new com.google.api.ads.admanager.axis.v202205.DeleteUserTeamAssociations();
        // Perform action.
        UpdateResult result = userTeamAssociationService.performUserTeamAssociationAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of user team associations deleted: %d%n", result.getNumChanges());
        } else {
            System.out.println("No user team associations were deleted.");
        }
    }
}
Also used : UserTeamAssociationServiceInterface(com.google.api.ads.admanager.axis.v202205.UserTeamAssociationServiceInterface) UserTeamAssociation(com.google.api.ads.admanager.axis.v202205.UserTeamAssociation) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) UserTeamAssociationPage(com.google.api.ads.admanager.axis.v202205.UserTeamAssociationPage) UpdateResult(com.google.api.ads.admanager.axis.v202205.UpdateResult)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)120 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)120 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)120 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)120 ArrayList (java.util.ArrayList)24 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 (com.google.api.ads.admanager.axis.v202205.UpdateResult)18 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202108.InventoryServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface)8 ResultSet (com.google.api.ads.admanager.axis.v202108.ResultSet)8 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202202.CustomTargetingServiceInterface)6 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface)5 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202111.InventoryServiceInterface)5 ProposalServiceInterface (com.google.api.ads.admanager.axis.v202111.ProposalServiceInterface)5 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface)5 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)5 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202202.PublisherQueryLanguageServiceInterface)5