Search in sources :

Example 51 with PageRequest

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());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) IUser(com.odysseusinc.arachne.portal.model.IUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 52 with PageRequest

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;
}
Also used : SubmissionInsightDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO) ArrayList(java.util.ArrayList) Commentable(com.odysseusinc.arachne.portal.api.v1.dto.Commentable) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 53 with PageRequest

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));
}
Also used : Comment(com.odysseusinc.arachne.portal.model.Comment) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable)

Example 54 with PageRequest

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));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) IUser(com.odysseusinc.arachne.portal.model.IUser) CommonUserDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonUserDTO) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 55 with PageRequest

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();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) EfoTrait(uk.ac.ebi.spot.goci.model.EfoTrait)

Aggregations

PageRequest (org.springframework.data.domain.PageRequest)106 Sort (org.springframework.data.domain.Sort)29 Pageable (org.springframework.data.domain.Pageable)25 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 Transactional (org.springframework.transaction.annotation.Transactional)9 UUID (java.util.UUID)8 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 ApiOperation (io.swagger.annotations.ApiOperation)7 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)6 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)6 List (java.util.List)6 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)5 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)5 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 PageImpl (org.springframework.data.domain.PageImpl)5