Check Scenario Schema
This task runs a checker on the selected scenario schema by calling CheckSchemaStatement.forScenario. Note that this statement returns exit code 1 when the check ends with errors. For that, we check in the following statement the return code of the check statement IfStatement.of(BooleanExpression.LAST_STATEMENT_EXIT_CODE_NOT_OK.... If the return code is not OK (not 0), we interrupt the task with ExitTaskStatement.failing.
The following statement is an example of how to check the data status of a scenario directly ScenarioStatusExpression.dataStatusIs (or ScenarioStatusExpression.dataStatusIs). In this sample task, we interrupt the execution with ExitTaskStatement.alerting if the data status is ScenarioStatusExpression.WARNING.
We could have replaced the condition, following which we do ExitTaskStatement.failing(StringExpression.of("Scenario Schema Check ended with ERRORS")), with:
IfStatement.of(ScenarioStatusExpression.dataStatusIs(VariableAccessExpression.of("scenario"), ScenarioStatusExpression.ERROR), ExitTaskStatement.failing(StringExpression.of("Scenario Schema Check ended with ERRORS")))
Note that the possible values for schema or data statuses are: UNCHECKED, CHECKING, VALID, WARNING, and ERROR
public class Tasks {
@Bean
public ScriptedTaskDescription checkScenarioSchemaTask() {
ScriptedTaskDescription task = new ScriptedTaskDescription("checkScenarioSchema", "Test - Check Scenario Schema using CheckSchemaStatement");
task.setDescription("Check Scenario Schema, using CheckSchemaStatement");
task.getScript()
.addStatement(AskInputStatement.of("scenario", true, JobInputType.scenarioId(WRITABLE)))
.addStatement(CheckSchemaStatement.forScenario(VariableAccessExpression.of("scenario")))
.addStatement(IfStatement.of(BooleanExpression.LAST_STATEMENT_EXIT_CODE_NOT_OK,
ExitTaskStatement.failing(StringExpression.of("Scenario Schema Check ended with ERRORS"))
))
.addStatement(ExitTaskStatement.alerting(StringExpression.of("Scenario Schema Check ended with WARNINGS"))
.when(ScenarioStatusExpression.dataStatusIs(VariableAccessExpression.of("scenario"), ScenarioStatusExpression.WARNING))
);
return task;
}
}