Search in sources :

Example 6 with DefaultCell

use of eu.esdihumboldt.hale.common.align.model.impl.DefaultCell 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());
}
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) 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) 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 7 with DefaultCell

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

the class AppSchemaMappingTest method testNestedJoinHandler.

@Test
public void testNestedJoinHandler() {
    DefaultCell joinCell = buildJoinCell(null);
    // create minimal alignment and pass it to JoinHandler
    DefaultCell renameCell = new DefaultCell();
    renameCell.setTransformationIdentifier(RenameFunction.ID);
    renameCell.setSource(getUuidSourceProperty(unitDenormType));
    renameCell.setTarget(getNestedUnitLocalIdTargetProperty());
    DefaultAlignment alignment = new DefaultAlignment();
    alignment.addCell(joinCell);
    alignment.addCell(renameCell);
    processJoinAlignment(alignment, null);
    // logMapping(mappingWrapper.getMainMapping());
    List<FeatureTypeMapping> ftMappings = mappingWrapper.getMainMapping().getTypeMappings().getFeatureTypeMapping();
    assertEquals(2, ftMappings.size());
    FeatureTypeMapping lcdMapping = null, lcuMapping = null;
    for (FeatureTypeMapping ftMapping : ftMappings) {
        if (SOURCE_DATASET.equals(ftMapping.getSourceType()) && "lcv:LandCoverDataset".equals(ftMapping.getTargetElement())) {
            lcdMapping = ftMapping;
        }
        if (SOURCE_UNIT_DENORM.equals(ftMapping.getSourceType()) && "lcv:LandCoverUnit".equals(ftMapping.getTargetElement())) {
            lcuMapping = ftMapping;
        }
    }
    assertNotNull(lcdMapping);
    assertNotNull(lcuMapping);
    // check feature chaining configuration
    List<AttributeMappingType> lcdAttrMappings = lcdMapping.getAttributeMappings().getAttributeMapping();
    List<AttributeMappingType> lcuAttrMappings = lcuMapping.getAttributeMappings().getAttributeMapping();
    assertNotNull(lcdAttrMappings);
    assertNotNull(lcuAttrMappings);
    assertEquals(1, lcdAttrMappings.size());
    assertEquals(2, lcuAttrMappings.size());
    AttributeMappingType containerMapping = lcdAttrMappings.get(0);
    assertEquals("lcv:member", containerMapping.getTargetAttribute());
    assertEquals("lcv:LandCoverUnit", containerMapping.getSourceExpression().getLinkElement());
    assertEquals("FEATURE_LINK[1]", containerMapping.getSourceExpression().getLinkField());
    assertEquals(SOURCE_DATASET_ID, containerMapping.getSourceExpression().getOCQL());
    assertTrue(containerMapping.isIsMultiple());
    AttributeMappingType nestedMapping = lcuAttrMappings.get(0);
    assertEquals("FEATURE_LINK[1]", nestedMapping.getTargetAttribute());
    assertEquals(SOURCE_DATASET_ID, nestedMapping.getSourceExpression().getOCQL());
    assertNull(nestedMapping.getSourceExpression().getLinkElement());
    assertNull(nestedMapping.getSourceExpression().getLinkField());
}
Also used : AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) Test(org.junit.Test)

Example 8 with DefaultCell

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

the class AppSchemaMappingTest method getDefaultTypeCell.

private Cell getDefaultTypeCell(TypeDefinition sourceType, TypeDefinition targetType) {
    DefaultCell typeCell = new DefaultCell();
    typeCell.setTransformationIdentifier(RetypeFunction.ID);
    ListMultimap<String, Type> source = ArrayListMultimap.create();
    source.put(null, new DefaultType(new TypeEntityDefinition(sourceType, SchemaSpaceID.SOURCE, null)));
    ListMultimap<String, Type> target = ArrayListMultimap.create();
    target.put(null, new DefaultType(new TypeEntityDefinition(targetType, SchemaSpaceID.TARGET, null)));
    typeCell.setSource(source);
    typeCell.setTarget(target);
    return typeCell;
}
Also used : Type(eu.esdihumboldt.hale.common.align.model.Type) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) AppSchemaDataAccessType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType)

Example 9 with DefaultCell

use of eu.esdihumboldt.hale.common.align.model.impl.DefaultCell 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 10 with DefaultCell

use of eu.esdihumboldt.hale.common.align.model.impl.DefaultCell 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());
}
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)

Aggregations

DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)47 Test (org.junit.Test)24 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)22 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)21 Cell (eu.esdihumboldt.hale.common.align.model.Cell)17 AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)17 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)16 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)15 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)13 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)12 Type (eu.esdihumboldt.hale.common.align.model.Type)11 ArrayList (java.util.ArrayList)10 Property (eu.esdihumboldt.hale.common.align.model.Property)9 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)9 ClientProperty (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty)9 Entity (eu.esdihumboldt.hale.common.align.model.Entity)8 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)8 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)7 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)7 AssignHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler)6