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);
}
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());
}
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);
}
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);
}
}
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);
}
}
Aggregations