Search in sources :

Example 1 with GmlInstanceReader

use of eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader in project hale by halestudio.

the class AbstractHandlerTest method loadXMLInstances.

/**
 * Load an instance collection from a GML file.
 *
 * @param schemaLocation the GML application schema location
 * @param xmlLocation the GML file location
 * @param interpolConfig the interpolation configuration
 * @return the instance collection
 * @throws IOException if reading schema or instances failed
 * @throws IOProviderConfigurationException if the I/O providers were not
 *             configured correctly
 */
public static InstanceCollection loadXMLInstances(URI schemaLocation, URI xmlLocation, @Nullable ReaderConfiguration interpolConfig) 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 GmlInstanceReader();
    instanceReader.setSource(new DefaultInputSupplier(xmlLocation));
    instanceReader.setSourceSchema(sourceSchema);
    if (interpolConfig != null) {
        interpolConfig.apply(instanceReader);
    }
    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) 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) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) GmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)

Example 2 with GmlInstanceReader

use of eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader in project hale by halestudio.

the class FilterTest method loadXML.

@Before
public void loadXML() throws Exception {
    if (init == false) {
        SchemaReader reader = new XmlSchemaReader();
        reader.setSharedTypes(null);
        reader.setSource(new DefaultInputSupplier((getClass().getResource("/testdata/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("/testdata/out/transformWrite_ERM_HPW.gml").toURI()));
        instanceReader.setSourceSchema(schema);
        instanceReader.validate();
        report = instanceReader.execute(null);
        assertTrue(report.isSuccess());
        FilterTest.complexinstances = instanceReader.getInstances();
        assertFalse(FilterTest.complexinstances.isEmpty());
        init = true;
    }
}
Also used : XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) ShapeSchemaReader(eu.esdihumboldt.hale.io.shp.reader.internal.ShapeSchemaReader) 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) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) 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) Before(org.junit.Before)

Example 3 with GmlInstanceReader

use of eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader in project hale by halestudio.

the class StreamGmlWriterTest method loadGML.

/**
 * Load GML from a file.
 *
 * @param sourceData the GML file
 * @param schema the schema location
 * @return the features
 * @throws IOException if loading the file fails
 * @throws IOProviderConfigurationException if the instance reader is not
 *             configured correctly
 */
public static InstanceCollection loadGML(URI sourceData, Schema schema) throws IOException, IOProviderConfigurationException {
    InstanceReader instanceReader = new GmlInstanceReader();
    instanceReader.setSource(new DefaultInputSupplier(sourceData));
    instanceReader.setSourceSchema(schema);
    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) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) GmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)

Example 4 with GmlInstanceReader

use of eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader in project hale by halestudio.

the class AbstractHandlerTest method loadXMLInstances.

/**
 * Load an instance collection from a GML file.
 *
 * @param schemaLocation the GML application schema location
 * @param xmlLocation the GML file location
 * @return the instance collection
 * @throws IOException if reading schema or instances failed
 * @throws IOProviderConfigurationException if the I/O providers were not
 *             configured correctly
 */
public static 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 GmlInstanceReader();
    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) SchemaReader(eu.esdihumboldt.hale.common.schema.io.SchemaReader) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) GmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)

Example 5 with GmlInstanceReader

use of eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader 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)

Aggregations

IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)5 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)5 GmlInstanceReader (eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)5 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)4 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)4 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)4 InstanceReader (eu.esdihumboldt.hale.common.instance.io.InstanceReader)3 StreamGmlReader (eu.esdihumboldt.hale.io.gml.reader.internal.StreamGmlReader)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)1 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)1 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)1 ShapeSchemaReader (eu.esdihumboldt.hale.io.shp.reader.internal.ShapeSchemaReader)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1