use of eu.esdihumboldt.hale.common.schema.model.PropertyDefinition in project hale by halestudio.
the class CustomTypeContentHelper method replaceTypeForProperty.
private static void replaceTypeForProperty(PropertyDefinition propDef, DefinitionGroup propParent, TypeDefinition newPropertyType) {
PropertyDefinition newProperty;
if (propDef instanceof PropertyTypeOverrideProperty) {
newProperty = new PropertyTypeOverrideProperty(((PropertyTypeOverrideProperty) propDef).getDecoratedProperty(), newPropertyType);
} else {
newProperty = new PropertyTypeOverrideProperty(propDef, newPropertyType);
}
if (propParent instanceof DefaultTypeDefinition) {
DefaultTypeDefinition type = (DefaultTypeDefinition) propParent;
type.overrideChild(newProperty);
} else // else if (propParent instanceof DefaultGroupPropertyDefinition) {
// // TODO
// }
{
log.error("Could not update custom content property because of unsupported parent definition group");
}
}
use of eu.esdihumboldt.hale.common.schema.model.PropertyDefinition in project hale by halestudio.
the class AppSchemaMappingGenerator method createNamespacesForPath.
private void createNamespacesForPath(List<ChildContext> propertyPath) {
if (propertyPath != null) {
for (ChildContext childContext : propertyPath) {
PropertyDefinition child = childContext.getChild().asProperty();
if (child != null) {
String namespaceURI = child.getName().getNamespaceURI();
String prefix = child.getName().getPrefix();
context.getOrCreateNamespace(namespaceURI, prefix);
}
}
}
}
use of eu.esdihumboldt.hale.common.schema.model.PropertyDefinition in project hale by halestudio.
the class ClassificationHandler method getSourceExpressionAsCQL.
/**
* @see eu.esdihumboldt.hale.io.appschema.writer.internal.AbstractPropertyTransformationHandler#getSourceExpressionAsCQL()
*/
@Override
protected String getSourceExpressionAsCQL() {
Property source = AppSchemaMappingUtils.getSourceProperty(propertyCell);
PropertyDefinition sourceDef = source.getDefinition().getDefinition();
Property target = AppSchemaMappingUtils.getTargetProperty(propertyCell);
PropertyDefinition targetDef = target.getDefinition().getDefinition();
String sourceName = source.getDefinition().getDefinition().getName().getLocalPart();
ListMultimap<String, ParameterValue> parameters = propertyCell.getTransformationParameters();
LookupTable lookup = ClassificationMappingUtil.getClassificationLookup(parameters, new ServiceManager(ServiceManager.SCOPE_PROJECT));
if (lookup == null) {
log.warn("No classification specified");
return "''";
} else {
String cqlTemplate = "if_then_else(in(%s), Recode(%s,%s), %s)";
// build args to Recode function
StringBuilder recodeArgsBuilder = new StringBuilder();
Map<Value, Value> valueMap = lookup.asMap();
int counter = 0;
for (Value sourceValue : valueMap.keySet()) {
Value targetValue = valueMap.get(sourceValue);
String sourceLiteral = asCqlLiteral(sourceDef, sourceValue.as(String.class));
String targetLiteral = asCqlLiteral(targetDef, targetValue.as(String.class));
recodeArgsBuilder.append(sourceLiteral).append(",").append(targetLiteral);
if (counter < valueMap.size() - 1) {
recodeArgsBuilder.append(",");
}
counter++;
}
String recodeArgs = recodeArgsBuilder.toString();
// build args for in function
List<String> values = new ArrayList<String>();
for (Value v : valueMap.keySet()) {
String valueLiteral = asCqlLiteral(sourceDef, v.as(String.class));
values.add(valueLiteral);
}
values.add(0, sourceName);
String inArgs = Joiner.on(",").join(values);
// determine what to put in the "else" branch, based on
// transformation parameters
String elsePart = null;
List<ParameterValue> notClassifiedParam = parameters.get(PARAMETER_NOT_CLASSIFIED_ACTION);
String notClassifiedAction = null;
if (notClassifiedParam != null && notClassifiedParam.size() > 0) {
notClassifiedAction = notClassifiedParam.get(0).as(String.class);
} else {
notClassifiedAction = USE_NULL_ACTION;
}
if (USE_SOURCE_ACTION.equals(notClassifiedAction))
elsePart = sourceName;
else if (notClassifiedAction.startsWith(USE_FIXED_VALUE_ACTION_PREFIX))
elsePart = asCqlLiteral(targetDef, notClassifiedAction.substring(notClassifiedAction.indexOf(':') + 1));
else if (USE_NULL_ACTION.equals(notClassifiedAction))
elsePart = "Expression.NIL";
return String.format(cqlTemplate, inArgs, sourceName, recodeArgs, elsePart);
}
}
use of eu.esdihumboldt.hale.common.schema.model.PropertyDefinition 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.common.schema.model.PropertyDefinition in project hale by halestudio.
the class SpatialDataSetConfigurationPage method createContent.
/**
* @see HaleWizardPage#createContent(Composite)
*/
@Override
protected void createContent(Composite page) {
GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).spacing(6, 12).applyTo(page);
// Get the property definitions of localId and namespace.
String action = getWizard().getActionId();
SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
SchemaSpaceID ssid = SchemaSpaceID.TARGET;
if (InstanceIO.ACTION_SAVE_SOURCE_DATA.equals(action)) {
ssid = SchemaSpaceID.SOURCE;
}
SchemaSpace target = ss.getSchemas(ssid);
XmlIndex index = StreamGmlWriter.getXMLIndex(target);
XmlElement sdsElement = InspireUtil.findSpatialDataSet(index);
TypeDefinition sdsType = null;
if (sdsElement != null) {
sdsType = sdsElement.getType();
}
// applicable.
if (sdsType == null)
return;
// find localId and namespace definitions
Path<Definition<?>> localIdPath = new DefinitionAccessor(sdsType).findChildren("identifier").findChildren("Identifier").findChildren("localId").eval(false);
List<Definition<?>> localIdDefs = localIdPath.getElements();
PropertyDefinition localIdDef = (PropertyDefinition) localIdDefs.get(localIdDefs.size() - 1);
Path<Definition<?>> namespacePath = new DefinitionAccessor(sdsType).findChildren("identifier").findChildren("Identifier").findChildren("namespace").eval(false);
List<Definition<?>> namespaceDefs = namespacePath.getElements();
PropertyDefinition nsDef = (PropertyDefinition) namespaceDefs.get(namespaceDefs.size() - 1);
IPropertyChangeListener changeListener = new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(AttributeEditor.IS_VALID) || event.getProperty().equals(FileFieldEditor.IS_VALID))
updateState();
}
};
// inspire identifier
Label inspireId = new Label(page, SWT.NONE);
inspireId.setText("Please specify the local ID and the namespace as part of the INSPIRE identifier of the Spatial Data Set:");
GridDataFactory.fillDefaults().span(2, 1).applyTo(inspireId);
AttributeEditorFactory aef = PlatformUI.getWorkbench().getService(AttributeEditorFactory.class);
Composite localIdtitle = new Composite(page, SWT.NONE);
localIdtitle.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).create());
DefinitionLabelFactory dlf = PlatformUI.getWorkbench().getService(DefinitionLabelFactory.class);
dlf.createLabel(localIdtitle, localIdDef, false);
Label label = new Label(localIdtitle, SWT.NONE);
label.setText(" = ");
localIdEditor = aef.createEditor(page, localIdDef, null, false);
localIdEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
localIdEditor.setPropertyChangeListener(changeListener);
Composite namespacetitle = new Composite(page, SWT.NONE);
namespacetitle.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).create());
dlf.createLabel(namespacetitle, nsDef, false);
label = new Label(namespacetitle, SWT.NONE);
label.setText(" = ");
namespaceEditor = aef.createEditor(page, nsDef, null, false);
namespaceEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
namespaceEditor.setPropertyChangeListener(changeListener);
// spacer
Composite spacer = new Composite(page, SWT.NONE);
GridDataFactory.fillDefaults().hint(0, 8).applyTo(spacer);
// metadata file
Label metadataLabel = new Label(page, SWT.NONE);
metadataLabel.setText("You can include metadata in the Spatial Data Set from a XML file with a MD_Metadata element:");
GridDataFactory.fillDefaults().span(2, 1).applyTo(metadataLabel);
// source file
Composite fileFieldComposite = new Composite(page, SWT.NONE);
fileFieldComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
metadataFile = new OpenFileFieldEditor("metadataFile", "ISO Geographic MetaData XML", true, FileFieldEditor.VALIDATE_ON_KEY_STROKE, fileFieldComposite);
metadataFile.setPage(this);
metadataFile.setEmptyStringAllowed(true);
metadataFile.setFileExtensions(new String[] { "*.xml" });
metadataFile.setPropertyChangeListener(changeListener);
// isValid starts with false even if emptyStringAllowed is true.
// -> force validation hack
metadataFile.setStringValue(" ");
metadataFile.setStringValue("");
updateState();
}
Aggregations