use of io.gravitee.management.service.exceptions.RoleReservedNameException in project gravitee-management-rest-api by gravitee-io.
the class RoleServiceImpl method delete.
@Override
public void delete(final RoleScope scope, final String name) {
if (isReserved(name)) {
throw new RoleReservedNameException(SystemRole.ADMIN.name());
}
try {
Optional<Role> optRole = roleRepository.findById(scope, name);
if (!optRole.isPresent()) {
throw new RoleNotFoundException(scope, name);
}
Role role = optRole.get();
roleRepository.delete(scope, name);
auditService.createPortalAuditLog(Collections.singletonMap(ROLE, role.getScope() + ":" + role.getName()), ROLE_DELETED, role.getUpdatedAt(), role, null);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to delete role {}/{}", scope, name, ex);
throw new TechnicalManagementException("An error occurs while trying to delete role " + scope + "/" + name, ex);
}
}
use of io.gravitee.management.service.exceptions.RoleReservedNameException in project gravitee-management-rest-api by gravitee-io.
the class RoleServiceImpl method update.
@Override
public RoleEntity update(final UpdateRoleEntity roleEntity) {
if (isReserved(roleEntity.getName())) {
throw new RoleReservedNameException(SystemRole.ADMIN.name());
}
RoleScope scope = convert(roleEntity.getScope());
try {
Optional<Role> optRole = roleRepository.findById(scope, roleEntity.getName());
if (!optRole.isPresent()) {
throw new RoleNotFoundException(scope, roleEntity.getName());
}
Role role = optRole.get();
Role updatedRole = convert(roleEntity);
updatedRole.setCreatedAt(role.getCreatedAt());
RoleEntity entity = convert(roleRepository.update(updatedRole));
auditService.createPortalAuditLog(Collections.singletonMap(ROLE, role.getScope() + ":" + role.getName()), ROLE_UPDATED, updatedRole.getUpdatedAt(), role, updatedRole);
if (entity.isDefaultRole()) {
toggleDefaultRole(scope, entity.getName());
}
return entity;
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to update role {}", roleEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to update role " + roleEntity.getName(), ex);
}
}
Aggregations