use of org.gitlab4j.api.NotesApi 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 org.gitlab4j.api.NotesApi 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);
}
}
use of org.gitlab4j.api.NotesApi in project catma by forTEXT.
the class GitlabManagerRestricted method removeReply.
@Override
public void removeReply(String projectId, Comment comment, Reply reply) throws IOException {
String resourceId = comment.getDocumentId();
String projectPath = projectId + "/" + resourceId;
NotesApi notesApi = restrictedGitLabApi.getNotesApi();
try {
notesApi.deleteIssueNote(projectPath, comment.getIid(), reply.getId());
comment.removeReply(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);
}
}
use of org.gitlab4j.api.NotesApi in project catma by forTEXT.
the class GitlabManagerRestricted method updateReply.
@Override
public void updateReply(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);
notesApi.updateIssueNote(projectPath, comment.getIid(), reply.getId(), noteBody);
} 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);
}
}
Aggregations