// Set the user to remove from its teams.
Long userId = Long.parseLong("INSERT_USER_ID_HERE");
// Create filter text to select user team associations by the user ID.
String statementText = "WHERE userId = :userId LIMIT 500";
Statement filterStatement =
new StatementBuilder("")
.putValue("userId", userId)
.toStatement();
// Set defaults for page and offset.
UserTeamAssociationPage page = new UserTeamAssociationPage();
int offset = 0;
do {
// Create a statement to page through user team associations.
filterStatement.setQuery(statementText + " OFFSET " + offset);
// Get user team associations by statement.
page = userTeamAssociationService.getUserTeamAssociationsByStatement(filterStatement);
if (page.getResults() != null) {
int i = page.getStartIndex();
for (UserTeamAssociation userTeamAssociation : page.getResults()) {
System.out.println(i + ") User team association between user with ID \""
+ userTeamAssociation.getUserId() + "\" and team with ID \""
+ userTeamAssociation.getTeamId() + "\" will be deleted.");
i++;
}
}
offset += 500;
} while (offset < page.getTotalResultSetSize());
System.out.println("Number of teams that the user will be removed from: "
+ page.getTotalResultSetSize());
if (page.getTotalResultSetSize() > 0) {
// Modify statement for action.
filterStatement.setQuery("WHERE userId = :userId");
// Create action.
DeleteUserTeamAssociations action = new DeleteUserTeamAssociations();
// Perform action.