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());
}
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;
}
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;
}
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><targetAttributeNode></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);
}
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;
}
Aggregations