use of de.catma.document.source.SourceDocument in project catma by forTEXT.
the class AnalyzeResourcePanel method initData.
private void initData() {
documentData = new TreeData<>();
try {
Collection<SourceDocument> documents = project.getSourceDocuments();
documentData.addRootItems(documents.stream().map(document -> new DocumentDataItem(document)));
for (DocumentTreeItem documentDataItem : documentData.getRootItems()) {
for (AnnotationCollectionReference umcRef : ((DocumentDataItem) documentDataItem).getDocument().getUserMarkupCollectionRefs()) {
documentData.addItem(documentDataItem, new CollectionDataItem(umcRef, project.hasPermission(project.getRoleForCollection(umcRef.getId()), RBACPermission.COLLECTION_WRITE)));
}
}
documentTree.setDataProvider(new TreeDataProvider<>(documentData));
Collection<SourceDocument> selectedDocuments = corpus.getSourceDocuments();
Collection<AnnotationCollectionReference> selectedCollections = corpus.getUserMarkupCollectionRefs();
documentData.getRootItems().stream().filter(documentItem -> selectedDocuments.contains(((DocumentDataItem) documentItem).getDocument())).forEach(documentTree::select);
for (DocumentTreeItem documentDataItem : documentData.getRootItems()) {
List<DocumentTreeItem> collectionItems = documentData.getChildren(documentDataItem);
for (DocumentTreeItem oneCollection : collectionItems) {
if (selectedCollections.contains(((CollectionDataItem) oneCollection).getCollectionRef())) {
documentTree.getSelectionModel().select(oneCollection);
}
}
}
documentTree.expand(documentData.getRootItems());
} catch (Exception e) {
((ErrorHandler) UI.getCurrent()).showAndLogError("error loading Project data", e);
}
}
use of de.catma.document.source.SourceDocument in project catma by forTEXT.
the class CollectionSelectionStep method initData.
private void initData() throws Exception {
documentData = new TreeData<>();
@SuppressWarnings("unchecked") Set<String> documentIds = (Set<String>) context.get(AnnotationWizardContextKey.DOCUMENTIDS);
for (String documentId : documentIds) {
SourceDocument srcDoc = project.getSourceDocument(documentId);
DocumentResource docResource = new DocumentResource(srcDoc, project.getProjectId(), project.hasPermission(project.getRoleForDocument(srcDoc.getUuid()), RBACPermission.DOCUMENT_WRITE));
if (project.hasPermission(project.getRoleForDocument(srcDoc.getUuid()), RBACPermission.DOCUMENT_READ)) {
documentData.addItem(null, docResource);
List<AnnotationCollectionReference> collections = srcDoc.getUserMarkupCollectionRefs();
List<Resource> readableCollectionResources = collections.stream().map(collectionRef -> (Resource) new CollectionResource(collectionRef, project.getProjectId(), project.hasPermission(project.getRoleForCollection(collectionRef.getId()), RBACPermission.COLLECTION_WRITE))).filter(colRes -> project.hasPermission(project.getRoleForCollection(colRes.getResourceId()), RBACPermission.COLLECTION_WRITE)).collect(Collectors.toList());
if (!collections.isEmpty()) {
documentData.addItems(docResource, readableCollectionResources);
} else {
// TODO: improve message
Notification.show("Info", String.format("You do not have a writable Collection available for Document %1$s", srcDoc.toString()), Type.HUMANIZED_MESSAGE);
}
}
}
documentDataProvider = new TreeDataProvider<Resource>(documentData);
documentGrid.setDataProvider(documentDataProvider);
}
use of de.catma.document.source.SourceDocument 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.source.SourceDocument in project catma by forTEXT.
the class AnalyzeResourcePanel method handleCollectionChanged.
@SuppressWarnings("unchecked")
@Subscribe
public void handleCollectionChanged(CollectionChangeEvent collectionChangeEvent) {
if (collectionChangeEvent.getChangeType().equals(ChangeType.CREATED)) {
SourceDocument document = collectionChangeEvent.getDocument();
AnnotationCollectionReference collectionReference = collectionChangeEvent.getCollectionReference();
CollectionDataItem collectionDataItem = new CollectionDataItem(collectionReference, project.hasPermission(project.getRoleForCollection(collectionReference.getId()), RBACPermission.COLLECTION_WRITE));
documentData.getRootItems().stream().filter(item -> ((DocumentDataItem) item).getDocument().equals(document)).findAny().ifPresent(documentDataItem -> {
documentData.addItem(documentDataItem, collectionDataItem);
documentTree.getDataProvider().refreshAll();
});
if (isAttached()) {
documentTree.expand(documentData.getParent(collectionDataItem));
Notification.show("Info", String.format("Collection %1$s has been created!", collectionReference.toString()), Type.TRAY_NOTIFICATION);
}
} else if (collectionChangeEvent.getChangeType().equals(ChangeType.DELETED)) {
Optional<DocumentTreeItem> optionalDocResource = documentData.getRootItems().stream().filter(item -> ((DocumentDataItem) item).getDocument().equals(collectionChangeEvent.getDocument())).findAny();
if (optionalDocResource.isPresent()) {
Optional<DocumentTreeItem> optionalCollectionResource = documentData.getChildren(optionalDocResource.get()).stream().filter(item -> ((CollectionDataItem) item).getCollectionRef().equals(collectionChangeEvent.getCollectionReference())).findAny();
if (optionalCollectionResource.isPresent()) {
DocumentTreeItem collectionItem = optionalCollectionResource.get();
documentData.removeItem(collectionItem);
documentTree.getDataProvider().refreshAll();
// selections needs manual update...
((SelectionModel.Multi<DocumentTreeItem>) documentTree.getSelectionModel()).updateSelection(Collections.emptySet(), Collections.singleton(collectionItem));
}
corpusChangedListener.corpusChanged();
}
} else {
documentTree.getDataProvider().refreshAll();
corpusChangedListener.corpusChanged();
}
}
use of de.catma.document.source.SourceDocument in project catma by forTEXT.
the class ProjectResourceExportApiRequestHandler method handleRequest.
@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
String requestPath = request.getPathInfo().toLowerCase();
if (requestPath.equals(handlerPath)) {
response.setContentType("application/json");
response.setNoCacheHeaders();
OutputStream outputStream = response.getOutputStream();
outputStream.write(serializeProjectResources().getBytes(StandardCharsets.UTF_8));
return true;
} else if (requestPath.startsWith(handlerPath + "/doc/")) {
try {
String[] requestPathParts = requestPath.split("/");
String documentUuid = requestPathParts[requestPathParts.length - 1];
SourceDocument sourceDocument = project.getSourceDocument(documentUuid.toUpperCase());
response.setContentType("text/plain; charset=UTF-8");
OutputStream outputStream = response.getOutputStream();
outputStream.write(sourceDocument.getContent().getBytes(StandardCharsets.UTF_8));
} catch (UncheckedExecutionException e) {
if (e.getCause() instanceof NoSuchElementException) {
response.setStatus(404);
} else {
throw e;
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Error handling document request", e);
response.setStatus(500);
}
return true;
}
return false;
}
Aggregations