Search in sources :

Example 1 with ChatButton

use of org.finos.symphony.toolkit.workflow.annotations.ChatButton in project spring-bot by finos.

the class ButtonsResponseHandler method initExposedHandlerMappings.

@SuppressWarnings("unchecked")
protected void initExposedHandlerMappings() {
    if (exposedHandlerMappings == null) {
        ResolvableType g = ResolvableType.forClassWithGenerics(ChatHandlerMapping.class, ChatButton.class);
        exposedHandlerMappings = Arrays.stream(applicationContext.getBeanNamesForType(g)).map(n -> (ChatHandlerMapping<ChatButton>) applicationContext.getBean(n)).collect(Collectors.toList());
    }
}
Also used : ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton) ResolvableType(org.springframework.core.ResolvableType)

Example 2 with ChatButton

use of org.finos.symphony.toolkit.workflow.annotations.ChatButton in project spring-bot by finos.

the class ClaimController method add.

@ChatButton(value = NewClaim.class, buttonText = "add")
public List<Response> add(NewClaim sc, User u, Addressable from) {
    OpenedClaim c = new OpenedClaim();
    c.amount = sc.amount;
    c.author = u;
    c.description = sc.description;
    c.status = Status.OPEN;
    Chat approvalRoom = conversations.getExistingChat("Claim Approval Room");
    return Arrays.asList(new WorkResponse(approvalRoom, c, WorkMode.VIEW), new MessageResponse(from, Message.of("Your claim has been sent to the Approval Room for processing")));
}
Also used : MessageResponse(org.finos.symphony.toolkit.workflow.response.MessageResponse) Chat(org.finos.symphony.toolkit.workflow.content.Chat) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton)

Example 3 with ChatButton

use of org.finos.symphony.toolkit.workflow.annotations.ChatButton in project spring-bot by finos.

the class PollController method poll.

@ChatButton(buttonText = "start", showWhen = WorkMode.EDIT, value = PollCreateForm.class)
public List<WorkResponse> poll(PollCreateForm cf, Chat r, User a) {
    int[] i = { 0 };
    List<String> options = Arrays.asList(cf.option1, cf.option2, cf.option3, cf.option4, cf.option5, cf.option6).stream().filter(s -> StringUtils.hasText(s)).collect(Collectors.toList());
    ButtonList buttons = new ButtonList(options.stream().map(s -> new Button(PollController.class, "poll" + (i[0]++), Type.ACTION, s)).collect(Collectors.toList()));
    HashTag id = new HashTag(UUID.randomUUID().toString());
    Poll p = new Poll(options);
    p.setPoller(a);
    p.setQuestion(cf.getQuestion());
    p.setOptions(options);
    p.setId(id);
    List<User> users = rooms.getChatMembers(r);
    List<WorkResponse> out = users.stream().filter(u -> !isMe(u)).map(u -> createResponseForUser(cf, options, id, buttons, u)).collect(Collectors.toList());
    out.add(new WorkResponse(r, p, WorkMode.VIEW));
    doScheduling(p, cf, r);
    return out;
}
Also used : Arrays(java.util.Arrays) ButtonList(org.finos.symphony.toolkit.workflow.form.ButtonList) User(org.finos.symphony.toolkit.workflow.content.User) SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) WorkMode(org.finos.symphony.toolkit.workflow.annotations.WorkMode) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) ArrayList(java.util.ArrayList) ResponseHandlers(org.finos.symphony.toolkit.workflow.response.handlers.ResponseHandlers) Conversations(org.finos.symphony.toolkit.workflow.conversations.Conversations) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton) ErrorMap(org.finos.symphony.toolkit.workflow.form.ErrorMap) Type(org.finos.symphony.toolkit.workflow.form.Button.Type) TaskScheduler(org.springframework.scheduling.TaskScheduler) Chat(org.finos.symphony.toolkit.workflow.content.Chat) UUID(java.util.UUID) Button(org.finos.symphony.toolkit.workflow.form.Button) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) History(org.finos.symphony.toolkit.workflow.history.History) List(java.util.List) ChatRequest(org.finos.symphony.toolkit.workflow.annotations.ChatRequest) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ChatResponseBody(org.finos.symphony.toolkit.workflow.annotations.ChatResponseBody) StringUtils(org.springframework.util.StringUtils) User(org.finos.symphony.toolkit.workflow.content.User) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton) Button(org.finos.symphony.toolkit.workflow.form.Button) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ButtonList(org.finos.symphony.toolkit.workflow.form.ButtonList) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton)

Example 4 with ChatButton

use of org.finos.symphony.toolkit.workflow.annotations.ChatButton 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

ChatButton (org.finos.symphony.toolkit.workflow.annotations.ChatButton)4 WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)3 Arrays (java.util.Arrays)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 WorkMode (org.finos.symphony.toolkit.workflow.annotations.WorkMode)2 Chat (org.finos.symphony.toolkit.workflow.content.Chat)2 Button (org.finos.symphony.toolkit.workflow.form.Button)2 Type (org.finos.symphony.toolkit.workflow.form.Button.Type)2 ButtonList (org.finos.symphony.toolkit.workflow.form.ButtonList)2 ResolvableType (org.springframework.core.ResolvableType)2 StringUtils (org.springframework.util.StringUtils)2 SymphonyIdentity (com.symphony.api.id.SymphonyIdentity)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 ChatRequest (org.finos.symphony.toolkit.workflow.annotations.ChatRequest)1 ChatResponseBody (org.finos.symphony.toolkit.workflow.annotations.ChatResponseBody)1