PlacementServiceInterface placementService =
user.getService(DfpService.V201308.PLACEMENT_SERVICE);
// Create statement text to select active placements.
String statementText = "WHERE status = :status LIMIT 500";
Statement filterStatement =
new StatementBuilder("")
.putValue("status", InventoryStatus.ACTIVE.toString())
.toStatement();
// Set defaults for page and offset.
PlacementPage page = new PlacementPage();
int offset = 0;
List<Long> placementIds = new ArrayList<Long>();
do {
// Create a statement to page through active placements.
filterStatement.setQuery(statementText + " OFFSET " + offset);
// Get placements by statement.
page = placementService.getPlacementsByStatement(filterStatement);
if (page.getResults() != null) {
int i = page.getStartIndex();
for (Placement placement : page.getResults()) {
System.out.println(i + ") Placement with ID \"" + placement.getId()
+ "\", name \"" + placement.getName()
+ "\", and status \"" + placement.getStatus() + "\" will be deactivated.");
placementIds.add(placement.getId());
i++;
}
}
offset += 500;
} while (offset < page.getTotalResultSetSize());
System.out.println("Number of placements to be deactivated: " + placementIds.size());
// Modify statement for action.
filterStatement.setQuery("WHERE id IN (" + StringUtils.join(placementIds, ",") + ")");
// Create action.
DeactivatePlacements action = new DeactivatePlacements();
// Perform action.