Shreyas arya

Generation

generate functionMon, 23 Jan 2023

We need to create validators for each status. The validator will check if transition from current state is allowed or not. WorkflowExecutionValidator will pick up an appropriate validator from a list and check if transition is allowed. Validators are implemented for each workflow execution status Validators are applied in production code

public class WorkflowExecutionValidator { private static final Map<WorkflowExecutionStatus, StatusValidator> statusValidatorMap = new HashMap<>(); static { statusValidatorMap.put(WorkflowExecutionStatus.WAITING_FOR_INPUT, new WaitingForInputValidator()); statusValidatorMap.put(WorkflowExecutionStatus.COMPLETED, new CompletedValidator()); statusValidatorMap.put(WorkflowExecutionStatus.FAILED, new FailedValidator()); } public static void validate(WorkflowExecution workflowExecution, WorkflowExecutionStatus targetStatus) { StatusValidator statusValidator = statusValidatorMap.get(workflowExecution.getStatus()); if (statusValidator == null) { throw new IllegalStateException("No validator for status " + workflowExecution.getStatus()); } statusValidator.validate(workflowExecution, targetStatus); } }

Questions about programming?Chat with your personal AI assistant