Shreyas arya

Generation

generate functionMon, 23 Jan 2023

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 { public static boolean isTransitionAllowed(WorkflowExecution wf, WorkflowExecution.State nextState) { if (wf.getState() == nextState) { // no transition if previous state and next state are the same return false; } return getValidator(wf.getState()).isTransitionAllowed(nextState); } private static StateValidator getValidator(WorkflowExecution.State state) { switch (state) { case STARTED: return new StartedValidator(); case RUNNING: return new RunningValidator(); case SUCCEEDED: return new SucceededValidator(); case FAILED: return new FailedValidator(); case CANCELLED: return new CancelledValidator(); case TIMED_OUT: return new TimedOutValidator(); default: throw new IllegalArgumentException("State not expected: " + state); }

Questions about programming?Chat with your personal AI assistant