use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping in project hale by halestudio.
the class AppSchemaMappingGenerator method createTypeMappings.
private void createTypeMappings(AppSchemaMappingContext context, IOReporter reporter) {
Collection<? extends Cell> typeCells = alignment.getTypeCells();
for (Cell typeCell : typeCells) {
String typeTransformId = typeCell.getTransformationIdentifier();
TypeTransformationHandler typeTransformHandler = null;
try {
typeTransformHandler = TypeTransformationHandlerFactory.getInstance().createTypeTransformationHandler(typeTransformId);
FeatureTypeMapping ftMapping = typeTransformHandler.handleTypeTransformation(typeCell, context);
if (ftMapping != null) {
Collection<? extends Cell> propertyCells = alignment.getPropertyCells(typeCell);
for (Cell propertyCell : propertyCells) {
String propertyTransformId = propertyCell.getTransformationIdentifier();
PropertyTransformationHandler propertyTransformHandler = null;
try {
propertyTransformHandler = PropertyTransformationHandlerFactory.getInstance().createPropertyTransformationHandler(propertyTransformId);
propertyTransformHandler.handlePropertyTransformation(typeCell, propertyCell, context);
} catch (UnsupportedTransformationException e) {
String errMsg = MessageFormat.format("Error processing property cell {0}", propertyCell.getId());
log.warn(errMsg, e);
if (reporter != null) {
reporter.warn(new IOMessageImpl(errMsg, e));
}
}
}
}
} catch (UnsupportedTransformationException e) {
String errMsg = MessageFormat.format("Error processing type cell{0}", typeCell.getId());
log.warn(errMsg, e);
if (reporter != null) {
reporter.warn(new IOMessageImpl(errMsg, e));
}
}
}
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping in project hale by halestudio.
the class JoinHandler method handleTypeTransformation.
/**
* @see eu.esdihumboldt.hale.io.appschema.writer.internal.TypeTransformationHandler#handleTypeTransformation(eu.esdihumboldt.hale.common.align.model.Cell,
* eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)
*/
@Override
public FeatureTypeMapping handleTypeTransformation(Cell typeCell, AppSchemaMappingContext context) {
AppSchemaMappingWrapper mapping = context.getMappingWrapper();
Alignment alignment = context.getAlignment();
FeatureChaining featureChaining = context.getFeatureChaining();
final JoinParameter joinParameter = typeCell.getTransformationParameters().get(PARAMETER_JOIN).get(0).as(JoinParameter.class);
String validation = joinParameter.validate();
if (validation != null)
throw new IllegalArgumentException("Join parameter invalid: " + validation);
// check only single predicate conditions have been used
int[] conditionCount = new int[joinParameter.getTypes().size()];
List<JoinCondition> joinConditions = getSortedJoinConditions(joinParameter);
for (JoinCondition joinCondition : joinConditions) {
TypeEntityDefinition joinType = AlignmentUtil.getTypeEntity(joinCondition.joinProperty);
int typeIdx = joinParameter.getTypes().indexOf(joinType);
conditionCount[typeIdx]++;
if (conditionCount[typeIdx] > 1) {
throw new IllegalArgumentException("Only single condition joins are supported so far");
}
}
FeatureTypeMapping topMostMapping = null;
for (int chainIdx = 0; chainIdx < joinParameter.getTypes().size() - 1; chainIdx++) {
ChainConfiguration previousChainConf = null;
ChainConfiguration chainConf = null;
if (featureChaining != null) {
chainConf = featureChaining.getChain(typeCell.getId(), chainIdx);
if (chainConf != null && chainConf.getPrevChainIndex() >= 0) {
previousChainConf = featureChaining.getChain(typeCell.getId(), chainConf.getPrevChainIndex());
}
}
// join is done pair-wise: I assume the first type is the container
// type, whereas the second type is nested in the first
JoinCondition joinCondition = joinConditions.get(chainIdx);
baseProperty = joinCondition.baseProperty;
joinProperty = joinCondition.joinProperty;
TypeEntityDefinition containerType = AlignmentUtil.getTypeEntity(baseProperty);
TypeEntityDefinition nestedType = AlignmentUtil.getTypeEntity(joinProperty);
// build FeatureTypeMapping for container type
// Entity containerTypeTarget = typeCell.getTarget().values().iterator().next();
// TypeDefinition containerTypeTargetType = containerTypeTarget.getDefinition().getType();
EntityDefinition containerTypeTarget = null;
TypeDefinition containerTypeTargetType = null;
String containerTypeTargetMappingName = null;
if (previousChainConf == null) {
containerTypeTarget = getTargetType(typeCell).getDefinition();
containerTypeTargetType = containerTypeTarget.getType();
} else {
containerTypeTarget = previousChainConf.getNestedTypeTarget();
containerTypeTargetType = previousChainConf.getNestedTypeTarget().getDefinition().getPropertyType();
containerTypeTargetMappingName = previousChainConf.getMappingName();
}
String containerMappingName = null;
if (previousChainConf != null) {
containerMappingName = previousChainConf.getMappingName();
}
FeatureTypeMapping containerFTMapping = context.getOrCreateFeatureTypeMapping(containerTypeTargetType, containerMappingName);
containerFTMapping.setSourceType(containerType.getDefinition().getName().getLocalPart());
// build FeatureTypeMapping for nested type
TypeDefinition nestedFT = null;
List<ChildContext> nestedFTPath = null;
FeatureTypeMapping nestedFTMapping = null;
if (chainConf != null) {
nestedFT = chainConf.getNestedTypeTarget().getDefinition().getPropertyType();
nestedFTPath = chainConf.getNestedTypeTarget().getPropertyPath();
// remove last element
nestedFTPath = nestedFTPath.subList(0, nestedFTPath.size() - 1);
nestedFTMapping = context.getOrCreateFeatureTypeMapping(nestedFT, chainConf.getMappingName());
nestedFTMapping.setSourceType(nestedType.getDefinition().getName().getLocalPart());
} else {
if (joinParameter.getTypes().size() > 2) {
throw new IllegalArgumentException("If no feature chaining configuration is provided, only join between 2 types is supported");
}
// do your best to figure it out on your own... good luck!
Collection<? extends Cell> propertyCells = alignment.getPropertyCells(typeCell);
for (Cell propertyCell : propertyCells) {
Property sourceProperty = AppSchemaMappingUtils.getSourceProperty(propertyCell);
if (sourceProperty != null) {
TypeDefinition sourceType = sourceProperty.getDefinition().getDefinition().getParentType();
if (sourceType.getName().equals(nestedType.getDefinition().getName())) {
// source property belongs to nested type: determine
// target type
Property targetProperty = getTargetProperty(propertyCell);
// nestedFT =
// findOwningFeatureType(targetProperty.getDefinition());
nestedFT = findOwningType(targetProperty.getDefinition(), context.getRelevantTargetTypes());
if (nestedFT != null && !nestedFT.getName().equals(containerTypeTargetType.getName())) {
// target property belongs to a feature type
// different from the already mapped one: build
// a new mapping
nestedFTPath = findOwningTypePath(targetProperty.getDefinition(), context.getRelevantTargetTypes());
nestedFTMapping = context.getOrCreateFeatureTypeMapping(nestedFT);
nestedFTMapping.setSourceType(nestedType.getDefinition().getName().getLocalPart());
// in the join
break;
} else if (isHRefAttribute(targetProperty.getDefinition().getDefinition())) {
// check if target property is a href attribute
Property hrefProperty = targetProperty;
List<ChildContext> hrefPropertyPath = hrefProperty.getDefinition().getPropertyPath();
List<ChildContext> hrefContainerPath = hrefPropertyPath.subList(0, hrefPropertyPath.size() - 1);
TypeDefinition hrefParentType = hrefProperty.getDefinition().getDefinition().getParentType();
// TypeDefinition childFT =
// findChildFeatureType(hrefParentType);
TypeDefinition childFT = AppSchemaMappingUtils.findChildType(hrefParentType, context.getRelevantTargetTypes());
if (childFT != null) {
nestedFTPath = hrefContainerPath;
nestedFTMapping = context.getOrCreateFeatureTypeMapping(childFT);
nestedFTMapping.setSourceType(nestedType.getDefinition().getName().getLocalPart());
// involved in the join
break;
}
}
}
}
}
}
// build join mapping
if (nestedFTMapping != null && nestedFTPath != null) {
AttributeMappingType containerJoinMapping = context.getOrCreateAttributeMapping(containerTypeTargetType, containerTypeTargetMappingName, nestedFTPath);
containerJoinMapping.setTargetAttribute(mapping.buildAttributeXPath(containerTypeTargetType, nestedFTPath));
// set isMultiple attribute
PropertyDefinition targetPropertyDef = nestedFTPath.get(nestedFTPath.size() - 1).getChild().asProperty();
if (AppSchemaMappingUtils.isMultiple(targetPropertyDef)) {
containerJoinMapping.setIsMultiple(true);
}
AttributeExpressionMappingType containerSourceExpr = new AttributeExpressionMappingType();
// join column extracted from join condition
containerSourceExpr.setOCQL(baseProperty.getDefinition().getName().getLocalPart());
containerSourceExpr.setLinkElement(getLinkElementValue(nestedFTMapping));
String linkField = context.getUniqueFeatureLinkAttribute(nestedFT, nestedFTMapping.getMappingName());
containerSourceExpr.setLinkField(linkField);
containerJoinMapping.setSourceExpression(containerSourceExpr);
AttributeMappingType nestedJoinMapping = new AttributeMappingType();
AttributeExpressionMappingType nestedSourceExpr = new AttributeExpressionMappingType();
// join column extracted from join condition
nestedSourceExpr.setOCQL(joinProperty.getDefinition().getName().getLocalPart());
nestedJoinMapping.setSourceExpression(nestedSourceExpr);
nestedJoinMapping.setTargetAttribute(linkField);
nestedFTMapping.getAttributeMappings().getAttributeMapping().add(nestedJoinMapping);
}
if (chainIdx == 0) {
topMostMapping = containerFTMapping;
}
}
return topMostMapping;
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping in project hale by halestudio.
the class MergeHandler method handleTypeTransformation.
@Override
public FeatureTypeMapping handleTypeTransformation(Cell typeCell, AppSchemaMappingContext context) {
FeatureTypeMapping ftMapping = super.handleTypeTransformation(typeCell, context);
// this is the only variation from RetypeHandler so far
ftMapping.setIsDenormalised(true);
return ftMapping;
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping in project hale by halestudio.
the class SingleSourceToTargetHandler method handleTypeTransformation.
/**
* @see eu.esdihumboldt.hale.io.appschema.writer.internal.TypeTransformationHandler#handleTypeTransformation(eu.esdihumboldt.hale.common.align.model.Cell,
* eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)
*/
@Override
public FeatureTypeMapping handleTypeTransformation(Cell typeCell, AppSchemaMappingContext context) {
ListMultimap<String, ? extends Entity> sourceEntities = typeCell.getSource();
if (sourceEntities == null || sourceEntities.size() == 0) {
throw new IllegalStateException("No source type has been specified.");
}
ListMultimap<String, ? extends Entity> targetEntities = typeCell.getTarget();
if (targetEntities == null || targetEntities.size() == 0) {
throw new IllegalStateException("No target type has been specified.");
}
// Maps 1 source to 1 target, so it is safe to pick the first entity in
// the list
Entity sourceType = sourceEntities.values().iterator().next();
Entity targetType = targetEntities.values().iterator().next();
TypeDefinition targetTypeDef = targetType.getDefinition().getType();
FeatureTypeMapping ftMapping = context.getOrCreateFeatureTypeMapping(targetTypeDef);
ftMapping.setSourceType(sourceType.getDefinition().getType().getName().getLocalPart());
return ftMapping;
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping in project hale by halestudio.
the class AppSchemaMappingWrapper method getIncludedTypesMapping.
/**
* Returns the mapping configuration for the included types mapping file.
*
* <p>
* If the mapping does not require multiple files, <code>null</code> is
* returned.
* </p>
*
* @return a copy of the included types mapping configuration, or
* <code>null</code>
*/
public AppSchemaDataAccessType getIncludedTypesMapping() {
if (requiresMultipleFiles()) {
AppSchemaDataAccessType includedTypesMapping = cloneMapping(appSchemaMapping);
Set<FeatureTypeMapping> toBeRemoved = new HashSet<FeatureTypeMapping>();
Set<FeatureTypeMapping> toBeKept = new HashSet<FeatureTypeMapping>();
groupTypeMappings(toBeRemoved, toBeKept);
purgeTypeMappings(includedTypesMapping, toBeRemoved);
return includedTypesMapping;
} else {
return null;
}
}
Aggregations