Search in sources :

Example 11 with AppSchemaMappingContext

use of eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext 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 12 with AppSchemaMappingContext

use of eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext 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());
}
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) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) Test(org.junit.Test)

Example 13 with AppSchemaMappingContext

use of eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext 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 14 with AppSchemaMappingContext

use of eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext in project hale by halestudio.

the class AppSchemaMappingTest method initMapping.

@Before
public void initMapping() {
    mappingWrapper = new AppSchemaMappingWrapper(new AppSchemaDataAccessType());
    mappingContext = new AppSchemaMappingContext(mappingWrapper);
    // initialize namespaces
    mappingContext.getOrCreateNamespace(LANDCOVER_NS, LANDCOVER_PREFIX);
    mappingContext.getOrCreateNamespace(BASE_NS, BASE_PREFIX);
    mappingContext.getOrCreateNamespace(GML_NS, GML_PREFIX);
    mappingContext.getOrCreateNamespace(GMD_NS, GMD_PREFIX);
    mappingContext.getOrCreateNamespace(XLINK_NS, XLINK_PREFIX);
}
Also used : AppSchemaDataAccessType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) AppSchemaMappingWrapper(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingWrapper) Before(org.junit.Before)

Example 15 with AppSchemaMappingContext

use of eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext 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

AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)20 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)18 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)17 Test (org.junit.Test)17 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)13 ClientProperty (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty)9 Cell (eu.esdihumboldt.hale.common.align.model.Cell)7 RenameHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler)7 Property (eu.esdihumboldt.hale.common.align.model.Property)6 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)6 AssignHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler)6 FormattedStringHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler)4 AppSchemaDataAccessType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType)3 UnsupportedTransformationException (eu.esdihumboldt.hale.io.appschema.writer.internal.UnsupportedTransformationException)2 AppSchemaMappingWrapper (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingWrapper)2 Type (eu.esdihumboldt.hale.common.align.model.Type)1 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)1 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)1 Value (eu.esdihumboldt.hale.common.core.io.Value)1 ComplexValue (eu.esdihumboldt.hale.common.core.io.impl.ComplexValue)1