use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.
the class HeaderTagResponseHandler method accept.
/**
* This ensures that the JSON data being sent will contain a HeaderDetails
* object, which contains a list of {@link HashTag}s that need to be present in
* the message for indexing purposes.
*/
@Override
public void accept(Response t) {
if (t instanceof WorkResponse) {
WorkResponse workResponse = (WorkResponse) t;
HeaderDetails hd = (HeaderDetails) workResponse.getData().get(HeaderDetails.KEY);
if (hd == null) {
hd = new HeaderDetails();
workResponse.getData().put(HeaderDetails.KEY, hd);
}
// make sure all tags are unique, maintain order from original.
Set<HashTag> tags = new LinkedHashSet<>();
tags.addAll(hd.getTags());
// check through other stuff in the json response
for (Object o2 : workResponse.getData().values()) {
Work w = o2 != null ? o2.getClass().getAnnotation(Work.class) : null;
if ((w != null) && (w.index())) {
tags.addAll(TagSupport.classHashTags(o2));
}
}
hd.setTags(new ArrayList<HashTag>(tags));
}
}
use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.
the class Scheduler method handleFeed.
public void handleFeed(Addressable a) {
try {
Optional<ReminderList> fl = h.getLastFromHistory(ReminderList.class, a);
if (fl.isPresent()) {
ReminderList updatedList = new ReminderList(fl.get());
ZoneId zone = updatedList.getTimeZone();
Instant currentTime = LocalDateTime.now().toInstant(ZoneOffset.UTC);
ZoneOffset zo = zone.getRules().getOffset(currentTime);
fl.get().getReminders().stream().forEach((currentReminder) -> {
Instant timeForReminder = currentReminder.getLocalTime().toInstant(zo);
if (timeForReminder.isBefore(currentTime)) {
Map<String, Object> ej = WorkResponse.createEntityMap(currentReminder, null, null);
updatedList.getReminders().remove(currentReminder);
ej.put("ReminderList", updatedList);
WorkResponse wr = new WorkResponse(a, ej, "display-reminder", WorkMode.VIEW, Reminder.class);
responseHandlers.accept(wr);
}
});
}
} catch (Exception e) {
responseHandlers.accept(new ErrorResponse(a, e));
}
}
use of org.finos.symphony.toolkit.workflow.response.WorkResponse 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.WorkResponse in project spring-bot by finos.
the class TimedAlerter method pauseRunningStreams.
private int pauseRunningStreams(Addressable a) {
Optional<FeedList> fl = h.getLastFromHistory(FeedList.class, a);
if ((fl.isPresent()) && (!fl.get().isPaused())) {
FeedList active = fl.get();
active.setPaused(true);
responseHandler.accept(new WorkResponse(a, active, WorkMode.VIEW));
flc.writeFeedList(a, active);
return 1;
}
return 0;
}
use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.
the class PollController method doScheduling.
private void doScheduling(Poll p, PollCreateForm cf, Chat r) {
if (cf.isEndAutomatically()) {
Instant endTime = Instant.now().plus(cf.getTime(), cf.getTimeUnit());
p.setEndTime(endTime);
taskScheduler.schedule(() -> {
Result result = end(p, r, h);
WorkResponse out = new WorkResponse(r, result, WorkMode.VIEW);
rh.accept(out);
}, endTime);
}
}
Aggregations