Search in sources :

Example 76 with Instance

use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.

the class PropertyResolverTest method testLoadShiporderWrapped.

/**
 * Test with a wrapper instance that has no definition itself.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testLoadShiporderWrapped() throws Exception {
    InstanceCollection instances = loadXMLInstances(getClass().getResource("/data/shiporder/shiporder.xsd").toURI(), getClass().getResource("/data/shiporder/shiporder.xml").toURI());
    ResourceIterator<Instance> it = instances.iterator();
    try {
        assertTrue(it.hasNext());
        Instance instance = it.next();
        assertNotNull(instance);
        // create dummy instance
        MutableInstance wrapperInstance = new DefaultInstance(null, null);
        wrapperInstance.addProperty(new QName("value"), instance);
        assertEquals(PropertyResolver.getValues(wrapperInstance, "value.shipto.city").iterator().next(), "4000 Stavanger");
    } finally {
        it.close();
    }
}
Also used : 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) QName(javax.xml.namespace.QName) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) Test(org.junit.Test)

Example 77 with Instance

use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.

the class PropertyResolverTest method testLoadShiporder.

/**
 * Test loading a simple XML file with one instance
 *
 * @throws Exception if an error occurs
 */
@Test
public void testLoadShiporder() throws Exception {
    InstanceCollection instances = loadXMLInstances(getClass().getResource("/data/shiporder/shiporder.xsd").toURI(), getClass().getResource("/data/shiporder/shiporder.xml").toURI());
    ResourceIterator<Instance> it = instances.iterator();
    try {
        assertTrue(it.hasNext());
        Instance instance = it.next();
        assertNotNull(instance);
        @SuppressWarnings("unused") TypeDefinition test = instance.getDefinition().getChildren().iterator().next().asProperty().getParentType();
        assertTrue(PropertyResolver.hasProperty(instance, "{http://www.example.com}orderperson"));
        assertTrue(PropertyResolver.hasProperty(instance, "{http://www.example.com}shipto.{http://www.example.com}city"));
        assertTrue(PropertyResolver.getQueryPath(instance, "{http://www.example.com}shipto.{http://www.example.com}city").contains("{http://www.example.com}shipto.{http://www.example.com}city"));
        assertTrue(PropertyResolver.hasProperty(instance, "orderperson"));
        assertTrue(PropertyResolver.hasProperty(instance, "shipto.city"));
        assertTrue(PropertyResolver.hasProperty(instance, "shipto.{http://www.example.com}city"));
        assertEquals(PropertyResolver.getValues(instance, "shipto.city").iterator().next(), "4000 Stavanger");
    } finally {
        it.close();
    }
}
Also used : 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) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Test(org.junit.Test)

Example 78 with Instance

use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.

the class SimplePartitionerTest method testIterate.

private void testIterate(int num, int partSize) {
    InstanceCollection c1 = createCollection(num);
    assertEquals(num, c1.size());
    try (ResourceIterator<InstanceCollection> it = new SimplePartitioner().partition(c1, partSize, SimpleLog.CONSOLE_LOG)) {
        int count = 0;
        while (it.hasNext()) {
            InstanceCollection part = it.next();
            try (ResourceIterator<Instance> partIt = part.iterator()) {
                while (partIt.hasNext()) {
                    Instance instance = partIt.next();
                    assertNotNull(instance);
                    count++;
                }
            }
        }
        assertEquals(num, count);
    }
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) DefaultInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstanceCollection)

Example 79 with Instance

use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.

the class SimplePartitionerTest method createCollection.

static InstanceCollection createCollection(int num) {
    Collection<Instance> instances = new ArrayList<>();
    for (int i = 0; i < num; i++) {
        instances.add(new DefaultInstance(null, null));
    }
    InstanceCollection res = new DefaultInstanceCollection(instances);
    return res;
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) DefaultInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstanceCollection) ArrayList(java.util.ArrayList) DefaultInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstanceCollection)

Example 80 with Instance

use of eu.esdihumboldt.hale.common.instance.model.Instance in project hale by halestudio.

the class GeometryUtil method getGeometryProperties.

/**
 * Try to get/create geometry properties from a property value.
 *
 * @param value the property value, e.g. a {@link Geometry},
 *            {@link GeometryProperty}, a {@link Collection} or
 *            {@link Instance}
 * @return the geometry properties or an empty list if none could be created
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Collection<GeometryProperty<?>> getGeometryProperties(Object value) {
    if (value instanceof Instance) {
        value = ((Instance) value).getValue();
    }
    if (value != null) {
        Collection<GeometryProperty<?>> result = new ArrayList<GeometryProperty<?>>();
        if (value instanceof GeometryProperty) {
            // return the encountered GeometryProperty
            result.add((GeometryProperty) value);
        }
        if (value instanceof Geometry) {
            // create a GeometryProperty wrapping the geometry
            // XXX any way to determine a CRS?
            GeometryProperty prop = new DefaultGeometryProperty(null, (Geometry) value);
            result.add(prop);
        }
        if (value instanceof Collection<?>) {
            // add results from collection values
            for (Object subValue : ((Iterable<?>) value)) {
                result.addAll(getGeometryProperties(subValue));
            }
        }
        return result;
    }
    return Collections.emptyList();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Aggregations

Instance (eu.esdihumboldt.hale.common.instance.model.Instance)203 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)131 Test (org.junit.Test)122 AbstractHandlerTest (eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest)97 QName (javax.xml.namespace.QName)29 ArrayList (java.util.ArrayList)26 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)25 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)23 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)22 Group (eu.esdihumboldt.hale.common.instance.model.Group)15 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)13 Coordinate (com.vividsolutions.jts.geom.Coordinate)12 Geometry (com.vividsolutions.jts.geom.Geometry)12 FamilyInstance (eu.esdihumboldt.hale.common.instance.model.FamilyInstance)10 Polygon (com.vividsolutions.jts.geom.Polygon)9 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)8 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)8 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)8 HashSet (java.util.HashSet)8 Point (com.vividsolutions.jts.geom.Point)7