use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace 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.schema.model.impl.DefaultSchemaSpace in project hale by halestudio.
the class AbstractDBTest method readInstances.
/**
* Read instances from the database.
*
* @param schema the source schema
* @return the database instances
*
* @throws Exception if reading the instances fails
*/
protected InstanceCollection readInstances(Schema schema) throws Exception {
JDBCInstanceReader reader = new JDBCInstanceReader();
reader.setSource(new NoStreamInputSupplier(jdbcUri));
reader.setParameter(JDBCInstanceWriter.PARAM_USER, Value.of(dbi.getUser()));
reader.setParameter(JDBCInstanceWriter.PARAM_PASSWORD, Value.of(dbi.getPassword()));
DefaultSchemaSpace sourceSchema = new DefaultSchemaSpace();
sourceSchema.addSchema(schema);
reader.setSourceSchema(sourceSchema);
IOReport report = reader.execute(null);
assertTrue(report.isSuccess());
assertTrue(report.getErrors().isEmpty());
return reader.getInstances();
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace 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;
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace in project hale by halestudio.
the class LoadSchemaAdvisor method getSchema.
/**
* Get the accumulated schemas.
*
* @return the schema space
*/
public SchemaSpace getSchema() {
// TODO cache?
DefaultSchemaSpace dss = new DefaultSchemaSpace();
// add all schemas
for (Schema schema : schemas) {
// load information about mapping relevant types
SchemaIO.loadMappingRelevantTypesConfig(schema, ssid, project);
dss.addSchema(schema);
}
return dss;
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace in project hale by halestudio.
the class AbstractDBTest method writeInstances.
/**
* Write instances to the database.
*
* @param instances the collection of instances
* @param schema the target schema
* @throws Exception if writing the instances fails
*/
protected void writeInstances(InstanceCollection instances, Schema schema) throws Exception {
JDBCInstanceWriter writer = new JDBCInstanceWriter();
writer.setTarget(new NoStreamOutputSupplier(jdbcUri));
writer.setParameter(JDBCInstanceWriter.PARAM_USER, Value.of(dbi.getUser()));
writer.setParameter(JDBCInstanceWriter.PARAM_PASSWORD, Value.of(dbi.getPassword()));
writer.setInstances(instances);
DefaultSchemaSpace targetSchema = new DefaultSchemaSpace();
targetSchema.addSchema(schema);
writer.setTargetSchema(targetSchema);
IOReport report = writer.execute(null);
assertTrue(report.isSuccess());
assertTrue(report.getErrors().isEmpty());
}
Aggregations