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;
}
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;
}
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;
}
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;
}
Aggregations