use of de.catma.document.annotation.AnnotationCollectionReference 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.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class CollectionSelectionStep method handleCollectionChanged.
@Subscribe
public void handleCollectionChanged(CollectionChangeEvent collectionChangeEvent) {
if (collectionChangeEvent.getChangeType().equals(ChangeType.CREATED)) {
AnnotationCollectionReference collectionReference = collectionChangeEvent.getCollectionReference();
addCollection(collectionReference);
}
}
use of de.catma.document.annotation.AnnotationCollectionReference 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.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class GraphWorktreeProject method commitAllChanges.
private void commitAllChanges(Function<AnnotationCollectionReference, String> collectionCcommitMsgProvider, String projectCommitMsg) throws Exception {
List<AnnotationCollectionReference> collectionRefs = getSourceDocuments().stream().flatMap(doc -> doc.getUserMarkupCollectionRefs().stream()).collect(Collectors.toList());
for (AnnotationCollectionReference collectionRef : collectionRefs) {
gitProjectHandler.addCollectionToStagedAndCommit(collectionRef.getId(), collectionCcommitMsgProvider.apply(collectionRef), false);
}
gitProjectHandler.commitProject(projectCommitMsg);
printStatus();
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class GraphWorktreeProject method printStatus.
@Override
public void printStatus() {
try {
Status status = gitProjectHandler.getStatus();
StatusPrinter.print(projectReference.toString(), status, System.out);
for (TagsetDefinition tagset : gitProjectHandler.getTagsets()) {
status = gitProjectHandler.getStatus(tagset);
StatusPrinter.print("Tagset " + tagset.getName() + " #" + tagset.getUuid(), status, System.out);
}
for (AnnotationCollectionReference collectionRef : gitProjectHandler.getDocuments().stream().flatMap(doc -> doc.getUserMarkupCollectionRefs().stream()).collect(Collectors.toList())) {
status = gitProjectHandler.getStatus(collectionRef);
StatusPrinter.print("Collection " + collectionRef.toString() + " #" + collectionRef.getId(), status, System.out);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations