// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the LabelService.
LabelServiceInterface labelService = user.getService(DfpService.V201306.LABEL_SERVICE);
// Create statement text to select active labels.
String statementText = "WHERE isActive = :isActive LIMIT 500";
Statement filterStatement =
new StatementBuilder("").putValue("isActive", true).toStatement();
// Set defaults for page and offset.
LabelPage page = new LabelPage();
int offset = 0;
List<Long> labelIds = new ArrayList<Long>();
do {
// Create a statement to page through active labels.
filterStatement.setQuery(statementText + " OFFSET " + offset);
// Get labels by statement.
page = labelService.getLabelsByStatement(filterStatement);
if (page.getResults() != null) {
int i = page.getStartIndex();
for (Label label : page.getResults()) {
System.out.println(i + ") Label with ID \"" + label.getId()
+ "\" and name \"" + label.getName()
+ "\" will be deactivated.");
labelIds.add(label.getId());
i++;
}
}
offset += 500;
} while (offset < page.getTotalResultSetSize());
System.out.println("Number of labels to be deactivated: " + labelIds.size());
if (labelIds.size() > 0) {
// Modify statement for action.
filterStatement.setQuery("WHERE id IN (" + StringUtils.join(labelIds, ",") + ")");
// Create action.
DeactivateLabels action = new DeactivateLabels();
// Perform action.
UpdateResult result = labelService.performLabelAction(action, filterStatement);
// Display results.
if (result != null && result.getNumChanges() > 0) {
System.out.println("Number of labels deactivated: " + result.getNumChanges());
} else {