Search in sources :

Example 1 with Action

use of org.finos.symphony.toolkit.workflow.actions.Action in project spring-bot by finos.

the class ChatWorkflowErrorHandler method handleError.

@Override
public void handleError(Throwable t) {
    LOG.error("Error thrown:", t);
    Action currentAction = Action.CURRENT_ACTION.get();
    if (currentAction != null) {
        ErrorResponse er = new ErrorResponse(currentAction.getAddressable(), t, templateName);
        try {
            rh.accept(er);
        } catch (Throwable e) {
            LOG.warn("Couldn't return error {} due to error {} ", er, e);
        }
    }
}
Also used : Action(org.finos.symphony.toolkit.workflow.actions.Action) ErrorResponse(org.finos.symphony.toolkit.workflow.response.ErrorResponse)

Example 2 with Action

use of org.finos.symphony.toolkit.workflow.actions.Action in project spring-bot by finos.

the class ChatRequestChatHandlerMapping method createMappingRegistration.

@Override
protected MappingRegistration<ChatRequest> createMappingRegistration(ChatRequest mapping, ChatHandlerMethod handlerMethod) {
    List<WildcardContent> wildcards = createWildcardContent(mapping, handlerMethod);
    List<MessageMatcher> matchers = createMessageMatchers(mapping, wildcards);
    return new MappingRegistration<ChatRequest>(mapping, handlerMethod) {

        @Override
        public ChatHandlerExecutor getExecutor(Action a) {
            if (a instanceof SimpleMessageAction) {
                if (!canBePerformedHere((SimpleMessageAction) a)) {
                    return null;
                }
                return matchesSimpleMessageAction((SimpleMessageAction) a);
            }
            if (a instanceof FormAction) {
                if (Objects.nonNull(((FormAction) a).getData().get("form")) && ((FormAction) a).getData().get("form").getClass() != HelpPage.class) {
                    return null;
                }
                if (!canBePerformedHere((FormAction) a)) {
                    return null;
                }
                return matchesFormAction((FormAction) a);
            }
            return null;
        }

        private boolean canBePerformedHere(Action a) {
            ChatRequest cb = getMapping();
            return canBePerformed(a.getAddressable(), a.getUser(), cb);
        }

        private ChatHandlerExecutor matchesSimpleMessageAction(SimpleMessageAction a) {
            return pathMatches(a.getMessage(), a);
        }

        private ChatHandlerExecutor matchesFormAction(FormAction a) {
            return pathMatches(Message.of(Word.build(a.getAction())), a);
        }

        private ChatHandlerExecutor pathMatches(Message words, Action a) {
            MappingRegistration<?> me = this;
            ChatHandlerExecutor bestMatch = null;
            for (MessageMatcher messageMatcher : matchers) {
                Map<ChatVariable, Object> map = new HashMap<>();
                if (messageMatcher.consume(words, map)) {
                    if ((bestMatch == null) || (bestMatch.getReplacements().size() < map.size())) {
                        bestMatch = new AbstractHandlerExecutor(wrf, rh, converters) {

                            @Override
                            public Map<ChatVariable, Object> getReplacements() {
                                return map;
                            }

                            @Override
                            public Action action() {
                                return a;
                            }

                            @Override
                            public ChatMapping<?> getOriginatingMapping() {
                                return me;
                            }
                        };
                    }
                }
            }
            return bestMatch;
        }

        @Override
        public boolean isButtonFor(Object o, WorkMode m) {
            return false;
        }
    };
}
Also used : Action(org.finos.symphony.toolkit.workflow.actions.Action) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) FormAction(org.finos.symphony.toolkit.workflow.actions.FormAction) Message(org.finos.symphony.toolkit.workflow.content.Message) HashMap(java.util.HashMap) ChatVariable(org.finos.symphony.toolkit.workflow.annotations.ChatVariable) HelpPage(org.finos.symphony.toolkit.workflow.help.HelpPage) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) FormAction(org.finos.symphony.toolkit.workflow.actions.FormAction) ChatRequest(org.finos.symphony.toolkit.workflow.annotations.ChatRequest) HashMap(java.util.HashMap) Map(java.util.Map) WorkMode(org.finos.symphony.toolkit.workflow.annotations.WorkMode)

Example 3 with Action

use of org.finos.symphony.toolkit.workflow.actions.Action in project spring-bot by finos.

the class TestHandlerMapping method pressButton.

private void pressButton(String s) throws Exception {
    EntityJson jsonObjects = new EntityJson();
    jsonObjects.put("1", new SymphonyUser(123l, "gaurav", "gaurav@example.com"));
    jsonObjects.put("2", new HashTag("SomeTopic"));
    Chat r = new SymphonyRoom("The Room Where It Happened", "abc123");
    User author = new SymphonyUser(ROB_EXAMPLE_ID, ROB_NAME, ROB_EXAMPLE_EMAIL);
    Object fd = new StartClaim();
    Action a = new FormAction(r, author, fd, s, jsonObjects);
    Action.CURRENT_ACTION.set(a);
    mc.accept(a);
}
Also used : Action(org.finos.symphony.toolkit.workflow.actions.Action) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) FormAction(org.finos.symphony.toolkit.workflow.actions.FormAction) EntityJson(org.finos.symphony.toolkit.json.EntityJson) User(org.finos.symphony.toolkit.workflow.content.User) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) StartClaim(org.finos.symphony.toolkit.workflow.fixture.StartClaim) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) Chat(org.finos.symphony.toolkit.workflow.content.Chat) FormAction(org.finos.symphony.toolkit.workflow.actions.FormAction) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) SymphonyRoom(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)

Example 4 with Action

use of org.finos.symphony.toolkit.workflow.actions.Action in project spring-bot by finos.

the class TestHandlerMapping method execute.

private void execute(String s) throws Exception {
    EntityJson jsonObjects = new EntityJson();
    jsonObjects.put("1", new SymphonyUser(123l, "gaurav", "gaurav@example.com"));
    jsonObjects.put("2", new Taxonomy(Arrays.asList(new HashTag("SomeTopic"))));
    Message m = smp.parse("<messageML>/" + s + "</messageML>", jsonObjects);
    Chat r = new SymphonyRoom("The Room Where It Happened", "abc123");
    User author = new SymphonyUser(ROB_EXAMPLE_ID, ROB_NAME, ROB_EXAMPLE_EMAIL);
    Action a = new SimpleMessageAction(r, author, m, jsonObjects);
    Action.CURRENT_ACTION.set(a);
    mc.accept(a);
}
Also used : Action(org.finos.symphony.toolkit.workflow.actions.Action) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) FormAction(org.finos.symphony.toolkit.workflow.actions.FormAction) EntityJson(org.finos.symphony.toolkit.json.EntityJson) User(org.finos.symphony.toolkit.workflow.content.User) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) Message(org.finos.symphony.toolkit.workflow.content.Message) Taxonomy(org.symphonyoss.Taxonomy) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) Chat(org.finos.symphony.toolkit.workflow.content.Chat) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) SymphonyRoom(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)

Example 5 with Action

use of org.finos.symphony.toolkit.workflow.actions.Action in project spring-bot by finos.

the class TestHandlerMapping method getMappingsFor.

private List<ChatMapping<ChatRequest>> getMappingsFor(String s) throws Exception {
    EntityJson jsonObjects = new EntityJson();
    Message m = smp.parse("<messageML>" + s + "</messageML>", jsonObjects);
    Action a = new SimpleMessageAction(null, null, m, jsonObjects);
    return hm.getHandlers(a);
}
Also used : Action(org.finos.symphony.toolkit.workflow.actions.Action) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) FormAction(org.finos.symphony.toolkit.workflow.actions.FormAction) EntityJson(org.finos.symphony.toolkit.json.EntityJson) Message(org.finos.symphony.toolkit.workflow.content.Message) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)

Aggregations

Action (org.finos.symphony.toolkit.workflow.actions.Action)5 FormAction (org.finos.symphony.toolkit.workflow.actions.FormAction)4 SimpleMessageAction (org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)4 EntityJson (org.finos.symphony.toolkit.json.EntityJson)3 Message (org.finos.symphony.toolkit.workflow.content.Message)3 Chat (org.finos.symphony.toolkit.workflow.content.Chat)2 User (org.finos.symphony.toolkit.workflow.content.User)2 HashTag (org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag)2 SymphonyRoom (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)2 SymphonyUser (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ChatRequest (org.finos.symphony.toolkit.workflow.annotations.ChatRequest)1 ChatVariable (org.finos.symphony.toolkit.workflow.annotations.ChatVariable)1 WorkMode (org.finos.symphony.toolkit.workflow.annotations.WorkMode)1 StartClaim (org.finos.symphony.toolkit.workflow.fixture.StartClaim)1 HelpPage (org.finos.symphony.toolkit.workflow.help.HelpPage)1 ErrorResponse (org.finos.symphony.toolkit.workflow.response.ErrorResponse)1 Taxonomy (org.symphonyoss.Taxonomy)1