Search in sources :

Example 11 with ExportedProject

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;
}
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 12 with ExportedProject

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());
}
Also used : ExportedProjectPermission(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProjectPermission) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ExportedProject(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) ProjectPermission(de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission) ExportedProjectPermission(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProjectPermission) ArrayList(java.util.ArrayList)

Example 13 with ExportedProject

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");
        }
    }
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) 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) FileNotFoundException(java.io.FileNotFoundException) ZipFile(java.util.zip.ZipFile) File(java.io.File) ProjectExportException(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportException)

Example 14 with ExportedProject

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");
        }
    }
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ExportedProject(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject) FileNotFoundException(java.io.FileNotFoundException) ZipFile(java.util.zip.ZipFile) File(java.io.File) ProjectExportException(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportException) ExportedTrainingDocument(de.tudarmstadt.ukp.clarin.webanno.automation.service.export.model.ExportedTrainingDocument) TrainingDocument(de.tudarmstadt.ukp.clarin.webanno.model.TrainingDocument)

Aggregations

ExportedProject (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject)14 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)8 ZipFile (java.util.zip.ZipFile)8 File (java.io.File)7 ProjectExportException (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportException)5 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)5 IOException (java.io.IOException)5 ProjectImportRequest (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectImportRequest)4 ArrayList (java.util.ArrayList)4 Pair (org.apache.commons.lang3.tuple.Pair)4 ProjectExporter (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExporter)3 ProjectExportRequest (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportRequest)2 ProjectExportTaskMonitor (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskMonitor)2 FormatSupport (de.tudarmstadt.ukp.clarin.webanno.api.format.FormatSupport)2 ExportedSourceDocument (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedSourceDocument)2 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)2 WebAnnoTsv3FormatSupport (de.tudarmstadt.ukp.clarin.webanno.tsv.WebAnnoTsv3FormatSupport)2 FileNotFoundException (java.io.FileNotFoundException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2