Search in sources :

Example 76 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition 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 77 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition 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 78 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition 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 79 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class FunctionExecutor method processValue.

/**
 * Processes the given value. Does not handle {@link MultiValue}!
 *
 * @param cellLog the transformation log
 * @param function the property function
 * @param value the value to process
 * @param node the target node
 * @return the processed value
 */
private Object processValue(TransformationLog cellLog, PropertyTransformation<?> function, Object value, TargetNode node) {
    if (function.allowAutomatedResultConversion()) {
        if (!(value instanceof Group)) {
            // convert value for target
            try {
                value = convert(value, toPropertyEntityDefinition(node.getEntityDefinition()));
            } catch (Throwable e) {
                // ignore, but create error
                cellLog.error(cellLog.createMessage("Conversion according to target property failed, using value as is.", e));
            }
        } else {
        // TODO any conversion necessary/possible
        }
    } else {
        // unwrap value
        if (value instanceof Value) {
            value = ((Value) value).getValue();
        }
    }
    /*
		 * If the value is no group, but it should be one, create an instance
		 * wrapping the value
		 */
    TypeDefinition propertyType = toPropertyEntityDefinition(node.getEntityDefinition()).getDefinition().getPropertyType();
    if (!(value instanceof Group) && !propertyType.getChildren().isEmpty()) {
        MutableInstance instance = new DefaultInstance(propertyType, null);
        instance.setValue(value);
        value = instance;
    }
    return value;
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) MultiValue(eu.esdihumboldt.cst.MultiValue) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) Value(eu.esdihumboldt.hale.common.core.io.Value) MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 80 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class CityGMLPropagate method generateMapping.

private void generateMapping() {
    System.out.println("Indexing example cells...");
    // index all cells based on the target property name
    SetMultimap<String, Cell> bgisExamples = HashMultimap.create();
    SetMultimap<QName, Cell> cityGMLExamples = HashMultimap.create();
    for (Cell cell : examples.getCells()) {
        if (cell.getTarget().size() == 1) {
            // only supports cells with one target
            EntityDefinition entityDef = CellUtil.getFirstEntity(cell.getTarget()).getDefinition();
            // XXX check source?!
            if (entityDef.getDefinition() instanceof PropertyDefinition) {
                QName name = entityDef.getDefinition().getName();
                if (ADE_NS.equals(name.getNamespaceURI())) {
                    bgisExamples.put(name.getLocalPart(), cell);
                } else if (name.getNamespaceURI().startsWith(CITYGML_NAMESPACE_CORE)) {
                    // XXX only support level 1 properties?
                    cityGMLExamples.put(name, cell);
                } else
                    System.out.println("WARNING: ignoring cell with target property neither from CityGML nor from BGIS ADE");
            } else
                System.out.println("WARNING: ignoring type cell");
        } else
            System.out.println("WARNING: ignoring cell with multiple or no targets");
    }
    // collect all ADE feature types
    List<TypeDefinition> featureTypes = BGISAppUtil.getADEFeatureTypes(targetSchema);
    // collect ADE display names
    Set<String> adeTypeNames = new HashSet<String>();
    for (TypeDefinition type : featureTypes) {
        adeTypeNames.add(type.getDisplayName());
    }
    // collect possibly relevant target CityGML feature types
    for (TypeDefinition type : targetSchema.getTypes()) {
        if (type.getName().getNamespaceURI().startsWith(CITYGML_NAMESPACE_CORE) && BGISAppUtil.isFeatureType(type)) {
            if (!adeTypeNames.contains(type.getDisplayName())) {
                /*
					 * But ensure to only add those that do not share the
					 * display name with an ADE type, as in the feature map the
					 * type identification is only done on based on the display
					 * name, and ADE types take precedent.
					 */
                featureTypes.add(type);
            }
        }
    }
    // visit ADE properties and create cells
    System.out.println("Generating mapping from example cells for");
    String cellNote = MessageFormat.format("Generated through propagation of example cells on CityGML and BGIS ADE feature types.\n" + "{0,date,medium}", new Date());
    CityGMLPropagateVisitor visitor = new CityGMLPropagateVisitor(cityGMLSource, bgisExamples, cityGMLExamples, config, cellNote);
    for (TypeDefinition type : featureTypes) {
        System.out.println(type.getDisplayName() + "...");
        visitor.accept(new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null));
    }
    if (visitor.getCells().isEmpty()) {
        System.out.println("WARNING: no cells were created");
    } else {
        System.out.println(visitor.getCells().size() + " cells were created.");
    }
    // create alignment
    MutableAlignment align = new DefaultAlignment();
    for (MutableCell cell : visitor.getCells()) {
        align.addCell(cell);
    }
    this.alignment = align;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) QName(javax.xml.namespace.QName) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) Date(java.util.Date) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) HashSet(java.util.HashSet)

Aggregations

TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)192 QName (javax.xml.namespace.QName)58 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)38 ArrayList (java.util.ArrayList)32 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)26 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)26 Test (org.junit.Test)24 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)22 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)21 HashSet (java.util.HashSet)21 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)20 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)20 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)16 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)15 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)15 Cell (eu.esdihumboldt.hale.common.align.model.Cell)14 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)14 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)12 Binding (eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding)12 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)12