Search in sources :

Example 1 with DefaultSchemaSpace

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());
}
Also used : DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) File(java.io.File) SpatiaLiteInstanceWriter(eu.esdihumboldt.hale.io.jdbc.spatialite.writer.internal.SpatiaLiteInstanceWriter)

Example 2 with DefaultSchemaSpace

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();
}
Also used : JDBCInstanceReader(eu.esdihumboldt.hale.io.jdbc.JDBCInstanceReader) DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) NoStreamInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier)

Example 3 with DefaultSchemaSpace

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;
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) ArrayList(java.util.ArrayList) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) File(java.io.File)

Example 4 with DefaultSchemaSpace

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;
}
Also used : Schema(eu.esdihumboldt.hale.common.schema.model.Schema) DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace)

Example 5 with DefaultSchemaSpace

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());
}
Also used : DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) NoStreamOutputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamOutputSupplier) JDBCInstanceWriter(eu.esdihumboldt.hale.io.jdbc.JDBCInstanceWriter)

Aggregations

DefaultSchemaSpace (eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace)11 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)7 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)4 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)3 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)3 JaxbAlignmentReader (eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentReader)2 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)2 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)2 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)2 File (java.io.File)2 BeforeClass (org.junit.BeforeClass)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 AlignmentReader (eu.esdihumboldt.hale.common.align.io.AlignmentReader)1 AlignmentWriter (eu.esdihumboldt.hale.common.align.io.AlignmentWriter)1