Search in sources :

Example 16 with PropertyEntityDefinition

use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition 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 17 with PropertyEntityDefinition

use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition 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)

Example 18 with PropertyEntityDefinition

use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition 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 19 with PropertyEntityDefinition

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

the class PropertyBean method createEntityDefinition.

/**
 * @see EntityBean#createEntityDefinition(TypeIndex, SchemaSpaceID)
 */
@Override
protected PropertyEntityDefinition createEntityDefinition(TypeIndex index, SchemaSpaceID schemaSpace) {
    TypeDefinition typeDef = index.getType(getTypeName());
    if (typeDef == null) {
        throw new IllegalStateException(MessageFormat.format("TypeDefinition for type {0} not found", getTypeName()));
    }
    List<ChildContext> path = new ArrayList<ChildContext>();
    DefinitionGroup parent = typeDef;
    for (ChildContextBean childContext : properties) {
        if (parent == null) {
            throw new IllegalStateException("Could not resolve property entity definition: child not present");
        }
        Pair<ChildDefinition<?>, List<ChildDefinition<?>>> childs = findChild(parent, childContext.getChildName());
        ChildDefinition<?> child = childs.getFirst();
        // if the child is still null throw an exception
        if (child == null) {
            throw new IllegalStateException("Could not resolve property entity definition: child not found");
        }
        if (childs.getSecond() != null) {
            for (ChildDefinition<?> pathElems : childs.getSecond()) {
                path.add(new ChildContext(childContext.getContextName(), childContext.getContextIndex(), createCondition(childContext.getConditionFilter()), pathElems));
            }
        }
        path.add(new ChildContext(childContext.getContextName(), childContext.getContextIndex(), createCondition(childContext.getConditionFilter()), child));
        if (child instanceof DefinitionGroup) {
            parent = (DefinitionGroup) child;
        } else if (child.asProperty() != null) {
            parent = child.asProperty().getPropertyType();
        } else {
            parent = null;
        }
    }
    return new PropertyEntityDefinition(typeDef, path, schemaSpace, FilterDefinitionManager.getInstance().parse(getFilter()));
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ArrayList(java.util.ArrayList) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) ArrayList(java.util.ArrayList) List(java.util.List) DefinitionGroup(eu.esdihumboldt.hale.common.schema.model.DefinitionGroup) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 20 with PropertyEntityDefinition

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

the class AlignmentUtil method getChildrenWithoutContexts.

/**
 * Get children of an {@link Entity} without context conditions
 *
 * @param entity the entity definition
 * @return Collection of entity definitions
 */
public static List<PropertyEntityDefinition> getChildrenWithoutContexts(Entity entity) {
    TypeEntityDefinition ted = (TypeEntityDefinition) entity.getDefinition();
    List<PropertyEntityDefinition> childProperties = new ArrayList<>();
    for (EntityDefinition child : getChildrenWithoutContexts(ted)) {
        if (child instanceof PropertyEntityDefinition) {
            childProperties.add((PropertyEntityDefinition) child);
        }
    }
    return childProperties;
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.ChildEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ArrayList(java.util.ArrayList)

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