use of org.finos.symphony.toolkit.workflow.annotations.WorkMode in project spring-bot by finos.
the class WorkResponseConverter method convert.
@Override
public Response convert(Object source, ChatHandlerExecutor creator) {
Addressable a = creator.action().getAddressable();
ChatResponseBody wr = creator.getOriginatingMapping().getHandlerMethod().getMethodAnnotation(ChatResponseBody.class);
WorkMode wm = WorkMode.VIEW;
if (wr != null) {
String template = wr.template();
WorkMode wmAnnotation = wr.workMode();
if (wmAnnotation == WorkMode.EDIT) {
wm = wmAnnotation;
}
if (StringUtils.hasText(template)) {
Map<String, Object> entityMap = WorkResponse.createEntityMap(source, null, null);
return new WorkResponse(a, entityMap, template, wm, source.getClass());
}
}
return new WorkResponse(a, source, wm, null, null);
}
use of org.finos.symphony.toolkit.workflow.annotations.WorkMode 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.annotations.WorkMode 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());
}
}
Aggregations