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();
}
}
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();
}
}
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);
}
}
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;
}
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();
}
Aggregations