Search in sources :

Example 11 with Button

use of org.finos.symphony.toolkit.workflow.form.Button in project spring-bot by finos.

the class ButtonsResponseHandler method accept.

@Override
public void accept(Response t) {
    if (t instanceof WorkResponse) {
        Object o = ((WorkResponse) t).getFormObject();
        WorkMode wm = ((WorkResponse) t).getMode();
        ButtonList obl = (ButtonList) ((WorkResponse) t).getData().get(ButtonList.KEY);
        if ((obl != null) && (obl.getContents().size() > 0)) {
            return;
        }
        obl = new ButtonList();
        ((WorkResponse) t).getData().put(ButtonList.KEY, obl);
        final ButtonList bl = obl;
        initExposedHandlerMappings();
        exposedHandlerMappings.stream().flatMap(hm -> hm.getAllHandlers(t.getAddress(), null).stream()).filter(cm -> exposedMatchesObject(cm.getMapping(), o)).filter(cm -> cm.isButtonFor(o, wm)).forEach(cm -> {
            ChatButton e = cm.getMapping();
            String value = cm.getUniqueName();
            String text = e.buttonText();
            text = StringUtils.hasText(text) ? text : formatFieldName(cm.getHandlerMethod().getMethod().getName());
            bl.add(new Button(value, Type.ACTION, text));
        });
        Collections.sort((List<Button>) bl.getContents());
    }
}
Also used : Arrays(java.util.Arrays) ButtonList(org.finos.symphony.toolkit.workflow.form.ButtonList) Type(org.finos.symphony.toolkit.workflow.form.Button.Type) WorkMode(org.finos.symphony.toolkit.workflow.annotations.WorkMode) Response(org.finos.symphony.toolkit.workflow.response.Response) BeansException(org.springframework.beans.BeansException) Button(org.finos.symphony.toolkit.workflow.form.Button) ChatHandlerMapping(org.finos.symphony.toolkit.workflow.java.mapping.ChatHandlerMapping) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) List(java.util.List) Optional(java.util.Optional) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ResolvableType(org.springframework.core.ResolvableType) Collections(java.util.Collections) ApplicationContextAware(org.springframework.context.ApplicationContextAware) StringUtils(org.springframework.util.StringUtils) Button(org.finos.symphony.toolkit.workflow.form.Button) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton) ButtonList(org.finos.symphony.toolkit.workflow.form.ButtonList) WorkMode(org.finos.symphony.toolkit.workflow.annotations.WorkMode)

Aggregations

Button (org.finos.symphony.toolkit.workflow.form.Button)11 WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)10 ButtonList (org.finos.symphony.toolkit.workflow.form.ButtonList)8 SymphonyRoom (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)4 ChatButton (org.finos.symphony.toolkit.workflow.annotations.ChatButton)3 Arrays (java.util.Arrays)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 EntityJson (org.finos.symphony.toolkit.json.EntityJson)2 ChatRequest (org.finos.symphony.toolkit.workflow.annotations.ChatRequest)2 WorkMode (org.finos.symphony.toolkit.workflow.annotations.WorkMode)2 User (org.finos.symphony.toolkit.workflow.content.User)2 Type (org.finos.symphony.toolkit.workflow.form.Button.Type)2 ErrorMap (org.finos.symphony.toolkit.workflow.form.ErrorMap)2 HashTag (org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag)2 Expression (org.springframework.expression.Expression)2 StringUtils (org.springframework.util.StringUtils)2 SymphonyIdentity (com.symphony.api.id.SymphonyIdentity)1 V4SymphonyElementsAction (com.symphony.api.model.V4SymphonyElementsAction)1 Instant (java.time.Instant)1