Search in sources :

Example 1 with CorpusExporter

use of de.catma.document.corpus.CorpusExporter in project catma by forTEXT.

the class CollectionXMLExportStreamSource method getStream.

@Override
public InputStream getStream() {
    final UI ui = UI.getCurrent();
    final Project project = projectSupplier.get();
    final Corpus corpus = new Corpus();
    final Collection<SourceDocument> documents = documentSupplier.get();
    final Collection<AnnotationCollectionReference> collectionReferences = collectionReferenceSupplier.get();
    try {
        Set<String> documentIds = documents.stream().map(doc -> doc.getUuid()).collect(Collectors.toSet());
        collectionReferences.stream().forEach(ref -> documentIds.add(ref.getSourceDocumentId()));
        for (String documentId : documentIds) {
            corpus.addSourceDocument(project.getSourceDocument(documentId));
        }
        if (corpus.getSourceDocuments().size() == 0) {
            return null;
        }
        collectionReferences.forEach(ref -> corpus.addUserMarkupCollectionReference(ref));
        File tempFile = File.createTempFile(new IDGenerator().generate() + "_AnnotationCollection_Export", "tgz");
        try (FileOutputStream fos = new FileOutputStream(tempFile)) {
            new CorpusExporter(project, true).export(project.getName(), corpus, fos);
        }
        return new FileInputStream(tempFile);
    } catch (Exception e) {
        ((ErrorHandler) ui).showAndLogError("Error exporting Documents and Collections!", e);
    }
    return null;
}
Also used : CorpusExporter(de.catma.document.corpus.CorpusExporter) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) Collection(java.util.Collection) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) FileInputStream(java.io.FileInputStream) SourceDocument(de.catma.document.source.SourceDocument) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) File(java.io.File) Corpus(de.catma.document.corpus.Corpus) ErrorHandler(de.catma.ui.module.main.ErrorHandler) IDGenerator(de.catma.util.IDGenerator) InputStream(java.io.InputStream) StreamSource(com.vaadin.server.StreamResource.StreamSource) SourceDocument(de.catma.document.source.SourceDocument) CorpusExporter(de.catma.document.corpus.CorpusExporter) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Corpus(de.catma.document.corpus.Corpus) FileInputStream(java.io.FileInputStream) Project(de.catma.project.Project) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) File(java.io.File) IDGenerator(de.catma.util.IDGenerator)

Aggregations

StreamSource (com.vaadin.server.StreamResource.StreamSource)1 UI (com.vaadin.ui.UI)1 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)1 Corpus (de.catma.document.corpus.Corpus)1 CorpusExporter (de.catma.document.corpus.CorpusExporter)1 SourceDocument (de.catma.document.source.SourceDocument)1 Project (de.catma.project.Project)1 ErrorHandler (de.catma.ui.module.main.ErrorHandler)1 IDGenerator (de.catma.util.IDGenerator)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 Set (java.util.Set)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1