use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier 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.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class InstanceExportWizard method performValidation.
/**
* Run the configured validators on the exported instance. May be overriden
* to customize validation process.
*
* @return true if all validations were successful
*/
protected boolean performValidation() {
boolean success = true;
for (InstanceValidator validator : validators) {
// set schemas
List<? extends Locatable> schemas = getProvider().getValidationSchemas();
validator.setSchemas(schemas.toArray(new Locatable[schemas.size()]));
// set service provider
validator.setServiceProvider(HaleUI.getServiceProvider());
ExportTarget<?> exportTarget = getSelectTargetPage().getExportTarget();
if (exportTarget instanceof FileTarget) {
LocatableOutputSupplier<? extends OutputStream> target = getProvider().getTarget();
List<String> fileNames = new ArrayList<>();
if (target instanceof MultiLocationOutputSupplier) {
for (URI location : ((MultiLocationOutputSupplier) target).getLocations()) {
if (!"file".equals(location.getScheme())) {
continue;
}
File targetFile = new File(location);
fileNames.add(targetFile.getAbsolutePath());
}
} else {
fileNames.add(((FileTarget<?>) exportTarget).getTargetFileName());
}
for (String fileName : fileNames) {
LocatableInputSupplier<? extends InputStream> source = new FileIOSupplier(new File(fileName));
validator.setSource(source);
validator.setContentType(getContentType());
IOReporter defReport = validator.createReporter();
// validate and execute provider
try {
// validate configuration
validator.validate();
IOReport report = execute(validator, defReport);
if (report != null) {
// add report to report server
ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
repService.addReport(report);
if (report.isSuccess()) {
log.info(report.getSummary());
} else {
log.error(report.getSummary());
success = false;
}
}
} catch (IOProviderConfigurationException e) {
log.error(MessageFormat.format("The validator '{0}' could not be executed", validator.getClass().getCanonicalName()), e);
success = false;
}
}
} else {
log.error("No input can be provided for validation (no file target)");
success = false;
}
}
if (success) {
log.userInfo("All validations completed successfully.");
} else {
log.userError("There were validation failures. Please check the report for more details.");
}
return success;
}
use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class FileSource method getSource.
/**
* @see AbstractProviderSource#getSource()
*/
@Override
protected LocatableInputSupplier<? extends InputStream> getSource() {
File file = new File(sourceFile.getStringValue());
if (file.isAbsolute())
return new FileIOSupplier(file);
else {
URI relativeURI = IOUtils.relativeFileToURI(file);
File absoluteFile = new File(projectLocation.resolve(relativeURI));
return new FileIOSupplier(absoluteFile, relativeURI);
}
}
use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class FileTarget method updateConfiguration.
@Override
public boolean updateConfiguration(P provider) {
try {
URI uri = new URI(targetFile.getStringValue());
if (!uri.isAbsolute()) {
// was a file
uri = new File(targetFile.getStringValue()).toURI();
}
final URI location = uri;
provider.setTarget(new LocatableOutputSupplier<OutputStream>() {
@Override
public OutputStream getOutput() throws IOException {
File file = new File(location);
return new FileOutputStream(file);
// XXX other URIs unsupported for now
}
@Override
public URI getLocation() {
return location;
}
});
return true;
} catch (URISyntaxException e) {
// ignore, assume it's a file
}
File file = new File(targetFile.getStringValue());
provider.setTarget(new FileIOSupplier(file));
return true;
}
Aggregations