use of com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExecutionPolicyActionType in project midpoint by Evolveum.
the class PolicyRuleScriptExecutor method executeScriptsFromCollectedRules.
private <O extends ObjectType> void executeScriptsFromCollectedRules(List<EvaluatedPolicyRuleImpl> rules, LensContext<O> context, Task task, OperationResult parentResult) {
// Must not be minor because of background OID information.
OperationResult result = parentResult.createSubresult(OP_EXECUTE_SCRIPTS_FROM_RULES);
try (RunAsRunner runAsRunner = runAsRunnerFactory.runner()) {
for (EvaluatedPolicyRuleImpl rule : rules) {
List<ScriptExecutionPolicyActionType> enabledActions = rule.getEnabledActions(ScriptExecutionPolicyActionType.class);
LOGGER.trace("Rule {} has {} enabled script execution actions", rule, enabledActions.size());
for (ScriptExecutionPolicyActionType action : enabledActions) {
ActionContext actx = new ActionContext(action, rule, context, task, this);
try {
// We should consider ordering actions to be executed by runAsRef to avoid unnecessary context switches.
runAsRunner.runAs(() -> executeScriptingAction(actx, result), actx.action.getRunAsRef(), result);
} catch (CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute scripting action - continuing with others (if present)", e);
}
}
}
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
// as we are used to. So this hack is definitely the lesser evil for now.
if (result.getStatus() == OperationResultStatus.FATAL_ERROR) {
result.setStatus(OperationResultStatus.PARTIAL_ERROR);
}
}
}
Aggregations