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

cancel
Showing results for 
Search instead for 
Did you mean: 
rohans
Member II

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

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.

1 Reply
Highlighted
ryandawson
Senior Member II

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

There is this example which talks about persistent databases (inc mysql) and uses what appears to be the same approach as you are using - GitHub - canchito-dev/integrate-activiti-with-spring: In this post, you will learn how to integrate ... But perhaps it is just not getting into the detail you're encountering. You could try wrapping your code in an if condition that checks whether the data is already present with a call to identityService.findUser. I did find an example of somebody doing a similar existence-check for Activiti users and groups in an InitializingBean (ctsms/SystemService.java at master · liuqingyu/ctsms · GitHub ).