use of de.catma.ui.client.ui.tagger.shared.ClientComment in project catma by forTEXT.
the class ClientCommentJSONSerializer method toJSON.
public String toJSON(Collection<Comment> comments) throws IOException {
JsonNodeFactory factory = JsonNodeFactory.instance;
ArrayNode collection = factory.arrayNode(comments.size());
for (Comment comment : comments) {
collection.add(toJSONObject(new ClientComment(comment.getUuid(), comment.getUsername(), comment.getUserId(), comment.getBody(), comment.getReplyCount(), comment.getRanges().stream().map(range -> new TextRange(range.getStartPoint(), range.getEndPoint())).collect(Collectors.toList()))));
}
return new ObjectMapper().writeValueAsString(collection);
}
use of de.catma.ui.client.ui.tagger.shared.ClientComment in project catma by forTEXT.
the class TaggerView method handleReplyChange.
@Subscribe
public void handleReplyChange(ReplyChangeEvent replyChangeEvent) {
switch(replyChangeEvent.getChangeType()) {
case CREATED:
{
try {
tagger.addReply(replyChangeEvent.getComment(), replyChangeEvent.getReply());
} catch (IOException e) {
errorHandler.showAndLogError("Error adding Reply!", e);
}
break;
}
case UPDATED:
{
try {
tagger.updateReply(replyChangeEvent.getComment(), replyChangeEvent.getReply());
} catch (IOException e) {
errorHandler.showAndLogError("Error updating Reply!", e);
}
break;
}
case DELETED:
{
try {
tagger.removeReply(replyChangeEvent.getComment(), replyChangeEvent.getReply());
} catch (IOException e) {
errorHandler.showAndLogError("Error removing Reply!", e);
}
break;
}
}
try {
if (commentTopic != null) {
Comment comment = replyChangeEvent.getComment();
ClientComment clientComment = new ClientComment(comment.getUuid(), comment.getUsername(), comment.getUserId(), comment.getBody(), comment.getReplyCount(), comment.getRanges().stream().map(r -> new TextRange(r.getStartPoint(), r.getEndPoint())).collect(Collectors.toList()));
Reply reply = replyChangeEvent.getReply();
ClientCommentReply clientCommentReply = new ClientCommentReply(reply.getUuid(), reply.getBody(), reply.getUsername(), reply.getUserId(), reply.getCommentUuid());
commentTopic.publish(new CommentMessage(comment.getId(), comment.getIid(), project.getUser().getUserId(), clientComment, comment.getDocumentId(), replyChangeEvent.getChangeType() == ChangeType.DELETED, reply.getId(), clientCommentReply));
}
} catch (Exception e) {
logger.log(Level.WARNING, "error publishing a comment message", e);
}
}
use of de.catma.ui.client.ui.tagger.shared.ClientComment in project catma by forTEXT.
the class TaggerView method handleCommentChange.
@Subscribe
public void handleCommentChange(CommentChangeEvent commentChangeEvent) {
switch(commentChangeEvent.getChangeType()) {
case CREATED:
{
try {
comments.add(commentChangeEvent.getComment());
tagger.addComment(commentChangeEvent.getComment());
} catch (IOException e) {
errorHandler.showAndLogError("Error adding Comment!", e);
}
break;
}
case UPDATED:
{
tagger.updateComment(commentChangeEvent.getComment());
break;
}
case DELETED:
{
this.comments.remove(commentChangeEvent.getComment());
tagger.removeComment(commentChangeEvent.getComment());
break;
}
}
try {
if (commentTopic != null) {
Comment comment = commentChangeEvent.getComment();
ClientComment clientComment = new ClientComment(comment.getUuid(), comment.getUsername(), comment.getUserId(), comment.getBody(), comment.getReplyCount(), comment.getRanges().stream().map(r -> new TextRange(r.getStartPoint(), r.getEndPoint())).collect(Collectors.toList()));
commentTopic.publish(new CommentMessage(comment.getId(), comment.getIid(), project.getUser().getUserId(), clientComment, comment.getDocumentId(), commentChangeEvent.getChangeType() == ChangeType.DELETED));
}
} catch (Exception e) {
logger.log(Level.WARNING, "error publishing a comment message", e);
}
}
use of de.catma.ui.client.ui.tagger.shared.ClientComment in project catma by forTEXT.
the class Pager method addComment.
public ClientComment addComment(Comment comment) {
List<TextRange> absoluteRanges = comment.getRanges().stream().map(range -> new TextRange(range.getStartPoint(), range.getEndPoint())).collect(Collectors.toList());
List<Page> pages = getPagesForAbsoluteTextRanges(absoluteRanges);
for (Page page : pages) {
page.addAbsoluteComment(comment);
}
if (pages.contains(getCurrentPage())) {
Page currentPage = getCurrentPage();
List<TextRange> overlappingRelativRanges = new ArrayList<>();
for (Range absoluteRange : comment.getRanges()) {
Range overlappingAbsoluteRange = currentPage.getOverlappingRange(absoluteRange);
if (overlappingAbsoluteRange != null) {
TextRange overlappingRelativeRange = currentPage.getRelativeRangeFor(overlappingAbsoluteRange);
overlappingRelativRanges.add(new TextRange(overlappingRelativeRange));
}
}
return new ClientComment(comment.getUuid(), comment.getUsername(), comment.getUserId(), comment.getBody(), comment.getReplyCount(), overlappingRelativRanges);
} else {
return null;
}
}
Aggregations