use of eu.esdihumboldt.util.groovy.paths.Path in project hale by halestudio.
the class AbstractGeotoolsFilter method resolveProperty.
/**
* Resolve a property name based on the given context.
*
* @param name the property name
* @param context the entity context
* @param log the operation log
* @return the resolved entity definition if it could be resolved uniquely
*/
private Optional<EntityDefinition> resolveProperty(PropertyName name, EntityDefinition context, SimpleLog log) {
List<QName> path = PropertyResolver.getQNamesFromPath(name.getPropertyName());
EntityAccessor acc = new EntityAccessor(context);
for (QName element : path) {
acc = acc.findChildren(element);
}
try {
return Optional.ofNullable(acc.toEntityDefinition());
} catch (IllegalStateException e) {
List<? extends Path<PathElement>> candidates = acc.all();
if (candidates.isEmpty()) {
log.error("Unable to find reference to {0}", name);
return Optional.empty();
} else {
log.warn("Could not find unique reference to {0}, trying first match", name);
Path<PathElement> selected = candidates.get(0);
/*
* XXX dirty hack to work around conditions in AdV
* GeographicalNames alignment not being defined properly
*/
if (candidates.size() > 1) {
// prefer next candidate if this one is name in gml
// namespace
List<PathElement> elements = selected.getElements();
PathElement last = elements.get(elements.size() - 1);
QName lastName = last.getDefinition().getName();
if ("name".equals(lastName.getLocalPart()) && "http://www.opengis.net/gml/3.2".equals(lastName.getNamespaceURI())) {
selected = candidates.get(1);
}
}
return Optional.ofNullable(EntityAccessorUtil.createEntity(selected));
}
}
}
Aggregations