use of eu.esdihumboldt.hale.common.align.model.ChildContext 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.align.model.ChildContext 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.ChildContext in project hale by halestudio.
the class AbstractPropertyTransformationHandler method findLongestNestedPath.
private ChainConfiguration findLongestNestedPath(List<ChildContext> targetPropertyPath, List<ChainConfiguration> chains) {
ChainConfiguration chainConf = null;
if (chains != null && chains.size() > 0 && targetPropertyPath != null && targetPropertyPath.size() > 0) {
int maxPathLength = 0;
for (ChainConfiguration chain : chains) {
List<ChildContext> nestedTargetPath = chain.getNestedTypeTarget().getPropertyPath();
boolean isNested = isNested(nestedTargetPath, targetPropertyPath);
if (isNested && maxPathLength < nestedTargetPath.size()) {
maxPathLength = nestedTargetPath.size();
chainConf = chain;
}
}
}
return chainConf;
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext 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><ClientProperty>
* <name>[target property name]</name>
* <value>[CQL expression]</value>
* </ClientProperty></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);
}
}
}
}
}
use of eu.esdihumboldt.hale.common.align.model.ChildContext 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?
}
Aggregations