use of de.catma.document.comment.Comment 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);
}
}
use of de.catma.document.comment.Comment in project catma by forTEXT.
the class GitlabManagerRestricted method addComment.
@Override
public void addComment(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);
Issue issue = issuesApi.createIssue(projectPath, title, description, null, null, null, CATMA_COMMENT_LABEL, null, null, null, null);
comment.setId(issue.getId());
comment.setIid(issue.getIid());
} catch (GitLabApiException e) {
throw new IOException(String.format("Failed to add a new Comment for resource %1$s in group %2$s!", resourceId, projectId), e);
}
}
use of de.catma.document.comment.Comment in project catma by forTEXT.
the class GitlabManagerRestricted method getComments.
@Override
public List<Comment> getComments(String projectId) throws IOException {
try {
List<Comment> result = new ArrayList<Comment>();
IssuesApi issuesApi = new IssuesApi(restrictedGitLabApi);
String projectPath = projectId;
List<Issue> issues = issuesApi.getGroupIssues(projectPath, new IssueFilter().withLabels(Collections.singletonList(CATMA_COMMENT_LABEL)).withState(IssueState.OPENED));
for (Issue issue : issues) {
String description = issue.getDescription();
int noteCount = issue.getUserNotesCount();
try {
Author author = issue.getAuthor();
Comment comment = new SerializationHelper<Comment>().deserialize(description, Comment.class);
comment.setId(issue.getId());
comment.setIid(issue.getIid());
comment.setUserId(author.getId());
comment.setUsername(author.getName());
comment.setReplyCount(noteCount);
result.add(comment);
} catch (Exception e) {
logger.log(Level.SEVERE, String.format("Error deserializing Comment #%1$d %2$s", issue.getId(), description), e);
}
}
return result;
} catch (GitLabApiException e) {
throw new IOException(String.format("Failed to retrieve Comments in group %1$s!", projectId), e);
}
}
use of de.catma.document.comment.Comment 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);
}
}
use of de.catma.document.comment.Comment in project catma by forTEXT.
the class TaggerView method loadReplies.
@Override
public void loadReplies(Optional<Comment> optionalComment) {
if (optionalComment.isPresent()) {
final Comment comment = optionalComment.get();
final UI ui = UI.getCurrent();
((BackgroundServiceProvider) ui).submit("load-comment-replies", new DefaultProgressCallable<Void>() {
@Override
public Void call() throws Exception {
ui.accessSynchronously(() -> {
try {
List<Reply> replies = project.getCommentReplies(comment);
tagger.setReplies(replies, comment);
ui.push();
} catch (IOException e) {
logger.log(Level.WARNING, "error loading replies", e);
}
});
return null;
}
}, new ExecutionListener<Void>() {
@Override
public void done(Void result) {
ui.push();
}
@Override
public void error(Throwable t) {
errorHandler.showAndLogError("Error loading Replies!", t);
}
});
}
}
Aggregations