Search in sources :

Example 1 with RenameHandler

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());
}
Also used : AssignHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) RenameHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Test(org.junit.Test)

Example 2 with RenameHandler

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());
}
Also used : AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) RenameHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) Test(org.junit.Test)

Example 3 with RenameHandler

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());
}
Also used : AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) RenameHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) Test(org.junit.Test)

Example 4 with RenameHandler

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());
}
Also used : AssignHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler) ClientProperty(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) RenameHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Test(org.junit.Test)

Example 5 with RenameHandler

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());
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) RenameHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) FormattedStringHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Property(eu.esdihumboldt.hale.common.align.model.Property) ClientProperty(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) Test(org.junit.Test)

Aggregations

DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)7 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)7 RenameHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler)7 AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)7 Test (org.junit.Test)7 Cell (eu.esdihumboldt.hale.common.align.model.Cell)4 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)4 ClientProperty (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty)3 Property (eu.esdihumboldt.hale.common.align.model.Property)2 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)2 AssignHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler)2 FormattedStringHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler)2