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);
}
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);
}
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;
}
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);
}
}
}
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());
}
Aggregations