use of eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler 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.AssignHandler in project hale by halestudio.
the class AppSchemaMappingTest method testAssignHandler.
@Test
public void testAssignHandler() {
final String ASSIGN_VALUE = "LCU_1234";
final String OCQL = "'" + ASSIGN_VALUE + "'";
final String OCQL_BOUND = "if_then_else(isNull(" + SOURCE_UUID_V1 + "), Expression.NIL, '" + ASSIGN_VALUE + "')";
Cell typeCell = getDefaultTypeCell(unitDenormType, landCoverUnitType);
DefaultCell cell = new DefaultCell();
cell.setTransformationIdentifier(AssignFunction.ID);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(ASSIGN_VALUE));
cell.setTarget(getLocalIdTargetProperty());
cell.setTransformationParameters(parameters);
AssignHandler assignHandler = new AssignHandler();
AttributeMappingType attrMapping = assignHandler.handlePropertyTransformation(typeCell, cell, new AppSchemaMappingContext(mappingWrapper));
assertEquals(OCQL, attrMapping.getSourceExpression().getOCQL());
assertEquals(TARGET_LOCAL_ID, attrMapping.getTargetAttribute());
// bound version of "Assign"
DefaultCell cellCopy = new DefaultCell(cell);
Collection<Property> anchor = getUuidSourceProperty(unitDenormType).values();
ListMultimap<String, Property> source = ArrayListMultimap.create();
source.putAll(AssignFunction.ENTITY_ANCHOR, anchor);
cellCopy.setSource(source);
cellCopy.setTransformationIdentifier(AssignFunction.ID_BOUND);
attrMapping = assignHandler.handlePropertyTransformation(typeCell, cellCopy, new AppSchemaMappingContext(mappingWrapper));
assertEquals(OCQL_BOUND, attrMapping.getSourceExpression().getOCQL());
assertEquals(TARGET_LOCAL_ID, attrMapping.getTargetAttribute());
}
use of eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler in project hale by halestudio.
the class AppSchemaMappingTest method testXmlAttributeEncodingUnqualified.
@Test
public void testXmlAttributeEncodingUnqualified() {
final String CODE_SPACE = "http://www.example.com/codespace";
final String OCQL = "'" + CODE_SPACE + "'";
DefaultCell cell = new DefaultCell();
cell.setTransformationIdentifier(AssignFunction.ID);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(CODE_SPACE));
cell.setTransformationParameters(parameters);
cell.setTarget(getCodeSpaceTargetProperty());
AssignHandler handler = new AssignHandler();
AttributeMappingType attrMapping = handler.handlePropertyTransformation(getDefaultTypeCell(unitDenormType, landCoverUnitType), cell, new AppSchemaMappingContext(mappingWrapper));
assertNull(attrMapping.getSourceExpression());
assertEquals("gml:name", attrMapping.getTargetAttribute());
assertNotNull(attrMapping.getClientProperty());
assertEquals(1, attrMapping.getClientProperty().size());
ClientProperty attr = attrMapping.getClientProperty().get(0);
assertEquals("codeSpace", attr.getName());
assertEquals(OCQL, attr.getValue());
}
use of eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler 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.io.appschema.writer.internal.AssignHandler 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());
}
Aggregations