Search in sources :

Example 26 with DefaultCell

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

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

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

the class AppSchemaMappingTest method buildJoinCell.

@SuppressWarnings("null")
private DefaultCell buildJoinCell(FeatureChaining chainingConf) {
    boolean withChaining = chainingConf != null;
    DefaultCell joinCell = new DefaultCell();
    joinCell.setTransformationIdentifier(JoinFunction.ID);
    if (withChaining) {
        // set cell ID from feature chaining configuration
        // WARNING: this code assumes only one join is configured
        joinCell.setId(chainingConf.getJoins().keySet().iterator().next());
    }
    TypeEntityDefinition datasetEntityDef = new TypeEntityDefinition(datasetType, SchemaSpaceID.SOURCE, null);
    TypeEntityDefinition unitEntityDef = null;
    TypeEntityDefinition observationEntityDef = null;
    if (!withChaining) {
        unitEntityDef = new TypeEntityDefinition(unitDenormType, SchemaSpaceID.SOURCE, null);
    } else {
        unitEntityDef = new TypeEntityDefinition(unitType, SchemaSpaceID.SOURCE, null);
        observationEntityDef = new TypeEntityDefinition(observationType, SchemaSpaceID.SOURCE, null);
    }
    ListMultimap<String, Type> source = ArrayListMultimap.create();
    source.put(JoinFunction.JOIN_TYPES, new DefaultType(datasetEntityDef));
    source.put(JoinFunction.JOIN_TYPES, new DefaultType(unitEntityDef));
    if (observationEntityDef != null) {
        source.put(JoinFunction.JOIN_TYPES, new DefaultType(observationEntityDef));
        assertEquals(3, source.get(JoinFunction.JOIN_TYPES).size());
    } else {
        assertEquals(2, source.get(JoinFunction.JOIN_TYPES).size());
    }
    ListMultimap<String, Type> target = ArrayListMultimap.create();
    target.put(null, new DefaultType(new TypeEntityDefinition(landCoverDatasetType, SchemaSpaceID.TARGET, null)));
    List<TypeEntityDefinition> types = new ArrayList<TypeEntityDefinition>(Arrays.asList(datasetEntityDef, unitEntityDef));
    Set<JoinCondition> conditions = new HashSet<JoinCondition>();
    // join dataset and unit
    PropertyEntityDefinition baseProperty = getDatasetIdSourceProperty().values().iterator().next().getDefinition();
    PropertyEntityDefinition joinProperty = getUnitDatasetIdSourceProperty(unitEntityDef.getType()).values().iterator().next().getDefinition();
    conditions.add(new JoinCondition(baseProperty, joinProperty));
    if (withChaining) {
        // add observation type
        types.add(observationEntityDef);
        // join unit and observation
        baseProperty = getUnitIdSourceProperty(unitEntityDef.getType()).values().iterator().next().getDefinition();
        joinProperty = getObservationUnitIdSourceProperty().values().iterator().next().getDefinition();
        conditions.add(new JoinCondition(baseProperty, joinProperty));
    }
    JoinParameter joinParam = new JoinParameter(types, conditions);
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    parameters.put(JoinFunction.PARAMETER_JOIN, new ParameterValue(new ComplexValue(joinParam)));
    joinCell.setSource(source);
    joinCell.setTarget(target);
    joinCell.setTransformationParameters(parameters);
    return joinCell;
}
Also used : ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) ArrayList(java.util.ArrayList) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) 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) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) HashSet(java.util.HashSet)

Example 29 with DefaultCell

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

the class AppSchemaMappingTest method testFeatureChainingJoin.

@Test
public void testFeatureChainingJoin() throws Exception {
    FeatureChaining chainingConf = readFeatureChainingConfiguration(FEATURE_CHAINING_CONF_PATH);
    assertNotNull(chainingConf);
    DefaultCell joinCell = buildJoinCell(chainingConf);
    // create minimal alignment and pass it to JoinHandler
    DefaultAlignment alignment = new DefaultAlignment();
    alignment.addCell(joinCell);
    DefaultCell renameCell = new DefaultCell();
    renameCell.setTransformationIdentifier(RenameFunction.ID);
    renameCell.setSource(getUuidSourceProperty(unitType));
    renameCell.setTarget(getNestedUnitLocalIdTargetProperty());
    alignment.addCell(renameCell);
    DefaultCell renameClassCell = new DefaultCell();
    renameClassCell.setTransformationIdentifier(RenameFunction.ID);
    renameClassCell.setSource(getObservationClassSourceProperty());
    renameClassCell.setTarget(getNestedObservationClassTargetProperty());
    alignment.addCell(renameClassCell);
    processJoinAlignment(alignment, chainingConf);
    // logMapping(mappingWrapper.getMainMapping());
    // logMapping(mappingWrapper.getIncludedTypesMapping());
    List<FeatureTypeMapping> mainMappings = mappingWrapper.getMainMapping().getTypeMappings().getFeatureTypeMapping();
    assertEquals(2, mainMappings.size());
    List<FeatureTypeMapping> includedMappings = mappingWrapper.getIncludedTypesMapping().getTypeMappings().getFeatureTypeMapping();
    assertEquals(1, includedMappings.size());
    FeatureTypeMapping obsMapping = includedMappings.get(0);
    assertTrue(SOURCE_OBSERVATION.equals(obsMapping.getSourceType()) && "lcv:LandCoverObservation".equals(obsMapping.getTargetElement()));
    FeatureTypeMapping lcdMapping = null, lcuMapping = null;
    for (FeatureTypeMapping ftMapping : mainMappings) {
        if (SOURCE_DATASET.equals(ftMapping.getSourceType()) && "lcv:LandCoverDataset".equals(ftMapping.getTargetElement())) {
            lcdMapping = ftMapping;
        }
        if (SOURCE_UNIT.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();
    List<AttributeMappingType> obsAttrMappings = obsMapping.getAttributeMappings().getAttributeMapping();
    assertNotNull(lcdAttrMappings);
    assertNotNull(lcuAttrMappings);
    assertNotNull(obsAttrMappings);
    assertEquals(1, lcdAttrMappings.size());
    assertEquals(3, lcuAttrMappings.size());
    assertEquals(2, obsAttrMappings.size());
    // NOTE: the order of attribute mappings is predictable, as it follows
    // the order of join conditions
    AttributeMappingType datasetContainerMapping = lcdAttrMappings.get(0);
    assertEquals("lcv:member", datasetContainerMapping.getTargetAttribute());
    assertEquals("lcv:LandCoverUnit", datasetContainerMapping.getSourceExpression().getLinkElement());
    assertEquals("FEATURE_LINK[1]", datasetContainerMapping.getSourceExpression().getLinkField());
    assertEquals(SOURCE_DATASET_ID, datasetContainerMapping.getSourceExpression().getOCQL());
    assertTrue(datasetContainerMapping.isIsMultiple());
    AttributeMappingType unitNestedMapping = lcuAttrMappings.get(0);
    assertEquals("FEATURE_LINK[1]", unitNestedMapping.getTargetAttribute());
    assertEquals(SOURCE_DATASET_ID, unitNestedMapping.getSourceExpression().getOCQL());
    assertNull(unitNestedMapping.getSourceExpression().getLinkElement());
    assertNull(unitNestedMapping.getSourceExpression().getLinkField());
    assertNull(unitNestedMapping.isIsMultiple());
    AttributeMappingType unitContainerMapping = lcuAttrMappings.get(1);
    assertEquals("lcv:landCoverObservation", unitContainerMapping.getTargetAttribute());
    assertEquals(SOURCE_UNIT_ID, unitContainerMapping.getSourceExpression().getOCQL());
    assertEquals("lcv:LandCoverObservation", unitContainerMapping.getSourceExpression().getLinkElement());
    assertEquals("FEATURE_LINK[1]", unitContainerMapping.getSourceExpression().getLinkField());
    assertTrue(unitContainerMapping.isIsMultiple());
    AttributeMappingType unitLocalIdMapping = lcuAttrMappings.get(2);
    assertEquals(TARGET_LOCAL_ID, unitLocalIdMapping.getTargetAttribute());
    assertEquals(SOURCE_UUID_V1, unitLocalIdMapping.getSourceExpression().getOCQL());
    assertNull(unitLocalIdMapping.getSourceExpression().getLinkElement());
    assertNull(unitLocalIdMapping.getSourceExpression().getLinkField());
    assertNull(unitLocalIdMapping.isIsMultiple());
    AttributeMappingType observationNestedMapping = obsAttrMappings.get(0);
    assertEquals("FEATURE_LINK[1]", observationNestedMapping.getTargetAttribute());
    assertEquals(SOURCE_OBS_UNIT_ID, observationNestedMapping.getSourceExpression().getOCQL());
    assertNull(observationNestedMapping.getSourceExpression().getLinkElement());
    assertNull(observationNestedMapping.getSourceExpression().getLinkField());
    assertNull(observationNestedMapping.isIsMultiple());
    AttributeMappingType observationClassMapping = obsAttrMappings.get(1);
    assertEquals("lcv:class", observationClassMapping.getTargetAttribute());
    assertEquals(SOURCE_OBS_CLASS, observationClassMapping.getSourceExpression().getOCQL());
    assertNull(observationClassMapping.getSourceExpression().getLinkElement());
    assertNull(observationClassMapping.getSourceExpression().getLinkField());
    assertNull(observationClassMapping.isIsMultiple());
}
Also used : FeatureChaining(eu.esdihumboldt.hale.io.appschema.model.FeatureChaining) 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 30 with DefaultCell

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