use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition 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.impl.PropertyEntityDefinition 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?
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class CityGMLPropagateVisitor method propagateCell.
/**
* Propagate a given cell to the given target property and possible source
* types.
*
* @param exampleCell the example cell
* @param ped the target property
*/
private void propagateCell(Cell exampleCell, PropertyEntityDefinition ped) {
/*
* Find the type where the property actually is defined, as if possible
* a super type mapping should be used.
*/
TypeDefinition targetType = findTypeDefining(ped);
if (!targetType.equals(ped.getType())) {
ped = new PropertyEntityDefinition(targetType, ped.getPropertyPath(), ped.getSchemaSpace(), ped.getFilter());
}
// check if the cell was already handled for the type
if (handledTargets.get(exampleCell).contains(targetType)) {
// don't produce any duplicates
return;
}
handledTargets.put(exampleCell, targetType);
TypeEntityIndex<List<ChildContext>> index = new TypeEntityIndex<List<ChildContext>>();
Collection<TypeDefinition> sourceTypes = findSourceTypes(exampleCell, targetType, index);
if (sourceTypes != null) {
for (TypeDefinition sourceType : sourceTypes) {
// copy cell
DefaultCell cell = new DefaultCell(exampleCell);
// reset ID
cell.setId(null);
// assign new target
ListMultimap<String, Entity> target = ArrayListMultimap.create();
target.put(cell.getTarget().keys().iterator().next(), new DefaultProperty(ped));
cell.setTarget(target);
// assign new source(s)
ListMultimap<String, Entity> source = ArrayListMultimap.create();
for (Entry<String, ? extends Entity> entry : cell.getSource().entries()) {
// create new source entity
List<ChildContext> path = index.get(sourceType, entry.getValue());
if (path == null) {
throw new IllegalStateException("No replacement property path computed");
}
Property newSource = new DefaultProperty(new PropertyEntityDefinition(sourceType, path, SchemaSpaceID.SOURCE, null));
source.put(entry.getKey(), newSource);
}
cell.setSource(source);
BGISAppUtil.appendNote(cell, cellNote);
cells.add(cell);
}
}
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class PropertyBean method createEntityDefinition.
/**
* @see EntityBean#createEntityDefinition(TypeIndex, SchemaSpaceID)
*/
@Override
protected PropertyEntityDefinition createEntityDefinition(TypeIndex index, SchemaSpaceID schemaSpace) {
TypeDefinition typeDef = index.getType(getTypeName());
if (typeDef == null) {
throw new IllegalStateException(MessageFormat.format("TypeDefinition for type {0} not found", getTypeName()));
}
List<ChildContext> path = new ArrayList<ChildContext>();
DefinitionGroup parent = typeDef;
for (ChildContextBean childContext : properties) {
if (parent == null) {
throw new IllegalStateException("Could not resolve property entity definition: child not present");
}
Pair<ChildDefinition<?>, List<ChildDefinition<?>>> childs = findChild(parent, childContext.getChildName());
ChildDefinition<?> child = childs.getFirst();
// if the child is still null throw an exception
if (child == null) {
throw new IllegalStateException("Could not resolve property entity definition: child not found");
}
if (childs.getSecond() != null) {
for (ChildDefinition<?> pathElems : childs.getSecond()) {
path.add(new ChildContext(childContext.getContextName(), childContext.getContextIndex(), createCondition(childContext.getConditionFilter()), pathElems));
}
}
path.add(new ChildContext(childContext.getContextName(), childContext.getContextIndex(), createCondition(childContext.getConditionFilter()), child));
if (child instanceof DefinitionGroup) {
parent = (DefinitionGroup) child;
} else if (child.asProperty() != null) {
parent = child.asProperty().getPropertyType();
} else {
parent = null;
}
}
return new PropertyEntityDefinition(typeDef, path, schemaSpace, FilterDefinitionManager.getInstance().parse(getFilter()));
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class AlignmentUtil method getChildrenWithoutContexts.
/**
* Get children of an {@link Entity} without context conditions
*
* @param entity the entity definition
* @return Collection of entity definitions
*/
public static List<PropertyEntityDefinition> getChildrenWithoutContexts(Entity entity) {
TypeEntityDefinition ted = (TypeEntityDefinition) entity.getDefinition();
List<PropertyEntityDefinition> childProperties = new ArrayList<>();
for (EntityDefinition child : getChildrenWithoutContexts(ted)) {
if (child instanceof PropertyEntityDefinition) {
childProperties.add((PropertyEntityDefinition) child);
}
}
return childProperties;
}
Aggregations