Search in sources :

Example 21 with Sort

use of org.springframework.data.domain.Sort in project ArachneCentralAPI by OHDSI.

the class BaseAnalysisController method getSubmissionInsight.

@ApiOperation("Get submission insight")
@RequestMapping(value = "/api/v1/analysis-management/submissions/{submissionId}/insight", method = GET)
public JsonResult<SubmissionInsightDTO> getSubmissionInsight(@PathVariable("submissionId") Long submissionId, @RequestParam(value = "size", required = false) Integer size, @RequestParam(value = "order", required = false) Sort.Direction order) throws NotExistException {
    if (size == null) {
        size = Integer.MAX_VALUE;
    }
    if (order == null) {
        order = Sort.Direction.ASC;
    }
    final SubmissionInsight insight = submissionInsightService.getSubmissionInsight(submissionId);
    final SubmissionInsightDTO insightDTO = conversionService.convert(insight, SubmissionInsightDTO.class);
    final Set<CommentTopic> recentTopics = submissionInsightService.getInsightComments(insight, size, new Sort(order, "id"));
    final List<Commentable> recentCommentables = getRecentCommentables(conversionService, recentTopics, insightDTO);
    insightDTO.setRecentCommentEntities(recentCommentables);
    final JsonResult<SubmissionInsightDTO> result = new JsonResult<>(NO_ERROR);
    result.setResult(insightDTO);
    return result;
}
Also used : SubmissionInsightDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO) Sort(org.springframework.data.domain.Sort) Commentable(com.odysseusinc.arachne.portal.api.v1.dto.Commentable) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with Sort

use of org.springframework.data.domain.Sort 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 23 with Sort

use of org.springframework.data.domain.Sort in project ArachneCentralAPI by OHDSI.

the class BaseUserServiceImpl method getAllAdmins.

@Override
public List<U> getAllAdmins(final String sortBy, final Boolean sortAsc) {
    Sort.Direction direction = sortAsc != null && sortAsc ? Sort.Direction.ASC : Sort.Direction.DESC;
    final Sort sort;
    if (sortBy == null || sortBy.isEmpty() || sortBy.equals("name")) {
        sort = new Sort(direction, "firstname", "lastname", "middlename");
    } else {
        sort = new Sort(direction, sortBy);
    }
    List<U> admins = rawUserRepository.findByRoles_name(ROLE_ADMIN, sort);
    return admins;
}
Also used : Sort(org.springframework.data.domain.Sort)

Example 24 with Sort

use of org.springframework.data.domain.Sort in project goci by EBISPOT.

the class DiseaseTraitController method allDiseaseTraits.

//Return all disease traits
@RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String allDiseaseTraits(Model model) {
    Sort sort = sortByTraitAsc();
    List<DiseaseTrait> allDiseaseTraits = diseaseTraitRepository.findAll(sort);
    model.addAttribute("diseaseTraits", allDiseaseTraits);
    model.addAttribute("totaldiseaseTraits", allDiseaseTraits.size());
    // Return an empty DiseaseTrait object so user can add a new one
    model.addAttribute("diseaseTrait", new DiseaseTrait());
    return "disease_traits";
}
Also used : DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) Sort(org.springframework.data.domain.Sort) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with Sort

use of org.springframework.data.domain.Sort 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

Sort (org.springframework.data.domain.Sort)49 PageRequest (org.springframework.data.domain.PageRequest)29 Pageable (org.springframework.data.domain.Pageable)14 ArrayList (java.util.ArrayList)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 List (java.util.List)5 Order (org.springframework.data.domain.Sort.Order)5 BooleanBuilder (com.querydsl.core.BooleanBuilder)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)4 Collectors (java.util.stream.Collectors)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 ApiOperation (io.swagger.annotations.ApiOperation)3 Date (java.util.Date)3 PageImpl (org.springframework.data.domain.PageImpl)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 Commentable (com.odysseusinc.arachne.portal.api.v1.dto.Commentable)2 SubmissionInsightDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO)2 CommentTopic (com.odysseusinc.arachne.portal.model.CommentTopic)2 SubmissionInsight (com.odysseusinc.arachne.portal.model.SubmissionInsight)2