use of org.eclipse.vorto.repository.domain.Comment in project vorto by eclipse.
the class CommentController method getCommentsforModelId.
@RequestMapping(method = RequestMethod.GET, value = "/{modelId:.+}", produces = "application/json")
@PreAuthorize("hasAuthority('model_viewer')")
public List<Comment> getCommentsforModelId(@ApiParam(value = "modelId", required = true) @PathVariable String modelId) {
final ModelId modelID = ModelId.fromPrettyFormat(modelId);
Optional<String> maybeWorkspaceId = namespaceService.resolveWorkspaceIdForNamespace(modelID.getNamespace());
if (!maybeWorkspaceId.isPresent()) {
LOGGER.error(String.format("Namespace [%s] does not exist.", modelID.getNamespace()));
return Collections.emptyList();
}
return commentService.getCommentsforModelId(modelID).stream().map(comment -> ModelDtoFactory.createDto(comment, UserContext.user(SecurityContextHolder.getContext().getAuthentication().getName(), maybeWorkspaceId.get()))).collect(Collectors.toList());
}
use of org.eclipse.vorto.repository.domain.Comment in project vorto by eclipse.
the class ModelDtoFactoryTest method testCreateComment.
@Test
public void testCreateComment() {
Comment comment = new Comment(ModelId.fromReference("org.eclipse.vorto.examples.type.Color", "1.0.0"), "erle", "test comment");
Comment dto = ModelDtoFactory.createDto(comment, UserContext.user("anon", "playground"));
assertEquals("erle", dto.getAuthor());
}
use of org.eclipse.vorto.repository.domain.Comment in project vorto by eclipse.
the class DefaultCommentService method notifyAllCommentAuthors.
private void notifyAllCommentAuthors(Comment comment, ModelInfo model) {
Set<String> recipients = new HashSet<>();
recipients.add(model.getAuthor());
List<Comment> existingComments = this.commentRepository.findByModelId(comment.getModelId());
for (Comment c : existingComments) {
recipients.add(c.getAuthor());
}
recipients.stream().filter(recipient -> !User.USER_ANONYMOUS.equalsIgnoreCase(recipient)).forEach(recipient -> {
User user = accountService.getUser(recipient);
if (user != null) {
notificationService.sendNotification(new CommentReplyMessage(user, model, comment.getContent()));
}
});
}
Aggregations