Search in sources :

Example 21 with WorkResponse

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));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) Work(org.finos.symphony.toolkit.workflow.annotations.Work) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) HeaderDetails(org.finos.symphony.toolkit.workflow.sources.symphony.json.HeaderDetails)

Example 22 with WorkResponse

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));
    }
}
Also used : ZoneId(java.time.ZoneId) Instant(java.time.Instant) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ReminderList(org.finos.symphony.toolkit.tools.reminders.ReminderList) ZoneOffset(java.time.ZoneOffset) ErrorResponse(org.finos.symphony.toolkit.workflow.response.ErrorResponse)

Example 23 with WorkResponse

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;
    }
}
Also used : Response(org.finos.symphony.toolkit.workflow.response.Response) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) Calendar(java.util.Calendar) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction) Addressable(org.finos.symphony.toolkit.workflow.content.Addressable) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) Test(org.junit.jupiter.api.Test)

Example 24 with WorkResponse

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;
}
Also used : FeedList(org.finos.symphony.rssbot.feed.FeedList) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse)

Example 25 with WorkResponse

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);
    }
}
Also used : Instant(java.time.Instant) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse)

Aggregations

WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)40 Test (org.junit.jupiter.api.Test)18 Button (org.finos.symphony.toolkit.workflow.form.Button)10 ButtonList (org.finos.symphony.toolkit.workflow.form.ButtonList)9 List (java.util.List)5 Addressable (org.finos.symphony.toolkit.workflow.content.Addressable)5 SymphonyRoom (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)5 Expression (org.springframework.expression.Expression)5 ChatButton (org.finos.symphony.toolkit.workflow.annotations.ChatButton)4 HashTag (org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag)4 Instant (java.time.Instant)3 WorkMode (org.finos.symphony.toolkit.workflow.annotations.WorkMode)3 User (org.finos.symphony.toolkit.workflow.content.User)3 Arrays (java.util.Arrays)2 Collectors (java.util.stream.Collectors)2 SimpleMessageAction (org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)2 ChatRequest (org.finos.symphony.toolkit.workflow.annotations.ChatRequest)2 ChatResponseBody (org.finos.symphony.toolkit.workflow.annotations.ChatResponseBody)2 Chat (org.finos.symphony.toolkit.workflow.content.Chat)2 TestCollections (org.finos.symphony.toolkit.workflow.fixture.TestCollections)2