Search in sources :

Example 86 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class AppSchemaMappingTest method testClassificationHandler.

@Test
public void testClassificationHandler() {
    final int FIRST_SOURCE = 1000;
    final String FIRST_TARGET = "http://www.example.com/first";
    final int SECOND_SOURCE = 2000;
    final String SECOND_TARGET = "http://www.example.com/second";
    final int THIRD_SOURCE = 3000;
    final String THIRD_TARGET = "http://www.example.com/third";
    final String FIXED_VALUE = "http://www.example.com/unknown";
    final String OCQL_PATTERN = "if_then_else(in(unit_id,%s), Recode(unit_id,%s), %s)";
    Cell typeCell = getDefaultTypeCell(unitDenormType, landCoverUnitType);
    DefaultCell cell = new DefaultCell();
    cell.setTransformationIdentifier(ClassificationMappingFunction.ID);
    cell.setSource(getUnitIdSourceProperty(unitDenormType));
    cell.setTarget(getMetaDataHrefTargetProperty());
    Map<Value, Value> tableValues = new HashMap<Value, Value>();
    tableValues.put(new StringValue(FIRST_SOURCE), new StringValue(FIRST_TARGET));
    tableValues.put(new StringValue(SECOND_SOURCE), new StringValue(SECOND_TARGET));
    tableValues.put(new StringValue(THIRD_SOURCE), new StringValue(THIRD_TARGET));
    LookupTable lookupTable = new LookupTableImpl(tableValues);
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    parameters.put(ClassificationMappingFunction.PARAMETER_LOOKUPTABLE, new ParameterValue(new ComplexValue(lookupTable)));
    parameters.put(ClassificationMapping.PARAMETER_NOT_CLASSIFIED_ACTION, new ParameterValue(ClassificationMapping.USE_SOURCE_ACTION));
    cell.setTransformationParameters(parameters);
    StringBuilder inArgs = new StringBuilder();
    StringBuilder recodeArgs = new StringBuilder();
    int count = 0;
    for (Value sourceValue : tableValues.keySet()) {
        inArgs.append(sourceValue.as(String.class));
        recodeArgs.append(sourceValue).append(",'").append(tableValues.get(sourceValue)).append("'");
        if (count < tableValues.size() - 1) {
            inArgs.append(",");
            recodeArgs.append(",");
        }
        count++;
    }
    final String OCQL_USE_SOURCE = String.format(OCQL_PATTERN, inArgs.toString(), recodeArgs.toString(), "unit_id");
    final String OCQL_USE_NULL = String.format(OCQL_PATTERN, inArgs.toString(), recodeArgs.toString(), "Expression.NIL");
    final String OCQL_USE_FIXED = String.format(OCQL_PATTERN, inArgs.toString(), recodeArgs.toString(), "'" + FIXED_VALUE + "'");
    ClassificationHandler classificationHandler = new ClassificationHandler();
    AttributeMappingType attrMapping = classificationHandler.handlePropertyTransformation(typeCell, cell, new AppSchemaMappingContext(mappingWrapper));
    assertNotNull(attrMapping.getClientProperty());
    assertEquals(1, attrMapping.getClientProperty().size());
    assertEquals("xlink:href", attrMapping.getClientProperty().get(0).getName());
    assertEquals(OCQL_USE_SOURCE, attrMapping.getClientProperty().get(0).getValue());
    assertEquals(TARGET_METADATA, attrMapping.getTargetAttribute());
    // reset mapping
    initMapping();
    parameters.removeAll(ClassificationMapping.PARAMETER_NOT_CLASSIFIED_ACTION);
    parameters.put(ClassificationMapping.PARAMETER_NOT_CLASSIFIED_ACTION, new ParameterValue(ClassificationMapping.USE_NULL_ACTION));
    cell.setTransformationParameters(parameters);
    attrMapping = classificationHandler.handlePropertyTransformation(typeCell, cell, new AppSchemaMappingContext(mappingWrapper));
    assertNotNull(attrMapping.getClientProperty());
    assertEquals(1, attrMapping.getClientProperty().size());
    assertEquals("xlink:href", attrMapping.getClientProperty().get(0).getName());
    assertEquals(OCQL_USE_NULL, attrMapping.getClientProperty().get(0).getValue());
    assertEquals(TARGET_METADATA, attrMapping.getTargetAttribute());
    // reset mapping
    initMapping();
    parameters.removeAll(ClassificationMapping.PARAMETER_NOT_CLASSIFIED_ACTION);
    parameters.put(ClassificationMapping.PARAMETER_NOT_CLASSIFIED_ACTION, new ParameterValue(ClassificationMapping.USE_FIXED_VALUE_ACTION_PREFIX + FIXED_VALUE));
    cell.setTransformationParameters(parameters);
    attrMapping = classificationHandler.handlePropertyTransformation(typeCell, cell, new AppSchemaMappingContext(mappingWrapper));
    assertNotNull(attrMapping.getClientProperty());
    assertEquals(1, attrMapping.getClientProperty().size());
    assertEquals("xlink:href", attrMapping.getClientProperty().get(0).getName());
    assertEquals(OCQL_USE_FIXED, attrMapping.getClientProperty().get(0).getValue());
    assertEquals(TARGET_METADATA, attrMapping.getTargetAttribute());
}
Also used : ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) HashMap(java.util.HashMap) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) StringValue(eu.esdihumboldt.hale.common.core.io.impl.StringValue) Value(eu.esdihumboldt.hale.common.core.io.Value) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) LookupTable(eu.esdihumboldt.hale.common.lookup.LookupTable) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) StringValue(eu.esdihumboldt.hale.common.core.io.impl.StringValue) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) ClassificationHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.ClassificationHandler) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl) Test(org.junit.Test)

Example 87 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell 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 88 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell 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 89 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell 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 90 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class AppSchemaMappingTest method processJoinAlignment.

private void processJoinAlignment(Alignment alignment, FeatureChaining chainingConf) {
    AppSchemaMappingContext context = new AppSchemaMappingContext(mappingWrapper, alignment, targetTypes, chainingConf, null);
    Cell joinCell = alignment.getTypeCells().iterator().next();
    JoinHandler handler = new JoinHandler();
    handler.handleTypeTransformation(joinCell, context);
    for (Cell propertyCell : alignment.getPropertyCells(joinCell)) {
        String propertyTransformId = propertyCell.getTransformationIdentifier();
        PropertyTransformationHandler propertyTransformHandler;
        try {
            propertyTransformHandler = PropertyTransformationHandlerFactory.getInstance().createPropertyTransformationHandler(propertyTransformId);
            propertyTransformHandler.handlePropertyTransformation(joinCell, propertyCell, context);
        } catch (UnsupportedTransformationException e) {
            Assert.fail("Unsupported transformation was found");
        }
    }
}
Also used : UnsupportedTransformationException(eu.esdihumboldt.hale.io.appschema.writer.internal.UnsupportedTransformationException) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) PropertyTransformationHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.PropertyTransformationHandler) JoinHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.JoinHandler) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Aggregations

Cell (eu.esdihumboldt.hale.common.align.model.Cell)123 ArrayList (java.util.ArrayList)33 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)28 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)28 Test (org.junit.Test)27 Entity (eu.esdihumboldt.hale.common.align.model.Entity)24 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)24 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)18 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)16 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)16 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)13 HashSet (java.util.HashSet)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 Type (eu.esdihumboldt.hale.common.align.model.Type)11 List (java.util.List)11 ModifiableCell (eu.esdihumboldt.hale.common.align.model.ModifiableCell)9 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)9 Property (eu.esdihumboldt.hale.common.align.model.Property)8