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);
}
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations