use of eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler in project hale by halestudio.
the class AppSchemaMappingTest method testNilReasonOnNotNillableElement.
@Test
public void testNilReasonOnNotNillableElement() {
final String nilReason = "missing";
final String nilReasonAssignCQL = "'" + nilReason + "'";
final String nilReasonRenameCQL = SOURCE_UUID_V1;
// --- test with a constant mapping --- //
DefaultCell assignNilReason = new DefaultCell();
assignNilReason.setTransformationIdentifier(AssignFunction.ID);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(nilReason));
assignNilReason.setTarget(getDescriptionNilReasonTargetProperty());
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("gml:description", attrMapping.getTargetAttribute());
assertNull(attrMapping.getSourceExpression());
assertEquals(1, attrMapping.getClientProperty().size());
assertEquals(GML_NIL_REASON, attrMapping.getClientProperty().get(0).getName());
assertEquals(nilReasonAssignCQL, attrMapping.getClientProperty().get(0).getValue());
// encodeIfEmpty=true because we are using a constant mapping
assertTrue(attrMapping.isEncodeIfEmpty());
// --- test with a non-constant mapping --- //
DefaultCell rename = new DefaultCell();
rename.setTransformationIdentifier(RenameFunction.ID);
rename.setSource(getUuidSourceProperty(unitType));
rename.setTarget(getDescriptionNilReasonTargetProperty());
// reset mapping
initMapping();
context = new AppSchemaMappingContext(mappingWrapper);
// process rename
RenameHandler renameHandler = new RenameHandler();
attrMapping = renameHandler.handlePropertyTransformation(typeCell, rename, context);
assertNotNull(attrMapping);
assertEquals("gml:description", attrMapping.getTargetAttribute());
assertNull(attrMapping.getSourceExpression());
assertEquals(1, attrMapping.getClientProperty().size());
assertEquals(GML_NIL_REASON, attrMapping.getClientProperty().get(0).getName());
assertEquals(nilReasonRenameCQL, attrMapping.getClientProperty().get(0).getValue());
// encodeIfEmpty has not been set, because we are using a mapping which
// is a function of the source value
assertNull(attrMapping.isEncodeIfEmpty());
}
use of eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler in project hale by halestudio.
the class AppSchemaMappingTest method testFeatureGmlIdEncoding.
@Test
public void testFeatureGmlIdEncoding() {
DefaultCell cell = new DefaultCell();
cell.setTransformationIdentifier(RenameFunction.ID);
cell.setSource(getUnitIdSourceProperty(unitDenormType));
cell.setTarget(getGmlIdTargetProperty());
RenameHandler renameHandler = new RenameHandler();
AttributeMappingType attrMapping = renameHandler.handlePropertyTransformation(getDefaultTypeCell(unitDenormType, landCoverUnitType), cell, new AppSchemaMappingContext(mappingWrapper));
assertNull(attrMapping.getSourceExpression());
assertEquals(SOURCE_UNIT_ID, attrMapping.getIdExpression().getOCQL());
assertEquals("lcv:LandCoverUnit", attrMapping.getTargetAttribute());
}
use of eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler in project hale by halestudio.
the class AppSchemaMappingTest method testRenameHandler.
@Test
public void testRenameHandler() {
DefaultCell cell = new DefaultCell();
cell.setTransformationIdentifier(RenameFunction.ID);
cell.setSource(getUuidSourceProperty(unitDenormType));
cell.setTarget(getLocalIdTargetProperty());
RenameHandler renameHandler = new RenameHandler();
AttributeMappingType attrMapping = renameHandler.handlePropertyTransformation(getDefaultTypeCell(unitDenormType, landCoverUnitType), cell, new AppSchemaMappingContext(mappingWrapper));
assertEquals("uuid_v1", attrMapping.getSourceExpression().getOCQL());
assertEquals(TARGET_LOCAL_ID, attrMapping.getTargetAttribute());
}
use of eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler 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.io.appschema.writer.internal.RenameHandler 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());
}
Aggregations