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);
}
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;
}
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);
}
}
Aggregations