use of io.gravitee.management.service.exceptions.GroupNameAlreadyExistsException in project gravitee-management-rest-api by gravitee-io.
the class GroupServiceImpl method create.
@Override
public GroupEntity create(NewGroupEntity group) {
try {
logger.debug("create {}", group);
if (!this.findByName(group.getName()).isEmpty()) {
throw new GroupNameAlreadyExistsException(group.getName());
}
Group newGroup = this.map(group);
newGroup.setId(UUID.toString(UUID.random()));
newGroup.setCreatedAt(new Date());
newGroup.setUpdatedAt(newGroup.getCreatedAt());
GroupEntity grp = this.map(groupRepository.create(newGroup));
// Audit
auditService.createPortalAuditLog(Collections.singletonMap(GROUP, newGroup.getId()), GROUP_CREATED, newGroup.getCreatedAt(), null, newGroup);
logger.debug("create {} - DONE", grp);
return grp;
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to create a group", ex);
throw new TechnicalManagementException("An error occurs while trying to create a group", ex);
}
}
Aggregations