private ViewFactory parseViewFactory(String view, String stateId, boolean endState, BinderModel binderModel) { if (!StringUtils.hasText(view)) { if (endState) { return null; } else { view = getLocalContext().getViewFactoryCreator().getViewIdByConvention(stateId); Expression viewId = getLocalContext().getExpressionParser().parseExpression(view, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return createViewFactory(viewId, binderModel); } } else if (view.startsWith("externalRedirect:")) { String encodedUrl = view.substring("externalRedirect:".length()); Expression externalUrl = getLocalContext().getExpressionParser().parseExpression(encodedUrl, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return new ActionExecutingViewFactory(new ExternalRedirectAction(externalUrl)); } else if (view.startsWith("flowRedirect:")) { String flowRedirect = view.substring("flowRedirect:".length()); Expression expression = getLocalContext().getExpressionParser().parseExpression(flowRedirect, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return new ActionExecutingViewFactory(new FlowDefinitionRedirectAction(expression)); } else { Expression viewId = getLocalContext().getExpressionParser().parseExpression(view, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return createViewFactory(viewId, binderModel); } }
public void testGetView() throws Exception { TestAction action = new TestAction(); ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action); MockRequestContext context = new MockRequestContext(); View view = factory.getView(context); assertFalse(action.isExecuted()); view.render(); assertTrue(action.isExecuted()); }
public void testViewStateExternalRedirect() { ViewStateModel state = new ViewStateModel("view"); state.setView("externalRedirect:http://www.paypal.com?_callbackUrl=#{flowExecutionUri}"); model.setStates(asList(state)); Flow flow = getFlow(model); ViewFactory vf = ((ViewState) flow.getStateInstance("view")).getViewFactory(); assertTrue(vf instanceof ActionExecutingViewFactory); ActionExecutingViewFactory avf = (ActionExecutingViewFactory) vf; assertTrue(avf.getAction() instanceof ExternalRedirectAction); }
public void testProcessUserEventNoEvent() throws IOException { TestAction action = new TestAction(); ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action); MockRequestContext context = new MockRequestContext(); View view = factory.getView(context); assertFalse(action.isExecuted()); view.render(); assertTrue(action.isExecuted()); view.processUserEvent(); assertFalse(view.hasFlowEvent()); assertNull(view.getFlowEvent()); } }
public void testViewStateFlowRedirect() { ViewStateModel state = new ViewStateModel("view"); state.setView("flowRedirect:myFlow?input=#{flowScope.foo}"); model.setStates(asList(state)); Flow flow = getFlow(model); ViewFactory vf = ((ViewState) flow.getStateInstance("view")).getViewFactory(); assertTrue(vf instanceof ActionExecutingViewFactory); ActionExecutingViewFactory avf = (ActionExecutingViewFactory) vf; assertTrue(avf.getAction() instanceof FlowDefinitionRedirectAction); }
public void testProcessUserEvent() throws IOException { TestAction action = new TestAction(); ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action); MockRequestContext context = new MockRequestContext(); View view = factory.getView(context); assertFalse(action.isExecuted()); view.render(); assertTrue(action.isExecuted()); context.putRequestParameter("_eventId", "foo"); view.processUserEvent(); assertTrue(view.hasFlowEvent()); assertEquals("foo", view.getFlowEvent().getId()); }
@Override public EndState createEndState(final Flow flow, final String id, final String viewId, final boolean redirect) { if (!redirect) { return createEndState(flow, id, viewId); } val expression = createExpression(viewId, String.class); val viewFactory = new ActionExecutingViewFactory(new ExternalRedirectAction(expression)); return createEndState(flow, id, viewFactory); }
public void testProcessUserEventButton() throws IOException { TestAction action = new TestAction(); ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action); MockRequestContext context = new MockRequestContext(); View view = factory.getView(context); assertFalse(action.isExecuted()); view.render(); assertTrue(action.isExecuted()); context.putRequestParameter("_eventId_foo", "doesn't matter"); view.processUserEvent(); assertTrue(view.hasFlowEvent()); assertEquals("foo", view.getFlowEvent().getId()); }
private ViewFactory parseViewFactory(String view, String stateId, boolean endState, BinderModel binderModel) { if (!StringUtils.hasText(view)) { if (endState) { return null; } else { view = getLocalContext().getViewFactoryCreator().getViewIdByConvention(stateId); Expression viewId = getLocalContext().getExpressionParser().parseExpression(view, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return createViewFactory(viewId, binderModel); } } else if (view.startsWith("externalRedirect:")) { String encodedUrl = view.substring("externalRedirect:".length()); Expression externalUrl = getLocalContext().getExpressionParser().parseExpression(encodedUrl, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return new ActionExecutingViewFactory(new ExternalRedirectAction(externalUrl)); } else if (view.startsWith("flowRedirect:")) { String flowRedirect = view.substring("flowRedirect:".length()); Expression expression = getLocalContext().getExpressionParser().parseExpression(flowRedirect, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return new ActionExecutingViewFactory(new FlowDefinitionRedirectAction(expression)); } else { Expression viewId = getLocalContext().getExpressionParser().parseExpression(view, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return createViewFactory(viewId, binderModel); } }
private ViewFactory parseViewFactory(String view, String stateId, boolean endState, BinderModel binderModel) { if (!StringUtils.hasText(view)) { if (endState) { return null; } else { view = getLocalContext().getViewFactoryCreator().getViewIdByConvention(stateId); Expression viewId = getLocalContext().getExpressionParser().parseExpression(view, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return createViewFactory(viewId, binderModel); } } else if (view.startsWith("externalRedirect:")) { String encodedUrl = view.substring("externalRedirect:".length()); Expression externalUrl = getLocalContext().getExpressionParser().parseExpression(encodedUrl, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return new ActionExecutingViewFactory(new ExternalRedirectAction(externalUrl)); } else if (view.startsWith("flowRedirect:")) { String flowRedirect = view.substring("flowRedirect:".length()); Expression expression = getLocalContext().getExpressionParser().parseExpression(flowRedirect, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return new ActionExecutingViewFactory(new FlowDefinitionRedirectAction(expression)); } else { Expression viewId = getLocalContext().getExpressionParser().parseExpression(view, new FluentParserContext().template().evaluate(RequestContext.class).expectResult(String.class)); return createViewFactory(viewId, binderModel); } }