Search in sources :

Example 1 with GroupNameAlreadyExistsException

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);
    }
}
Also used : GroupNameAlreadyExistsException(io.gravitee.management.service.exceptions.GroupNameAlreadyExistsException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

GroupNameAlreadyExistsException (io.gravitee.management.service.exceptions.GroupNameAlreadyExistsException)1 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1