use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class GroupServiceImpl method findAll.
@Override
public List<GroupEntity> findAll() {
try {
logger.debug("Find all groups");
Set<Group> all = groupRepository.findAll();
logger.debug("Find all groups - DONE");
return all.stream().map(this::map).collect(Collectors.toList());
} 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);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class GroupServiceImpl method update.
@Override
public GroupEntity update(String groupId, UpdateGroupEntity group) {
try {
logger.debug("update {}", group);
GroupEntity updatedGroupEntity = this.findById(groupId);
Group previousGroup = this.map(updatedGroupEntity);
updatedGroupEntity.setName(group.getName());
updatedGroupEntity.setUpdatedAt(new Date());
updatedGroupEntity.setEventRules(group.getEventRules());
Group updatedGroup = this.map(updatedGroupEntity);
GroupEntity grp = this.map(groupRepository.update(updatedGroup));
logger.debug("update {} - DONE", grp);
// Audit
auditService.createPortalAuditLog(Collections.singletonMap(GROUP, groupId), GROUP_UPDATED, updatedGroupEntity.getUpdatedAt(), previousGroup, updatedGroup);
return grp;
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to update a group", ex);
throw new TechnicalManagementException("An error occurs while trying to update a group", ex);
}
}
use of io.gravitee.management.service.exceptions.TechnicalManagementException 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.management.service.exceptions.TechnicalManagementException 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.management.service.exceptions.TechnicalManagementException in project gravitee-management-rest-api by gravitee-io.
the class LogsServiceImpl method findByApplication.
@Override
public SearchLogResponse findByApplication(String application, LogQuery query) {
try {
TabularResponse response = logRepository.query(QueryBuilders.tabular().page(query.getPage()).size(query.getSize()).query(query.getQuery()).timeRange(DateRangeBuilder.between(query.getFrom(), query.getTo()), IntervalBuilder.interval(query.getInterval())).root("application", application).build());
SearchLogResponse<ApplicationRequestItem> logResponse = new SearchLogResponse<>(response.getSize());
// Transform repository logs
logResponse.setLogs(response.getLogs().stream().map(this::toApplicationRequestItem).collect(Collectors.toList()));
// Add metadata (only if they are results)
if (response.getSize() > 0) {
Map<String, Map<String, String>> metadata = new HashMap<>();
logResponse.getLogs().forEach(logItem -> {
String api = logItem.getApi();
String plan = logItem.getPlan();
if (api != null) {
metadata.computeIfAbsent(api, getAPIMetadata(api));
}
if (plan != null) {
metadata.computeIfAbsent(plan, getPlanMetadata(plan));
}
});
logResponse.setMetadata(metadata);
}
return logResponse;
} catch (AnalyticsException ae) {
logger.error("Unable to retrieve logs: ", ae);
throw new TechnicalManagementException("Unable to retrieve logs", ae);
}
}
Aggregations