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;
}
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;
}
Aggregations