use of eu.esdihumboldt.hale.common.align.groovy.accessor.PathElement in project hale by halestudio.
the class EntityAccessorUtil method createEntity.
/**
* Create an entity definition from a path.
*
* @param path the path, the topmost element has to represent an
* {@link EntityDefinition}, all other elements must represent
* {@link ChildContext}s
* @return the created entity definition or <code>null</code> if the path
* was <code>null</code>
*/
public static EntityDefinition createEntity(Path<PathElement> path) {
if (path == null) {
return null;
}
List<PathElement> elements = new ArrayList<>(path.getElements());
// create entity definition
PathElement top = elements.remove(0);
if (top.getRoot() == null) {
throw new IllegalArgumentException("Topmost path element must be an entity definition");
}
EntityDefinition entity = top.getRoot();
// collect type information
TypeDefinition type = entity.getType();
SchemaSpaceID schemaSpace = entity.getSchemaSpace();
Filter filter = entity.getFilter();
List<ChildContext> contextPath = new ArrayList<>(entity.getPropertyPath());
for (PathElement element : elements) {
ChildContext cc = element.getChild();
if (cc == null) {
throw new IllegalArgumentException("All child elements must be defined by a child context");
}
contextPath.add(cc);
}
return AlignmentUtil.createEntity(type, contextPath, schemaSpace, filter);
}
use of eu.esdihumboldt.hale.common.align.groovy.accessor.PathElement 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