use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class SpatiaLiteTestSuite method writeInstances.
/**
* Writes the provided instances to a SpatiaLite database.
*
* @param schema the target schema
* @param targetFilePath the path to the target database file
* @param instances the instances to write
* @throws Exception any exception thrown by
* {@link SpatiaLiteInstanceWriter}
*/
public void writeInstances(Schema schema, String targetFilePath, InstanceCollection instances) throws Exception {
SpatiaLiteInstanceWriter instanceWriter = new SpatiaLiteInstanceWriter();
instanceWriter.setInstances(instances);
DefaultSchemaSpace ss = new DefaultSchemaSpace();
ss.addSchema(schema);
instanceWriter.setTargetSchema(ss);
instanceWriter.setTarget(new FileIOSupplier(new File(targetFilePath)));
// Test instances
IOReport report = instanceWriter.execute(new LogProgressIndicator());
assertTrue("Data export was not successfull.", report.isSuccess());
}
use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class SpatiaLiteTestSuite method readSchema.
/**
* Reads a schema from a SpatiaLite database file.
*
* @param sourceFilePath the path to the source database file
* @return the schema
* @throws Exception any exception thrown by {@link SpatiaLiteSchemaReader}
*/
public Schema readSchema(String sourceFilePath) throws Exception {
SpatiaLiteSchemaReader schemaReader = new SpatiaLiteSchemaReader();
schemaReader.setSource(new FileIOSupplier(new File(sourceFilePath)));
IOReport report = schemaReader.execute(new LogProgressIndicator());
assertTrue(report.isSuccess());
return schemaReader.getSchema();
}
use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class SpatiaLiteTestSuite method readInstances.
/**
* Reads instances from from a SpatiaLite database file with the provided
* schema.
*
* @param sourceSchema the schema of the source database
* @param sourceFilePath the path to the source database file
* @return the read instances
* @throws Exception any exception thrown by
* {@link SpatiaLiteInstanceReader}
*/
public InstanceCollection readInstances(Schema sourceSchema, String sourceFilePath) throws Exception {
SpatiaLiteInstanceReader instanceReader = new SpatiaLiteInstanceReader();
instanceReader.setSource(new FileIOSupplier(new File(sourceFilePath)));
instanceReader.setSourceSchema(sourceSchema);
// Test instances
IOReport report = instanceReader.execute(new LogProgressIndicator());
assertTrue("Data import was not successfull.", report.isSuccess());
return instanceReader.getInstances();
}
use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class ProjectServiceImpl method save.
/**
* @see ProjectService#save()
*/
@Override
public void save() {
File projectFile;
IOConfiguration saveConfig;
synchronized (this) {
projectFile = this.projectFile;
saveConfig = main.getSaveConfiguration();
}
if (projectFile != null || canSaveTo(projectLocation)) {
Collection<IOProviderDescriptor> providers = HaleIO.getProviderFactories(ProjectWriter.class);
// use configuration from previous save if possible
if (saveConfig != null) {
// get provider ...
ProjectWriter writer = null;
for (IOProviderDescriptor factory : providers) {
if (factory.getIdentifier().equals(saveConfig.getProviderId())) {
/*
* Check if the content type the project was loaded with
* is supported for saving.
*
* Example for a changed content type: A saved project
* archive may have been extracted and the internal XML
* project file loaded.
*/
if (projectLoadContentType != null) {
if (factory.getSupportedTypes() == null || !factory.getSupportedTypes().contains(projectLoadContentType)) {
log.warn("Project cannot be saved with the same settings it was originally saved with, as the content type has changed.");
break;
}
}
try {
writer = (ProjectWriter) factory.createExtensionObject();
} catch (Exception e) {
log.error("Could not create project writer", e);
}
}
}
if (writer != null) {
// configure provider
writer.loadConfiguration(saveConfig.getProviderConfiguration());
// moved externally)
if (projectFile != null) {
writer.setTarget(new FileIOSupplier(projectFile));
} else {
writer.setTarget(new NoStreamOutputSupplier(projectLocation));
}
ListenableFuture<IOReport> result = ProjectResourcesUtil.executeProvider(writer, saveProjectAdvisor, true, null);
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
try {
IOReport report = result.get();
if (!report.isSuccess()) {
log.userError("The project could not be saved. Please check the report for more details.");
}
} catch (InterruptedException | ExecutionException e) {
log.userError("The project could not be saved.", e);
}
}
});
} else {
log.info("The project cannot be saved because the format the project was saved with is not available or has changed.");
// use save as instead
saveAs();
}
} else if (projectFile != null) {
// use I/O provider and content type mechanisms to try saving
// the project file
ProjectWriter writer = HaleIO.findIOProvider(ProjectWriter.class, new FileIOSupplier(projectFile), projectFile.getAbsolutePath());
if (writer != null) {
ProjectResourcesUtil.executeProvider(writer, saveProjectAdvisor, null);
} else {
log.error("The project cannot be saved because the format is not available.");
// use save as instead
saveAs();
}
} else {
saveAs();
}
} else {
saveAs();
}
}
use of eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier in project hale by halestudio.
the class XsltTransformationTest method transformData.
@Override
protected List<Instance> transformData(TransformationExample example) throws Exception {
// export alignment to XSLT
XsltExport export = new XsltExport();
export.setAlignment(example.getAlignment());
export.setSourceSchema(new DefaultSchemaSpace().addSchema(example.getSourceSchema()));
export.setTargetSchema(new DefaultSchemaSpace().addSchema(example.getTargetSchema()));
export.setParameter(XsltExport.PARAM_ROOT_ELEMENT_NAMESPACE, Value.of(example.getTargetContainerNamespace()));
export.setParameter(XsltExport.PARAM_ROOT_ELEMENT_NAME, Value.of(example.getTargetContainerName()));
File tempXsltFile = File.createTempFile("xsltest", ".xsl");
export.setTarget(new FileIOSupplier(tempXsltFile));
IOReport res = export.execute(new LogProgressIndicator());
assertTrue("XSLT export not successful", res.isSuccess());
assertTrue("Errors during XSLT export", res.getErrors().isEmpty());
// invoke XSLT on source file to produce target
File target = File.createTempFile("xsltest", ".xml");
executeXslt(example.getSourceDataInput(), tempXsltFile, target);
// load target and return instances
InstanceCollection instances = TestUtil.loadInstances(target.toURI(), example.getTargetSchema());
List<Instance> list = new ArrayList<Instance>();
ResourceIterator<Instance> it = instances.iterator();
try {
while (it.hasNext()) {
list.add(it.next());
}
} finally {
it.close();
}
// clean up
tempXsltFile.delete();
target.delete();
return list;
}
Aggregations