Search in sources :

Example 1 with Reply

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

the class GitlabManagerRestricted method getCommentReplies.

@Override
public List<Reply> getCommentReplies(String projectId, Comment comment) throws IOException {
    String resourceId = comment.getDocumentId();
    String projectPath = projectId + "/" + resourceId;
    NotesApi notesApi = restrictedGitLabApi.getNotesApi();
    List<Reply> result = new ArrayList<Reply>();
    try {
        List<Note> notes = notesApi.getIssueNotes(projectPath, comment.getIid());
        for (Note note : notes.stream().filter(n -> !n.getSystem()).collect(Collectors.toList())) {
            // filter system notes
            String noteBody = note.getBody();
            Reply reply = null;
            try {
                reply = new SerializationHelper<Reply>().deserialize(noteBody, Reply.class);
                reply.setCommentUuid(comment.getUuid());
                reply.setId(note.getId());
                reply.setUserId(note.getAuthor().getId());
                reply.setUsername(note.getAuthor().getName());
            } catch (Exception e) {
                logger.log(Level.SEVERE, String.format("Error deserializing Reply #%1$d %2$s", note.getId(), noteBody), e);
                IDGenerator idGenerator = new IDGenerator();
                reply = new Reply(idGenerator.generate(), noteBody, note.getAuthor().getUsername(), note.getAuthor().getId(), comment.getUuid(), note.getId());
            }
            result.add(reply);
        }
        comment.setReplies(result);
        return result;
    } catch (GitLabApiException e) {
        throw new IOException(String.format("Failed to retrieve Replies for Comment %1$s %2$d for resource %3$s in group %4$s!", comment.getUuid(), comment.getIid(), resourceId, projectId), e);
    }
}
Also used : NotesApi(org.gitlab4j.api.NotesApi) JsonObject(com.google.gson.JsonObject) Reply(de.catma.document.comment.Reply) AccessLevel(org.gitlab4j.api.models.AccessLevel) ProjectFilter(org.gitlab4j.api.models.ProjectFilter) StringUtils(org.apache.commons.lang3.StringUtils) Author(org.gitlab4j.api.models.Author) IssuesApi(org.gitlab4j.api.IssuesApi) ChangeUserAttributeEvent(de.catma.ui.events.ChangeUserAttributeEvent) Map(java.util.Map) Group(org.gitlab4j.api.models.Group) IssueState(org.gitlab4j.api.Constants.IssueState) GroupApi(org.gitlab4j.api.GroupApi) Visibility(org.gitlab4j.api.models.Visibility) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) IGitUserInformation(de.catma.repository.git.interfaces.IGitUserInformation) GitMember(de.catma.repository.git.GitMember) Pager(org.gitlab4j.api.Pager) GitlabUtils(de.catma.repository.git.GitlabUtils) Set(java.util.Set) Logger(java.util.logging.Logger) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) Collectors(java.util.stream.Collectors) ProjectReference(de.catma.project.ProjectReference) Objects(java.util.Objects) List(java.util.List) ProjectApi(org.gitlab4j.api.ProjectApi) Optional(java.util.Optional) GitLabApiException(org.gitlab4j.api.GitLabApiException) Status(org.gitlab4j.api.models.ImportStatus.Status) CacheBuilder(com.google.common.cache.CacheBuilder) GitLabApi(org.gitlab4j.api.GitLabApi) RBACPermission(de.catma.rbac.RBACPermission) Permissions(org.gitlab4j.api.models.Permissions) GroupFilter(org.gitlab4j.api.models.GroupFilter) Namespace(org.gitlab4j.api.models.Namespace) HashMap(java.util.HashMap) RBACRole(de.catma.rbac.RBACRole) JsonParser(com.google.gson.JsonParser) User(de.catma.user.User) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) EventBus(com.google.common.eventbus.EventBus) IRemoteGitManagerRestricted(de.catma.repository.git.interfaces.IRemoteGitManagerRestricted) Comment(de.catma.document.comment.Comment) ForkStatus(de.catma.project.ForkStatus) GitProjectManager(de.catma.repository.git.GitProjectManager) Note(org.gitlab4j.api.models.Note) IDGenerator(de.catma.util.IDGenerator) Subscribe(com.google.common.eventbus.Subscribe) CreateRepositoryResponse(de.catma.repository.git.CreateRepositoryResponse) Issue(org.gitlab4j.api.models.Issue) IOException(java.io.IOException) Project(org.gitlab4j.api.models.Project) Maps(com.google.common.collect.Maps) IssueFilter(org.gitlab4j.api.models.IssueFilter) TimeUnit(java.util.concurrent.TimeUnit) Member(org.gitlab4j.api.models.Member) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) BackgroundService(de.catma.backgroundservice.BackgroundService) GitUser(de.catma.repository.git.GitUser) ArrayList(java.util.ArrayList) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) Note(org.gitlab4j.api.models.Note) Reply(de.catma.document.comment.Reply) IDGenerator(de.catma.util.IDGenerator) NotesApi(org.gitlab4j.api.NotesApi)

Example 2 with Reply

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

the class TaggerView method updateReplyToComment.

public void updateReplyToComment(Optional<Comment> optionalComment, String replyUuid, int x, int y) {
    if (optionalComment.isPresent()) {
        Comment comment = optionalComment.get();
        Reply reply = comment.getReply(replyUuid);
        if (reply != null) {
            CommentDialog commentDialog = new CommentDialog(reply.getBody(), true, replyBody -> {
                try {
                    reply.setBody(replyBody);
                    project.updateReply(optionalComment.get(), reply);
                } catch (IOException e) {
                    errorHandler.showAndLogError("Error updating Reply!", e);
                }
            });
            commentDialog.show(x, y);
        } else {
            Notification.show("Info", "Couldn't find a Reply to edit!", Type.HUMANIZED_MESSAGE);
        }
    } else {
        Notification.show("Info", "Couldn't find the Comment of the reply!", Type.HUMANIZED_MESSAGE);
    }
}
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) Reply(de.catma.document.comment.Reply) IOException(java.io.IOException)

Example 3 with Reply

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

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

the class CommentReplyJSONSerializer method toJSONArrayString.

public String toJSONArrayString(List<Reply> replies) throws IOException {
    Collections.sort(replies, (r1, r2) -> r1.getId().compareTo(r2.getId()));
    JsonNodeFactory factory = JsonNodeFactory.instance;
    ArrayNode collection = factory.arrayNode(replies.size());
    for (Reply reply : replies) {
        collection.add(toJSONObject(reply));
    }
    return new ObjectMapper().writeValueAsString(collection);
}
Also used : Reply(de.catma.document.comment.Reply) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 5 with Reply

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

the class GitlabManagerRestricted method addReply.

@Override
public void addReply(String projectId, Comment comment, Reply reply) throws IOException {
    String resourceId = comment.getDocumentId();
    String projectPath = projectId + "/" + resourceId;
    NotesApi notesApi = restrictedGitLabApi.getNotesApi();
    try {
        String noteBody = new SerializationHelper<Reply>().serialize(reply);
        Note note = notesApi.createIssueNote(projectPath, comment.getIid(), noteBody);
        reply.setId(note.getId());
        comment.addReply(reply);
    } catch (GitLabApiException e) {
        throw new IOException(String.format("Failed to create Reply for Comment %1$s %2$d for resource %3$s in group %4$s!", comment.getUuid(), comment.getIid(), resourceId, projectId), e);
    }
}
Also used : Note(org.gitlab4j.api.models.Note) Reply(de.catma.document.comment.Reply) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) NotesApi(org.gitlab4j.api.NotesApi)

Aggregations

Reply (de.catma.document.comment.Reply)10 IOException (java.io.IOException)7 Comment (de.catma.document.comment.Comment)6 ClientCommentReply (de.catma.ui.client.ui.tagger.shared.ClientCommentReply)4 ClientComment (de.catma.ui.client.ui.tagger.shared.ClientComment)3 User (de.catma.user.User)3 Subscribe (com.google.common.eventbus.Subscribe)2 CommentMessage (de.catma.ui.events.CommentMessage)2 IDGenerator (de.catma.util.IDGenerator)2 List (java.util.List)2 Optional (java.util.Optional)2 Level (java.util.logging.Level)2 Logger (java.util.logging.Logger)2 GitLabApiException (org.gitlab4j.api.GitLabApiException)2 NotesApi (org.gitlab4j.api.NotesApi)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1