use of eu.esdihumboldt.hale.common.align.model.ParameterValue in project hale by halestudio.
the class AppSchemaMappingTest method testXmlAttributeEncodingQualified.
@Test
public void testXmlAttributeEncodingQualified() {
final String GML_ID = "ti.ds.landcover";
final String OCQL = "'" + GML_ID + "'";
DefaultCell cell = new DefaultCell();
cell.setTransformationIdentifier(AssignFunction.ID);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(GML_ID));
cell.setTransformationParameters(parameters);
cell.setTarget(getTimeInstantGmlIdTargetProperty());
AssignHandler handler = new AssignHandler();
AttributeMappingType attrMapping = handler.handlePropertyTransformation(getDefaultTypeCell(datasetType, landCoverDatasetType), cell, new AppSchemaMappingContext(mappingWrapper));
assertNull(attrMapping.getSourceExpression());
assertEquals("lcv:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimeInstant", attrMapping.getTargetAttribute());
assertNotNull(attrMapping.getClientProperty());
assertEquals(1, attrMapping.getClientProperty().size());
ClientProperty attr = attrMapping.getClientProperty().get(0);
assertEquals("gml:id", attr.getName());
assertEquals(OCQL, attr.getValue());
}
use of eu.esdihumboldt.hale.common.align.model.ParameterValue in project hale by halestudio.
the class AppSchemaMappingTest method testNillable.
@Test
public void testNillable() {
final String nilReason = "missing";
final String nilReasonCQL = "'" + nilReason + "'";
final String expectedXsiNilWithSource = "if_then_else(isNull(" + SOURCE_UNIT_ID + "), 'true', Expression.NIL)";
DefaultCell renameBeginLifespan = new DefaultCell();
renameBeginLifespan.setTransformationIdentifier(RenameFunction.ID);
renameBeginLifespan.setSource(getUnitIdSourceProperty(unitType));
renameBeginLifespan.setTarget(getBeginLifespanTargetProperty());
DefaultCell assignNilReason = new DefaultCell();
assignNilReason.setTransformationIdentifier(AssignFunction.ID);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(nilReason));
assignNilReason.setTarget(getBeginLifespanNilReasonTargetProperty());
assignNilReason.setTransformationParameters(parameters);
Cell typeCell = getDefaultTypeCell(unitType, landCoverUnitType);
AttributeMappingType attrMapping = null;
AppSchemaMappingContext context = new AppSchemaMappingContext(mappingWrapper);
AssignHandler assignHandler = new AssignHandler();
attrMapping = assignHandler.handlePropertyTransformation(typeCell, assignNilReason, context);
assertNotNull(attrMapping);
assertEquals("lcv:beginLifespanVersion", attrMapping.getTargetAttribute());
assertNull(attrMapping.getSourceExpression());
assertEquals(2, attrMapping.getClientProperty().size());
assertEquals(GML_NIL_REASON, attrMapping.getClientProperty().get(0).getName());
assertEquals(nilReasonCQL, attrMapping.getClientProperty().get(0).getValue());
assertEquals("xsi:nil", attrMapping.getClientProperty().get(1).getName());
assertEquals("if_then_else(isNull(" + nilReasonCQL + "), Expression.NIL, 'true')", attrMapping.getClientProperty().get(1).getValue());
assertTrue(attrMapping.isEncodeIfEmpty());
// element mapping should cause xsi:nil expression being overridden
RenameHandler renameHandler = new RenameHandler();
attrMapping = renameHandler.handlePropertyTransformation(typeCell, renameBeginLifespan, context);
assertNotNull(attrMapping);
assertNotNull(attrMapping.getSourceExpression());
assertEquals(SOURCE_UNIT_ID, attrMapping.getSourceExpression().getOCQL());
assertEquals("lcv:beginLifespanVersion", attrMapping.getTargetAttribute());
assertEquals(2, attrMapping.getClientProperty().size());
boolean xsiNilFound = false;
for (ClientProperty property : attrMapping.getClientProperty()) {
if ("xsi:nil".equals(property.getName())) {
assertEquals(expectedXsiNilWithSource, property.getValue());
xsiNilFound = true;
}
}
assertTrue(xsiNilFound);
assertTrue(attrMapping.isEncodeIfEmpty());
// remove nilReason client property
attrMapping.getClientProperty().remove(0);
// run again assing handler, nothing should change
attrMapping = assignHandler.handlePropertyTransformation(typeCell, assignNilReason, context);
assertEquals(2, attrMapping.getClientProperty().size());
assertEquals("xsi:nil", attrMapping.getClientProperty().get(0).getName());
assertEquals(expectedXsiNilWithSource, attrMapping.getClientProperty().get(0).getValue());
}
use of eu.esdihumboldt.hale.common.align.model.ParameterValue in project hale by halestudio.
the class AppSchemaMappingTest method buildJoinCell.
@SuppressWarnings("null")
private DefaultCell buildJoinCell(FeatureChaining chainingConf) {
boolean withChaining = chainingConf != null;
DefaultCell joinCell = new DefaultCell();
joinCell.setTransformationIdentifier(JoinFunction.ID);
if (withChaining) {
// set cell ID from feature chaining configuration
// WARNING: this code assumes only one join is configured
joinCell.setId(chainingConf.getJoins().keySet().iterator().next());
}
TypeEntityDefinition datasetEntityDef = new TypeEntityDefinition(datasetType, SchemaSpaceID.SOURCE, null);
TypeEntityDefinition unitEntityDef = null;
TypeEntityDefinition observationEntityDef = null;
if (!withChaining) {
unitEntityDef = new TypeEntityDefinition(unitDenormType, SchemaSpaceID.SOURCE, null);
} else {
unitEntityDef = new TypeEntityDefinition(unitType, SchemaSpaceID.SOURCE, null);
observationEntityDef = new TypeEntityDefinition(observationType, SchemaSpaceID.SOURCE, null);
}
ListMultimap<String, Type> source = ArrayListMultimap.create();
source.put(JoinFunction.JOIN_TYPES, new DefaultType(datasetEntityDef));
source.put(JoinFunction.JOIN_TYPES, new DefaultType(unitEntityDef));
if (observationEntityDef != null) {
source.put(JoinFunction.JOIN_TYPES, new DefaultType(observationEntityDef));
assertEquals(3, source.get(JoinFunction.JOIN_TYPES).size());
} else {
assertEquals(2, source.get(JoinFunction.JOIN_TYPES).size());
}
ListMultimap<String, Type> target = ArrayListMultimap.create();
target.put(null, new DefaultType(new TypeEntityDefinition(landCoverDatasetType, SchemaSpaceID.TARGET, null)));
List<TypeEntityDefinition> types = new ArrayList<TypeEntityDefinition>(Arrays.asList(datasetEntityDef, unitEntityDef));
Set<JoinCondition> conditions = new HashSet<JoinCondition>();
// join dataset and unit
PropertyEntityDefinition baseProperty = getDatasetIdSourceProperty().values().iterator().next().getDefinition();
PropertyEntityDefinition joinProperty = getUnitDatasetIdSourceProperty(unitEntityDef.getType()).values().iterator().next().getDefinition();
conditions.add(new JoinCondition(baseProperty, joinProperty));
if (withChaining) {
// add observation type
types.add(observationEntityDef);
// join unit and observation
baseProperty = getUnitIdSourceProperty(unitEntityDef.getType()).values().iterator().next().getDefinition();
joinProperty = getObservationUnitIdSourceProperty().values().iterator().next().getDefinition();
conditions.add(new JoinCondition(baseProperty, joinProperty));
}
JoinParameter joinParam = new JoinParameter(types, conditions);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(JoinFunction.PARAMETER_JOIN, new ParameterValue(new ComplexValue(joinParam)));
joinCell.setSource(source);
joinCell.setTarget(target);
joinCell.setTransformationParameters(parameters);
return joinCell;
}
use of eu.esdihumboldt.hale.common.align.model.ParameterValue in project hale by halestudio.
the class AppSchemaMappingTest method testGmlGeometryPropertyIdEncoding.
@Test
public void testGmlGeometryPropertyIdEncoding() {
final String GML_ID_PATTERN = "geom.{dataset_id}.{unit_id}";
final String GML_ID_OCQL = "strConcat(strConcat(strConcat('geom.', dataset_id), '.'), unit_id)";
// create mapping context
AppSchemaMappingContext context = new AppSchemaMappingContext(mappingWrapper);
// create retype cell
Cell retypeCell = getDefaultTypeCell(unitDenormType, landCoverUnitType);
// create rename cell to produce LCU's geometry
DefaultCell geomRenameCell = new DefaultCell();
geomRenameCell.setTransformationIdentifier(RenameFunction.ID);
geomRenameCell.setSource(getUnitGeomSourceProperty(unitDenormType));
geomRenameCell.setTarget(getLandCoverUnitGeometryTargetProperty());
// create formatted string cell to produce LCU geometry's gml:id
DefaultCell geomGmlIdFormatCell = new DefaultCell();
geomGmlIdFormatCell.setTransformationIdentifier(FormattedStringFunction.ID);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(FormattedStringFunction.PARAMETER_PATTERN, new ParameterValue(GML_ID_PATTERN));
ListMultimap<String, Property> source = ArrayListMultimap.create();
source.putAll(FormattedStringFunction.ENTITY_VARIABLE, getUnitDatasetIdSourceProperty(unitDenormType).values());
source.putAll(FormattedStringFunction.ENTITY_VARIABLE, getUnitIdSourceProperty(unitDenormType).values());
geomGmlIdFormatCell.setSource(source);
geomGmlIdFormatCell.setTarget(getLandCoverUnitGeometryGmlIdTargetProperty());
geomGmlIdFormatCell.setTransformationParameters(parameters);
// process cells in whatever order
FormattedStringHandler formatHandler = new FormattedStringHandler();
formatHandler.handlePropertyTransformation(retypeCell, geomGmlIdFormatCell, context);
RenameHandler renameHandler = new RenameHandler();
AttributeMappingType attrMapping = renameHandler.handlePropertyTransformation(retypeCell, geomRenameCell, context);
assertEquals(SOURCE_GEOM, attrMapping.getSourceExpression().getOCQL());
assertNull(attrMapping.getTargetAttributeNode());
assertEquals(TARGET_GEOMETRY_LCU, attrMapping.getTargetAttribute());
assertNotNull(attrMapping.getIdExpression());
assertEquals(GML_ID_OCQL, attrMapping.getIdExpression().getOCQL());
}
use of eu.esdihumboldt.hale.common.align.model.ParameterValue in project hale by halestudio.
the class AppSchemaMappingTest method testGenericGeometryPropertyIdEncoding.
@Test
public void testGenericGeometryPropertyIdEncoding() {
final String GML_ID_PATTERN = "geom.{dataset_id}";
final String GML_ID_OCQL = "strConcat('geom.', dataset_id)";
// create mapping context
AppSchemaMappingContext context = new AppSchemaMappingContext(mappingWrapper);
// create retype cell
Cell retypeCell = getDefaultTypeCell(datasetType, landCoverDatasetType);
// create rename cell to produce LCD's geometry
DefaultCell geomRenameCell = new DefaultCell();
geomRenameCell.setTransformationIdentifier(RenameFunction.ID);
geomRenameCell.setSource(getDatasetGeomSourceProperty());
geomRenameCell.setTarget(getLandCoverDatasetGeometryTargetProperty());
// create formatted string cell to produce LCD geometry's gml:id
DefaultCell geomGmlIdFormatCell = new DefaultCell();
geomGmlIdFormatCell.setTransformationIdentifier(FormattedStringFunction.ID);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(FormattedStringFunction.PARAMETER_PATTERN, new ParameterValue(GML_ID_PATTERN));
ListMultimap<String, Property> source = ArrayListMultimap.create();
source.putAll(FormattedStringFunction.ENTITY_VARIABLE, getDatasetIdSourceProperty().values());
geomGmlIdFormatCell.setSource(source);
geomGmlIdFormatCell.setTarget(getLandCoverDatasetGeometryGmlIdTargetProperty());
geomGmlIdFormatCell.setTransformationParameters(parameters);
// process cells in whatever order
FormattedStringHandler formatHandler = new FormattedStringHandler();
formatHandler.handlePropertyTransformation(retypeCell, geomGmlIdFormatCell, context);
RenameHandler renameHandler = new RenameHandler();
AttributeMappingType attrMapping = renameHandler.handlePropertyTransformation(retypeCell, geomRenameCell, context);
assertEquals(SOURCE_GEOM, attrMapping.getSourceExpression().getOCQL());
assertEquals("gml:MultiSurfaceType", attrMapping.getTargetAttributeNode());
assertEquals(TARGET_GEOMETRY_LCD, attrMapping.getTargetAttribute());
assertNotNull(attrMapping.getIdExpression());
assertEquals(GML_ID_OCQL, attrMapping.getIdExpression().getOCQL());
}
Aggregations