Search in sources :

Example 31 with ParameterValue

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

the class ExtentHandler method getSourceExpressionAsCQL.

/**
 * @see eu.esdihumboldt.hale.io.appschema.writer.internal.AbstractPropertyTransformationHandler#getSourceExpressionAsCQL()
 */
@Override
protected String getSourceExpressionAsCQL() {
    Property source = getSourceProperty(propertyCell);
    ParameterValue extentTypeParam = getTransformationParameter(propertyCell, ExtentFunction.PARAM_TYPE);
    String extentType = (extentTypeParam != null) ? extentTypeParam.as(String.class, ExtentFunction.PARAM_BOUNDING_BOX) : ExtentFunction.PARAM_BOUNDING_BOX;
    String extentFunction = "";
    if (extentType.equals(ExtentFunction.PARAM_BOUNDING_BOX)) {
        extentFunction = "envelope";
    } else if (extentType.equals(ExtentFunction.PARAM_CONVEX_HULL)) {
        extentFunction = "convexHull";
    } else {
        throw new IllegalArgumentException("Extent type not supported: " + extentType);
    }
    String geomProperty = source.getDefinition().getDefinition().getName().getLocalPart();
    String cqlExpression = String.format("%s(%s)", extentFunction, geomProperty);
    return getConditionalExpression(source.getDefinition(), cqlExpression);
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Property(eu.esdihumboldt.hale.common.align.model.Property) AppSchemaMappingUtils.getSourceProperty(eu.esdihumboldt.hale.io.appschema.writer.AppSchemaMappingUtils.getSourceProperty)

Example 32 with ParameterValue

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

the class AbstractScriptedPropertyTransformation method evaluate.

@Override
protected final ListMultimap<String, Object> evaluate(String transformationIdentifier, E engine, ListMultimap<String, PropertyValue> variables, ListMultimap<String, PropertyEntityDefinition> resultNames, Map<String, String> executionParameters, TransformationLog log) throws TransformationException {
    ListMultimap<String, ParameterValue> originalParameters = getParameters();
    ListMultimap<String, Value> transformedParameters = ArrayListMultimap.create();
    if (originalParameters != null) {
        for (Map.Entry<String, ParameterValue> entry : originalParameters.entries()) {
            if (!entry.getValue().needsProcessing()) {
                Value value = entry.getValue().intern();
                if (!value.isRepresentedAsDOM()) {
                    value = Value.simple(getExecutionContext().getVariables().replaceVariables(value.getStringRepresentation()));
                }
                transformedParameters.put(entry.getKey(), value);
            } else {
                // type is a script
                ScriptFactory factory = ScriptExtension.getInstance().getFactory(entry.getValue().getType());
                if (factory == null)
                    throw new TransformationException("Couldn't find factory for script id " + entry.getValue().getType());
                Script script;
                try {
                    script = factory.createExtensionObject();
                } catch (Exception e) {
                    throw new TransformationException("Couldn't create script from factory", e);
                }
                Object result;
                try {
                    String scriptStr = entry.getValue().as(String.class);
                    if (script.requiresReplacedTransformationVariables()) {
                        // replace transformation variables
                        scriptStr = getExecutionContext().getVariables().replaceVariables(scriptStr);
                    }
                    result = script.evaluate(scriptStr, variables.values(), getExecutionContext());
                } catch (ScriptException e) {
                    throw new TransformationException("Couldn't evaluate a transformation parameter", e);
                }
                // XXX use conversion service instead of valueOf?
                transformedParameters.put(entry.getKey(), Value.simple(result));
            }
        }
    }
    this.transformedParameters = Multimaps.unmodifiableListMultimap(transformedParameters);
    return evaluateImpl(transformationIdentifier, engine, variables, resultNames, executionParameters, log);
}
Also used : Script(eu.esdihumboldt.hale.common.scripting.Script) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) ScriptException(javax.script.ScriptException) ScriptException(javax.script.ScriptException) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) Value(eu.esdihumboldt.hale.common.core.io.Value) Map(java.util.Map) ScriptFactory(eu.esdihumboldt.hale.common.scripting.ScriptFactory)

Example 33 with ParameterValue

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

the class MergeMigrator method updateCell.

@Override
public MutableCell updateCell(Cell originalCell, AlignmentMigration migration, MigrationOptions options, SimpleLog log) {
    MutableCell result = super.updateCell(originalCell, migration, options, log);
    SimpleLog cellLog = SimpleLog.all(log, new CellLog(result, CELL_LOG_CATEGORY));
    if (options.updateSource() && originalCell.getSource() != null) {
        Entity sourceType = CellUtil.getFirstEntity(originalCell.getSource());
        if (sourceType != null) {
            TypeDefinition sourceDef = sourceType.getDefinition().getType();
            ListMultimap<String, ParameterValue> modParams = ArrayListMultimap.create(result.getTransformationParameters());
            for (String property : PROPERTY_PATH_PARAMETERS) {
                updateProperties(modParams, migration, sourceDef, property, cellLog);
            }
            result.setTransformationParameters(modParams);
        }
    }
    return result;
}
Also used : SimpleLog(eu.esdihumboldt.hale.common.core.report.SimpleLog) Entity(eu.esdihumboldt.hale.common.align.model.Entity) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) CellLog(eu.esdihumboldt.hale.common.align.model.annotations.messages.CellLog) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 34 with ParameterValue

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

the class ParameterBinding method getProperty.

@Override
public Object getProperty(String property) {
    boolean getAsList = true;
    final Optional<FunctionParameterDefinition> paramDef;
    if (function != null) {
        paramDef = function.getDefinedParameters().stream().filter(param -> Objects.equals(property, param.getName())).findFirst();
    } else {
        paramDef = Optional.empty();
    }
    if (paramDef.isPresent()) {
        if (paramDef.get().getMaxOccurrence() == 1) {
            getAsList = false;
        }
    }
    List<ParameterValue> values;
    if (cell != null && cell.getTransformationParameters() != null) {
        values = cell.getTransformationParameters().get(property);
    } else {
        values = Collections.emptyList();
    }
    if (getAsList) {
        // yield parameters as list
        return values.stream().map(value -> extractParameterValue(value, paramDef)).collect(Collectors.toList());
    } else {
        // yield parameter value or null if there is none
        if (values.isEmpty()) {
            if (paramDef.isPresent()) {
                ParameterValueDescriptor descriptor = paramDef.get().getValueDescriptor();
                if (descriptor != null && descriptor.getDefaultValue() != null) {
                    // use default value as parameter value
                    return extractParameterValue(new ParameterValue(descriptor.getDefaultValue()), paramDef);
                }
            }
            return null;
        } else {
            return extractParameterValue(values.get(0), paramDef);
        }
    }
}
Also used : Objects(java.util.Objects) List(java.util.List) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) Cell(eu.esdihumboldt.hale.common.align.model.Cell) ParameterValueDescriptor(eu.esdihumboldt.hale.common.core.parameter.ParameterValueDescriptor) Optional(java.util.Optional) GroovyObjectSupport(groovy.lang.GroovyObjectSupport) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition) ParameterValueDescriptor(eu.esdihumboldt.hale.common.core.parameter.ParameterValueDescriptor) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) FunctionParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionParameterDefinition)

Example 35 with ParameterValue

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

the class OMLReaderTest method testAssign1.

/**
 * Test assign function in alignment4
 */
@Test
@Ignore
public // because now NilReasonFunction also produces assign cells
void testAssign1() {
    Collection<? extends Cell> cells = alignment4.getCells();
    Iterator<? extends Cell> it = cells.iterator();
    List<Cell> assignCells = new ArrayList<Cell>();
    while (it.hasNext()) {
        Cell temp = it.next();
        if (temp.getTransformationIdentifier().equals("eu.esdihumboldt.hale.align.assign")) {
            assignCells.add(temp);
        }
    }
    // test all cells that have an assign function
    for (int i = 0; i < assignCells.size(); i++) {
        Cell cell = assignCells.get(i);
        ListMultimap<String, ParameterValue> params = cell.getTransformationParameters();
        List<ParameterValue> values = params.get("value");
        assertEquals(1, values.size());
        // size is always 1
        String temp = values.get(0).as(String.class);
        // test cell #1
        if (i == 0) {
            assertEquals("FR", temp);
        }
        // test cell #2
        if (i == 1) {
            assertEquals("FR.IGN.ERM", temp);
        }
        // test cell #3
        if (i == 2) {
            assertEquals("250000", temp);
        }
    }
    // check if all cells with an assign function were tested
    assertEquals(3, assignCells.size());
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) ArrayList(java.util.ArrayList) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)80 Test (org.junit.Test)29 Cell (eu.esdihumboldt.hale.common.align.model.Cell)28 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)21 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)14 AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)13 ArrayList (java.util.ArrayList)13 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)9 Property (eu.esdihumboldt.hale.common.align.model.Property)9 ClientProperty (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty)9 Entity (eu.esdihumboldt.hale.common.align.model.Entity)8 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)8 Value (eu.esdihumboldt.hale.common.core.io.Value)8 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)8 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)7 Type (eu.esdihumboldt.hale.common.align.model.Type)6 AssignHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler)6 JoinParameter (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter)5 HashSet (java.util.HashSet)5 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)4