Search in sources :

Example 6 with AttributeMappingType

use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType in project hale by halestudio.

the class AppSchemaMappingWrapper method getOrCreateAttributeMapping.

/**
 * Return the attribute mapping associated to the provided property.
 *
 * <p>
 * If an attribute mapping for the provided property already exists, it is
 * returned; otherwise, a new one is created.
 * </p>
 *
 * @param owningType the type owning the property
 * @param mappingName the mapping name
 * @param propertyPath the property path
 * @return the attribute mapping
 */
AttributeMappingType getOrCreateAttributeMapping(TypeDefinition owningType, String mappingName, List<ChildContext> propertyPath) {
    if (propertyPath == null || propertyPath.isEmpty()) {
        return null;
    }
    Integer hashKey = getAttruteMappingHashKey(owningType, propertyPath);
    if (!attributeMappings.containsKey(hashKey)) {
        // create
        AttributeMappingType attrMapping = new AttributeMappingType();
        // add to owning type mapping
        FeatureTypeMapping ftMapping = getOrCreateFeatureTypeMapping(owningType, mappingName);
        ftMapping.getAttributeMappings().getAttributeMapping().add(attrMapping);
        // put into internal map
        attributeMappings.put(hashKey, attrMapping);
    }
    return attributeMappings.get(hashKey);
}
Also used : AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)

Example 7 with AttributeMappingType

use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType in project hale by halestudio.

the class AppSchemaMappingTest method testXrefJoinHandler.

@Test
public void testXrefJoinHandler() {
    DefaultCell joinCell = buildJoinCell(null);
    // create minimal alignment and pass it to JoinHandler
    DefaultCell renameCell = new DefaultCell();
    renameCell.setTransformationIdentifier(RenameFunction.ID);
    renameCell.setSource(getUnitIdSourceProperty(unitDenormType));
    renameCell.setTarget(getNestedUnitHrefTargetProperty());
    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(1, 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());
    assertNotNull(containerMapping.getClientProperty());
    assertEquals(1, containerMapping.getClientProperty().size());
    assertEquals("xlink:href", containerMapping.getClientProperty().get(0).getName());
    assertEquals(SOURCE_UNIT_ID, containerMapping.getClientProperty().get(0).getValue());
    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 AttributeMappingType

use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType 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 9 with AttributeMappingType

use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType in project hale by halestudio.

the class AppSchemaMappingTest method testDateExtractionHandler.

@Test
public void testDateExtractionHandler() {
    final String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";
    final String OCQL = "dateParse(" + SOURCE_UUID_V1 + ", '" + DATE_FORMAT + "')";
    DefaultCell cell = new DefaultCell();
    cell.setTransformationIdentifier(DateExtractionFunction.ID);
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    parameters.put(DateExtractionFunction.PARAMETER_DATE_FORMAT, new ParameterValue(DATE_FORMAT));
    cell.setSource(getUuidSourceProperty(unitDenormType));
    cell.setTarget(getFirstObservationDateTargetProperty());
    cell.setTransformationParameters(parameters);
    DateExtractionHandler handler = new DateExtractionHandler();
    AttributeMappingType attrMapping = handler.handlePropertyTransformation(getDefaultTypeCell(unitDenormType, landCoverUnitType), cell, new AppSchemaMappingContext(mappingWrapper));
    assertEquals(OCQL, attrMapping.getSourceExpression().getOCQL());
    assertEquals(TARGET_FIRST_OBSERVATION_DATE, 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) DateExtractionHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.DateExtractionHandler) Test(org.junit.Test)

Example 10 with AttributeMappingType

use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType in project hale by halestudio.

the class AppSchemaMappingTest method testMathematicalExpressionHandler.

@Test
public void testMathematicalExpressionHandler() {
    final String EXPRESSION = "100 * unit_id / 2";
    final String OCQL = EXPRESSION;
    DefaultCell cell = new DefaultCell();
    cell.setTransformationIdentifier(MathematicalExpressionFunction.ID);
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    parameters.put(MathematicalExpressionFunction.PARAMETER_EXPRESSION, new ParameterValue(EXPRESSION));
    ListMultimap<String, Property> source = ArrayListMultimap.create();
    source.putAll(MathematicalExpressionFunction.ENTITY_VARIABLE, getUnitIdSourceProperty(unitDenormType).values());
    cell.setSource(source);
    cell.setTarget(getLocalIdTargetProperty());
    cell.setTransformationParameters(parameters);
    MathematicalExpressionHandler handler = new MathematicalExpressionHandler();
    AttributeMappingType attrMapping = handler.handlePropertyTransformation(getDefaultTypeCell(unitDenormType, landCoverUnitType), cell, new AppSchemaMappingContext(mappingWrapper));
    assertEquals(OCQL, attrMapping.getSourceExpression().getOCQL());
    assertEquals(TARGET_LOCAL_ID, 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) MathematicalExpressionHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.MathematicalExpressionHandler) 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

AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)23 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)19 Test (org.junit.Test)19 AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)16 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)13 ClientProperty (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty)10 Cell (eu.esdihumboldt.hale.common.align.model.Cell)7 Property (eu.esdihumboldt.hale.common.align.model.Property)7 RenameHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler)7 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)6 FeatureTypeMapping (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)6 AssignHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler)6 FormattedStringHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler)4 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)3 FeatureChaining (eu.esdihumboldt.hale.io.appschema.model.FeatureChaining)2 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)1 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 JoinParameter (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter)1 JoinCondition (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)1