Search in sources :

Example 16 with Property

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

the class GroovyTransformationPage method validate.

@Override
protected boolean validate(String document) {
    super.validate(document);
    List<PropertyValue> values = new ArrayList<PropertyValue>();
    for (EntityDefinition var : getVariables()) {
        if (var instanceof PropertyEntityDefinition) {
            PropertyEntityDefinition property = (PropertyEntityDefinition) var;
            values.add(new PropertyValueImpl(testValues.get(property), property));
        }
    }
    Property targetProperty = (Property) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
    if (targetProperty == null) {
        // not yet selected (NewRelationWizard)
        return false;
    }
    InstanceBuilder builder = GroovyTransformation.createBuilder(targetProperty.getDefinition());
    Cell cell = getWizard().getUnfinishedCell();
    boolean useInstanceValues = CellUtil.getOptionalParameter(cell, GroovyTransformation.PARAM_INSTANCE_VARIABLES, Value.of(false)).as(Boolean.class);
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    GroovyService gs = HaleUI.getServiceProvider().getService(GroovyService.class);
    Script script = null;
    try {
        Collection<? extends Cell> typeCells = as.getAlignment().getTypeCells(cell);
        // select one matching type cell, the script has to run for all
        // matching cells
        // if there is no matching cell it may produce a npe, which is okay
        Cell typeCell = null;
        if (!typeCells.isEmpty()) {
            typeCell = typeCells.iterator().next();
        }
        CellLog log = new CellLog(new DefaultTransformationReporter("dummy", false), cell);
        ExecutionContext context = new DummyExecutionContext(HaleUI.getServiceProvider());
        groovy.lang.Binding binding;
        if (cell.getTransformationIdentifier().equals(GroovyGreedyTransformation.ID)) {
            binding = GroovyGreedyTransformation.createGroovyBinding(values, null, cell, typeCell, builder, useInstanceValues, log, context, targetProperty.getDefinition().getDefinition().getPropertyType());
        } else {
            binding = GroovyTransformation.createGroovyBinding(values, null, cell, typeCell, builder, useInstanceValues, log, context, targetProperty.getDefinition().getDefinition().getPropertyType());
        }
        script = gs.parseScript(document, binding);
        GroovyTransformation.evaluate(script, builder, targetProperty.getDefinition().getDefinition().getPropertyType(), gs, log);
    } catch (NoResultException e) {
    // continue
    } catch (final Exception e) {
        return handleValidationResult(script, e);
    }
    return handleValidationResult(script, null);
}
Also used : Script(groovy.lang.Script) ArrayList(java.util.ArrayList) DefaultTransformationReporter(eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) NoResultException(eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException) GroovyService(eu.esdihumboldt.util.groovy.sandbox.GroovyService) NoResultException(eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ExecutionContext(eu.esdihumboldt.hale.common.align.transformation.function.ExecutionContext) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) Property(eu.esdihumboldt.hale.common.align.model.Property) Cell(eu.esdihumboldt.hale.common.align.model.Cell) CellLog(eu.esdihumboldt.hale.common.align.transformation.report.impl.CellLog) PropertyValueImpl(eu.esdihumboldt.hale.common.align.transformation.function.impl.PropertyValueImpl) InstanceBuilder(eu.esdihumboldt.hale.common.instance.groovy.InstanceBuilder)

Example 17 with Property

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

Example 18 with Property

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

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

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

the class AppSchemaMappingTest method testFormattedStringHandler.

@Test
public void testFormattedStringHandler() {
    final String PATTERN = "Class 2007: {ucs2007}; Class 2013: {ucs2013}";
    final String OCQL = "strConcat(strConcat(strConcat('Class 2007: ', ucs2007), '; Class 2013: '), ucs2013)";
    DefaultCell cell = new DefaultCell();
    cell.setTransformationIdentifier(FormattedStringFunction.ID);
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    parameters.put(FormattedStringFunction.PARAMETER_PATTERN, new ParameterValue(PATTERN));
    ListMultimap<String, Property> source = ArrayListMultimap.create();
    source.putAll(FormattedStringFunction.ENTITY_VARIABLE, getUcs2007SourceProperty().values());
    source.putAll(FormattedStringFunction.ENTITY_VARIABLE, getUcs2013SourceProperty().values());
    cell.setSource(source);
    cell.setTarget(getDescriptionTargetProperty());
    cell.setTransformationParameters(parameters);
    FormattedStringHandler handler = new FormattedStringHandler();
    AttributeMappingType attrMapping = handler.handlePropertyTransformation(getDefaultTypeCell(unitDenormType, landCoverUnitType), cell, new AppSchemaMappingContext(mappingWrapper));
    assertEquals(OCQL, attrMapping.getSourceExpression().getOCQL());
    assertEquals(TARGET_DESCRIPTION, 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) 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)

Aggregations

Property (eu.esdihumboldt.hale.common.align.model.Property)25 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)13 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)11 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)9 ArrayList (java.util.ArrayList)9 Cell (eu.esdihumboldt.hale.common.align.model.Cell)8 ClientProperty (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty)8 Test (org.junit.Test)8 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)7 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)7 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)6 AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)6 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 Type (eu.esdihumboldt.hale.common.align.model.Type)5 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)5 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)5 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)3 FormattedStringHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler)3 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)2