use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class CorpusExporter method export.
public void export(String exportName, Corpus corpus, OutputStream os) throws IOException {
OutputStream tarFileOs = new GZIPOutputStream(os);
TarArchiveOutputStream taOut = new TarArchiveOutputStream(tarFileOs, "UTF-8");
try {
taOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
taOut.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
for (SourceDocument sd : corpus.getSourceDocuments()) {
TarArchiveEntry sdEntry = new TarArchiveEntry(getSourceDocEntryName(exportName, sd));
byte[] sdContent = sd.getContent().getBytes(Charset.forName("UTF8"));
sdEntry.setSize(sdContent.length);
taOut.putArchiveEntry(sdEntry);
taOut.write(sdContent);
taOut.closeArchiveEntry();
for (AnnotationCollectionReference umcRef : corpus.getUserMarkupCollectionRefs(sd)) {
AnnotationCollection umc = repo.getUserMarkupCollection(umcRef);
TeiUserMarkupCollectionSerializationHandler handler = new TeiUserMarkupCollectionSerializationHandler(repo.getTagManager(), false);
ByteArrayOutputStream teiDocOut = new ByteArrayOutputStream();
handler.serialize(repo.getUserMarkupCollection(umcRef), sd, teiDocOut);
byte[] umcContent = teiDocOut.toByteArray();
String umcEntryName = getUmcEntryName(exportName, umc, sd);
TarArchiveEntry umcEntry = new TarArchiveEntry(umcEntryName);
umcEntry.setSize(umcContent.length);
taOut.putArchiveEntry(umcEntry);
taOut.write(umcContent);
taOut.closeArchiveEntry();
}
}
} finally {
taOut.finish();
taOut.close();
}
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class ProjectResourceExportApiRequestHandler method serializeProjectResources.
private String serializeProjectResources() {
try {
Export export = new Export();
for (SourceDocument sourceDocument : project.getSourceDocuments()) {
ArrayList<AnnotationCollection> annotationCollections = new ArrayList<>();
for (AnnotationCollectionReference annotationCollectionReference : sourceDocument.getUserMarkupCollectionRefs()) {
annotationCollections.add(project.getUserMarkupCollection(annotationCollectionReference));
}
ArrayList<TagDefinition> tagDefinitions = new ArrayList<>();
ArrayList<TagReference> tagReferences = new ArrayList<>();
for (AnnotationCollection annotationCollection : annotationCollections) {
for (TagsetDefinition tagsetDefinition : annotationCollection.getTagLibrary().getTagsetDefinitions()) {
tagDefinitions.addAll(tagsetDefinition.stream().collect(Collectors.toList()));
}
tagReferences.addAll(annotationCollection.getTagReferences());
}
ExportDocument exportDocument = new ExportDocument(new PreApiSourceDocument(sourceDocument, String.format("%s%s/doc/%s", BASE_URL, handlerPath.substring(1), sourceDocument.getUuid().toLowerCase())), tagDefinitions.stream().map(PreApiTagDefinition::new).collect(Collectors.toList()), tagReferences.stream().map((TagReference tagReference) -> {
try {
return new PreApiAnnotation(tagReference, tagDefinitions.stream().filter(td -> td.getUuid().equals(tagReference.getTagDefinitionId())).findFirst().get(), sourceDocument);
} catch (IOException e) {
logger.log(Level.WARNING, String.format("Error serializing TagReference: %s", tagReference), e);
return null;
}
}).collect(Collectors.toList()));
export.addExportDocument(exportDocument);
}
return new SerializationHelper<Export>().serialize(export);
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to serialize project resources", e);
return "{\"error\": \"Failed to serialize project resources, please contact CATMA support\"}";
}
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class ProjectView method buildResourceDataProvider.
private TreeDataProvider<Resource> buildResourceDataProvider() throws Exception {
if (project != null) {
TreeData<Resource> treeData = new TreeData<>();
Collection<SourceDocument> srcDocs = project.getSourceDocuments();
Locale locale = Locale.getDefault();
for (SourceDocument srcDoc : srcDocs) {
locale = srcDoc.getSourceContentHandler().getSourceDocumentInfo().getIndexInfoSet().getLocale();
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)) {
treeData.addItem(null, docResource);
List<AnnotationCollectionReference> collections = srcDoc.getUserMarkupCollectionRefs();
List<Resource> readableCollectionResources = collections.stream().filter(collectionRef -> project.hasPermission(project.getRoleForCollection(collectionRef.getId()), RBACPermission.COLLECTION_READ)).map(collectionRef -> new CollectionResource(collectionRef, project.getProjectId(), project.hasPermission(project.getRoleForCollection(collectionRef.getId()), RBACPermission.COLLECTION_WRITE))).collect(Collectors.toList());
if (!collections.isEmpty()) {
treeData.addItems(docResource, readableCollectionResources);
}
}
}
Collator collator = Collator.getInstance(locale);
collator.setStrength(Collator.PRIMARY);
documentGrid.getColumn(DocumentGridColumn.NAME.name()).setComparator((r1, r2) -> collator.compare(r1.getName(), r2.getName()));
tagsetGrid.getColumn(TagsetGridColumn.NAME.name()).setComparator((t1, t2) -> collator.compare(t1.getName(), t2.getName()));
return new TreeDataProvider<>(treeData);
}
return new TreeDataProvider<>(new TreeData<>());
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class ProjectView method handleResourceItemClick.
private void handleResourceItemClick(ItemClick<Resource> itemClickEvent) {
if (itemClickEvent.getMouseEventDetails().isDoubleClick()) {
Resource resource = itemClickEvent.getItem();
@SuppressWarnings("unchecked") TreeDataProvider<Resource> resourceDataProvider = (TreeDataProvider<Resource>) documentGrid.getDataProvider();
Resource root = resourceDataProvider.getTreeData().getParent(resource);
Resource child = null;
if (root == null) {
root = resource;
} else {
child = resource;
}
if (root != null) {
SourceDocument document = ((DocumentResource) root).getDocument();
AnnotationCollectionReference collectionReference = (child == null ? null : ((CollectionResource) child).getCollectionReference());
eventBus.post(new RouteToAnnotateEvent(project, document, collectionReference));
}
}
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class ProjectView method handleEditResources.
private void handleEditResources() {
final Set<Resource> selectedResources = documentGrid.getSelectedItems();
if (selectedResources.isEmpty()) {
Notification.show("Info", "Please select a resource first!", Type.HUMANIZED_MESSAGE);
} else {
final Resource resource = selectedResources.iterator().next();
if (selectedResources.size() > 1) {
documentGridComponent.setSelectionMode(SelectionMode.SINGLE);
}
if (resource.isCollection()) {
final AnnotationCollectionReference collectionRef = ((CollectionResource) selectedResources.iterator().next()).getCollectionReference();
SingleTextInputDialog collectionNameDlg = new SingleTextInputDialog("Edit Collection", "Please enter the new collection name:", new SaveCancelListener<String>() {
@Override
public void savePressed(String result) {
collectionRef.getContentInfoSet().setTitle(result);
try {
project.update(collectionRef, collectionRef.getContentInfoSet());
documentGrid.getDataProvider().refreshItem(resource);
} catch (Exception e) {
errorHandler.showAndLogError("Error updating collection", e);
}
}
});
collectionNameDlg.show();
} else {
final SourceDocument document = ((DocumentResource) selectedResources.iterator().next()).getDocument();
SingleTextInputDialog collectionNameDlg = new SingleTextInputDialog("Edit Document", "Please enter the new document name:", new SaveCancelListener<String>() {
@Override
public void savePressed(String result) {
document.getSourceContentHandler().getSourceDocumentInfo().getContentInfoSet().setTitle(result);
try {
project.update(document, document.getSourceContentHandler().getSourceDocumentInfo().getContentInfoSet());
} catch (Exception e) {
errorHandler.showAndLogError("Error updating document", e);
}
}
});
collectionNameDlg.show();
}
}
}
Aggregations