// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the UserService.
UserServiceInterface userService =
user.getService(DfpService.V201311.USER_SERVICE);
// Set the ID of the user to deactivate
Long userId = Long.parseLong("INSERT_USER_ID_HERE");
// Create filter text to select user by id.
String statementText = "WHERE id = :userId LIMIT 500";
Statement filterStatement =
new StatementBuilder("")
.putValue("userId", userId)
.toStatement();
// Set defaults for page and offset.
UserPage page = new UserPage();
int offset = 0;
List<Long> userIds = new ArrayList<Long>();
do {
// Create a statement to page through users.
filterStatement.setQuery(statementText + " OFFSET " + offset);
// Get users by statement.
page = userService.getUsersByStatement(filterStatement);
if (page.getResults() != null) {
int i = page.getStartIndex();
for (User userResult : page.getResults()) {
System.out.println(i + ") User with ID \"" + userResult.getId()
+ "\", email \"" + userResult.getEmail()
+ "\", and status \"" + (userResult.getIsActive() ? "ACTIVE" : "INACTIVE")
+ "\" will be deactivated.");
userIds.add(userResult.getId());
i++;
}
}
offset += 500;
} while (offset < page.getTotalResultSetSize());
System.out.println("Number of users to be deactivated: " + userIds.size());
if (userIds.size() > 0) {
// Modify statement for action.
filterStatement.setQuery("WHERE id IN (" + StringUtils.join(userIds, ",") + ")");
// Create action.
DeactivateUsers action = new DeactivateUsers();
// Perform action.
UpdateResult result = userService.performUserAction(action, filterStatement);
// Display results.
if (result != null && result.getNumChanges() > 0) {
System.out.println("Number of users deactivated: " + result.getNumChanges());
} else {