Search in sources :

Example 1 with ReportFile

use of eu.esdihumboldt.hale.common.headless.report.ReportFile in project hale by halestudio.

the class TemplateProject method onSuccess.

@Override
protected void onSuccess(Void context, String projectId, File projectFile, Project project, ReportFile reportFile) {
    super.onSuccess(context, projectId, projectFile, project, reportFile);
    // update locations in project file
    LocationUpdater updater = new LocationUpdater(project, projectFile.toURI());
    updater.updateProject(false);
    resources.clear();
    List<Path> invalidSources = new ArrayList<>();
    Path projectFolder = getProjectFolder().toPath();
    // validate resources
    for (IOConfiguration config : project.getResources()) {
        Resource resource = new IOConfigurationResource(config, getProjectFile().toURI());
        // check if file URIs are valid and inside project folder
        URI source = resource.getSource();
        if (source != null) {
            Path path = null;
            if (source.getScheme() == null) {
                // is a relative URI
                path = projectFile.toPath().resolve(source.toString()).normalize();
            } else if ("file".equals(source.getScheme())) {
                // is a file URI
                path = Paths.get(source).normalize();
            }
            if (path != null) {
                if (!path.startsWith(projectFolder) || !Files.exists(path)) {
                    // invalid source
                    invalidSources.add(path);
                }
            }
        }
        resources.put(resource.getActionId(), resource);
    }
    valid = invalidSources.isEmpty();
    if (!valid) {
        StringBuilder builder = new StringBuilder("Files referenced by the project could not be found: ");
        for (int i = 0; i < invalidSources.size(); i++) {
            if (i > 0)
                builder.append(", ");
            Path path = invalidSources.get(i);
            builder.append(path.getFileName().toString());
        }
        notValidMessage = builder.toString();
    } else {
        notValidMessage = "";
    }
    // additionally, try to find out cell count
    definedRelations = 0;
    // check if default alignment file exists
    try {
        File defAlignmentFile = new File(URI.create(projectFile.toURI().toASCIIString() + "." + AlignmentIO.PROJECT_FILE_ALIGNMENT));
        if (defAlignmentFile.exists()) {
            try (InputStream in = new BufferedInputStream(new FileInputStream(defAlignmentFile))) {
                /*
					 * Try loading the file with JAXB - only supports 2.6+
					 * projects.
					 */
                AlignmentType alignment = JaxbToAlignment.load(in, null);
                // XXX ignoring base alignments
                int count = 0;
                for (Object element : alignment.getCellOrModifier()) {
                    if (element instanceof CellType) {
                        count++;
                    }
                }
                definedRelations = count;
            } catch (Exception e) {
            // ignore
            }
        }
    } catch (Exception e) {
    // ignore
    }
}
Also used : Path(java.nio.file.Path) LocationUpdater(eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOConfigurationResource(eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) IOConfigurationResource(eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource) URI(java.net.URI) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) AlignmentType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType) BufferedInputStream(java.io.BufferedInputStream) CellType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType) ReportFile(eu.esdihumboldt.hale.common.headless.report.ReportFile) File(java.io.File)

Example 2 with ReportFile

use of eu.esdihumboldt.hale.common.headless.report.ReportFile in project hale by halestudio.

the class ProjectReference method update.

/**
 * Updates the project status from the configuration and if needed loads the
 * project and transformation environment and adds or removes the
 * transformation environment.
 *
 * @param context the update context
 */
public void update(C context) {
    File projectFile = getProjectFile();
    if (projectFile == null || !projectFile.exists()) {
        // no project file
        // reset any runtime information
        projectInfo = null;
        onNotAvailable(context, projectId);
    } else {
        File reportFile = getLoadReportFile();
        if ((projectInfo == null || isForceClearReports()) && reportFile.exists()) {
            // delete old reports
            reportFile.delete();
        }
        // store reports in file
        ReportFile rf = new ReportFile(reportFile);
        // load project info if not yet done
        if (projectInfo == null) {
            projectInfo = loadProjectInfo(projectFile, rf);
        }
        if (projectInfo == null) {
            // can't load project
            onFailure(context, projectId);
        } else {
            onSuccess(context, projectId, projectFile, projectInfo, rf);
        }
    }
}
Also used : ReportFile(eu.esdihumboldt.hale.common.headless.report.ReportFile) ReportFile(eu.esdihumboldt.hale.common.headless.report.ReportFile) File(java.io.File)

Example 3 with ReportFile

use of eu.esdihumboldt.hale.common.headless.report.ReportFile in project hale by halestudio.

the class ExecTransformation method setupReportHandler.

private void setupReportHandler() {
    final ReportHandler delegateTo;
    if (context.getReportsOut() != null) {
        delegateTo = new ReportFile(context.getReportsOut());
    } else {
        delegateTo = null;
    }
    /*
		 * The report handler writes a summary to std out
		 */
    reportHandler = new ReportHandler() {

        @Override
        public void publishReport(Report<?> report) {
            ExecUtil.printSummary(report);
            if (delegateTo != null) {
                delegateTo.publishReport(report);
            }
        }
    };
}
Also used : ReportFile(eu.esdihumboldt.hale.common.headless.report.ReportFile) ReportHandler(eu.esdihumboldt.hale.common.core.report.ReportHandler)

Example 4 with ReportFile

use of eu.esdihumboldt.hale.common.headless.report.ReportFile in project hale by halestudio.

the class TransformationWorkspace method transform.

/**
 * Transform the instances provided through the given instance readers and
 * by default stores the result in the {@link #getTargetFolder()}.
 *
 * @param env the transformation environment
 * @param sources the instance readers
 * @param target the configuration of the target instance writer
 * @param customTarget the custom output supplier to use for the target,
 *            <code>null</code> to use the default target in thet
 *            {@link #getTargetFolder()}
 * @return the future representing the successful completion of the
 *         transformation (note that a successful completion doesn't
 *         necessary mean there weren't any internal transformation errors)
 * @throws Exception if launching the transformation fails
 */
public ListenableFuture<Boolean> transform(TransformationEnvironment env, List<InstanceReader> sources, IOConfiguration target, LocatableOutputSupplier<? extends OutputStream> customTarget) throws Exception {
    InstanceWriter writer = (InstanceWriter) HeadlessIO.loadProvider(target);
    // output file
    if (customTarget != null) {
        writer.setTarget(customTarget);
    } else {
        File out = new File(targetFolder, "result." + getFileExtension(writer.getContentType()));
        writer.setTarget(new FileIOSupplier(out));
    }
    ListenableFuture<Boolean> result = Transformation.transform(sources, writer, env, new ReportFile(reportFile), workspace.getName(), new DefaultTransformationSettings());
    Futures.addCallback(result, new FutureCallback<Boolean>() {

        @Override
        public void onSuccess(Boolean result) {
            try {
                setTransformationSuccess(result);
            } catch (IOException e) {
                log.error("Failed to set transformation success for workspace", e);
            }
        }

        @Override
        public void onFailure(Throwable t) {
            try {
                setTransformationSuccess(false);
            } catch (IOException e) {
                log.error("Failed to set transformation success for workspace", e);
            }
        }
    }, MoreExecutors.directExecutor());
    return result;
}
Also used : InstanceWriter(eu.esdihumboldt.hale.common.instance.io.InstanceWriter) ReportFile(eu.esdihumboldt.hale.common.headless.report.ReportFile) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) IOException(java.io.IOException) ReportFile(eu.esdihumboldt.hale.common.headless.report.ReportFile) File(java.io.File)

Aggregations

ReportFile (eu.esdihumboldt.hale.common.headless.report.ReportFile)4 File (java.io.File)3 IOException (java.io.IOException)2 AlignmentType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType)1 CellType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType)1 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1 IOConfigurationResource (eu.esdihumboldt.hale.common.core.io.project.model.IOConfigurationResource)1 Resource (eu.esdihumboldt.hale.common.core.io.project.model.Resource)1 LocationUpdater (eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater)1 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)1 ReportHandler (eu.esdihumboldt.hale.common.core.report.ReportHandler)1 InstanceWriter (eu.esdihumboldt.hale.common.instance.io.InstanceWriter)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1