use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionParameterValueType in project midpoint by Evolveum.
the class AssignExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean raw = getParamRaw(expression, input, context, globalResult);
boolean dryRun = getParamDryRun(expression, input, context, globalResult);
ActionParameterValueType resourceParameterValue = expressionHelper.getArgument(expression.getParameter(), PARAM_RESOURCE, false, false, NAME);
ActionParameterValueType roleParameterValue = expressionHelper.getArgument(expression.getParameter(), PARAM_ROLE, false, false, NAME);
Collection<ObjectReferenceType> resources;
if (resourceParameterValue != null) {
PipelineData data = expressionHelper.evaluateParameter(resourceParameterValue, null, input, context, globalResult);
resources = data.getDataAsReferences(ResourceType.COMPLEX_TYPE);
} else {
resources = null;
}
Collection<ObjectReferenceType> roles;
if (roleParameterValue != null) {
PipelineData data = expressionHelper.evaluateParameter(roleParameterValue, null, input, context, globalResult);
roles = data.getDataAsReferences(RoleType.COMPLEX_TYPE);
} else {
roles = null;
}
if (resources == null && roles == null) {
throw new ScriptExecutionException("Nothing to assign: neither resource nor role specified");
}
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue && ((PrismObjectValue) value).asObjectable() instanceof FocusType) {
PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
ObjectType objectType = prismObject.asObjectable();
long started = operationsHelper.recordStart(context, objectType);
Throwable exception = null;
try {
operationsHelper.applyDelta(createDelta(objectType, resources, roles), operationsHelper.createExecutionOptions(raw), dryRun, context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
exception = processActionException(ex, NAME, value, context);
}
context.println((exception != null ? "Attempted to modify " : "Modified ") + prismObject.toString() + rawDrySuffix(raw, dryRun) + exceptionSuffix(exception));
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject of FocusType"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
// TODO updated objects?
return input;
}
use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionParameterValueType in project midpoint by Evolveum.
the class ExpressionHelper method getActionArgument.
public <T> T getActionArgument(Class<T> clazz, ActionExpressionType action, ItemName staticName, String dynamicName, PipelineData input, ExecutionContext context, T defaultValue, String contextName, OperationResult parentResult) throws ScriptExecutionException, SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
List<ActionParameterValueType> arguments = action.getParameter();
ActionParameterValueType dynamicValue = getArgument(arguments, dynamicName, false, false, contextName);
if (dynamicValue != null) {
if (dynamicValue.getScriptingExpression() != null) {
PipelineData data = scriptingExpressionEvaluator.evaluateExpression(dynamicValue.getScriptingExpression(), input, context, parentResult);
if (data != null) {
return data.getSingleValue(clazz);
}
} else if (dynamicValue.getValue() != null) {
return ScriptingDataUtil.getRealValue(dynamicValue.getValue(), clazz);
} else {
throw new IllegalStateException("No expression nor value specified in parameter '" + dynamicName + "'");
}
}
T staticValue = ScriptingBeansUtil.getBeanPropertyValue(action, staticName.getLocalPart(), clazz);
if (staticValue != null) {
return staticValue;
}
return defaultValue;
}
use of com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionParameterValueType in project midpoint by Evolveum.
the class ExpressionHelper method getSingleArgumentValue.
public <T> T getSingleArgumentValue(List<ActionParameterValueType> arguments, String parameterName, boolean required, boolean requiredNonNull, String context, PipelineData input, ExecutionContext executionContext, Class<T> clazz, OperationResult result) throws ScriptExecutionException, SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
ActionParameterValueType paramValue = getArgument(arguments, parameterName, required, requiredNonNull, context);
if (paramValue == null) {
return null;
}
PipelineData paramData = evaluateParameter(paramValue, clazz, input, executionContext, result);
if (paramData.getData().size() != 1) {
throw new ScriptExecutionException("Exactly one item was expected in '" + parameterName + "' parameter. Got " + paramData.getData().size());
}
PrismValue prismValue = paramData.getData().get(0).getValue();
if (!(prismValue instanceof PrismPropertyValue)) {
throw new ScriptExecutionException("A prism property value was expected in '" + parameterName + "' parameter. Got " + prismValue.getClass().getName() + " instead.");
}
Object value = ((PrismPropertyValue) prismValue).getValue();
try {
return JavaTypeConverter.convert(clazz, value);
} catch (Throwable t) {
throw new ScriptExecutionException("Couldn't retrieve value of parameter '" + parameterName + "': " + t.getMessage(), t);
}
}
Aggregations