Search in sources :

Example 1 with WorkflowResolvers

use of org.finos.symphony.toolkit.workflow.java.resolvers.WorkflowResolvers in project spring-bot by finos.

the class AbstractHandlerExecutor method execute.

@Override
public void execute() throws Throwable {
    ChatHandlerMethod hm = getOriginatingMapping().getHandlerMethod();
    Method m = hm.getMethod();
    Object o = hm.getBean();
    WorkflowResolvers wr = buildWorkflowResolvers(action());
    Object[] args = new Object[hm.getMethodParameters().length];
    for (int i = 0; i < args.length; i++) {
        MethodParameter mp = hm.getMethodParameters()[i];
        Optional<Object> oo = wr.resolve(mp);
        if (oo.isPresent()) {
            args[i] = oo.get();
        }
    }
    Object out;
    try {
        out = m.invoke(o, args);
    } catch (InvocationTargetException ite) {
        throw ite.getTargetException();
    }
    if (out instanceof Response) {
        rh.accept((Response) out);
    } else if (out instanceof Collection) {
        for (Object object : (List<?>) out) {
            if (object instanceof Response) {
                rh.accept((Response) object);
            } else {
                Response r = convert(object);
                if (r != null) {
                    rh.accept(r);
                }
            }
        }
    } else {
        Response r = convert(out);
        if (r != null) {
            rh.accept(r);
        }
    }
}
Also used : Response(org.finos.symphony.toolkit.workflow.response.Response) WorkflowResolvers(org.finos.symphony.toolkit.workflow.java.resolvers.WorkflowResolvers) Collection(java.util.Collection) Method(java.lang.reflect.Method) MethodParameter(org.springframework.core.MethodParameter) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 WorkflowResolvers (org.finos.symphony.toolkit.workflow.java.resolvers.WorkflowResolvers)1 Response (org.finos.symphony.toolkit.workflow.response.Response)1 MethodParameter (org.springframework.core.MethodParameter)1