Search in sources :

Example 21 with ChildContext

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

the class AppSchemaMappingUtils method findOwningTypeIndex.

private static int findOwningTypeIndex(List<ChildContext> propertyPath, Collection<? extends TypeDefinition> allowedTypes) {
    for (int i = propertyPath.size() - 1; i >= 0; i--) {
        ChildContext childContext = propertyPath.get(i);
        TypeDefinition parentType = childContext.getChild().getParentType();
        if (allowedTypes.contains(parentType)) {
            return i;
        }
    }
    return -1;
}
Also used : ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 22 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext 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 23 with ChildContext

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

the class AbstractPropertyTransformationHandler method findLongestNestedPath.

private ChainConfiguration findLongestNestedPath(List<ChildContext> targetPropertyPath, List<ChainConfiguration> chains) {
    ChainConfiguration chainConf = null;
    if (chains != null && chains.size() > 0 && targetPropertyPath != null && targetPropertyPath.size() > 0) {
        int maxPathLength = 0;
        for (ChainConfiguration chain : chains) {
            List<ChildContext> nestedTargetPath = chain.getNestedTypeTarget().getPropertyPath();
            boolean isNested = isNested(nestedTargetPath, targetPropertyPath);
            if (isNested && maxPathLength < nestedTargetPath.size()) {
                maxPathLength = nestedTargetPath.size();
                chainConf = chain;
            }
        }
    }
    return chainConf;
}
Also used : ChainConfiguration(eu.esdihumboldt.hale.io.appschema.model.ChainConfiguration) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 24 with ChildContext

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

the class AbstractPropertyTransformationHandler method handleAsXmlAttribute.

/**
 * This method is invoked when the target property is an XML attribute (
 * {@link XmlAttributeFlag} constraint is set).
 *
 * <p>
 * The property transformation is translated to:
 *
 * <pre>
 *   <code>&lt;ClientProperty&gt;
 *     &lt;name&gt;[target property name]&lt;/name&gt;
 *     &lt;value&gt;[CQL expression]&lt;/value&gt;
 *   &lt;/ClientProperty&gt;</code>
 * </pre>
 *
 * and added to the attribute mapping generated for the XML element owning
 * the attribute.
 * </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 handleAsXmlAttribute(TypeDefinition featureType, String mappingName, AppSchemaMappingContext context) {
    PropertyEntityDefinition targetPropertyEntityDef = targetProperty.getDefinition();
    PropertyDefinition targetPropertyDef = targetPropertyEntityDef.getDefinition();
    // fetch attribute mapping for parent property
    EntityDefinition parentDef = AlignmentUtil.getParent(targetPropertyEntityDef);
    if (parentDef != null) {
        List<ChildContext> parentPropertyPath = parentDef.getPropertyPath();
        PropertyDefinition parentPropertyDef = parentPropertyPath.get(parentPropertyPath.size() - 1).getChild().asProperty();
        if (parentPropertyDef != null) {
            attributeMapping = context.getOrCreateAttributeMapping(featureType, mappingName, parentPropertyPath);
            // set targetAttribute if empty
            if (attributeMapping.getTargetAttribute() == null || attributeMapping.getTargetAttribute().isEmpty()) {
                attributeMapping.setTargetAttribute(mapping.buildAttributeXPath(featureType, parentPropertyPath));
            }
            Namespace targetPropNS = context.getOrCreateNamespace(targetPropertyDef.getName().getNamespaceURI(), targetPropertyDef.getName().getPrefix());
            String unqualifiedName = targetPropertyDef.getName().getLocalPart();
            boolean isQualified = targetPropNS != null && !Strings.isNullOrEmpty(targetPropNS.getPrefix());
            // encode attribute as <ClientProperty>
            ClientProperty clientProperty = new ClientProperty();
            @SuppressWarnings("null") String clientPropName = (isQualified) ? targetPropNS.getPrefix() + ":" + unqualifiedName : unqualifiedName;
            clientProperty.setName(clientPropName);
            clientProperty.setValue(getSourceExpressionAsCQL());
            setEncodeIfEmpty(clientProperty);
            // don't add client property if it already exists
            if (!hasClientProperty(clientProperty.getName())) {
                attributeMapping.getClientProperty().add(clientProperty);
                // when nilReason is null and viceversa)
                if (isNilReason(targetPropertyDef) && isNillable(parentPropertyDef) && attributeMapping.getSourceExpression() == null) {
                    addOrReplaceXsiNilAttribute(clientProperty.getValue(), true, context);
                }
            }
        }
    }
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ClientProperty(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) Namespace(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.NamespacesPropertyType.Namespace)

Example 25 with ChildContext

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

the class AbstractPropertyTransformationHandler method handleAsXmlElement.

/**
 * This method is invoked when the target property is a regular XML element.
 *
 * @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 handleAsXmlElement(TypeDefinition featureType, String mappingName, AppSchemaMappingContext context) {
    PropertyEntityDefinition targetPropertyEntityDef = targetProperty.getDefinition();
    PropertyDefinition targetPropertyDef = targetPropertyEntityDef.getDefinition();
    TypeDefinition targetPropertyType = targetPropertyDef.getPropertyType();
    if (isGeometryType(targetPropertyType)) {
        handleXmlElementAsGeometryType(featureType, mappingName, context);
    } else {
        attributeMapping = context.getOrCreateAttributeMapping(featureType, mappingName, targetPropertyEntityDef.getPropertyPath());
        List<ChildContext> targetPropertyPath = targetPropertyEntityDef.getPropertyPath();
        // set target attribute
        attributeMapping.setTargetAttribute(mapping.buildAttributeXPath(featureType, targetPropertyPath));
    }
    // set source expression
    AttributeExpressionMappingType sourceExpression = new AttributeExpressionMappingType();
    // TODO: is this general enough?
    sourceExpression.setOCQL(getSourceExpressionAsCQL());
    attributeMapping.setSourceExpression(sourceExpression);
    if (AppSchemaMappingUtils.isMultiple(targetPropertyDef)) {
        attributeMapping.setIsMultiple(true);
    }
    // (i.e. null if source expression is NOT null, and viceversa)
    if (isNillable(targetPropertyDef)) {
        addOrReplaceXsiNilAttribute(attributeMapping.getSourceExpression().getOCQL(), false, context);
    }
// TODO: isList?
// TODO: targetAttributeNode?
// TODO: encodeIfEmpty?
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) AttributeExpressionMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeExpressionMappingType) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

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