use of org.finos.symphony.toolkit.workflow.response.Response in project spring-bot by finos.
the class TimeFinderIT method applyTest.
@SuppressWarnings("unchecked")
@Test
public void applyTest() {
try {
SimpleMessageAction action = getAction();
lenient().when(history.getLastFromHistory(Mockito.any(Class.class), Mockito.any(Addressable.class))).thenReturn(reminderList());
timefinder.initializingStanfordProperties();
timefinder.accept(action);
ArgumentCaptor<Response> args = ArgumentCaptor.forClass(Response.class);
Mockito.verify(responseHandlers).accept(args.capture());
Assertions.assertEquals(args.getAllValues().size(), 1);
WorkResponse fr = (WorkResponse) args.getValue();
Reminder r = (Reminder) fr.getFormObject();
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
Assertions.assertEquals(r.getLocalTime(), LocalDateTime.of(year, month + 1, day, 21, 20, 0));
} catch (OutOfMemoryError e) {
// see this on our own machines
return;
}
}
use of org.finos.symphony.toolkit.workflow.response.Response in project spring-bot by finos.
the class AbstractHandlerExecutor method execute.
@Override
public void execute() throws Throwable {
ChatHandlerMethod hm = getOriginatingMapping().getHandlerMethod();
Method m = hm.getMethod();
Object o = hm.getBean();
WorkflowResolvers wr = buildWorkflowResolvers(action());
Object[] args = new Object[hm.getMethodParameters().length];
for (int i = 0; i < args.length; i++) {
MethodParameter mp = hm.getMethodParameters()[i];
Optional<Object> oo = wr.resolve(mp);
if (oo.isPresent()) {
args[i] = oo.get();
}
}
Object out;
try {
out = m.invoke(o, args);
} catch (InvocationTargetException ite) {
throw ite.getTargetException();
}
if (out instanceof Response) {
rh.accept((Response) out);
} else if (out instanceof Collection) {
for (Object object : (List<?>) out) {
if (object instanceof Response) {
rh.accept((Response) object);
} else {
Response r = convert(object);
if (r != null) {
rh.accept(r);
}
}
}
} else {
Response r = convert(out);
if (r != null) {
rh.accept(r);
}
}
}
use of org.finos.symphony.toolkit.workflow.response.Response in project spring-bot by finos.
the class ReminderController method timezones.
@ChatRequest(value = "timezones", description = "List Time Zones")
public Response timezones(Addressable a) {
Map<String, List<String>> zoneMap = ZoneId.getAvailableZoneIds().stream().sorted().collect(Collectors.groupingBy(k -> {
int slashIndex = k.indexOf("/");
if (slashIndex == -1) {
return "none";
} else {
return k.substring(0, slashIndex);
}
}));
List<? extends Content> headers = Word.build("Region Zone");
List<List<? extends Content>> tableCells = zoneMap.keySet().stream().map(m -> Arrays.asList(Word.of(m), bulletsOf(zoneMap.get(m)))).collect(Collectors.toList());
Table t = Table.of(headers, tableCells);
return new MessageResponse(a, t);
}
use of org.finos.symphony.toolkit.workflow.response.Response 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