/** * Factory method that creates a new end state, a state where an executing flow session terminates. This method is * an atomic operation that returns a fully initialized state. It encapsulates the selection of the end state * implementation as well as the state assembly. * @param id the identifier to assign to the state, must be unique to its owning flow (required) * @param flow the flow that will own (contain) this state (required) * @param entryActions any state entry actions; may be null * @param finalResponseAction the state response renderer; may be null * @param outputMapper the state output mapper; may be null * @param exceptionHandlers any exception handlers; may be null * @param attributes attributes to assign to the State, which may also be used to affect state construction; may be * null * @return the fully initialized subflow state instance */ public State createEndState(String id, Flow flow, Action[] entryActions, Action finalResponseAction, Mapper outputMapper, FlowExecutionExceptionHandler[] exceptionHandlers, AttributeMap<?> attributes) { EndState endState = new EndState(flow, id); if (finalResponseAction != null) { endState.setFinalResponseAction(finalResponseAction); } if (outputMapper != null) { endState.setOutputMapper(outputMapper); } configureCommonProperties(endState, entryActions, exceptionHandlers, attributes); return endState; }
/** * Add end state backed by view. * * @param flow the flow * @param id the id * @param viewFactory the view factory */ protected void createEndState(final Flow flow, final String id, final ViewFactory viewFactory) { try { final EndState endState = new EndState(flow, id); final Action finalResponseAction = new ViewFactoryActionAdapter(viewFactory); endState.setFinalResponseAction(finalResponseAction); logger.debug("Created end state state {} on flow id {}, backed by view factory {}", id, flow.getId(), viewFactory); } catch (final Exception e) { logger.error(e.getMessage(), e); } }
@Override public EndState createEndState(final Flow flow, final String id, final ViewFactory viewFactory) { if (containsFlowState(flow, id)) { LOGGER.trace("Flow [{}] already contains a definition for state id [{}]", flow.getId(), id); return (EndState) flow.getStateInstance(id); } val endState = new EndState(flow, id); if (viewFactory != null) { val finalResponseAction = new ViewFactoryActionAdapter(viewFactory); endState.setFinalResponseAction(finalResponseAction); LOGGER.trace("Created end state state [{}] on flow id [{}], backed by view factory [{}]", id, flow.getId(), viewFactory); } else { LOGGER.trace("Created end state state [{}] on flow id [{}]", id, flow.getId()); } return endState; }
/** * Factory method that creates a new end state, a state where an executing flow session terminates. This method is * an atomic operation that returns a fully initialized state. It encapsulates the selection of the end state * implementation as well as the state assembly. * @param id the identifier to assign to the state, must be unique to its owning flow (required) * @param flow the flow that will own (contain) this state (required) * @param entryActions any state entry actions; may be null * @param finalResponseAction the state response renderer; may be null * @param outputMapper the state output mapper; may be null * @param exceptionHandlers any exception handlers; may be null * @param attributes attributes to assign to the State, which may also be used to affect state construction; may be * null * @return the fully initialized subflow state instance */ public State createEndState(String id, Flow flow, Action[] entryActions, Action finalResponseAction, Mapper outputMapper, FlowExecutionExceptionHandler[] exceptionHandlers, AttributeMap<?> attributes) { EndState endState = new EndState(flow, id); if (finalResponseAction != null) { endState.setFinalResponseAction(finalResponseAction); } if (outputMapper != null) { endState.setOutputMapper(outputMapper); } configureCommonProperties(endState, entryActions, exceptionHandlers, attributes); return endState; }
/** * Factory method that creates a new end state, a state where an executing flow session terminates. This method is * an atomic operation that returns a fully initialized state. It encapsulates the selection of the end state * implementation as well as the state assembly. * @param id the identifier to assign to the state, must be unique to its owning flow (required) * @param flow the flow that will own (contain) this state (required) * @param entryActions any state entry actions; may be null * @param finalResponseAction the state response renderer; may be null * @param outputMapper the state output mapper; may be null * @param exceptionHandlers any exception handlers; may be null * @param attributes attributes to assign to the State, which may also be used to affect state construction; may be * null * @return the fully initialized subflow state instance */ public State createEndState(String id, Flow flow, Action[] entryActions, Action finalResponseAction, Mapper outputMapper, FlowExecutionExceptionHandler[] exceptionHandlers, AttributeMap attributes) { EndState endState = new EndState(flow, id); if (finalResponseAction != null) { endState.setFinalResponseAction(finalResponseAction); } if (outputMapper != null) { endState.setOutputMapper(outputMapper); } configureCommonProperties(endState, entryActions, exceptionHandlers, attributes); return endState; }
/** * Add end state backed by view. * * @param flow the flow * @param id the id * @param viewId the view id */ protected void addEndStateBackedByView(final Flow flow, final String id, final String viewId) { try { final EndState endState = new EndState(flow, id); final ViewFactory viewFactory = this.flowBuilderServices.getViewFactoryCreator().createViewFactory( new LiteralExpression(viewId), this.flowBuilderServices.getExpressionParser(), this.flowBuilderServices.getConversionService(), null, this.flowBuilderServices.getValidator(), this.flowBuilderServices.getValidationHintResolver()); final Action finalResponseAction = new ViewFactoryActionAdapter(viewFactory); endState.setFinalResponseAction(finalResponseAction); LOGGER.debug("Created end state state {} on flow id {}, backed by view {}", id, flow.getId(), viewId); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } }
public void testEnterEndStateWithFinalResponseRenderer() { Flow flow = new Flow("myFlow"); EndState state = new EndState(flow, "end"); StubFinalResponseAction action = new StubFinalResponseAction(); state.setFinalResponseAction(action); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); assertTrue(action.executeCalled); }
public void testEnterEndStateWithFinalResponseRendererResponseAlreadyComplete() { Flow flow = new Flow("myFlow"); EndState state = new EndState(flow, "end"); StubFinalResponseAction action = new StubFinalResponseAction(); state.setFinalResponseAction(action); MockRequestControlContext context = new MockRequestControlContext(flow); context.getExternalContext().recordResponseComplete(); state.enter(context); assertFalse(action.executeCalled); }
public void testRenderNoKey() throws Exception { MockRequestControlContext context = new MockRequestControlContext(); EndState endState = new EndState(context.getRootFlow(), "end"); endState.setFinalResponseAction(new ViewFactoryActionAdapter(new StubViewFactory())); context.setCurrentState(endState); context.getRequestScope().put("foo", "bar"); context.getFlowScope().put("bar", "baz"); context.getFlowScope().put("bindBean", new BindBean()); context.getConversationScope().put("baz", "boop"); context.getFlashScope().put("boop", "bing"); context.getMockExternalContext().setCurrentUser("Keith"); context.getMockExternalContext().setNativeContext(new MockServletContext()); context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest()); context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse()); org.springframework.web.servlet.View mvcView = new MockView(); AbstractMvcView view = new MockMvcView(mvcView, context); view.setExpressionParser(createExpressionParser()); view.render(); assertTrue(renderCalled); assertEquals("bar", model.get("foo")); assertEquals("baz", model.get("bar")); assertEquals("boop", model.get("baz")); assertEquals("bing", model.get("boop")); assertFalse(model.containsKey("flowExecutionKey")); assertFalse(model.containsKey("flowExecutionUrl")); assertEquals("Keith", ((Principal) model.get("currentUser")).getName()); assertEquals(context, model.get("flowRequestContext")); assertNull(model.get(BindingResult.MODEL_KEY_PREFIX + "bindBean")); }
public void testResumeViewStateForEventWithTransitionFlowEnded() { Flow flow = new Flow("myFlow"); StubViewFactory viewFactory = new StubViewFactory(); ViewState state = new ViewState(flow, "viewState", viewFactory); state.getTransitionSet().add(new Transition(on("submit"), to("finish"))); EndState end = new EndState(flow, "finish"); TestAction testAction = new TestAction(); end.setFinalResponseAction(testAction); MockRequestControlContext context = new MockRequestControlContext(flow); state.enter(context); context = new MockRequestControlContext(context.getFlowExecutionContext()); context.putRequestParameter("_eventId", "submit"); state.resume(context); assertTrue(context.getExternalContext().isResponseComplete()); assertFalse(context.getFlowExecutionContext().isActive()); assertTrue(testAction.isExecuted()); }