Search in sources :

Example 1 with CommentDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO 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 2 with CommentDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO in project ArachneCentralAPI by OHDSI.

the class CommentController method addComment.

@ApiOperation(value = "Add new comment")
@RequestMapping(value = "/api/v1/comments/{topicId}", method = RequestMethod.POST)
public JsonResult<CommentDTO> addComment(@PathVariable("topicId") Long topicId, @Validated @RequestBody CommentDTO commentDTO, Principal principal) throws PermissionDeniedException {
    final IUser user = getUser(principal);
    final Comment comment = conversionService.convert(commentDTO, Comment.class);
    comment.setAuthor(user);
    final Comment saved = commentService.addComment(topicId, commentDTO.getParentId(), comment);
    JsonResult<CommentDTO> result = new JsonResult<>(NO_ERROR);
    result.setResult(conversionService.convert(saved, CommentDTO.class));
    return result;
}
Also used : Comment(com.odysseusinc.arachne.portal.model.Comment) IUser(com.odysseusinc.arachne.portal.model.IUser) CommentDTO(com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with CommentDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO in project ArachneCentralAPI by OHDSI.

the class CommentToCommentDTOConverter method convert.

@Override
public CommentDTO convert(Comment source) {
    final CommentDTO commentDTO = new CommentDTO();
    commentDTO.setId(source.getId());
    commentDTO.setDate(source.getDate());
    commentDTO.setComment(source.getComment());
    commentDTO.setAuthor(conversionService.convert(source.getAuthor(), UserInfoDTO.class));
    /*
        final List<CommentDTO> commentDTOS = source.getComments()
                .stream()
                .map(c -> conversionService.convert(c, CommentDTO.class))
                .collect(Collectors.toList());
        commentDTO.setComments(commentDTOS);
        */
    return commentDTO;
}
Also used : CommentDTO(com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO) UserInfoDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserInfoDTO)

Example 4 with CommentDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO in project ArachneCentralAPI by OHDSI.

the class CommentTopicToCommentTopicDTOConverter method convert.

@Override
public CommentTopicDTO convert(CommentTopic source) {
    final CommentTopicDTO commentTopicDTO = new CommentTopicDTO();
    final List<CommentDTO> commentDTOS = source.getComments().stream().map(c -> conversionService.convert(c, CommentDTO.class)).collect(Collectors.toList());
    commentTopicDTO.setId(source.getId());
    commentTopicDTO.setComments(commentDTOS);
    return commentTopicDTO;
}
Also used : List(java.util.List) Component(org.springframework.stereotype.Component) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) CommentTopicDTO(com.odysseusinc.arachne.portal.api.v1.dto.CommentTopicDTO) Autowired(org.springframework.beans.factory.annotation.Autowired) BaseConversionServiceAwareConverter(com.odysseusinc.arachne.portal.api.v1.dto.converters.BaseConversionServiceAwareConverter) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) CommentDTO(com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO) Collectors(java.util.stream.Collectors) CommentTopicDTO(com.odysseusinc.arachne.portal.api.v1.dto.CommentTopicDTO) CommentDTO(com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO)

Aggregations

CommentDTO (com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO)3 CommentTopic (com.odysseusinc.arachne.portal.model.CommentTopic)2 ApiOperation (io.swagger.annotations.ApiOperation)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)1 CommentTopicDTO (com.odysseusinc.arachne.portal.api.v1.dto.CommentTopicDTO)1 Commentable (com.odysseusinc.arachne.portal.api.v1.dto.Commentable)1 SubmissionInsightDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO)1 UserInfoDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserInfoDTO)1 BaseConversionServiceAwareConverter (com.odysseusinc.arachne.portal.api.v1.dto.converters.BaseConversionServiceAwareConverter)1 Comment (com.odysseusinc.arachne.portal.model.Comment)1 IUser (com.odysseusinc.arachne.portal.model.IUser)1 SubmissionInsight (com.odysseusinc.arachne.portal.model.SubmissionInsight)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 GenericConversionService (org.springframework.core.convert.support.GenericConversionService)1 PageRequest (org.springframework.data.domain.PageRequest)1 Pageable (org.springframework.data.domain.Pageable)1