Search in sources :

Example 66 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class ExecTransformation method setupReader.

private void setupReader(URI uri, int index) {
    LocatableInputSupplier<? extends InputStream> sourceIn = new DefaultInputSupplier(uri);
    // create I/O provider
    InstanceReader source = null;
    String customProvider = context.getSourceProviderIds().get(index);
    if (customProvider != null) {
        // use specified provider
        source = HaleIO.createIOProvider(InstanceReader.class, null, customProvider);
        if (source == null) {
            fail("Could not find instance reader with ID " + customProvider);
        }
    }
    if (source == null) {
        // find applicable reader
        source = HaleIO.findIOProvider(InstanceReader.class, sourceIn, uri.getPath());
    }
    if (source == null) {
        throw fail("Could not determine instance reader to use for source data");
    }
    // apply custom settings
    source.loadConfiguration(context.getSourcesSettings().get(index));
    source.setSource(sourceIn);
    // source schema is set in Transformation.transform
    // CRS provider is set in headless transformation
    sources.add(source);
}
Also used : InstanceReader(eu.esdihumboldt.hale.common.instance.io.InstanceReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)

Example 67 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class TestUtil method loadInstances.

/**
 * Loads an instance collection from the specified XML file with the given
 * source types.
 *
 * @param location the URI specifying the location of the xml instance file
 * @param types the type index
 * @return the loaded instance collection
 * @throws IOException if loading the instance failed
 * @throws IOProviderConfigurationException if configuring the instance
 *             reader failed
 */
public static InstanceCollection loadInstances(URI location, Schema types) throws IOProviderConfigurationException, IOException {
    DefaultInputSupplier input = new DefaultInputSupplier(location);
    XmlInstanceReader instanceReader = new XmlInstanceReader();
    instanceReader.setSource(input);
    instanceReader.setSourceSchema(types);
    IOReport report = instanceReader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue("Errors are contained in the report", report.getErrors().isEmpty());
    return instanceReader.getInstances();
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) XmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.XmlInstanceReader) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 68 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class TestUtil method loadSchema.

/**
 * Loads the specified XML Schema.
 *
 * @param location the URI specifying the location of the schema
 * @return the loaded schema
 * @throws IOProviderConfigurationException if the schema reader
 *             configuration failed
 * @throws IOException if the schema could not be loaded
 */
public static Schema loadSchema(URI location) throws IOProviderConfigurationException, IOException {
    DefaultInputSupplier input = new DefaultInputSupplier(location);
    XmlSchemaReader reader = new XmlSchemaReader();
    reader.setSharedTypes(new DefaultTypeIndex());
    reader.setSource(input);
    reader.validate();
    IOReport report = reader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue("Errors are contained in the report", report.getErrors().isEmpty());
    return reader.getSchema();
}
Also used : DefaultTypeIndex(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeIndex) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 69 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class PropertyResolverTest method testComplexInstances.

/**
 * Test with complex instances.
 *
 * @throws Exception if an error occurs
 */
@Ignore
public void testComplexInstances() throws Exception {
    SchemaReader reader = new XmlSchemaReader();
    reader.setSharedTypes(null);
    reader.setSource(new DefaultInputSupplier((getClass().getResource("/data/erm/inspire3/HydroPhysicalWaters.xsd").toURI())));
    IOReport report = reader.execute(null);
    assertTrue(report.isSuccess());
    Schema schema = reader.getSchema();
    StreamGmlReader instanceReader = new GmlInstanceReader();
    instanceReader.setSource(new DefaultInputSupplier(getClass().getResource("/data/out/transformWrite_ERM_HPW.gml").toURI()));
    instanceReader.setSourceSchema(schema);
    instanceReader.validate();
    report = instanceReader.execute(null);
    assertTrue(report.isSuccess());
    InstanceCollection instances = instanceReader.getInstances();
    assertFalse(instances.isEmpty());
    ResourceIterator<Instance> ri = instances.iterator();
    try {
        Instance instance = ri.next();
        assertTrue(PropertyResolver.hasProperty(instance, "description"));
        assertTrue(PropertyResolver.hasProperty(instance, "{http://www.opengis.net/gml/3.2}description"));
        assertTrue(PropertyResolver.hasProperty(instance, "boundedBy.Envelope.coordinates"));
        assertTrue(PropertyResolver.hasProperty(instance, "boundedBy.Envelope.{http://www.opengis.net/gml/3.2}coordinates"));
        assertTrue(PropertyResolver.hasProperty(instance, "{http://www.opengis.net/gml/3.2}boundedBy.{http://www.opengis.net/gml/3.2}Envelope.{http://www.opengis.net/gml/3.2}coordinates"));
        assertFalse(PropertyResolver.hasProperty(instance, "boundedBy.Envelope.{http://www.opengis.net/gml/3.2}coordinates.description"));
        assertTrue(PropertyResolver.hasProperty(instance, "location.AbstractSolid.id"));
        assertTrue(PropertyResolver.hasProperty(instance, "location.CompositeCurve.curveMember.CompositeCurve.curveMember.type"));
        assertTrue(PropertyResolver.hasProperty(instance, "{http://www.opengis.net/gml/3.2}location.{http://www.opengis.net/gml/3.2}CompositeCurve.{http://www.opengis.net/gml/3.2}curveMember.{http://www.opengis.net/gml/3.2}CompositeCurve.{http://www.opengis.net/gml/3.2}curveMember.type"));
        assertTrue(PropertyResolver.hasProperty(instance, "{http://www.opengis.net/gml/3.2}location.CompositeCurve.{http://www.opengis.net/gml/3.2}curveMember.{http://www.opengis.net/gml/3.2}CompositeCurve.curveMember.type"));
        assertEquals("EPSG:4326", PropertyResolver.getValues(instance, "geometry.Polygon.srsName").iterator().next().toString());
    // TODO
    } finally {
        ri.close();
    }
}
Also used : XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) SchemaReader(eu.esdihumboldt.hale.common.schema.io.SchemaReader) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) StreamGmlReader(eu.esdihumboldt.hale.io.gml.reader.internal.StreamGmlReader) GmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader) Ignore(org.junit.Ignore)

Example 70 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class PropertyResolverTest method loadXMLInstances.

private InstanceCollection loadXMLInstances(URI schemaLocation, URI xmlLocation) throws IOException, IOProviderConfigurationException {
    SchemaReader reader = new XmlSchemaReader();
    reader.setSharedTypes(null);
    reader.setSource(new DefaultInputSupplier(schemaLocation));
    IOReport schemaReport = reader.execute(null);
    assertTrue(schemaReport.isSuccess());
    Schema sourceSchema = reader.getSchema();
    // 
    InstanceReader instanceReader = new XmlInstanceReader();
    instanceReader.setParameter(XmlInstanceReader.PARAM_IGNORE_ROOT, Value.of(false));
    instanceReader.setSource(new DefaultInputSupplier(xmlLocation));
    instanceReader.setSourceSchema(sourceSchema);
    IOReport instanceReport = instanceReader.execute(null);
    assertTrue(instanceReport.isSuccess());
    return instanceReader.getInstances();
}
Also used : InstanceReader(eu.esdihumboldt.hale.common.instance.io.InstanceReader) GmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader) XmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.XmlInstanceReader) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) SchemaReader(eu.esdihumboldt.hale.common.schema.io.SchemaReader) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) XmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.XmlInstanceReader) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Aggregations

DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)73 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)34 URI (java.net.URI)30 Test (org.junit.Test)21 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)15 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)15 IOException (java.io.IOException)13 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)11 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)11 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)10 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)10 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)10 QName (javax.xml.namespace.QName)10 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)9 InstanceReader (eu.esdihumboldt.hale.common.instance.io.InstanceReader)7 CSVSchemaReader (eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader)7 GmlInstanceReader (eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)7 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)6 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)6 File (java.io.File)6