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);
}
}
}
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;
}
};
}
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);
}
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);
}
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);
}
Aggregations