use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class GroupServiceImpl method delete.
@Override
public void delete(String groupId) {
try {
logger.debug("delete {}", groupId);
Optional<Group> group = groupRepository.findById(groupId);
if (!group.isPresent()) {
throw new GroupNotFoundException(groupId);
}
// remove all members
membershipRepository.findByReferenceAndRole(MembershipReferenceType.GROUP, groupId, null, null).forEach(member -> {
try {
membershipRepository.delete(member);
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to delete a group", ex);
throw new TechnicalManagementException("An error occurs while trying to delete a group", ex);
}
});
// remove all applications or apis
Date updatedDate = new Date();
apiRepository.findByGroups(Collections.singletonList(groupId)).forEach(api -> {
api.getGroups().remove(groupId);
api.setUpdatedAt(updatedDate);
try {
apiRepository.update(api);
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to delete a group", ex);
throw new TechnicalManagementException("An error occurs while trying to delete a group", ex);
}
});
applicationRepository.findByGroups(Collections.singletonList(groupId)).forEach(application -> {
application.getGroups().remove(groupId);
application.setUpdatedAt(updatedDate);
try {
applicationRepository.update(application);
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to delete a group", ex);
throw new TechnicalManagementException("An error occurs while trying to delete a group", ex);
}
});
// remove group
groupRepository.delete(groupId);
// Audit
auditService.createPortalAuditLog(Collections.singletonMap(GROUP, groupId), GROUP_DELETED, new Date(), group.get(), null);
logger.debug("delete {} - DONE", groupId);
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to delete a group", ex);
throw new TechnicalManagementException("An error occurs while trying to delete a group", ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class GroupServiceImpl method isUserAuthorizedToAccessPortalData.
@Override
public boolean isUserAuthorizedToAccessPortalData(List<String> excludedGroups, String username) {
// in anonymous mode, only pages without restrictions are authorized
if (username == null) {
return (excludedGroups == null || excludedGroups.isEmpty());
}
if (excludedGroups != null && !excludedGroups.isEmpty()) {
// for public apis, default authorized groups are all groups,
Set<String> authorizedGroups;
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.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class MembershipServiceImpl method removeRole.
@Override
public boolean removeRole(MembershipReferenceType referenceType, String referenceId, String userId, RoleScope roleScope) {
try {
Optional<Membership> optionalMembership = membershipRepository.findById(userId, referenceType, referenceId);
if (optionalMembership.isPresent()) {
Membership membership = optionalMembership.get();
Membership previousMembership = new Membership(membership);
membership.getRoles().remove(roleScope.getId());
membership.setUpdatedAt(new Date());
if (membership.getRoles().isEmpty()) {
throw new MemberWithoutRoleException(membership.getUserId());
} else {
membershipRepository.update(membership);
createAuditLog(MEMBERSHIP_UPDATED, membership.getUpdatedAt(), previousMembership, membership);
return true;
}
}
return false;
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to get membership for {} {} and user", referenceType, referenceId, userId, ex);
throw new TechnicalManagementException("An error occurs while trying to get members for " + referenceType + " " + referenceId + " and user " + userId, ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class MetadataServiceImpl method findDefaultByKey.
@Override
public MetadataEntity findDefaultByKey(final String key) {
try {
LOGGER.debug("Find default metadata by key");
final Optional<Metadata> optMetadata = metadataRepository.findById(key, DEFAUT_REFERENCE_ID, MetadataReferenceType.DEFAULT);
if (optMetadata.isPresent()) {
return convert(optMetadata.get());
} else {
return null;
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurred while trying to find default metadata by key", ex);
throw new TechnicalManagementException("An error occurred while trying to find default metadata by key", ex);
}
}
use of io.gravitee.repository.exceptions.TechnicalException in project gravitee-management-rest-api by gravitee-io.
the class PageServiceImpl method findMaxPortalPageOrder.
@Override
public int findMaxPortalPageOrder() {
try {
logger.debug("Find Max Order Portal Page");
final Integer maxPageOrder = pageRepository.findMaxPortalPageOrder();
return maxPageOrder == null ? 0 : maxPageOrder;
} catch (TechnicalException ex) {
logger.error("An error occured when searching max order portal page", ex);
throw new TechnicalManagementException("An error occured when searching max order portal ", ex);
}
}
Aggregations