use of io.gravitee.management.service.exceptions.RoleAlreadyExistsException in project gravitee-management-rest-api by gravitee-io.
the class RoleServiceImpl method create.
@Override
public RoleEntity create(final NewRoleEntity roleEntity) {
try {
Role role = convert(roleEntity);
if (roleRepository.findById(role.getScope(), role.getName()).isPresent()) {
throw new RoleAlreadyExistsException(role.getScope(), role.getName());
}
role.setCreatedAt(new Date());
role.setUpdatedAt(role.getCreatedAt());
RoleEntity entity = convert(roleRepository.create(role));
auditService.createPortalAuditLog(Collections.singletonMap(ROLE, role.getScope() + ":" + role.getName()), ROLE_CREATED, role.getCreatedAt(), null, role);
if (entity.isDefaultRole()) {
toggleDefaultRole(convert(roleEntity.getScope()), entity.getName());
}
return entity;
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create role {}", roleEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to create role " + roleEntity.getName(), ex);
}
}
Aggregations