Search in sources :

Example 6 with InstanceWriter

use of eu.esdihumboldt.hale.common.instance.io.InstanceWriter 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());
    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);
            }
        }
    });
    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)

Example 7 with InstanceWriter

use of eu.esdihumboldt.hale.common.instance.io.InstanceWriter in project hale by halestudio.

the class InstanceExportWizard method getFactories.

/**
 * @see IOWizard#getFactories()
 */
@Override
public List<IOProviderDescriptor> getFactories() {
    if (cachedFactories != null) {
        return cachedFactories;
    }
    List<IOProviderDescriptor> providers = super.getFactories();
    IOAdvisor<InstanceWriter> advisor = getAdvisor();
    if (advisor == null) {
        return providers;
    }
    List<IOProviderDescriptor> result = new ArrayList<IOProviderDescriptor>();
    for (IOProviderDescriptor providerFactory : providers) {
        // create a dummy provider
        InstanceWriter provider;
        try {
            provider = (InstanceWriter) providerFactory.createExtensionObject();
        } catch (Exception e) {
            log.error("Error creating an instance writer: " + providerFactory.getIdentifier(), e);
            // ignore this provider as it cannot be created
            continue;
        }
        // assign the basic configuration
        advisor.prepareProvider(provider);
        advisor.updateConfiguration(provider);
        // and check the compatibility
        try {
            provider.checkCompatibility();
            result.add(providerFactory);
        } catch (IOProviderConfigurationException e) {
        // ignore this export provider, it is not compatible
        }
    }
    cachedFactories = result;
    return cachedFactories;
}
Also used : IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) InstanceWriter(eu.esdihumboldt.hale.common.instance.io.InstanceWriter) ArrayList(java.util.ArrayList) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)

Aggregations

InstanceWriter (eu.esdihumboldt.hale.common.instance.io.InstanceWriter)7 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)3 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)3 IOException (java.io.IOException)3 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)2 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)2 InstanceReader (eu.esdihumboldt.hale.common.instance.io.InstanceReader)2 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)2 File (java.io.File)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)1 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)1 Point (com.vividsolutions.jts.geom.Point)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 IOProvider (eu.esdihumboldt.hale.common.core.io.IOProvider)1 AbstractIOAdvisor (eu.esdihumboldt.hale.common.core.io.impl.AbstractIOAdvisor)1 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)1 ProjectTransformationEnvironment (eu.esdihumboldt.hale.common.headless.impl.ProjectTransformationEnvironment)1 ReportFile (eu.esdihumboldt.hale.common.headless.report.ReportFile)1