// 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.