Search in sources :

Example 11 with PropertyEntityDefinition

use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.

the class AppSchemaMappingTest method createTargetProperty.

private ListMultimap<String, Property> createTargetProperty(TypeDefinition targetType, List<ChildDefinition<?>> childDefs, List<Integer> contextNames, List<Condition> conditions) {
    if (contextNames == null) {
        contextNames = Collections.emptyList();
    }
    if (conditions == null) {
        conditions = Collections.emptyList();
    }
    List<ChildContext> childContext = new ArrayList<ChildContext>();
    for (int i = 0; i < childDefs.size(); i++) {
        ChildDefinition<?> childDef = childDefs.get(i);
        Integer contextName = (contextNames.size() > i) ? contextNames.get(i) : null;
        Condition condition = (conditions.size() > 1) ? conditions.get(i) : null;
        childContext.add(new ChildContext(contextName, null, condition, childDef));
    }
    ListMultimap<String, Property> target = ArrayListMultimap.create();
    target.put(null, new DefaultProperty(new PropertyEntityDefinition(targetType, childContext, SchemaSpaceID.TARGET, null)));
    return target;
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) Property(eu.esdihumboldt.hale.common.align.model.Property) ClientProperty(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 12 with PropertyEntityDefinition

use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.

the class AppSchemaMappingTest method createSourceProperty.

private ListMultimap<String, Property> createSourceProperty(TypeDefinition sourceType, ChildDefinition<?> childDef) {
    List<ChildContext> childContext = new ArrayList<ChildContext>();
    childContext.add(new ChildContext(childDef));
    ListMultimap<String, Property> source = ArrayListMultimap.create();
    source.put(null, new DefaultProperty(new PropertyEntityDefinition(sourceType, childContext, SchemaSpaceID.SOURCE, null)));
    return source;
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) Property(eu.esdihumboldt.hale.common.align.model.Property) ClientProperty(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 13 with PropertyEntityDefinition

use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.

the class AbstractPropertyTransformationHandler method handleXmlElementAsGeometryType.

/**
 * This method is invoked when the target property is a GML geometry type.
 *
 * <p>
 * The target attribute is set to <code>gml:AbstractGeometry</code> and the
 * concrete geometry type is specified in a
 * <code>&lt;targetAttributeNode&gt;</code> tag.
 * </p>
 *
 * @param featureType the target feature type
 * @param mappingName the target feature type's mapping name (may be
 *            <code>null</code>)
 * @param context the app-schema mapping context
 */
protected void handleXmlElementAsGeometryType(TypeDefinition featureType, String mappingName, AppSchemaMappingContext context) {
    PropertyEntityDefinition geometry = targetProperty.getDefinition();
    createGeometryAttributeMapping(featureType, mappingName, geometry, context);
    // GeometryTypes require special handling
    TypeDefinition geometryType = geometry.getDefinition().getPropertyType();
    QName geomTypeName = geometryType.getName();
    Namespace geomNS = context.getOrCreateNamespace(geomTypeName.getNamespaceURI(), geomTypeName.getPrefix());
    attributeMapping.setTargetAttributeNode(geomNS.getPrefix() + ":" + geomTypeName.getLocalPart());
    // set target attribute to parent (should be gml:AbstractGeometry)
    // TODO: this is really ugly, but I don't see a better way to do it
    // since HALE renames
    // {http://www.opengis.net/gml/3.2}AbstractGeometry element
    // to
    // {http://www.opengis.net/gml/3.2/AbstractGeometry}choice
    EntityDefinition parentEntityDef = AlignmentUtil.getParent(geometry);
    Definition<?> parentDef = parentEntityDef.getDefinition();
    String parentQName = geomNS.getPrefix() + ":" + parentDef.getDisplayName();
    List<ChildContext> targetPropertyPath = parentEntityDef.getPropertyPath();
    attributeMapping.setTargetAttribute(mapping.buildAttributeXPath(featureType, targetPropertyPath) + "/" + parentQName);
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) QName(javax.xml.namespace.QName) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) Namespace(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.NamespacesPropertyType.Namespace) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 14 with PropertyEntityDefinition

use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.

the class AbstractPropertyTransformationHandler method handlePropertyTransformation.

/**
 * @see eu.esdihumboldt.hale.io.appschema.writer.internal.PropertyTransformationHandler#handlePropertyTransformation(eu.esdihumboldt.hale.common.align.model.Cell,
 *      eu.esdihumboldt.hale.common.align.model.Cell,
 *      eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)
 */
@Override
public AttributeMappingType handlePropertyTransformation(Cell typeCell, Cell propertyCell, AppSchemaMappingContext context) {
    this.mapping = context.getMappingWrapper();
    this.typeCell = typeCell;
    this.propertyCell = propertyCell;
    // TODO: does this hold for any transformation function?
    this.targetProperty = getTargetProperty(propertyCell);
    PropertyEntityDefinition targetPropertyEntityDef = targetProperty.getDefinition();
    PropertyDefinition targetPropertyDef = targetPropertyEntityDef.getDefinition();
    TypeDefinition featureType = null;
    String mappingName = null;
    if (AppSchemaMappingUtils.isJoin(typeCell)) {
        if (context.getFeatureChaining() != null) {
            ChainConfiguration chainConf = findChainConfiguration(context);
            if (chainConf != null) {
                featureType = chainConf.getNestedTypeTargetType();
                mappingName = chainConf.getMappingName();
            }
        } else {
            // this is just a best effort attempt to determine the target
            // feature type, may result in incorrect mappings
            featureType = findOwningType(targetPropertyEntityDef, context.getRelevantTargetTypes());
        }
    }
    if (featureType == null) {
        featureType = getTargetType(typeCell).getDefinition().getType();
    }
    // chaining configuration other than the current one
    if (context.getFeatureChaining() != null) {
        for (String joinId : context.getFeatureChaining().getJoins().keySet()) {
            List<ChainConfiguration> chains = context.getFeatureChaining().getChains(joinId);
            ChainConfiguration chainConf = findLongestNestedPath(targetPropertyEntityDef.getPropertyPath(), chains);
            if (chainConf != null && !chainConf.getNestedTypeTargetType().equals(featureType)) {
                // don't translate mapping, will do it (or have done it)
                // elsewhere!
                featureType = null;
                break;
            }
        }
    }
    if (featureType != null) {
        // fetch FeatureTypeMapping from mapping configuration
        this.featureTypeMapping = context.getOrCreateFeatureTypeMapping(featureType, mappingName);
        // fetch AttributeMappingType from mapping
        if (isXmlAttribute(targetPropertyDef)) {
            // gml:id attribute requires special handling, i.e. an
            // <idExpression> tag must be added to the attribute mapping for
            // target feature types and geometry types
            TypeDefinition parentType = targetPropertyDef.getParentType();
            if (isGmlId(targetPropertyDef)) {
                // TODO: handle gml:id for geometry types
                if (featureType.equals(parentType)) {
                    handleAsFeatureGmlId(featureType, mappingName, context);
                } else if (isGeometryType(parentType)) {
                    handleAsGeometryGmlId(featureType, mappingName, context);
                } else {
                    handleAsXmlAttribute(featureType, mappingName, context);
                }
            } else {
                handleAsXmlAttribute(featureType, mappingName, context);
            }
        } else {
            handleAsXmlElement(featureType, mappingName, context);
        }
    }
    return attributeMapping;
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChainConfiguration(eu.esdihumboldt.hale.io.appschema.model.ChainConfiguration) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 15 with PropertyEntityDefinition

use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.

the class AbstractPropertyTransformationHandler method handleAsGeometryGmlId.

/**
 * This method is invoked when the target property's parent is a geometry
 * and the target property is <code>gml:id</code> (which needs special
 * handling).
 *
 * <p>
 * In practice, this means that <code>&lt;idExpression&gt;</code> is used in
 * place of:
 *
 * <pre>
 *   &lt;ClientProperty&gt;
 *     &lt;name&gt;...&lt;/name&gt;
 *     &lt;value&gt;...&lt;/value&gt;
 *   &lt;/ClientProperty&gt;
 * </pre>
 *
 * @param featureType the target feature type
 * @param mappingName the target feature type's mapping name (may be
 *            <code>null</code>)
 * @param context the app-schema mapping context
 */
protected void handleAsGeometryGmlId(TypeDefinition featureType, String mappingName, AppSchemaMappingContext context) {
    PropertyEntityDefinition targetPropertyEntityDef = targetProperty.getDefinition();
    PropertyEntityDefinition geometry = (PropertyEntityDefinition) AlignmentUtil.getParent(targetPropertyEntityDef);
    createGeometryAttributeMapping(featureType, mappingName, geometry, context);
    // set id expression
    AttributeExpressionMappingType idExpression = new AttributeExpressionMappingType();
    idExpression.setOCQL(getSourceExpressionAsCQL());
    // TODO: not sure whether any CQL expression can be used here
    attributeMapping.setIdExpression(idExpression);
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) AttributeExpressionMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeExpressionMappingType)

Aggregations

PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)55 ArrayList (java.util.ArrayList)26 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)19 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)19 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)16 List (java.util.List)15 Entity (eu.esdihumboldt.hale.common.align.model.Entity)12 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)12 QName (javax.xml.namespace.QName)11 Cell (eu.esdihumboldt.hale.common.align.model.Cell)10 HashSet (java.util.HashSet)10 Property (eu.esdihumboldt.hale.common.align.model.Property)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)7 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)6 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)6 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)6 Collectors (java.util.stream.Collectors)6 Type (eu.esdihumboldt.hale.common.align.model.Type)5 JoinCondition (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)5