Search in sources :

Example 6 with ClientComment

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);
}
Also used : Comment(de.catma.document.comment.Comment) ClientComment(de.catma.ui.client.ui.tagger.shared.ClientComment) ClientComment(de.catma.ui.client.ui.tagger.shared.ClientComment) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 7 with ClientComment

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);
    }
}
Also used : ClientComment(de.catma.ui.client.ui.tagger.shared.ClientComment) Comment(de.catma.document.comment.Comment) ClientCommentReply(de.catma.ui.client.ui.tagger.shared.ClientCommentReply) CommentMessage(de.catma.ui.events.CommentMessage) ClientComment(de.catma.ui.client.ui.tagger.shared.ClientComment) ClientCommentReply(de.catma.ui.client.ui.tagger.shared.ClientCommentReply) Reply(de.catma.document.comment.Reply) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) IOException(java.io.IOException) ValueOutOfBoundsException(com.vaadin.ui.Slider.ValueOutOfBoundsException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Subscribe(com.google.common.eventbus.Subscribe)

Example 8 with ClientComment

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);
    }
}
Also used : ClientComment(de.catma.ui.client.ui.tagger.shared.ClientComment) Comment(de.catma.document.comment.Comment) CommentMessage(de.catma.ui.events.CommentMessage) ClientComment(de.catma.ui.client.ui.tagger.shared.ClientComment) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) IOException(java.io.IOException) ValueOutOfBoundsException(com.vaadin.ui.Slider.ValueOutOfBoundsException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Subscribe(com.google.common.eventbus.Subscribe)

Example 9 with ClientComment

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;
    }
}
Also used : Range(de.catma.document.Range) Iterator(java.util.Iterator) ClientComment(de.catma.ui.client.ui.tagger.shared.ClientComment) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ClientTagInstance(de.catma.ui.client.ui.tagger.shared.ClientTagInstance) List(java.util.List) Matcher(java.util.regex.Matcher) Comment(de.catma.document.comment.Comment) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) TagDefinition(de.catma.tag.TagDefinition) Optional(java.util.Optional) CRC32(java.util.zip.CRC32) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) ClientComment(de.catma.ui.client.ui.tagger.shared.ClientComment) ArrayList(java.util.ArrayList) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) Range(de.catma.document.Range) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange)

Aggregations

ClientComment (de.catma.ui.client.ui.tagger.shared.ClientComment)9 TextRange (de.catma.ui.client.ui.tagger.shared.TextRange)6 Comment (de.catma.document.comment.Comment)4 ClientCommentReply (de.catma.ui.client.ui.tagger.shared.ClientCommentReply)3 Subscribe (com.google.common.eventbus.Subscribe)2 JSONArray (com.google.gwt.json.client.JSONArray)2 ValueOutOfBoundsException (com.vaadin.ui.Slider.ValueOutOfBoundsException)2 Line (de.catma.ui.client.ui.tagger.editor.Line)2 ClientTagInstance (de.catma.ui.client.ui.tagger.shared.ClientTagInstance)2 CommentMessage (de.catma.ui.events.CommentMessage)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1 JSONObject (com.google.gwt.json.client.JSONObject)1 JSONString (com.google.gwt.json.client.JSONString)1 Timer (com.google.gwt.user.client.Timer)1