Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Nov 13, 2018
1 parent 3d0ab26 commit c03967b
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,22 @@ public static class SampleAdminUsersCreator {
@Autowired
AdminRoleRepository adminRoleRepository;

@Transactional
@EventListener
void createSampleAdminUsers(ApplicationStartedEvent e) {
//TODO: this is wip. Having a hard time with many-to-many saving with Hibernate's detatched entity exceptions, etc.
if(adminUserRepository.count() == 0L) {
AdminRole role = new AdminRole();
role.setName("ADMIN");
role.setName("ROLE_ADMIN");
AdminUser user = new AdminUser();
user.setUsername("admin");
user.setPassword("{noop}adminpass");

Arrays.asList("1", "2").forEach(it -> {
AdminUser user = new AdminUser();
user.setUsername(String.format("admin%s", it));
user.setPassword(String.format("{noop}adminpass%s", it));
//role.getAdmins().add(user);
//user.getRoles().add(role);
adminUserRepository.save(user);
});
//The complexity of managing bi-directional many-to-many. TODO: to encapsulate this association
//managing logic into domain model itself
role.getAdmins().add(user);
user.getRoles().add(role);

adminUserRepository.save(user);
}
}
}
Expand Down

0 comments on commit c03967b

Please sign in to comment.