private static void setupNodeStates ( WorkflowState current , WorkflowStateImpl parent , StepIdentifier ident ) { //create a new mutable map HashMap < String , WorkflowNodeState > nodeStates = new HashMap <> ( ) ; if ( null != parent . getNodeStates ( ) ) { //include original states nodeStates . putAll ( parent . getNodeStates ( ) ) ; } ArrayList < String > allNodes = new ArrayList <> ( ) ; if ( null != parent . getNodeSet ( ) ) { allNodes . addAll ( parent . getNodeSet ( ) ) ; } parent . setNodeStates ( nodeStates ) ; parent . setAllNodes ( allNodes ) ; for ( WorkflowStepState workflowStepState : current . getStepStates ( ) ) { StepIdentifier thisident = stepIdentifierAppend ( ident , workflowStepState . getStepIdentifier ( ) ) ; if ( workflowStepState . isNodeStep ( ) ) { //add node states for this step for ( String nodeName : current . getNodeSet ( ) ) { //new mutable map to store step states for this node HashMap < StepIdentifier , StepState > stepStatesForNode = new HashMap <> ( ) ; //get node state for this step StepState state = workflowStepState . getNodeStateMap ( ) . get ( nodeName ) ; stepStatesForNode . put ( thisident , state ) ; //if already exists an entry for this node in the workflow's node states, import the states WorkflowNodeState orig = nodeStates . get ( nodeName ) ; if ( null != orig && null != orig . getStepStateMap ( ) ) { stepStatesForNode . putAll ( orig . getStepStateMap ( ) ) ; } if ( ! allNodes . contains ( nodeName ) ) { allNodes . add ( nodeName ) ; } //create new workflowNodeState for this node WorkflowNodeState workflowNodeState = workflowNodeState ( nodeName , state , thisident , stepStatesForNode ) ; nodeStates . put ( nodeName , workflowNodeState ) ; } } else if ( workflowStepState . hasSubWorkflow ( ) ) { //descend setupNodeStates ( workflowStepState . getSubWorkflowState ( ) , parent , thisident ) ; } } }
Configure the nodeStates map for the workflow by visiting each step in the workflow and connecting the step + node state for nodeSteps to the nodeStates map