use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class AppSchemaMappingTest method createTargetProperty.
private ListMultimap<String, Property> createTargetProperty(TypeDefinition targetType, List<ChildDefinition<?>> childDefs, List<Integer> contextNames, List<Condition> conditions) {
if (contextNames == null) {
contextNames = Collections.emptyList();
}
if (conditions == null) {
conditions = Collections.emptyList();
}
List<ChildContext> childContext = new ArrayList<ChildContext>();
for (int i = 0; i < childDefs.size(); i++) {
ChildDefinition<?> childDef = childDefs.get(i);
Integer contextName = (contextNames.size() > i) ? contextNames.get(i) : null;
Condition condition = (conditions.size() > 1) ? conditions.get(i) : null;
childContext.add(new ChildContext(contextName, null, condition, childDef));
}
ListMultimap<String, Property> target = ArrayListMultimap.create();
target.put(null, new DefaultProperty(new PropertyEntityDefinition(targetType, childContext, SchemaSpaceID.TARGET, null)));
return target;
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class AppSchemaMappingTest method createSourceProperty.
private ListMultimap<String, Property> createSourceProperty(TypeDefinition sourceType, ChildDefinition<?> childDef) {
List<ChildContext> childContext = new ArrayList<ChildContext>();
childContext.add(new ChildContext(childDef));
ListMultimap<String, Property> source = ArrayListMultimap.create();
source.put(null, new DefaultProperty(new PropertyEntityDefinition(sourceType, childContext, SchemaSpaceID.SOURCE, null)));
return source;
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition 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.align.model.impl.PropertyEntityDefinition 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;
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class AbstractPropertyTransformationHandler method handleAsGeometryGmlId.
/**
* This method is invoked when the target property's parent is a geometry
* and the target property is <code>gml:id</code> (which needs special
* handling).
*
* <p>
* In practice, this means that <code><idExpression></code> is used in
* place of:
*
* <pre>
* <ClientProperty>
* <name>...</name>
* <value>...</value>
* </ClientProperty>
* </pre>
*
* @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 handleAsGeometryGmlId(TypeDefinition featureType, String mappingName, AppSchemaMappingContext context) {
PropertyEntityDefinition targetPropertyEntityDef = targetProperty.getDefinition();
PropertyEntityDefinition geometry = (PropertyEntityDefinition) AlignmentUtil.getParent(targetPropertyEntityDef);
createGeometryAttributeMapping(featureType, mappingName, geometry, context);
// set id expression
AttributeExpressionMappingType idExpression = new AttributeExpressionMappingType();
idExpression.setOCQL(getSourceExpressionAsCQL());
// TODO: not sure whether any CQL expression can be used here
attributeMapping.setIdExpression(idExpression);
}
Aggregations