Search in sources :

Example 1 with ExportedSourceDocument

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedSourceDocument in project webanno by webanno.

the class SourceDocumentExporter method exportSourceDocuments.

private void exportSourceDocuments(Project aProject, ExportedProject exProject) {
    List<ExportedSourceDocument> sourceDocuments = new ArrayList<>();
    // add source documents to a project
    List<SourceDocument> documents = documentService.listSourceDocuments(aProject);
    for (SourceDocument sourceDocument : documents) {
        ExportedSourceDocument exDocument = new ExportedSourceDocument();
        exDocument.setFormat(sourceDocument.getFormat());
        exDocument.setName(sourceDocument.getName());
        exDocument.setState(sourceDocument.getState());
        exDocument.setTimestamp(sourceDocument.getTimestamp());
        exDocument.setSentenceAccessed(sourceDocument.getSentenceAccessed());
        exDocument.setCreated(sourceDocument.getCreated());
        exDocument.setUpdated(sourceDocument.getUpdated());
        sourceDocuments.add(exDocument);
    }
    exProject.setSourceDocuments(sourceDocuments);
}
Also used : ExportedSourceDocument(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedSourceDocument) ArrayList(java.util.ArrayList) ExportedSourceDocument(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedSourceDocument) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)

Example 2 with ExportedSourceDocument

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedSourceDocument in project webanno by webanno.

the class AnnotationDocumentsExporterTest method runImportAndFetchDocuments.

private List<Pair<SourceDocument, String>> runImportAndFetchDocuments(ZipFile aZipFile) throws Exception {
    // Import the project again
    ExportedProject exProject = ProjectExportServiceImpl.loadExportedProject(aZipFile);
    // Provide source documents based on data in the exported project
    when(documentService.listSourceDocuments(any())).then(invocation -> {
        long i = 1;
        List<SourceDocument> docs = new ArrayList<>();
        for (ExportedSourceDocument exDoc : exProject.getSourceDocuments()) {
            SourceDocument doc = new SourceDocument();
            doc.setId(i++);
            doc.setName(exDoc.getName());
            doc.setProject(project);
            docs.add(doc);
        }
        return docs;
    });
    ProjectImportRequest importRequest = new ProjectImportRequest(true);
    sut.importData(importRequest, project, exProject, aZipFile);
    List<Pair<SourceDocument, String>> importedCases = new ArrayList<>();
    for (SourceDocument doc : documentService.listSourceDocuments(project)) {
        File annFolder = casStorageService.getAnnotationFolder(doc);
        for (File serFile : annFolder.listFiles((dir, name) -> name.endsWith(".ser"))) {
            importedCases.add(Pair.of(doc, removeExtension(serFile.getName())));
        }
    }
    return importedCases;
}
Also used : ExportedSourceDocument(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedSourceDocument) ExportedProject(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject) ExportedSourceDocument(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedSourceDocument) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) ZipFile(java.util.zip.ZipFile) File(java.io.File) ProjectImportRequest(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectImportRequest) Pair(org.apache.commons.lang3.tuple.Pair)

Example 3 with ExportedSourceDocument

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedSourceDocument in project webanno by webanno.

the class SourceDocumentExporter method importSourceDocuments.

/**
 * Create s {@link SourceDocument} from the exported {@link SourceDocument}
 *
 * @param aImportedProjectSetting
 *            the exported project.
 * @param aImportedProject
 *            the project.
 * @throws IOException
 *             if an I/O error occurs.
 */
private void importSourceDocuments(ExportedProject aImportedProjectSetting, Project aImportedProject) throws IOException {
    for (ExportedSourceDocument importedSourceDocument : aImportedProjectSetting.getSourceDocuments()) {
        SourceDocument sourceDocument = new SourceDocument();
        sourceDocument.setFormat(importedSourceDocument.getFormat());
        sourceDocument.setName(importedSourceDocument.getName());
        sourceDocument.setState(importedSourceDocument.getState());
        sourceDocument.setProject(aImportedProject);
        sourceDocument.setTimestamp(importedSourceDocument.getTimestamp());
        sourceDocument.setSentenceAccessed(importedSourceDocument.getSentenceAccessed());
        sourceDocument.setCreated(importedSourceDocument.getCreated());
        sourceDocument.setUpdated(importedSourceDocument.getUpdated());
        documentService.createSourceDocument(sourceDocument);
    }
}
Also used : ExportedSourceDocument(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedSourceDocument) ExportedSourceDocument(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedSourceDocument) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)

Aggregations

ExportedSourceDocument (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedSourceDocument)3 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)3 ArrayList (java.util.ArrayList)2 ProjectImportRequest (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectImportRequest)1 ExportedProject (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject)1 File (java.io.File)1 ZipFile (java.util.zip.ZipFile)1 Pair (org.apache.commons.lang3.tuple.Pair)1