Search in sources :

Example 21 with Group

use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.

the class OInstance method setMetaData.

/**
 * {@inheritDoc} The parameter values may not contain an ODocument
 */
@Override
public void setMetaData(String key, Object... values) {
    for (Object value : values) {
        Preconditions.checkArgument(!(value instanceof ODocument || value instanceof Instance || value instanceof Group));
    }
    ODocument metaData;
    if (document.field(FIELD_METADATA) == null) {
        metaData = new ODocument();
        document.field(FIELD_METADATA, metaData);
    } else
        metaData = ((ODocument) document.field(FIELD_METADATA));
    setPropertyInternal(metaData, new QName(key), values);
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) QName(javax.xml.namespace.QName) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 22 with Group

use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.

the class GeometryUtil method getGeometries.

/**
 * Get the default geometry of an instance.
 *
 * @param instance the instance
 * @param path the property path to start the search at, a <code>null</code>
 *            will yield no geometries
 * @return the default geometries or an empty collection if there is none
 */
public static Collection<GeometryProperty<?>> getGeometries(Instance instance, List<QName> path) {
    Collection<GeometryProperty<?>> geometries = new ArrayList<GeometryProperty<?>>();
    if (path == null) {
        return geometries;
    }
    // descend path and return the geometries found
    Queue<Group> parents = new LinkedList<Group>();
    parents.add(instance);
    for (int i = 0; i < path.size(); i++) {
        QName name = path.get(i);
        Queue<Group> children = new LinkedList<Group>();
        for (Group parent : parents) {
            Object[] values = parent.getProperty(name);
            if (values != null) {
                for (Object value : values) {
                    if (value instanceof Group) {
                        children.add((Group) value);
                    }
                    if (value instanceof Instance) {
                        value = ((Instance) value).getValue();
                    }
                    if (value != null && !(value instanceof Group) && i == path.size() - 1) {
                        // detect geometry values at end of path
                        // as they are not searched later on
                        Collection<GeometryProperty<?>> geoms = getGeometryProperties(value);
                        geometries.addAll(geoms);
                    }
                }
            }
        }
        // prepare for next step
        parents = children;
    }
    // early exit #1
    if (!geometries.isEmpty()) {
        // XXX is this OK in all cases?
        return geometries;
    }
    // search in those groups/instances for additional geometries
    while (!parents.isEmpty()) {
        Group parent = parents.poll();
        // add values contained in the instance
        Collection<GeometryProperty<?>> geoms = getGeometryProperties(parent);
        if (!geoms.isEmpty()) {
            geometries.addAll(geoms);
        // early exit #2
        // don't check the children as they usually are only parts of
        // the geometry found here
        } else {
            // check children for geometries
            for (QName name : parent.getPropertyNames()) {
                Object[] values = parent.getProperty(name);
                if (values != null) {
                    for (Object value : values) {
                        if (value instanceof Group) {
                            // check group later on
                            parents.add((Group) value);
                        } else {
                            // add geometries for value
                            geometries.addAll(getGeometryProperties(value));
                        }
                    }
                }
            }
        }
    }
    return geometries;
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 23 with Group

use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.

the class ChoiceFlagValidator method validateGroupPropertyConstraint.

@Override
public void validateGroupPropertyConstraint(Object[] values, GroupPropertyConstraint constraint, GroupPropertyDefinition property, InstanceValidationContext context) throws ValidationException {
    if (((ChoiceFlag) constraint).isEnabled() && values != null) {
        for (Object value : values) {
            if (value instanceof Group) {
                Iterator<QName> properties = ((Group) value).getPropertyNames().iterator();
                if (!properties.hasNext())
                    throw new ValidationException("A choice with no child.");
                properties.next();
                if (properties.hasNext())
                    throw new ValidationException("A choice with different children.");
            }
        // XXX what if value is null or not a Group?
        // XXX what if it is an Instance? May it have a value?
        }
    }
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) ValidationException(eu.esdihumboldt.hale.common.instance.extension.validation.ValidationException) QName(javax.xml.namespace.QName)

Example 24 with Group

use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.

the class EntityPopulationCount method evaluateContext.

/**
 * count the population for the given entity with all contexts
 *
 * @param group A {@link Group}
 * @param groupDef An {@link EntityDefinition}
 */
private void evaluateContext(Group group, EntityDefinition groupDef) {
    List<ChildContext> path = groupDef.getPropertyPath();
    if (path != null && !path.isEmpty()) {
        ChildContext context = path.get(path.size() - 1);
        Object[] values = group.getProperty(context.getChild().getName());
        if (values != null) {
            // apply the possible source contexts
            if (context.getIndex() != null) {
                // select only the item at the index
                int index = context.getIndex();
                if (index < values.length) {
                    values = new Object[] { values[index] };
                } else {
                    values = new Object[] {};
                }
            }
            if (context.getCondition() != null) {
                // select only values that match the condition
                List<Object> matchedValues = new ArrayList<Object>();
                for (Object value : values) {
                    if (AlignmentUtil.matchCondition(context.getCondition(), value, group)) {
                        matchedValues.add(value);
                    }
                }
                values = matchedValues.toArray();
            }
            if (context.getChild().getName().equals(groupDef.getDefinition().getName())) {
                increase(groupDef, values.length);
            }
            for (Object value : values) {
                if (value instanceof Group) {
                    addToPopulation((Group) value, groupDef);
                }
            }
        } else {
            increase(groupDef, 0);
        }
    }
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 25 with Group

use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.

the class Rename method structuralRename.

/**
 * Performs a structural rename on the given source object to the given
 * target definition.
 *
 * @param source the source value (or group/instance)
 * @param targetDefinition the target definition
 * @param allowIgnoreNamespaces if for the structure comparison, namespaces
 *            may be ignored
 * @param instanceFactory the instance factory
 * @param copyGeometries specifies if geometry objects should be copied
 * @return the transformed value (or group/instance) or NO_MATCH
 */
public static Object structuralRename(Object source, ChildDefinition<?> targetDefinition, boolean allowIgnoreNamespaces, InstanceFactory instanceFactory, boolean copyGeometries) {
    if (!(source instanceof Group)) {
        // source simple value
        if (targetDefinition.asProperty() != null) {
            // target can have value
            TypeDefinition propertyType = targetDefinition.asProperty().getPropertyType();
            if (copyGeometries || !isGeometry(source)) {
                if (propertyType.getChildren().isEmpty()) {
                    // simple value
                    return convertValue(source, targetDefinition.asProperty().getPropertyType());
                } else {
                    // instance with value
                    MutableInstance instance = instanceFactory.createInstance(propertyType);
                    instance.setDataSet(DataSet.TRANSFORMED);
                    instance.setValue(convertValue(source, propertyType));
                    return instance;
                }
            } else {
                return Result.NO_MATCH;
            }
        }
    }
    // source is group or instance
    if (targetDefinition.asProperty() != null) {
        // target can have value
        TypeDefinition propertyType = targetDefinition.asProperty().getPropertyType();
        if (source instanceof Instance) {
            // source has value
            if (propertyType.getChildren().isEmpty()) {
                // simple value
                return convertValue(((Instance) source).getValue(), targetDefinition.asProperty().getPropertyType());
            } else {
                // instance with value
                MutableInstance instance = instanceFactory.createInstance(targetDefinition.asProperty().getPropertyType());
                instance.setDataSet(DataSet.TRANSFORMED);
                if (copyGeometries || !isGeometry(((Instance) source).getValue())) {
                    instance.setValue(convertValue(((Instance) source).getValue(), targetDefinition.asProperty().getPropertyType()));
                }
                renameChildren((Group) source, instance, targetDefinition, allowIgnoreNamespaces, instanceFactory, copyGeometries);
                return instance;
            }
        } else {
            // source has no value
            if (targetDefinition.asProperty().getPropertyType().getChildren().isEmpty())
                // no match possible
                return Result.NO_MATCH;
            else {
                // instance with no value set
                MutableInstance instance = instanceFactory.createInstance(targetDefinition.asProperty().getPropertyType());
                instance.setDataSet(DataSet.TRANSFORMED);
                if (renameChildren((Group) source, instance, targetDefinition, allowIgnoreNamespaces, instanceFactory, copyGeometries))
                    return instance;
                else
                    // no child matched and no value
                    return Result.NO_MATCH;
            }
        }
    } else if (targetDefinition.asGroup() != null) {
        // target can not have a value
        if (targetDefinition.asGroup().getDeclaredChildren().isEmpty())
            // target neither has a value nor
            return Result.NO_MATCH;
        else // children?
        {
            // group
            MutableGroup group = new DefaultGroup(targetDefinition.asGroup());
            if (renameChildren((Group) source, group, targetDefinition, allowIgnoreNamespaces, instanceFactory, copyGeometries))
                return group;
            else
                // no child matched and no value
                return Result.NO_MATCH;
        }
    } else {
        // neither asProperty nor asGroup -> illegal ChildDefinition
        throw new IllegalStateException("Illegal child type.");
    }
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) MutableGroup(eu.esdihumboldt.hale.common.instance.model.MutableGroup) DefaultGroup(eu.esdihumboldt.hale.common.instance.model.impl.DefaultGroup) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) DefaultGroup(eu.esdihumboldt.hale.common.instance.model.impl.DefaultGroup) MutableGroup(eu.esdihumboldt.hale.common.instance.model.MutableGroup) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

Group (eu.esdihumboldt.hale.common.instance.model.Group)26 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)15 QName (javax.xml.namespace.QName)10 ArrayList (java.util.ArrayList)6 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)5 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)5 SourceNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode)4 Pair (eu.esdihumboldt.util.Pair)4 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)3 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 CellNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode)2 TargetNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode)2 TransformationContext (eu.esdihumboldt.hale.common.align.model.transformation.tree.context.TransformationContext)2 InstanceValidationReport (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport)2 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)2 DefinitionGroup (eu.esdihumboldt.hale.common.schema.model.DefinitionGroup)2 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)2 HasValueFlag (eu.esdihumboldt.hale.common.schema.model.constraint.type.HasValueFlag)2 LinkedList (java.util.LinkedList)2