Search in sources :

Example 6 with Comment

use of de.catma.document.comment.Comment in project catma by forTEXT.

the class TaggerView method addComment.

@Override
public void addComment(List<Range> absoluteRanges, int x, int y) {
    User user = project.getUser();
    IDGenerator idGenerator = new IDGenerator();
    CommentDialog commentDialog = new CommentDialog(commentBody -> {
        try {
            project.addComment(new Comment(idGenerator.generate(), user.getName(), user.getUserId(), commentBody, absoluteRanges, this.sourceDocument.getUuid()));
        } catch (IOException e) {
            errorHandler.showAndLogError("Error adding Comment!", e);
        }
    });
    commentDialog.show(x, y);
}
Also used : ClientComment(de.catma.ui.client.ui.tagger.shared.ClientComment) Comment(de.catma.document.comment.Comment) User(de.catma.user.User) IOException(java.io.IOException) IDGenerator(de.catma.util.IDGenerator)

Example 7 with Comment

use of de.catma.document.comment.Comment in project catma by forTEXT.

the class KwicItemHandler method getKeywordDescription.

public String getKeywordDescription(QueryResultRow row) {
    if (row instanceof TagQueryResultRow) {
        TagQueryResultRow tRow = (TagQueryResultRow) row;
        TagDefinition tagDefinition = project.getTagManager().getTagLibrary().getTagDefinition(tRow.getTagDefinitionId());
        try {
            return AnnotatedTextProvider.buildAnnotatedKeywordInContext(new ArrayList<>(tRow.getRanges()), kwicProviderCache.get(tRow.getSourceDocumentId()), tagDefinition, tRow.getTagDefinitionPath());
        } catch (ExecutionException e) {
            logger.log(Level.SEVERE, "error retrieving keyword description for " + row, e);
        }
    }
    if (row instanceof CommentQueryResultRow) {
        CommentQueryResultRow cRow = (CommentQueryResultRow) row;
        Comment comment = cRow.getComment();
        return AnnotatedTextProvider.buildCommentedKeyword(row.getPhrase(), comment);
    }
    return Cleaner.clean(row.getPhrase());
}
Also used : TagDefinition(de.catma.tag.TagDefinition) Comment(de.catma.document.comment.Comment) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) CommentQueryResultRow(de.catma.queryengine.result.CommentQueryResultRow) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with Comment

use of de.catma.document.comment.Comment 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 9 with Comment

use of de.catma.document.comment.Comment 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 10 with Comment

use of de.catma.document.comment.Comment in project catma by forTEXT.

the class GitlabManagerRestricted method updateComment.

@Override
public void updateComment(String projectId, Comment comment) throws IOException {
    String resourceId = comment.getDocumentId();
    try {
        String projectPath = projectId + "/" + resourceId;
        IssuesApi issuesApi = restrictedGitLabApi.getIssuesApi();
        String title = comment.getBody().substring(0, Math.min(100, comment.getBody().length()));
        if (title.length() < comment.getBody().length()) {
            title += "...";
        }
        String description = new SerializationHelper<Comment>().serialize(comment);
        issuesApi.updateIssue(projectPath, comment.getIid(), title, description, null, null, null, CATMA_COMMENT_LABEL, null, null, null);
    } catch (GitLabApiException e) {
        throw new IOException(String.format("Failed to update Comment %1$s %2$d for resource %3$s in group %4$s!", comment.getUuid(), comment.getIid(), resourceId, projectId), e);
    }
}
Also used : Comment(de.catma.document.comment.Comment) IssuesApi(org.gitlab4j.api.IssuesApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Aggregations

Comment (de.catma.document.comment.Comment)15 IOException (java.io.IOException)10 ClientComment (de.catma.ui.client.ui.tagger.shared.ClientComment)8 Reply (de.catma.document.comment.Reply)6 TextRange (de.catma.ui.client.ui.tagger.shared.TextRange)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Subscribe (com.google.common.eventbus.Subscribe)3 ValueOutOfBoundsException (com.vaadin.ui.Slider.ValueOutOfBoundsException)3 CommentMessage (de.catma.ui.events.CommentMessage)3 User (de.catma.user.User)3 GitLabApiException (org.gitlab4j.api.GitLabApiException)3 IssuesApi (org.gitlab4j.api.IssuesApi)3 Issue (org.gitlab4j.api.models.Issue)3 UI (com.vaadin.ui.UI)2 CommentQueryResultRow (de.catma.queryengine.result.CommentQueryResultRow)2 TagDefinition (de.catma.tag.TagDefinition)2 ClientCommentReply (de.catma.ui.client.ui.tagger.shared.ClientCommentReply)2 IDGenerator (de.catma.util.IDGenerator)2 URISyntaxException (java.net.URISyntaxException)2