Search in sources :

Example 1 with TypeDefinition

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

the class FeatureChainingComplexTypeTest method testBackAndForth.

/**
 * Tests converting a feature chaining configuration to DOM and back.
 */
@Test
public void testBackAndForth() {
    FeatureChaining testConf = new FeatureChaining();
    TypeDefinition fakeType = new DefaultTypeDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeType"));
    PropertyDefinition fakeProperty0 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "fakeProperty0"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType0PropertyType")));
    PropertyDefinition fakeProperty1 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeNestedType0"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType0Type")));
    List<ChildContext> path0 = Arrays.asList(new ChildContext[] { new ChildContext(fakeProperty0), new ChildContext(fakeProperty1) });
    ChainConfiguration chain0 = new ChainConfiguration();
    chain0.setChainIndex(0);
    chain0.setPrevChainIndex(-1);
    chain0.setNestedTypeTarget(new PropertyEntityDefinition(fakeType, path0, SchemaSpaceID.TARGET, null));
    PropertyDefinition fakeProperty2 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "fakeProperty1"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType1PropertyType")));
    PropertyDefinition fakeProperty3 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeNestedType1"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType1Type")));
    List<ChildContext> path1 = Arrays.asList(new ChildContext[] { new ChildContext(fakeProperty0), new ChildContext(fakeProperty1), new ChildContext(fakeProperty2), new ChildContext(fakeProperty3) });
    ChainConfiguration chain1 = new ChainConfiguration();
    chain1.setChainIndex(1);
    chain1.setPrevChainIndex(0);
    chain1.setNestedTypeTarget(new PropertyEntityDefinition(fakeType, path1, SchemaSpaceID.TARGET, null));
    chain1.setMappingName("fakeMapping");
    testConf.putChain("test-join", 0, chain0);
    testConf.putChain("test-join", 1, chain1);
    // convert to DOM
    Element fragment = HaleIO.getComplexElement(testConf);
    // convert back
    FeatureChaining converted = HaleIO.getComplexValue(fragment, FeatureChaining.class, null);
    assertNotNull(converted);
    assertFalse(converted.equals(testConf));
    Map<String, JoinConfiguration> joins = converted.getJoins();
    assertNotNull(joins);
    assertEquals(1, joins.size());
    JoinConfiguration join = joins.get("test-join");
    assertNotNull(join);
    assertEquals(2, join.getChains().size());
    ChainConfiguration convChain0 = join.getChain(0);
    assertNotNull(convChain0);
    assertEquals(0, convChain0.getChainIndex());
    assertEquals(-1, convChain0.getPrevChainIndex());
    assertTrue(convChain0.getMappingName() == null);
    PropertyType convPropertyType0 = convChain0.getJaxbNestedTypeTarget();
    assertNotNull(convPropertyType0);
    assertEquals("FakeType", convPropertyType0.getType().getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getType().getNs());
    assertEquals(2, convPropertyType0.getChild().size());
    assertEquals("fakeProperty0", convPropertyType0.getChild().get(0).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getChild().get(0).getNs());
    assertEquals("FakeNestedType0", convPropertyType0.getChild().get(1).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getChild().get(1).getNs());
    ChainConfiguration convChain1 = join.getChain(1);
    assertNotNull(convChain1);
    assertEquals(1, convChain1.getChainIndex());
    assertEquals(0, convChain1.getPrevChainIndex());
    assertEquals("fakeMapping", convChain1.getMappingName());
    PropertyType convPropertyType1 = convChain1.getJaxbNestedTypeTarget();
    assertNotNull(convPropertyType1);
    assertEquals("FakeType", convPropertyType1.getType().getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getType().getNs());
    assertEquals(4, convPropertyType1.getChild().size());
    assertEquals("fakeProperty0", convPropertyType1.getChild().get(0).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(0).getNs());
    assertEquals("FakeNestedType0", convPropertyType1.getChild().get(1).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(1).getNs());
    assertEquals("fakeProperty1", convPropertyType1.getChild().get(2).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(2).getNs());
    assertEquals("FakeNestedType1", convPropertyType1.getChild().get(3).getName());
    assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(3).getNs());
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) PropertyType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.PropertyType) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) Test(org.junit.Test)

Example 2 with TypeDefinition

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

the class AppSchemaMappingUtils method findOwningFeatureTypeIndex.

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

Example 3 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition 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 4 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 5 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)

Aggregations

TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)211 QName (javax.xml.namespace.QName)62 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)48 ArrayList (java.util.ArrayList)34 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)29 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)28 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)26 Test (org.junit.Test)25 HashSet (java.util.HashSet)24 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)23 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)22 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)21 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)21 IOException (java.io.IOException)19 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)18 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)15 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)15 Binding (eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding)15 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)15 URI (java.net.URI)15