And here’s the code to remove already bootstrapped demo data:
/**
* Removes demo data bootstrapped by Flowable:
* com.flowable.platform.tenant.TenantBootstrapper#TenantBootstrapper(boolean)
* com.flowable.platform.tenant.TenantBootstrapper#setupTenants()
*/
@Slf4j
@Component
public class IdentityCleanupService {
public static final List<String> DEMO_USERS = List.of(
"jessica.adams",
"shane.bowen",
"anne.barton",
"roger.black",
"lilly.garden",
"sunny.flower",
"kenny.cole",
"ben.snow",
"james.cox",
"mike.miller",
"trevor.jones",
"emma.gant",
"peter.schmid",
"lisa.schmid",
"annie.austin",
"stephen.springer",
"oliver.morgan",
"ella.martin",
"clark.kent",
"lois.lane",
"amanda.long",
"boris.blue",
"david.davidson",
"pippa.pepper",
"tim.lee",
"ryan.morrison",
"sophie.may",
"admin",
"operation.admin"
);
public static final List<String> DEMO_GROUPS = List.of(
"client",
"clientLookup",
"externalUser",
"employee",
"employeeLookup",
"clientAdvisor",
"clientSupporter",
"reporting",
"complianceOfficer",
"operationAdmin"
);
public static final List<String> DEMO_USER_DEFINITIONS = List.of(
"user-client-supporter",
"user-compliance",
"user-client-advisor",
"user-reporting",
"user-temporary",
"user-external-client",
"user-client",
"user-operation-admin"
);
private final IdentityService identityService;
private final UserDefinitionService userDefinitionService;
private final ContentService contentService;
public IdentityCleanupService(IdentityService identityService, UserDefinitionService userDefinitionService, ContentService contentService) {
this.identityService = identityService;
this.userDefinitionService = userDefinitionService;
this.contentService = contentService;
}
@EventListener(ApplicationReadyEvent.class)
public void cleanup() {
// takes care of removing memberships as well
// See com.flowable.idm.engine.impl.persistence.entity.GroupEntityManagerImpl#delete
DEMO_GROUPS.forEach(id -> {
if (identityService.createGroupQuery().groupId(id).count() > 0) {
identityService.deleteGroup(id);
log.info("Deleted group '{}'", id);
}
});
DEMO_USERS.forEach(id -> {
PlatformUserEntity user = (PlatformUserEntity) identityService.createUserQuery().userId(id).singleResult();
if (user != null) {
if (user.getAvatarId() != null) {
contentService.deleteContentItem(user.getAvatarId());
log.info("Deleted avatar for user '{}'", id);
}
// Removes other related resources as well:
// See com.flowable.idm.engine.impl.persistence.entity.UserEntityManagerImpl#delete
identityService.deleteUser(id);
log.info("Deleted user '{}'", id);
}
});
DEMO_USER_DEFINITIONS.forEach(key -> {
var def = userDefinitionService.getUserDefinitionByKeyAndTenantId(key, "");
if (def != null) {
userDefinitionService.removeUserDefinition(def.getId());
log.info("Deleted user definition for key '{}'", key);
}
});
}
}
Beware that this also deletes the admin
user, but keeps the user-default
and user-admin
user templates that can be used in OAuth2 setups to map to users.