Search in sources :

Example 1 with FormattedStringHandler

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

the class AppSchemaMappingTest method testEncodeIfEmptyFalse.

@Test
public void testEncodeIfEmptyFalse() {
    final String XLINK_HREF_PATTERN = "#lcu.{dataset_id}";
    final String OCQL_STR_CONCAT = "strConcat('#lcu.', dataset_id)";
    DefaultCell format = new DefaultCell();
    format.setTransformationIdentifier(FormattedStringFunction.ID);
    ListMultimap<String, ParameterValue> formatParameters = ArrayListMultimap.create();
    formatParameters.put(FormattedStringFunction.PARAMETER_PATTERN, new ParameterValue(XLINK_HREF_PATTERN));
    ListMultimap<String, Property> source = ArrayListMultimap.create();
    source.putAll(FormattedStringFunction.ENTITY_VARIABLE, getDatasetIdSourceProperty().values());
    format.setSource(source);
    format.setTarget(getNestedUnitHrefTargetProperty());
    format.setTransformationParameters(formatParameters);
    FormattedStringHandler formatHandler = new FormattedStringHandler();
    AttributeMappingType attrMapping = formatHandler.handlePropertyTransformation(getDefaultTypeCell(datasetType, landCoverDatasetType), format, new AppSchemaMappingContext(mappingWrapper));
    assertNull(attrMapping.getSourceExpression());
    assertEquals("lcv:member", attrMapping.getTargetAttribute());
    assertNotNull(attrMapping.getClientProperty());
    assertEquals(1, attrMapping.getClientProperty().size());
    assertEquals("xlink:href", attrMapping.getClientProperty().get(0).getName());
    assertEquals(OCQL_STR_CONCAT, attrMapping.getClientProperty().get(0).getValue());
    // expression is NOT constant, so encodeIfEmpty=null (won't be XML
    // encoded)
    assertNull(attrMapping.isEncodeIfEmpty());
}
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) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) FormattedStringHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler) 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)

Example 2 with FormattedStringHandler

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

Example 3 with FormattedStringHandler

use of eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler 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());
}
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)

Example 4 with FormattedStringHandler

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

the class AppSchemaMappingTest method testFormattedStringHandler.

@Test
public void testFormattedStringHandler() {
    final String PATTERN = "Class 2007: {ucs2007}; Class 2013: {ucs2013}";
    final String OCQL = "strConcat(strConcat(strConcat('Class 2007: ', ucs2007), '; Class 2013: '), ucs2013)";
    DefaultCell cell = new DefaultCell();
    cell.setTransformationIdentifier(FormattedStringFunction.ID);
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    parameters.put(FormattedStringFunction.PARAMETER_PATTERN, new ParameterValue(PATTERN));
    ListMultimap<String, Property> source = ArrayListMultimap.create();
    source.putAll(FormattedStringFunction.ENTITY_VARIABLE, getUcs2007SourceProperty().values());
    source.putAll(FormattedStringFunction.ENTITY_VARIABLE, getUcs2013SourceProperty().values());
    cell.setSource(source);
    cell.setTarget(getDescriptionTargetProperty());
    cell.setTransformationParameters(parameters);
    FormattedStringHandler handler = new FormattedStringHandler();
    AttributeMappingType attrMapping = handler.handlePropertyTransformation(getDefaultTypeCell(unitDenormType, landCoverUnitType), cell, new AppSchemaMappingContext(mappingWrapper));
    assertEquals(OCQL, attrMapping.getSourceExpression().getOCQL());
    assertEquals(TARGET_DESCRIPTION, attrMapping.getTargetAttribute());
}
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) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) FormattedStringHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler) 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

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