Search in sources :

Example 1 with AppSchemaMappingContext

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

the class AppSchemaMappingTest method testNilReasonOnNotNillableElement.

@Test
public void testNilReasonOnNotNillableElement() {
    final String nilReason = "missing";
    final String nilReasonAssignCQL = "'" + nilReason + "'";
    final String nilReasonRenameCQL = SOURCE_UUID_V1;
    // --- test with a constant mapping --- //
    DefaultCell assignNilReason = new DefaultCell();
    assignNilReason.setTransformationIdentifier(AssignFunction.ID);
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(nilReason));
    assignNilReason.setTarget(getDescriptionNilReasonTargetProperty());
    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("gml:description", attrMapping.getTargetAttribute());
    assertNull(attrMapping.getSourceExpression());
    assertEquals(1, attrMapping.getClientProperty().size());
    assertEquals(GML_NIL_REASON, attrMapping.getClientProperty().get(0).getName());
    assertEquals(nilReasonAssignCQL, attrMapping.getClientProperty().get(0).getValue());
    // encodeIfEmpty=true because we are using a constant mapping
    assertTrue(attrMapping.isEncodeIfEmpty());
    // --- test with a non-constant mapping --- //
    DefaultCell rename = new DefaultCell();
    rename.setTransformationIdentifier(RenameFunction.ID);
    rename.setSource(getUuidSourceProperty(unitType));
    rename.setTarget(getDescriptionNilReasonTargetProperty());
    // reset mapping
    initMapping();
    context = new AppSchemaMappingContext(mappingWrapper);
    // process rename
    RenameHandler renameHandler = new RenameHandler();
    attrMapping = renameHandler.handlePropertyTransformation(typeCell, rename, context);
    assertNotNull(attrMapping);
    assertEquals("gml:description", attrMapping.getTargetAttribute());
    assertNull(attrMapping.getSourceExpression());
    assertEquals(1, attrMapping.getClientProperty().size());
    assertEquals(GML_NIL_REASON, attrMapping.getClientProperty().get(0).getName());
    assertEquals(nilReasonRenameCQL, attrMapping.getClientProperty().get(0).getValue());
    // encodeIfEmpty has not been set, because we are using a mapping which
    // is a function of the source value
    assertNull(attrMapping.isEncodeIfEmpty());
}
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) 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 2 with AppSchemaMappingContext

use of eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext 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 3 with AppSchemaMappingContext

use of eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext 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 4 with AppSchemaMappingContext

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

Example 5 with AppSchemaMappingContext

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

the class AppSchemaMappingGenerator method generateMapping.

/**
 * Generates the app-schema mapping configuration.
 *
 * @param reporter status reporter
 * @return the generated app-schema mapping configuration
 * @throws IOException if an error occurs loading the mapping template file
 */
public AppSchemaMappingWrapper generateMapping(IOReporter reporter) throws IOException {
    // reset wrapper
    resetMappingState();
    try {
        AppSchemaDataAccessType mapping = loadMappingTemplate();
        mappingWrapper = new AppSchemaMappingWrapper(mapping);
        context = new AppSchemaMappingContext(mappingWrapper, alignment, targetSchema.getMappingRelevantTypes(), chainingConf, workspaceConf);
        // create namespace objects for all target types / properties
        // TODO: this removes all namespaces that were defined in the
        // template file, add code to cope with pre-configured namespaces
        // instead
        mapping.getNamespaces().getNamespace().clear();
        createNamespaces();
        // apply datastore configuration, if any
        // TODO: for now, only a single datastore is supported
        applyDataStoreConfig();
        // populate targetTypes element
        createTargetTypes();
        // populate typeMappings element
        createTypeMappings(context, reporter);
        // cache mainMapping and includedTypesMapping for performance
        mainMapping = mappingWrapper.getMainMapping();
        includedTypesMapping = mappingWrapper.getIncludedTypesMapping();
        return mappingWrapper;
    } catch (Exception e) {
        // making sure state is reset in case an exception is thrown
        resetMappingState();
        throw e;
    }
}
Also used : AppSchemaDataAccessType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) AppSchemaMappingWrapper(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingWrapper) JAXBException(javax.xml.bind.JAXBException) UnsupportedTransformationException(eu.esdihumboldt.hale.io.appschema.writer.internal.UnsupportedTransformationException) IOException(java.io.IOException)

Aggregations

AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)20 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)18 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)17 Test (org.junit.Test)17 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)13 ClientProperty (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty)9 Cell (eu.esdihumboldt.hale.common.align.model.Cell)7 RenameHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler)7 Property (eu.esdihumboldt.hale.common.align.model.Property)6 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)6 AssignHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler)6 FormattedStringHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler)4 AppSchemaDataAccessType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType)3 UnsupportedTransformationException (eu.esdihumboldt.hale.io.appschema.writer.internal.UnsupportedTransformationException)2 AppSchemaMappingWrapper (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingWrapper)2 Type (eu.esdihumboldt.hale.common.align.model.Type)1 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)1 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)1 Value (eu.esdihumboldt.hale.common.core.io.Value)1 ComplexValue (eu.esdihumboldt.hale.common.core.io.impl.ComplexValue)1