use of org.finos.symphony.toolkit.workflow.actions.consumers.ActionConsumer in project spring-bot by finos.
the class ElementsHandler method accept.
@SuppressWarnings("unchecked")
@Override
public void accept(V4Event t) {
try {
V4SymphonyElementsAction action = t.getPayload().getSymphonyElementsAction();
if (action != null) {
Map<String, Object> formValues = (Map<String, Object>) action.getFormValues();
String verb = (String) formValues.get("action");
String formId = action.getFormId();
Object currentForm;
if (hasFormData(formValues)) {
currentForm = formConverter.convert(formValues, formId);
} else {
currentForm = null;
}
EntityJson data = retrieveData(action.getFormMessageId());
Addressable rr = ruBuilder.loadRoomById(action.getStream().getStreamId());
User u = ruBuilder.loadUserById(t.getInitiator().getUser().getUserId());
// if we're not in a room, address the user directly.
rr = rr == null ? u : rr;
Errors e = ErrorHelp.createErrorHolder();
if (validated(currentForm, e)) {
FormAction ea = new FormAction(rr, u, currentForm, verb, data);
try {
Action.CURRENT_ACTION.set(ea);
for (ActionConsumer c : elementsConsumers) {
try {
c.accept(ea);
} catch (Exception ee) {
LOG.error("Failed to handle consumer " + c, ee);
}
}
} finally {
Action.CURRENT_ACTION.set(Action.NULL_ACTION);
}
} else {
WorkResponse fr = new WorkResponse(rr, currentForm, WorkMode.EDIT, ButtonList.of(new Button(verb, Button.Type.ACTION, "Retry")), convertErrorsToMap(e));
rh.accept(fr);
}
}
} catch (Exception e) {
LOG.error("Couldn't handle event " + t, e);
}
}
use of org.finos.symphony.toolkit.workflow.actions.consumers.ActionConsumer in project spring-bot by finos.
the class PresentationMLHandler method accept.
@Override
public void accept(V4Event t) {
try {
V4MessageSent ms = t.getPayload().getMessageSent();
if ((ms != null) && (!ms.getMessage().getUser().getEmail().equals(botIdentity.getEmail()))) {
// ok, this is a message, and it's from a third party. Parse it.
EntityJson ej = jsonConverter.readValue(ms.getMessage().getData());
Message words = messageParser.parse(ms.getMessage().getMessage(), ej);
Addressable rr = ruBuilder.loadRoomById(ms.getMessage().getStream().getStreamId());
User u = ruBuilder.loadUserById(ms.getMessage().getUser().getUserId());
// TODO: multi-user chat (not room)
rr = rr == null ? u : rr;
SimpleMessageAction sma = new SimpleMessageAction(rr, u, words, ej);
try {
Action.CURRENT_ACTION.set(sma);
for (ActionConsumer c : messageConsumers) {
c.accept(sma);
}
} finally {
Action.CURRENT_ACTION.set(Action.NULL_ACTION);
}
}
} catch (Exception e) {
LOG.error("Couldn't handle event " + t, e);
}
}
Aggregations