use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ScriptingExpressionEvaluator method evaluateExpression.
private ExecutionContext evaluateExpression(@NotNull ExecuteScriptType executeScript, VariablesMap initialVariables, boolean privileged, boolean recordProgressAndIterationStatistics, Task task, OperationResult result) throws ScriptExecutionException {
Validate.notNull(executeScript.getScriptingExpression(), "Scripting expression must be present");
ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
try {
VariablesMap frozenVariables = VariablesUtil.initialPreparation(initialVariables, executeScript.getVariables(), expressionFactory, modelObjectResolver, prismContext, expressionProfile, task, result);
PipelineData pipelineData = PipelineData.parseFrom(executeScript.getInput(), frozenVariables, prismContext);
ExecutionContext context = new ExecutionContext(executeScript.getOptions(), task, this, privileged, recordProgressAndIterationStatistics, frozenVariables);
PipelineData output = evaluateExpression(executeScript.getScriptingExpression().getValue(), pipelineData, context, result);
context.setFinalOutput(output);
result.computeStatusIfUnknown();
context.computeResults();
return context;
} catch (ExpressionEvaluationException | SchemaException | ObjectNotFoundException | RuntimeException | CommunicationException | ConfigurationException | SecurityViolationException e) {
result.recordFatalError("Couldn't execute script", e);
throw new ScriptExecutionException("Couldn't execute script: " + e.getMessage(), e);
} catch (Throwable t) {
result.recordFatalError("Couldn't execute script", t);
throw t;
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ExecuteScriptExecutor method executeScript.
private <I> Object executeScript(ScriptExpression scriptExpression, TypedValue<I> inputTypedValue, VariablesMap externalVariables, ExecutionContext context, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
VariablesMap variables = createVariables(externalVariables);
variables.put(ExpressionConstants.VAR_INPUT, inputTypedValue);
LensContext<?> lensContext = getLensContext(externalVariables);
List<?> rv = ModelImplUtils.evaluateScript(scriptExpression, lensContext, variables, true, "in '" + NAME + "' action", context.getTask(), result);
if (rv.isEmpty()) {
return null;
} else if (rv.size() == 1) {
return rv.get(0);
} else {
// shouldn't occur; would cause problems
return rv;
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ScriptingTaskCreator method customizeTask.
TaskType customizeTask(TaskType preparedTask, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ExpressionType customizer = asynchronousScriptExecution.getTaskCustomizer();
if (customizer == null) {
return preparedTask;
} else {
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(actx.context, null, actx.task, result));
try {
PrismObjectDefinition<TaskType> taskDefinition = preparedTask.asPrismObject().getDefinition();
VariablesMap variables = createVariables();
variables.addVariableDefinition(VAR_PREPARED_TASK, preparedTask, taskDefinition);
ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
PrismValue customizedTaskValue = ExpressionUtil.evaluateExpression(variables, taskDefinition, customizer, expressionProfile, beans.expressionFactory, "task customizer", actx.task, result);
if (customizedTaskValue == null) {
throw new IllegalStateException("Task customizer returned no value");
}
if (!(customizedTaskValue instanceof PrismObjectValue)) {
throw new IllegalStateException("Task customizer returned a value that is not a PrismObjectValue: " + customizedTaskValue);
}
Objectable customizedTaskBean = ((PrismObjectValue<?>) customizedTaskValue).asObjectable();
if (!(customizedTaskBean instanceof TaskType)) {
throw new IllegalStateException("Task customizer returned a value that is not a TaskType: " + customizedTaskBean);
}
return (TaskType) customizedTaskBean;
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
}
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class UnassignExecutor method createVariables.
private VariablesMap createVariables(AssignmentHolderType input, PipelineItem item) {
VariablesMap variables = createVariables(item.getVariables());
variables.put(ExpressionConstants.VAR_INPUT, input, AssignmentHolderType.class);
return variables;
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class SynchronousScriptExecutor method executeScript.
private void executeScript(ExecuteScriptType specifiedExecuteScriptBean, OperationResult parentResult) {
OperationResult result = parentResult.createSubresult(OP_EXECUTE_SCRIPT);
try {
ExecuteScriptType executeScriptBean = addInputIfNeeded(specifiedExecuteScriptBean, result);
VariablesMap initialVariables = createInitialVariables();
actx.beans.scriptingExpressionEvaluator.evaluateExpression(executeScriptBean, initialVariables, false, actx.task, result);
} catch (Throwable t) {
result.recordFatalError("Couldn't execute script policy action: " + t.getMessage(), t);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute script with id={} in scriptExecution policy action '{}' (rule '{}'): {}", t, actx.action.getId(), actx.action.getName(), actx.rule.getName(), t.getMessage());
} finally {
result.computeStatusIfUnknown();
}
}
Aggregations