Search in sources :

Example 31 with EntityDefinition

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

the class GroovyGreedyTransformation method createGroovyBinding.

/**
 * Create a Groovy binding from the list of variables.
 *
 * @param vars the variable values
 * @param varDefs definition of the assigned variables, in case some
 *            variable values are not set, may be <code>null</code>
 * @param cell the cell the binding is created for
 * @param typeCell the type cell the binding is created for, may be
 *            <code>null</code>
 * @param builder the instance builder for creating target instances, or
 *            <code>null</code> if not applicable
 * @param useInstanceVariables if instances should be used as variables for
 *            the binding instead of extracting the instance values
 * @param log the transformation log
 * @param context the execution context
 * @param targetInstanceType the type of the target instance
 * @return the binding for use with {@link GroovyShell}
 */
public static Binding createGroovyBinding(List<PropertyValue> vars, List<? extends Entity> varDefs, Cell cell, Cell typeCell, InstanceBuilder builder, boolean useInstanceVariables, TransformationLog log, ExecutionContext context, TypeDefinition targetInstanceType) {
    Binding binding = GroovyUtil.createBinding(builder, cell, typeCell, log, context, targetInstanceType);
    // collect definitions to check if all were provided
    Set<EntityDefinition> notDefined = new HashSet<>();
    if (varDefs != null) {
        for (Entity entity : varDefs) {
            notDefined.add(entity.getDefinition());
        }
    }
    // keep only defs where no value is provided
    if (!notDefined.isEmpty()) {
        for (PropertyValue var : vars) {
            notDefined.remove(var.getProperty());
        }
    }
    // add empty lists to environment if necessary
    if (!notDefined.isEmpty()) {
        for (EntityDefinition entity : notDefined) {
            GroovyTransformation.addToBinding(binding, (PropertyEntityDefinition) entity, Collections.emptyList());
        }
    }
    Map<PropertyEntityDefinition, InstanceAccessorArrayList<Object>> bindingMap = new HashMap<>();
    // collect the values
    for (PropertyValue var : vars) {
        PropertyEntityDefinition property = var.getProperty();
        InstanceAccessorArrayList<Object> valueList = bindingMap.get(property);
        if (valueList == null) {
            valueList = new InstanceAccessorArrayList<>();
            bindingMap.put(property, valueList);
        }
        valueList.add(GroovyTransformation.getUseValue(var.getValue(), useInstanceVariables));
    }
    // add collected values to environment
    for (Entry<PropertyEntityDefinition, InstanceAccessorArrayList<Object>> entry : bindingMap.entrySet()) {
        GroovyTransformation.addToBinding(binding, entry.getKey(), entry.getValue());
    }
    return binding;
}
Also used : Binding(groovy.lang.Binding) Entity(eu.esdihumboldt.hale.common.align.model.Entity) HashMap(java.util.HashMap) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) 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) InstanceAccessorArrayList(eu.esdihumboldt.cst.functions.groovy.internal.InstanceAccessorArrayList) HashSet(java.util.HashSet)

Example 32 with EntityDefinition

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

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

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

the class EntityVisitor method accept.

/**
 * Apply the visitor on a type entity definition.
 *
 * @param ted the type entity definition
 */
public void accept(TypeEntityDefinition ted) {
    if (visit(ted)) {
        for (ChildDefinition<?> child : ted.getDefinition().getChildren()) {
            EntityDefinition ed = AlignmentUtil.getChild(ted, child.getName());
            accept(ed);
        }
    }
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.ChildEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition)

Example 35 with EntityDefinition

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

EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)99 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)39 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)37 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)23 ArrayList (java.util.ArrayList)22 Entity (eu.esdihumboldt.hale.common.align.model.Entity)21 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)20 Cell (eu.esdihumboldt.hale.common.align.model.Cell)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)11 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)10 HashSet (java.util.HashSet)10 QName (javax.xml.namespace.QName)10 HashMap (java.util.HashMap)9 Condition (eu.esdihumboldt.hale.common.align.model.Condition)8 SimpleLog (eu.esdihumboldt.hale.common.core.report.SimpleLog)7 ISelection (org.eclipse.jface.viewers.ISelection)7 List (java.util.List)6 TreePath (org.eclipse.jface.viewers.TreePath)6 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)5