Search in sources :

Example 11 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class EventServiceImpl method delete.

@Override
public void delete(String eventId) {
    try {
        LOGGER.debug("Delete Event {}", eventId);
        eventRepository.delete(eventId);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to delete Event {}", eventId, ex);
        throw new TechnicalManagementException("An error occurs while trying to delete Event " + eventId, ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 12 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class GenericNotificationConfigServiceImpl method create.

@Override
public GenericNotificationConfigEntity create(GenericNotificationConfigEntity entity) {
    if (entity.getNotifier() == null || entity.getNotifier().isEmpty() || entity.getName() == null || entity.getName().isEmpty()) {
        throw new BadNotificationConfigException("Name or notifier is missing !");
    }
    try {
        GenericNotificationConfig notificationConfig = convert(entity);
        notificationConfig.setId(UUID.toString(UUID.random()));
        notificationConfig.setCreatedAt(new Date());
        notificationConfig.setUpdatedAt(notificationConfig.getCreatedAt());
        return convert(genericNotificationConfigRepository.create(notificationConfig));
    } catch (TechnicalException te) {
        LOGGER.error("An error occurs while trying to save the generic notification settings {}", entity, te);
        throw new TechnicalManagementException("An error occurs while trying to save the generic notification settings " + entity, te);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) GenericNotificationConfig(io.gravitee.repository.management.model.GenericNotificationConfig) BadNotificationConfigException(io.gravitee.management.service.exceptions.BadNotificationConfigException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 13 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class GroupServiceImpl method findByIds.

@Override
public Set<GroupEntity> findByIds(Set<String> groupIds) {
    try {
        logger.debug("findByIds {}", groupIds);
        Set<Group> groups = groupRepository.findByIds(groupIds);
        if (groups == null || groups.size() != groupIds.size()) {
            List<String> groupsFound = groups == null ? Collections.emptyList() : groups.stream().map(Group::getId).collect(Collectors.toList());
            Set<String> groupIdsNotFound = new HashSet<>(groupIds);
            groupIdsNotFound.removeAll(groupsFound);
            throw new GroupsNotFoundException(groupIdsNotFound);
        }
        logger.debug("findByIds {} - DONE", groups);
        return groups.stream().map(this::map).collect(Collectors.toSet());
    } catch (TechnicalException ex) {
        logger.error("An error occurs while trying to find groups", ex);
        throw new TechnicalManagementException("An error occurs while trying to find groups", ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) GroupsNotFoundException(io.gravitee.management.service.exceptions.GroupsNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 14 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class GroupServiceImpl method isUserAuthorizedToAccessApiData.

@Override
public boolean isUserAuthorizedToAccessApiData(ApiEntity api, List<String> excludedGroups, String username) {
    // in anonymous mode, only public API without restrictions are authorized
    if (username == null) {
        return (excludedGroups == null || excludedGroups.isEmpty()) && (Visibility.PUBLIC.equals(api.getVisibility()));
    }
    if (// plan contains excluded groups
    excludedGroups != null && !excludedGroups.isEmpty() && // user is not directly member of the API
    membershipService.getMember(MembershipReferenceType.API, api.getId(), username, RoleScope.API) == null) {
        // for public apis, default authorized groups are all groups,
        // for private apis, default authorized groups are all apis groups
        Set<String> authorizedGroups = Collections.emptySet();
        if (Visibility.PRIVATE.equals(api.getVisibility()) && api.getGroups() != null && !api.getGroups().isEmpty()) {
            authorizedGroups = new HashSet<>(api.getGroups());
        }
        if (Visibility.PUBLIC.equals(api.getVisibility())) {
            try {
                authorizedGroups = groupRepository.findAll().stream().map(Group::getId).collect(Collectors.toSet());
            } catch (TechnicalException ex) {
                logger.error("An error occurs while trying to find all groups", ex);
                throw new TechnicalManagementException("An error occurs while trying to find all groups", ex);
            }
        }
        authorizedGroups.removeAll(excludedGroups);
        for (String authorizedGroupId : authorizedGroups) {
            if (membershipService.getMember(MembershipReferenceType.GROUP, authorizedGroupId, username, RoleScope.API) != null) {
                return true;
            }
        }
        return false;
    }
    return true;
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 15 with TechnicalManagementException

use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.

the class GroupServiceImpl method findById.

@Override
public GroupEntity findById(String groupId) {
    try {
        logger.debug("findById {}", groupId);
        Optional<Group> group = groupRepository.findById(groupId);
        if (!group.isPresent()) {
            throw new GroupNotFoundException(groupId);
        }
        logger.debug("findById {} - DONE", group.get());
        return this.map(group.get());
    } catch (TechnicalException ex) {
        logger.error("An error occurs while trying to find a group", ex);
        throw new TechnicalManagementException("An error occurs while trying to find a group", ex);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) GroupNotFoundException(io.gravitee.management.service.exceptions.GroupNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)90 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)83 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 Component (org.springframework.stereotype.Component)17 Collectors (java.util.stream.Collectors)13 java.util (java.util)11 Date (java.util.Date)11 AuditService (io.gravitee.management.service.AuditService)10 IdGenerator (io.gravitee.common.utils.IdGenerator)9 io.gravitee.management.model (io.gravitee.management.model)9 User (io.gravitee.repository.management.model.User)9 ApiRatingUnavailableException (io.gravitee.management.service.exceptions.ApiRatingUnavailableException)8 UserNotFoundException (io.gravitee.management.service.exceptions.UserNotFoundException)8 Metadata (io.gravitee.repository.management.model.Metadata)8 Rating (io.gravitee.repository.management.model.Rating)8 DuplicateMetadataNameException (io.gravitee.management.service.exceptions.DuplicateMetadataNameException)7 ApiService (io.gravitee.management.service.ApiService)6 MetadataService (io.gravitee.management.service.MetadataService)6