Search in sources :

Example 1 with ExternalRedirectAction

use of org.springframework.webflow.action.ExternalRedirectAction in project cas by apereo.

the class AbstractCasWebflowConfigurer method createEndState.

@Override
public EndState createEndState(final Flow flow, final String id, final String viewId, final boolean redirect) {
    if (!redirect) {
        return createEndState(flow, id, viewId);
    }
    final Expression expression = createExpression(viewId, String.class);
    final ActionExecutingViewFactory viewFactory = new ActionExecutingViewFactory(new ExternalRedirectAction(expression));
    return createEndState(flow, id, viewFactory);
}
Also used : Expression(org.springframework.binding.expression.Expression) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) ActionExecutingViewFactory(org.springframework.webflow.engine.support.ActionExecutingViewFactory) ExternalRedirectAction(org.springframework.webflow.action.ExternalRedirectAction)

Example 2 with ExternalRedirectAction

use of org.springframework.webflow.action.ExternalRedirectAction in project cas by apereo.

the class SpringWebflowEndpoint method getStateDetails.

private static Map<String, Object> getStateDetails(final Flow flowDefinition, final String st) {
    val state = (State) flowDefinition.getState(st);
    val stateMap = new LinkedHashMap<String, Object>();
    if (!state.getAttributes().asMap().isEmpty()) {
        stateMap.put("attributes", CollectionUtils.wrap(state.getAttributes()));
    }
    if (StringUtils.isNotBlank(state.getCaption())) {
        stateMap.put("caption", state.getCaption());
    }
    var acts = StreamSupport.stream(state.getEntryActionList().spliterator(), false).map(SpringWebflowEndpoint::convertActionToString).collect(Collectors.toList());
    if (!acts.isEmpty()) {
        stateMap.put("entryActions", acts);
    }
    if (state instanceof ActionState) {
        acts = StreamSupport.stream(((ActionState) state).getActionList().spliterator(), false).map(SpringWebflowEndpoint::convertActionToString).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            stateMap.put("actionList", acts);
        }
    }
    if (state instanceof EndState) {
        stateMap.put("isEndState", Boolean.TRUE);
    }
    if (state.isViewState()) {
        val viewState = (ViewState) state;
        stateMap.put("isViewState", state.isViewState());
        stateMap.put("isRedirect", viewState.getRedirect());
        acts = StreamSupport.stream(state.getEntryActionList().spliterator(), false).map(Object::toString).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            stateMap.put("renderActions", viewState.getRenderActionList());
        }
        acts = Arrays.stream(viewState.getVariables()).map(variable -> variable.getName() + " -> " + variable.getValueFactory().toString()).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            stateMap.put("viewVariables", acts);
        }
        val field = ReflectionUtils.findField(viewState.getViewFactory().getClass(), "viewId");
        if (field != null) {
            ReflectionUtils.makeAccessible(field);
            val exp = (Expression) ReflectionUtils.getField(field, viewState.getViewFactory());
            stateMap.put("viewId", StringUtils.defaultIfBlank(Objects.requireNonNull(exp).getExpressionString(), exp.getValue(null).toString()));
        } else if (viewState.getViewFactory() instanceof ActionExecutingViewFactory) {
            val factory = (ActionExecutingViewFactory) viewState.getViewFactory();
            if (factory.getAction() instanceof ExternalRedirectAction) {
                val redirect = (ExternalRedirectAction) factory.getAction();
                val uri = ReflectionUtils.findField(redirect.getClass(), "resourceUri");
                ReflectionUtils.makeAccessible(Objects.requireNonNull(uri));
                val exp = (Expression) ReflectionUtils.getField(uri, redirect);
                stateMap.put("viewId", "externalRedirect -> #{" + Objects.requireNonNull(exp).getExpressionString() + '}');
            } else {
                stateMap.put("viewId", factory.getAction().toString());
            }
        } else {
            LOGGER.info("Field viewId cannot be located on view state [{}]", state);
        }
    }
    if (state instanceof TransitionableState) {
        val stDef = (TransitionableState) state;
        acts = StreamSupport.stream(stDef.getExitActionList().spliterator(), false).map(Object::toString).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            stateMap.put("exitActions", acts);
        }
        acts = Arrays.stream(stDef.getTransitions()).map(tr -> tr.getId() + " -> " + tr.getTargetStateId()).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            stateMap.put("transitions", acts);
        }
    }
    return stateMap;
}
Also used : lombok.val(lombok.val) ViewState(org.springframework.webflow.engine.ViewState) TransitionableState(org.springframework.webflow.engine.TransitionableState) ExternalRedirectAction(org.springframework.webflow.action.ExternalRedirectAction) LinkedHashMap(java.util.LinkedHashMap) Expression(org.springframework.binding.expression.Expression) ActionState(org.springframework.webflow.engine.ActionState) TransitionableState(org.springframework.webflow.engine.TransitionableState) State(org.springframework.webflow.engine.State) EndState(org.springframework.webflow.engine.EndState) ViewState(org.springframework.webflow.engine.ViewState) ActionExecutingViewFactory(org.springframework.webflow.engine.support.ActionExecutingViewFactory) ActionState(org.springframework.webflow.engine.ActionState) EndState(org.springframework.webflow.engine.EndState)

Example 3 with ExternalRedirectAction

use of org.springframework.webflow.action.ExternalRedirectAction in project cas by apereo.

the class AbstractCasWebflowConfigurer method createEndState.

@Override
public EndState createEndState(final Flow flow, final String id, final String viewId, final boolean redirect) {
    if (!redirect) {
        return createEndState(flow, id, viewId);
    }
    final Expression expression = createExpression(viewId, String.class);
    final ActionExecutingViewFactory viewFactory = new ActionExecutingViewFactory(new ExternalRedirectAction(expression));
    return createEndState(flow, id, viewFactory);
}
Also used : Expression(org.springframework.binding.expression.Expression) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) ActionExecutingViewFactory(org.springframework.webflow.engine.support.ActionExecutingViewFactory) ExternalRedirectAction(org.springframework.webflow.action.ExternalRedirectAction)

Aggregations

Expression (org.springframework.binding.expression.Expression)3 ExternalRedirectAction (org.springframework.webflow.action.ExternalRedirectAction)3 ActionExecutingViewFactory (org.springframework.webflow.engine.support.ActionExecutingViewFactory)3 LiteralExpression (org.springframework.binding.expression.support.LiteralExpression)2 LinkedHashMap (java.util.LinkedHashMap)1 lombok.val (lombok.val)1 ActionState (org.springframework.webflow.engine.ActionState)1 EndState (org.springframework.webflow.engine.EndState)1 State (org.springframework.webflow.engine.State)1 TransitionableState (org.springframework.webflow.engine.TransitionableState)1 ViewState (org.springframework.webflow.engine.ViewState)1