Search in sources :

Example 21 with Placement

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

the class DeactivatePlacements method runExample.

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

Example 22 with Placement

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

the class GetAllPlacements 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 PlacementService.
    PlacementServiceInterface placementService = adManagerServices.get(session, PlacementServiceInterface.class);
    // Create a statement to get all placements.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get placements by statement.
        PlacementPage page = placementService.getPlacementsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Placement placement : page.getResults()) {
                System.out.printf("%d) Placement with ID %d and name '%s' was found.%n", i++, placement.getId(), placement.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : PlacementPage(com.google.api.ads.admanager.axis.v202205.PlacementPage) Placement(com.google.api.ads.admanager.axis.v202205.Placement) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) PlacementServiceInterface(com.google.api.ads.admanager.axis.v202205.PlacementServiceInterface)

Example 23 with Placement

use of com.google.api.ads.admanager.axis.v202205.Placement in project kubernetes-client by fabric8io.

the class PlacementTest method get.

@Test
void get() {
    // Given
    server.expect().get().withPath("/apis/cluster.open-cluster-management.io/v1alpha1/namespaces/ns1/placements/test-get").andReturn(HttpURLConnection.HTTP_OK, createNewPlacement("test-get")).once();
    // When
    Placement placement = client.clusters().placements().inNamespace("ns1").withName("test-get").get();
    // Then
    assertThat(placement).isNotNull().hasFieldOrPropertyWithValue("metadata.name", "test-get");
}
Also used : Placement(io.fabric8.openclustermanagement.api.model.cluster.v1alpha1.Placement) Test(org.junit.jupiter.api.Test)

Aggregations

Placement (com.google.api.ads.admanager.axis.v202108.Placement)5 PlacementServiceInterface (com.google.api.ads.admanager.axis.v202108.PlacementServiceInterface)5 Placement (com.google.api.ads.admanager.axis.v202111.Placement)5 PlacementServiceInterface (com.google.api.ads.admanager.axis.v202111.PlacementServiceInterface)5 Placement (com.google.api.ads.admanager.axis.v202202.Placement)5 PlacementServiceInterface (com.google.api.ads.admanager.axis.v202202.PlacementServiceInterface)5 Placement (com.google.api.ads.admanager.axis.v202205.Placement)5 PlacementServiceInterface (com.google.api.ads.admanager.axis.v202205.PlacementServiceInterface)5 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)4 PlacementPage (com.google.api.ads.admanager.axis.v202108.PlacementPage)4 PlacementPage (com.google.api.ads.admanager.axis.v202111.PlacementPage)4 PlacementPage (com.google.api.ads.admanager.axis.v202202.PlacementPage)4 PlacementPage (com.google.api.ads.admanager.axis.v202205.PlacementPage)4 ArrayList (java.util.ArrayList)4 Random (java.util.Random)4 Placement (io.fabric8.openclustermanagement.api.model.cluster.v1alpha1.Placement)3 Test (org.junit.jupiter.api.Test)3