static NextStepSelection findNextStep()

in flux/src/main/java/software/amazon/aws/clients/swf/flux/poller/DecisionTaskPoller.java [1004:1031]


    static NextStepSelection findNextStep(Workflow workflow, WorkflowStep currentStep, String resultCode) {
        WorkflowGraph graph = workflow.getGraph();

        // If there isn't a current step, then the workflow has just started, and we pick the first step.
        if (currentStep == null) {
            return NextStepSelection.scheduleNextStep(graph.getFirstStep());
        } else if (resultCode == null || resultCode.isEmpty()) {
            return NextStepSelection.scheduleNextStep(currentStep);
        }

        WorkflowGraphNode currentNode = graph.getNodes().get(currentStep.getClass());
        String effectiveResultCode = resultCode;
        if (currentNode.getNextStepsByResultCode().containsKey(StepResult.ALWAYS_RESULT_CODE)) {
            effectiveResultCode = StepResult.ALWAYS_RESULT_CODE;
        } else if (!currentNode.getNextStepsByResultCode().containsKey(effectiveResultCode)) {
            // this can happen during deployments that add new result codes, on the workers with the old code
            return NextStepSelection.unknownResultCode();
        }

        WorkflowGraphNode selectedStep = currentNode.getNextStepsByResultCode().get(effectiveResultCode);

        // if the transition for this result code is null, we should close the workflow.
        if (selectedStep == null) {
            return NextStepSelection.closeWorkflow();
        }

        return NextStepSelection.scheduleNextStep(selectedStep.getStep());
    }