use of io.gravitee.management.service.exceptions.GroupNotFoundException 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);
}
}
use of io.gravitee.management.service.exceptions.GroupNotFoundException 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);
}
}
Aggregations