use of com.odysseusinc.arachne.portal.model.search.SubmissionGroupSpecification in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionServiceImpl method getSubmissionGroups.
@Override
@PreAuthorize("hasPermission(#submissoinGroupSearch.analysisId, 'Analysis', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).ACCESS_STUDY)")
@PostAuthorize("@ArachnePermissionEvaluator.addPermissionsToSubmissions(principal, returnObject )")
public Page<SubmissionGroup> getSubmissionGroups(SubmissionGroupSearch submissoinGroupSearch) {
final SubmissionGroupSpecification submissionGroupSpecification = new SubmissionGroupSpecification(submissoinGroupSearch);
final Integer page = submissoinGroupSearch.getPage();
final PageRequest pageRequest = new PageRequest(page == null ? 0 : page - 1, submissoinGroupSearch.getPageSize(), new Sort(Sort.Direction.DESC, "created"));
final Page<SubmissionGroup> submissionGroups = submissionGroupRepository.findAll(submissionGroupSpecification, pageRequest);
final List<SubmissionGroup> content = submissionGroups.getContent();
final Map<Long, SubmissionGroup> submissionGroupMap = content.stream().collect(Collectors.toMap(SubmissionGroup::getId, sg -> {
sg.setSubmissions(new ArrayList<>());
return sg;
}));
final Set<Long> submissionGroupIds = submissionGroupMap.keySet();
if (!CollectionUtils.isEmpty(submissionGroupIds)) {
final SubmissionSpecification<T> submissionSpecification = SubmissionSpecification.<T>builder(submissionGroupIds).withStatuses(submissoinGroupSearch.getSubmissionStatuses()).withDataSourceIds(submissoinGroupSearch.getDataSourceIds()).hasInsight(submissoinGroupSearch.getHasInsight()).showHidden(submissoinGroupSearch.getShowHidden()).build();
submissionRepository.findAll(submissionSpecification).forEach(s -> submissionGroupMap.get(s.getSubmissionGroup().getId()).getSubmissions().add(s));
}
return submissionGroups;
}
Aggregations