Execute a Ruleset on a Scenario

This task executes a ruleset on a scenario.

    @Bean
    public ScriptedTaskDescription executeRulesTask() {
        ScriptedTaskDescription task = new ScriptedTaskDescription(
            "ExecuteRulesetOnScenarioTask",
            "Execute Ruleset On Scenario Task (Experimental)");
        task.setDescription("Execute the given ruleset on the given scenario");
        setI18nKeys(task, "EXECUTE_RULES");



        var scenario = VariableAccessExpression.ofScenario();
        var scriptParameterName = VariableAccessExpression.of("scriptParameterName");
        var executionLogs = VariableAccessExpression.of("executionLogs");
        var exitCode = VariableAccessExpression.of("exitCode");

        task.getScript()
            .addStatement(AskInputStatement.ofVariable(scenario, true, JobInputType.SCENARIO_ID))
            .addStatement(AskInputStatement.ofVariable(scriptParameterName, true, JobInputType.TEXT))
            .addStatement(ExecuteRoutineStatement
                // For the given routine
                .of(EXECUTE_RULESET_ROUTINE_NAME)
                // Pass the input parameters
                .withInput(ScenarioDataExpression.of(scenario))
                .withInput(scriptParameterName)
                // And retrieve the logs of the routine execution in a variable
                .withOutput(executionLogs.getVariableName(), executionLogs.getVariableName()))
            // Keep the exit code of the routine in a variable
            .addStatement(SetVariableStatement.of(exitCode.getVariableName(), NumericExpression.LAST_STATEMENT_EXIT_CODE))
            // Set the output of the task to the routine execution logs
            .addStatement(SetTaskOutputStatement.of(executionLogs.getVariableName(), executionLogs))
            // Process routine errors exit codes
            .addStatement(alertingTheTaskWithMessageWhen(exitCode, "An error occurred during the processing the routine input parameters", ROUTINE_PARAMETER_ERROR_EXIT_CODE))
            .addStatement(alertingTheTaskWithMessageWhen(exitCode, "An error occurred during the compilation of the ruleset", RULESET_COMPILATION_ERROR_EXIT_CODE))
            .addStatement(alertingTheTaskWithMessageWhen(exitCode, "An error occurred during the execution of the ruleset", RULESET_EXECUTION_ERROR_EXIT_CODE))
            .addStatement(alertingTheTaskWithMessageWhen(exitCode, "An unexpected error occurred during the routine execution", UNKNOWN_ERROR_EXIT_CODE));

        return task;
    }