use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class CityGMLPropagateVisitor method hasCompatibleProperty.
private List<ChildContext> hasCompatibleProperty(DefinitionGroup type, List<ChildContext> propertyPath) {
int propIndex = -1;
// find index of first property (ignoring groups)
for (int i = 0; i < propertyPath.size() && propIndex < 0; i++) {
if (propertyPath.get(i).getChild().asProperty() != null) {
propIndex = i;
}
}
if (propIndex < 0) {
// now there something is not right
return null;
}
QName name = propertyPath.get(propIndex).getChild().getName();
if (!name.getNamespaceURI().startsWith(CITYGML_NAMESPACE_CORE)) {
System.err.println("ERROR: only cells on CityGML source properties will be propagated");
return null;
}
// look for a potential match
Collection<? extends ChildDefinition<?>> children = DefinitionUtil.getAllChildren(type);
for (ChildDefinition<?> candidate : children) {
if (candidate.asProperty() != null) {
if (candidate.getName().getNamespaceURI().startsWith(CITYGML_NAMESPACE_CORE) && candidate.getName().getLocalPart().equals(name.getLocalPart()) && candidate.asProperty().getPropertyType().getName().getLocalPart().equals(propertyPath.get(propIndex).getChild().asProperty().getPropertyType().getName().getLocalPart())) {
/*
* Property has CityGML namespace, matching local name and
* matching property type local name.
*/
List<ChildContext> newPath = new ArrayList<ChildContext>();
ChildContext org = propertyPath.get(propIndex);
ChildContext rep = new ChildContext(org.getContextName(), org.getIndex(), org.getCondition(), candidate);
newPath.add(rep);
if (propIndex + 1 >= propertyPath.size()) {
// last property, return
return newPath;
} else {
// check path further
List<ChildContext> childPath = hasCompatibleProperty(candidate.asProperty().getPropertyType(), propertyPath.subList(propIndex + 1, propertyPath.size()));
if (childPath != null) {
newPath.addAll(childPath);
return newPath;
}
}
}
} else if (candidate.asGroup() != null) {
// check path further for the same property
List<ChildContext> childPath = hasCompatibleProperty(candidate.asGroup(), propertyPath.subList(propIndex, propertyPath.size()));
if (childPath != null) {
// prepend group to path
childPath.add(0, new ChildContext(candidate));
return childPath;
}
}
}
return null;
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class CityGMLPropagateVisitor method propagateCell.
/**
* Propagate a given cell to the given target property and possible source
* types.
*
* @param exampleCell the example cell
* @param ped the target property
*/
private void propagateCell(Cell exampleCell, PropertyEntityDefinition ped) {
/*
* Find the type where the property actually is defined, as if possible
* a super type mapping should be used.
*/
TypeDefinition targetType = findTypeDefining(ped);
if (!targetType.equals(ped.getType())) {
ped = new PropertyEntityDefinition(targetType, ped.getPropertyPath(), ped.getSchemaSpace(), ped.getFilter());
}
// check if the cell was already handled for the type
if (handledTargets.get(exampleCell).contains(targetType)) {
// don't produce any duplicates
return;
}
handledTargets.put(exampleCell, targetType);
TypeEntityIndex<List<ChildContext>> index = new TypeEntityIndex<List<ChildContext>>();
Collection<TypeDefinition> sourceTypes = findSourceTypes(exampleCell, targetType, index);
if (sourceTypes != null) {
for (TypeDefinition sourceType : sourceTypes) {
// copy cell
DefaultCell cell = new DefaultCell(exampleCell);
// reset ID
cell.setId(null);
// assign new target
ListMultimap<String, Entity> target = ArrayListMultimap.create();
target.put(cell.getTarget().keys().iterator().next(), new DefaultProperty(ped));
cell.setTarget(target);
// assign new source(s)
ListMultimap<String, Entity> source = ArrayListMultimap.create();
for (Entry<String, ? extends Entity> entry : cell.getSource().entries()) {
// create new source entity
List<ChildContext> path = index.get(sourceType, entry.getValue());
if (path == null) {
throw new IllegalStateException("No replacement property path computed");
}
Property newSource = new DefaultProperty(new PropertyEntityDefinition(sourceType, path, SchemaSpaceID.SOURCE, null));
source.put(entry.getKey(), newSource);
}
cell.setSource(source);
BGISAppUtil.appendNote(cell, cellNote);
cells.add(cell);
}
}
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class PopulationContainer method getChildren.
/**
* @see eu.esdihumboldt.hale.common.service.helper.population.IPopulationUpdater#getChildren(eu.esdihumboldt.hale.common.align.model.EntityDefinition)
*/
@Override
public Collection<? extends EntityDefinition> getChildren(EntityDefinition entityDef) {
List<ChildContext> path = entityDef.getPropertyPath();
Collection<? extends ChildDefinition<?>> children;
if (path == null || path.isEmpty()) {
// entity is a type, children are the type children
children = entityDef.getType().getChildren();
} else {
// get parent context
ChildContext parentContext = path.get(path.size() - 1);
if (parentContext.getChild().asGroup() != null) {
children = parentContext.getChild().asGroup().getDeclaredChildren();
} else if (parentContext.getChild().asProperty() != null) {
children = parentContext.getChild().asProperty().getPropertyType().getChildren();
} else {
throw new IllegalStateException("Illegal child definition type encountered");
}
}
if (children == null || children.isEmpty()) {
return Collections.emptyList();
}
Collection<EntityDefinition> result = new ArrayList<EntityDefinition>(children.size());
for (ChildDefinition<?> child : children) {
// add default child entity definition to result
ChildContext context = new ChildContext(child);
EntityDefinition defaultEntity = createEntity(entityDef.getType(), createPath(entityDef.getPropertyPath(), context), entityDef.getSchemaSpace(), entityDef.getFilter());
result.add(defaultEntity);
}
return result;
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class EntityPopulationCount method evaluateChildEntityDefinition.
private void evaluateChildEntityDefinition(Group group, EntityDefinition groupDef, List<ChildContext> path) {
if (path.size() == 1) {
evaluateContext(group, groupDef);
} else {
ChildContext context = path.get(0);
List<ChildContext> subPath = path.subList(1, path.size());
Object[] values = group.getProperty(context.getChild().getName());
if (values != null) {
for (Object value : values) {
if (value instanceof Group) {
evaluateChildEntityDefinition((Group) value, groupDef, subPath);
}
}
} else {
evaluateChildEntityDefinition(group, groupDef, subPath);
}
}
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.
the class AppSchemaMappingWrapper method getAttruteMappingHashKey.
private Integer getAttruteMappingHashKey(TypeDefinition owningType, List<ChildContext> propertyPath) {
final String SEPARATOR = "__";
StringBuilder pathBuilder = new StringBuilder();
if (owningType != null) {
pathBuilder.append(owningType.getName().toString()).append(SEPARATOR);
for (ChildContext childContext : propertyPath) {
pathBuilder.append(childContext.getChild().getName().toString());
if (childContext.getContextName() != null) {
pathBuilder.append(childContext.getContextName());
}
pathBuilder.append(SEPARATOR);
}
} else {
throw new IllegalArgumentException("Could not find feature type owning property");
}
return pathBuilder.toString().hashCode();
}
Aggregations