Search in sources :

Example 26 with ChildContext

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;
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 27 with ChildContext

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);
        }
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) TypeEntityIndex(eu.esdihumboldt.hale.app.bgis.ade.propagate.internal.TypeEntityIndex) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Property(eu.esdihumboldt.hale.common.align.model.Property) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 28 with ChildContext

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;
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 29 with ChildContext

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);
        }
    }
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 30 with ChildContext

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();
}
Also used : ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Aggregations

ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)63 ArrayList (java.util.ArrayList)32 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)29 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)24 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)12 QName (javax.xml.namespace.QName)11 Property (eu.esdihumboldt.hale.common.align.model.Property)7 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)7 List (java.util.List)7 Condition (eu.esdihumboldt.hale.common.align.model.Condition)6 Entity (eu.esdihumboldt.hale.common.align.model.Entity)6 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)5 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)5 Cell (eu.esdihumboldt.hale.common.align.model.Cell)4 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)4 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)3 Type (eu.esdihumboldt.hale.common.align.model.Type)3 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)3