AnsweredAssumed Answered

Creating users and group for a persistent database using spring boot and activiti.

Question asked by rohans on Aug 29, 2017
Latest reply on Sep 1, 2017 by ryandawson

I am trying to use MySql database to persist the data. I am using Spring boot project. When I first run the application, the database is created and data is inserted fine. When the application is restarted, I get an error as the users and group already exists in the database, and I get error for duplicate insertion.

### SQL: insert into ACT_ID_GROUP (ID_, REV_, NAME_, TYPE_) values ( ?, 1, ?, ? )
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'whamtech' for key 'PRIMARY'

 

How can I configure the beans as show here,

@Bean
InitializingBean usersAndGroupsInitializer(final IdentityService identityService) {

return new InitializingBean() {
public void afterPropertiesSet() throws Exception {

Group approvers = group("groupName");

User u1 = user("user1", "FirstName1", "LastName1");
User u2 = user("user2", "FirstName2", "LastName2");
identityService.createMembership(u1.getId(), approvers.getId());
identityService.createMembership(u2.getId(), approvers.getId());

}

private User user(String userName, String f, String l) {
User u = identityService.newUser(userName);
u.setFirstName(f);
u.setLastName(l);
u.setPassword("password");
identityService.saveUser(u);
return u;
}

private Group group(String groupName) {
Group group = identityService.newGroup(groupName);
group.setName(groupName);
group.setType("security-role");
identityService.saveGroup(group);
return group;
}
};

}

Can anyone point me to an example code, that uses persistent database to configure an Activiti process.

Outcomes