use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject 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.ExportedProject in project webanno by webanno.
the class PermissionsExporter method exportData.
@Override
public void exportData(ProjectExportRequest aRequest, ProjectExportTaskMonitor aMonitor, ExportedProject aExProject, File aStage) throws Exception {
Project project = aRequest.getProject();
// add project permissions to the project
List<ExportedProjectPermission> projectPermissions = new ArrayList<>();
for (User user : projectService.listProjectUsersWithPermissions(project)) {
for (ProjectPermission permission : projectService.listProjectPermissionLevel(user, project)) {
ExportedProjectPermission permissionToExport = new ExportedProjectPermission();
permissionToExport.setLevel(permission.getLevel());
permissionToExport.setUser(user.getUsername());
projectPermissions.add(permissionToExport);
}
}
aExProject.setProjectPermissions(projectPermissions);
LOG.info("Exported [{}] permissions for project [{}]", projectPermissions.size(), aRequest.getProject().getName());
}
use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject in project webanno by webanno.
the class SourceDocumentExporter method exportSourceDocumentContents.
private void exportSourceDocumentContents(ProjectExportRequest aRequest, ProjectExportTaskMonitor aMonitor, ExportedProject aExProject, File aStage) throws IOException, ProjectExportException {
Project project = aRequest.getProject();
File sourceDocumentDir = new File(aStage, SOURCE_FOLDER);
FileUtils.forceMkdir(sourceDocumentDir);
// Get all the source documents from the project
List<SourceDocument> documents = documentService.listSourceDocuments(project);
int i = 1;
for (SourceDocument sourceDocument : documents) {
try {
FileUtils.copyFileToDirectory(documentService.getSourceDocumentFile(sourceDocument), sourceDocumentDir);
aMonitor.setProgress((int) Math.ceil(((double) i) / documents.size() * 10.0));
i++;
log.info("Exported content for source document [" + sourceDocument.getId() + "] in project [" + project.getName() + "] with id [" + project.getId() + "]");
} catch (FileNotFoundException e) {
log.error("Source file [{}] related to project couldn't be located in repository", sourceDocument.getName(), ExceptionUtils.getRootCause(e));
aMonitor.addMessage(LogMessage.error(this, "Source file [%s] related to project couldn't be located in repository", sourceDocument.getName()));
throw new ProjectExportException("Couldn't find some source file(s) related to project");
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject in project webanno by webanno.
the class AutomationTrainingDocumentExporter method exportTrainingDocumentContents.
private void exportTrainingDocumentContents(ProjectExportRequest aRequest, ProjectExportTaskMonitor aMonitor, ExportedProject aExProject, File aCopyDir) throws IOException, ProjectExportException {
Project project = aRequest.getProject();
File trainDocumentDir = new File(aCopyDir + TRAIN_FOLDER);
FileUtils.forceMkdir(trainDocumentDir);
// Get all the training documents from the project
List<TrainingDocument> documents = automationService.listTrainingDocuments(project);
int i = 1;
for (TrainingDocument trainingDocument : documents) {
try {
FileUtils.copyFileToDirectory(automationService.getTrainingDocumentFile(trainingDocument), trainDocumentDir);
aMonitor.setProgress((int) Math.ceil(((double) i) / documents.size() * 10.0));
i++;
log.info("Imported content for training document [" + trainingDocument.getId() + "] in project [" + project.getName() + "] with id [" + project.getId() + "]");
} catch (FileNotFoundException e) {
log.error("Source file [{}] related to project couldn't be located in repository", trainingDocument.getName(), ExceptionUtils.getRootCause(e));
aMonitor.addMessage(LogMessage.error(this, "Source file [%s] related to project couldn't be located in repository", trainingDocument.getName()));
throw new ProjectExportException("Couldn't find some source file(s) related to project");
}
}
}
Aggregations