use of org.springframework.data.domain.PageRequest in project ArachneCentralAPI by OHDSI.
the class BaseDataSourceController method getUserDataSources.
@RequestMapping(value = "/api/v1/data-sources/my", method = RequestMethod.GET)
public Page<DS_DTO> getUserDataSources(Principal principal, @RequestParam(name = "query", required = false, defaultValue = "") String query, @ModelAttribute PageDTO pageDTO) throws PermissionDeniedException {
final IUser user = getUser(principal);
PageRequest pageRequest = getPageRequest(pageDTO);
Page<DS> dataSources = dataSourceService.getUserDataSources(query, user.getId(), pageRequest);
List<DS_DTO> dataSourceDTOs = converterUtils.convertList(dataSources.getContent(), getDataSourceDTOClass());
return new CustomPageImpl<>(dataSourceDTOs, pageRequest, dataSources.getTotalElements());
}
use of org.springframework.data.domain.PageRequest in project ArachneCentralAPI by OHDSI.
the class BaseStudyController method getStudyInsights.
@ApiOperation("Get recent Insights of Study")
@RequestMapping(value = "/api/v1/study-management/studies/{studyId}/insights", method = GET)
public List<SubmissionInsightDTO> getStudyInsights(@PathVariable("studyId") Long studyId, @RequestParam(value = "size", required = false) Integer size, @RequestParam(value = "commentsPerInsight", required = false) Integer commentsPerInsight, @RequestParam(value = "order", required = false) Sort.Direction order) {
if (size == null) {
size = Integer.MAX_VALUE;
}
if (commentsPerInsight == null) {
commentsPerInsight = Integer.MAX_VALUE;
}
if (order == null) {
order = Sort.Direction.DESC;
}
List<SubmissionInsightDTO> submissionInsightDTOS = new ArrayList<>();
Pageable pageRequest = new PageRequest(0, size, new Sort(order, "created"));
final Page<SubmissionInsight> page = submissionInsightService.getInsightsByStudyId(studyId, pageRequest);
final List<SubmissionInsight> insights = page.getContent();
for (int i = 0; i < insights.size(); i++) {
final SubmissionInsight insight = insights.get(i);
final Set<CommentTopic> recentTopics = submissionInsightService.getInsightComments(insight, commentsPerInsight, new Sort(Sort.Direction.DESC, "id"));
final SubmissionInsightDTO insightDTO = conversionService.convert(insight, SubmissionInsightDTO.class);
final List<Commentable> recentCommentables = getRecentCommentables(conversionService, recentTopics, insightDTO);
insightDTO.setRecentCommentEntities(recentCommentables);
submissionInsightDTOS.add(insightDTO);
}
if (LOG.isDebugEnabled()) {
submissionInsightDTOS.stream().forEach(submissionInsightDTO -> {
LOG.debug("+" + submissionInsightDTO.getName());
submissionInsightDTO.getRecentCommentEntities().stream().forEach(commentable -> {
LOG.debug("|+" + commentable.getName());
commentable.getTopic().getComments().stream().forEach(commentDTO -> {
LOG.debug(" |-" + commentDTO.getAuthor().getFirstname() + ":" + commentDTO.getDate() + ":" + commentDTO.getComment());
});
});
});
}
return submissionInsightDTOS;
}
use of org.springframework.data.domain.PageRequest in project ArachneCentralAPI by OHDSI.
the class CommentServiceImpl method list.
@Override
public Set<CommentTopic> list(Set<CommentTopic> topics, Integer size, Sort sort) {
Pageable pageable = new PageRequest(0, size, sort);
final Page<Comment> page = commentRepository.getAllByTopicIn(topics, pageable);
final List<Comment> comments = page.getContent();
comments.forEach(comment -> connectToTopic(topics, comment));
return comments.stream().map(Comment::getTopic).collect(Collectors.toCollection(LinkedHashSet::new));
}
use of org.springframework.data.domain.PageRequest in project ArachneCentralAPI by OHDSI.
the class BaseAdminController method getAll.
@ApiOperation(value = "Get all users.", hidden = true)
@RequestMapping(value = "/api/v1/admin/users", method = RequestMethod.GET)
public Page<CommonUserDTO> getAll(@PageableDefault(page = 1) @SortDefault.SortDefaults({ @SortDefault(sort = "name", direction = Sort.Direction.ASC) }) Pageable pageable, UserSearch userSearch) throws PermissionDeniedException, UserNotFoundException {
Pageable search = new PageRequest(pageable.getPageNumber() - 1, pageable.getPageSize(), pageable.getSort());
Iterator<Sort.Order> pageIt = pageable.getSort().iterator();
Stream<Sort.Order> pageStream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(pageIt, Spliterator.ORDERED), false);
if (pageStream.anyMatch(order -> order.getProperty().equals("name"))) {
search = new PageRequest(pageable.getPageNumber() - 1, pageable.getPageSize(), pageable.getSort().getOrderFor("name").getDirection(), "firstname", "middlename", "lastname");
}
Page<IUser> users = userService.getAll(search, userSearch);
return users.map(user -> conversionService.convert(user, CommonUserDTO.class));
}
use of org.springframework.data.domain.PageRequest in project goci by EBISPOT.
the class SolrIndexer method mapEfo.
Integer mapEfo() {
Sort sort = new Sort(new Sort.Order("id"));
Pageable pager = new PageRequest(0, pageSize, sort);
Page<EfoTrait> efoTraitPage = efoTraitRepository.findAll(pager);
efoMapper.map(efoTraitPage.getContent());
while (efoTraitPage.hasNext()) {
if (maxPages != -1 && efoTraitPage.getNumber() >= maxPages - 1) {
break;
}
pager = pager.next();
efoTraitPage = efoTraitRepository.findAll(pager);
efoMapper.map(efoTraitPage.getContent());
if (sysOutLogging) {
System.out.print(".");
}
}
return (int) efoTraitPage.getTotalElements();
}
Aggregations