/** * Add given state definition to this flow definition. Marked protected, as this method is to be called by the * (privileged) state definition classes themselves during state construction as part of a FlowBuilder invocation. * @param state the state to add * @throws IllegalArgumentException when the state cannot be added to the flow; for instance if another state shares * the same id as the one provided or if given state already belongs to another flow */ protected void add(State state) throws IllegalArgumentException { if (this != state.getFlow() && state.getFlow() != null) { throw new IllegalArgumentException("State " + state + " cannot be added to this flow '" + getId() + "' -- it already belongs to a different flow: '" + state.getFlow().getId() + "'"); } if (this.states.contains(state) || this.containsState(state.getId())) { throw new IllegalArgumentException("This flow '" + getId() + "' already contains a state with id '" + state.getId() + "' -- state ids must be locally unique to the flow definition; " + "existing state-ids of this flow include: " + StylerUtils.style(getStateIds())); } boolean firstAdd = states.isEmpty(); states.add(state); if (firstAdd) { setStartState(state); } }
/** * Returns a flag indicating if this state is the start state of its owning flow. * @return true if the flow is the start state, false otherwise */ public boolean isStartState() { return flow.getStartState() == this; }
/** * Handle an exception that occurred during an execution of this flow. * @param exception the exception that occurred * @param context the flow execution control context */ public boolean handleException(FlowExecutionException exception, RequestControlContext context) throws FlowExecutionException { return getExceptionHandlerSet().handleException(exception, context); }
/** * Set the start state for this flow to the state with the provided <code>stateId</code>; a state must exist by the * provided <code>stateId</code>. * @param stateId the id of the new start state * @throws IllegalArgumentException when no state exists with the id you provided */ public void setStartState(String stateId) throws IllegalArgumentException { setStartState(getStateInstance(stateId)); }
/** * Return the <code>TransitionableState</code> with given <code>stateId</code>. * @param stateId id of the state to look up * @return the transitionable state * @throws IllegalArgumentException if the identified state cannot be found * @throws ClassCastException when the identified state is not transitionable */ public TransitionableState getTransitionableState(String stateId) throws IllegalArgumentException, ClassCastException { State state = getStateInstance(stateId); if (state != null && !(state instanceof TransitionableState)) { throw new ClassCastException("The state '" + stateId + "' of flow '" + getId() + "' must be transitionable"); } return (TransitionableState) state; }
/** * Create a new flow with the given id and attributes. * @param id the flow id * @param attributes the attributes * @return the flow */ public static Flow create(String id, AttributeMap<?> attributes) { Flow flow = new Flow(id); flow.getAttributes().putAll(attributes); return flow; }
public void testAddStates() { Flow flow = new Flow("myFlow"); new EndState(flow, "myState1"); new EndState(flow, "myState2"); assertEquals("Wrong start state:", "myState1", flow.getStartState().getId()); assertEquals("State count wrong:", 2, flow.getStateCount()); assertTrue(flow.containsState("myState1")); assertTrue(flow.containsState("myState2")); State state = flow.getStateInstance("myState1"); assertEquals("Wrong flow:", flow.getId(), state.getFlow().getId()); assertEquals("Wrong state:", "myState1", flow.getState("myState1").getId()); assertEquals("Wrong state:", "myState2", flow.getState("myState2").getId()); }
public void testHandleException() { flow.getExceptionHandlerSet().add( new TransitionExecutingFlowExecutionExceptionHandler().add(TestException.class, "myState2")); MockRequestControlContext context = new MockRequestControlContext(flow); context.setCurrentState(flow.getStateInstance("myState1")); FlowExecutionException e = new FlowExecutionException(flow.getId(), flow.getStartState().getId(), "Oops!", new TestException()); flow.handleException(e, context); assertFalse(context.getFlowExecutionContext().isActive()); }
public void testResourceBackedFlowBuilder() { ClassPathResource resource = new ClassPathResource("flow-endstate.xml", XmlFlowModelBuilderTests.class); Flow flow = getFlow(resource); assertEquals("flow", flow.getId()); assertEquals("end", flow.getStartState().getId()); }
val mfaFlow = (Flow) mfaProviderFlowRegistry.getFlowDefinition(subflowId); mfaFlow.getStartActionList().add(createSetAction("flowScope.".concat(CasWebflowConstants.VAR_ID_MFA_PROVIDER_ID), StringUtils.quote(providerId))); val initStartState = (ActionState) mfaFlow.getStartState(); val transition = (Transition) initStartState.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS); val targetStateId = transition.getTargetStateId(); if (mfaFlow.containsState(CasWebflowConstants.STATE_ID_MFA_PRE_AUTH)) { createTransitionForState(availableAction, CasWebflowConstants.TRANSITION_ID_YES, CasWebflowConstants.STATE_ID_MFA_PRE_AUTH); } else { CasWebflowConstants.STATE_ID_MFA_UNAVAILABLE, CasWebflowConstants.VIEW_ID_MFA_UNAVAILABLE, flow.getId()); createEndState(flow, CasWebflowConstants.STATE_ID_MFA_UNAVAILABLE, CasWebflowConstants.VIEW_ID_MFA_UNAVAILABLE); CasWebflowConstants.STATE_ID_MFA_DENIED, CasWebflowConstants.VIEW_ID_MFA_DENIED, flow.getId()); createEndState(flow, CasWebflowConstants.STATE_ID_MFA_DENIED, CasWebflowConstants.VIEW_ID_MFA_DENIED); augmentMultifactorProviderFlowRegistry(mfaProviderFlowRegistry); LOGGER.trace("Registering the [{}] flow into the flow [{}]", subflowId, flow.getId()); val startState = flow.getTransitionableState(flow.getStartState().getId()); createTransitionForState(startState, subflowId, subflowId); });
/** * Returns the de-serialized id indicating the flow id of this session. */ String getFlowId() { if (flow == null) { return flowId; } else { return flow.getId(); } }
public void testHandleExceptionNoMatch() { MockRequestControlContext context = new MockRequestControlContext(flow); FlowExecutionException e = new FlowExecutionException(flow.getId(), flow.getStartState().getId(), "Oops!", new TestException()); try { flow.handleException(e, context); } catch (FlowExecutionException ex) { // expected } }
private void createTransitionStateToAcceptableUsagePolicy(final Flow flow) { final ActionState submit = (ActionState) flow.getState(CasWebflowConstants.TRANSITION_ID_REAL_SUBMIT); createTransitionForState(submit, CasWebflowConstants.TRANSITION_ID_SUCCESS, STATE_ID_AUP_CHECK, true); }
/** * Builds any start actions to execute when the flow starts. * @throws FlowBuilderException an exception occurred building the flow */ public void buildStartActions() throws FlowBuilderException { getFlow().getStartActionList().addAll(parseActions(flowModel.getOnStartActions())); }
private void buildInlineFlow(Element flowElement, Flow inlineFlow) { parseAndAddFlowVariables(flowElement, inlineFlow); inlineFlow.setInputMapper(parseInputMapper(flowElement)); parseAndAddStartActions(flowElement, inlineFlow); parseAndAddInlineFlowDefinitions(flowElement, inlineFlow); parseAndAddStateDefinitions(flowElement, inlineFlow); parseAndAddGlobalTransitions(flowElement, inlineFlow); parseAndAddEndActions(flowElement, inlineFlow); inlineFlow.setOutputMapper(parseOutputMapper(flowElement)); inlineFlow.getExceptionHandlerSet().addAll(parseExceptionHandlers(flowElement)); destroyLocalServiceRegistry(); }
private static void configureFlowStartState(final Flow flow, final ActionState terminateSessionActionState) { LOGGER.trace("Setting the start state of the logout webflow identified by [{}] to [{}]", flow.getId(), terminateSessionActionState.getId()); flow.setStartState(terminateSessionActionState); }
public StateDefinition getState(String stateId) { return getStateInstance(stateId); }
/** * Creates a new mock flow session that sets a flow with id "mockFlow" as the 'active flow' in state "mockState". */ public MockFlowSession() { setDefinition(new Flow("mockFlow")); State state = new TransitionableState(definition, "mockState") { protected void doEnter(RequestControlContext context) throws FlowExecutionException { // nothing to do } }; setState(state); }
private void parseAndSetStartState(Element element, Flow flow) { String startStateId = getStartStateId(element); flow.setStartState(startStateId); }
/** * Adds flow variables. * @param variables the variables */ public void addVariables(FlowVariable... variables) { if (variables == null) { return; } for (FlowVariable variable : variables) { addVariable(variable); } }