- Set<String> existingRoles = userAdminService.listEditableRoles();
- if (role != null && !existingRoles.contains(role))
- newRole(role);
- for (String r : roles) {
- if (!existingRoles.contains(r))
- newRole(r);
+ try {
+ userTransaction.begin();
+ if (role != null && !roleExists(role))
+ newRole(toDn(role));
+
+ for (String r : roles)
+ if (!roleExists(r))
+ newRole(toDn(r));
+ userTransaction.commit();
+ } catch (Exception e) {
+ try {
+ userTransaction.rollback();
+ } catch (Exception e1) {
+ log.error("Cannot rollback", e1);
+ }
+ throw new ArgeoException("Cannot add roles", e);