use of org.finos.symphony.toolkit.workflow.form.Button in project spring-bot by finos.
the class TableAddRow method newRowFormAction.
protected void newRowFormAction(FormAction ea, String verb) {
Map<String, Object> ej = ea.getData();
Object workflowObject = ej.get(WorkResponse.OBJECT_KEY);
String tableLocation = verb.substring(0, verb.length() - ACTION_SUFFIX.length() - 1);
tableLocation = TableEditRow.fixSpel(tableLocation);
Expression e = spel.parseExpression(tableLocation);
TypeDescriptor td = e.getValueTypeDescriptor(workflowObject);
Class<?> c = td.getResolvableType().getGeneric(0).resolve();
Object out = null;
try {
out = c.getConstructor().newInstance();
} catch (Exception e1) {
// this is called for primitives where we can't construct the new instance.
}
Map<String, Object> data = WorkResponse.createEntityMap(out, ButtonList.of(new Button(tableLocation + "." + DO_SUFFIX, Type.ACTION, "Add")), null);
// keep track of the original data
data.put(WORKFLOW_001, workflowObject);
WorkResponse wr = new WorkResponse(ea.getAddressable(), data, WorkResponse.getTemplateNameForClass(WorkMode.EDIT, c), WorkMode.EDIT, c);
rh.accept(wr);
}
use of org.finos.symphony.toolkit.workflow.form.Button 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.form.Button in project spring-bot by finos.
the class WebHookOps method template.
@Exposed(description = "Change the template used by the last called webhook", addToHelp = true, isButton = true, isMessage = true)
public static Response template(SymphonyHistory hist, Addressable a, Workflow wf) {
Optional<EntityJson> ej = hist.getLastEntityJsonFromHistory(ActiveWebHooks.class, a);
if (ej.isEmpty()) {
return new ErrorResponse(wf, a, "No webhooks defined");
}
Optional<WebHook> activeHook = hist.getFromEntityJson(ej.get(), WebHook.class);
if (activeHook.isEmpty()) {
return new ErrorResponse(wf, a, "Active Hook not set");
}
Template t = activeHook.get().getTemplate();
ButtonList bl = new ButtonList();
bl.add(new Button(TEMPLATE_UPDATE, Type.ACTION, "Update Template"));
return new FormResponse(wf, a, ej.get(), "Template Edit", "Update the template used by " + activeHook.get().getDisplayName(), t, true, bl);
}
use of org.finos.symphony.toolkit.workflow.form.Button in project spring-bot by finos.
the class AbstractMockSymphonyTest method createWorkAddSubmit.
protected WorkResponse createWorkAddSubmit(WorkMode wm, Object ob5) {
SymphonyRoom theRoom = new SymphonyRoom("tesxt room", "abc123");
WorkResponse wr = new WorkResponse(theRoom, ob5, wm);
ButtonList bl = (ButtonList) wr.getData().get(ButtonList.KEY);
Button submit = new Button("submit", Type.ACTION, "GO");
bl.add(submit);
return wr;
}
use of org.finos.symphony.toolkit.workflow.form.Button in project spring-bot by finos.
the class OurController method form1.
@ChatRequest(description = "Do blah with a form", value = "form1")
public WorkResponse form1(Addressable a) {
ButtonList bl = new ButtonList();
bl.add(new Button("go", Type.ACTION, "Do The Thing"));
return new WorkResponse(a, new TestObject(), WorkMode.EDIT, bl, null);
}
Aggregations