Search in sources :

Example 6 with ProjectExportException

use of de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportException 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 7 with ProjectExportException

use of de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportException 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

ProjectExportException (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportException)7 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)6 ExportedProject (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject)5 File (java.io.File)5 IOException (java.io.IOException)5 ZipFile (java.util.zip.ZipFile)3 ProjectExporter (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExporter)2 FormatSupport (de.tudarmstadt.ukp.clarin.webanno.api.format.FormatSupport)2 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)2 WebAnnoTsv3FormatSupport (de.tudarmstadt.ukp.clarin.webanno.tsv.WebAnnoTsv3FormatSupport)2 FileNotFoundException (java.io.FileNotFoundException)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 ProjectExportRequest (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportRequest)1 ExportedTrainingDocument (de.tudarmstadt.ukp.clarin.webanno.automation.service.export.model.ExportedTrainingDocument)1 ExportedSourceDocument (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedSourceDocument)1 Mode (de.tudarmstadt.ukp.clarin.webanno.model.Mode)1 TrainingDocument (de.tudarmstadt.ukp.clarin.webanno.model.TrainingDocument)1 HashMap (java.util.HashMap)1 Pair (org.apache.commons.lang3.tuple.Pair)1