Search in sources :

Example 1 with CommentMessage

use of de.catma.ui.events.CommentMessage in project catma by forTEXT.

the class CommentMessageListener method uiOnMessage.

@Override
public void uiOnMessage(Message<CommentMessage> message) {
    boolean autoShowcomments = (boolean) cbAutoShowComments.getData();
    if (!autoShowcomments) {
        return;
    }
    try {
        CommentMessage commentMessage = message.getMessageObject();
        final String documentId = commentMessage.getDocumentId();
        final boolean replyMessage = commentMessage.isReplyMessage();
        final int senderId = commentMessage.getSenderId();
        final boolean deleted = commentMessage.isDeleted();
        final SourceDocument document = documentSupplier.get();
        if ((document != null) && document.getUuid().equals(documentId)) {
            User user = project.getUser();
            Integer receiverId = user.getUserId();
            if (!receiverId.equals(senderId)) {
                final Comment comment = commentMessage.toComment();
                Optional<Comment> optionalExistingComment = this.comments.stream().filter(c -> c.getUuid().equals(comment.getUuid())).findFirst();
                if (replyMessage) {
                    if (optionalExistingComment.isPresent()) {
                        Comment existingComment = optionalExistingComment.get();
                        Reply reply = commentMessage.toReply();
                        Reply existingReply = existingComment.getReply(reply.getUuid());
                        if (existingReply != null) {
                            if (deleted) {
                                existingComment.removeReply(existingReply);
                                tagger.removeReply(existingComment, existingReply);
                            } else {
                                existingReply.setBody(reply.getBody());
                                tagger.updateReply(existingComment, existingReply);
                            }
                        } else {
                            existingComment.addReply(reply);
                            tagger.addReply(existingComment, reply);
                        }
                    }
                } else {
                    if (deleted) {
                        optionalExistingComment.ifPresent(existingComment -> {
                            this.comments.remove(existingComment);
                            tagger.removeComment(existingComment);
                        });
                    } else {
                        if (optionalExistingComment.isPresent()) {
                            Comment existingComment = optionalExistingComment.get();
                            existingComment.setBody(comment.getBody());
                            tagger.updateComment(existingComment);
                        } else {
                            comments.add(comment);
                            tagger.addComment(comment);
                        }
                    }
                }
                getUi().push();
            }
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, "error processing an incoming Comment", e);
    }
}
Also used : Reply(de.catma.document.comment.Reply) Project(de.catma.project.Project) UI(com.vaadin.ui.UI) SourceDocument(de.catma.document.source.SourceDocument) Logger(java.util.logging.Logger) CommentMessage(de.catma.ui.events.CommentMessage) Supplier(java.util.function.Supplier) UIMessageListener(de.catma.ui.UIMessageListener) User(de.catma.user.User) Level(java.util.logging.Level) List(java.util.List) Comment(de.catma.document.comment.Comment) Message(com.hazelcast.core.Message) Optional(java.util.Optional) IconButton(de.catma.ui.component.IconButton) Comment(de.catma.document.comment.Comment) User(de.catma.user.User) CommentMessage(de.catma.ui.events.CommentMessage) SourceDocument(de.catma.document.source.SourceDocument) Reply(de.catma.document.comment.Reply)

Example 2 with CommentMessage

use of de.catma.ui.events.CommentMessage 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 3 with CommentMessage

use of de.catma.ui.events.CommentMessage 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)

Aggregations

Comment (de.catma.document.comment.Comment)3 CommentMessage (de.catma.ui.events.CommentMessage)3 Subscribe (com.google.common.eventbus.Subscribe)2 ValueOutOfBoundsException (com.vaadin.ui.Slider.ValueOutOfBoundsException)2 Reply (de.catma.document.comment.Reply)2 ClientComment (de.catma.ui.client.ui.tagger.shared.ClientComment)2 TextRange (de.catma.ui.client.ui.tagger.shared.TextRange)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 Message (com.hazelcast.core.Message)1 UI (com.vaadin.ui.UI)1 SourceDocument (de.catma.document.source.SourceDocument)1 Project (de.catma.project.Project)1 UIMessageListener (de.catma.ui.UIMessageListener)1 ClientCommentReply (de.catma.ui.client.ui.tagger.shared.ClientCommentReply)1 IconButton (de.catma.ui.component.IconButton)1 User (de.catma.user.User)1 List (java.util.List)1 Optional (java.util.Optional)1 Supplier (java.util.function.Supplier)1