Search in sources :

Example 1 with Response

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;
    }
}
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 2 with Response

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);
        }
    }
}
Also used : Response(org.finos.symphony.toolkit.workflow.response.Response) WorkflowResolvers(org.finos.symphony.toolkit.workflow.java.resolvers.WorkflowResolvers) Collection(java.util.Collection) Method(java.lang.reflect.Method) MethodParameter(org.springframework.core.MethodParameter) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with Response

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);
}
Also used : Paragraph(org.finos.symphony.toolkit.workflow.content.Paragraph) Arrays(java.util.Arrays) UnorderedList(org.finos.symphony.toolkit.workflow.content.UnorderedList) Table(org.finos.symphony.toolkit.workflow.content.Table) User(org.finos.symphony.toolkit.workflow.content.User) Word(org.finos.symphony.toolkit.workflow.content.Word) WorkMode(org.finos.symphony.toolkit.workflow.annotations.WorkMode) Autowired(org.springframework.beans.factory.annotation.Autowired) Response(org.finos.symphony.toolkit.workflow.response.Response) ChatVariable(org.finos.symphony.toolkit.workflow.annotations.ChatVariable) Controller(org.springframework.stereotype.Controller) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) History(org.finos.symphony.toolkit.workflow.history.History) List(java.util.List) Addressable(org.finos.symphony.toolkit.workflow.content.Addressable) MessageResponse(org.finos.symphony.toolkit.workflow.response.MessageResponse) Map(java.util.Map) ChatRequest(org.finos.symphony.toolkit.workflow.annotations.ChatRequest) Optional(java.util.Optional) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton) ChatResponseBody(org.finos.symphony.toolkit.workflow.annotations.ChatResponseBody) Content(org.finos.symphony.toolkit.workflow.content.Content) Table(org.finos.symphony.toolkit.workflow.content.Table) Content(org.finos.symphony.toolkit.workflow.content.Content) MessageResponse(org.finos.symphony.toolkit.workflow.response.MessageResponse) UnorderedList(org.finos.symphony.toolkit.workflow.content.UnorderedList) List(java.util.List) ChatRequest(org.finos.symphony.toolkit.workflow.annotations.ChatRequest)

Example 4 with Response

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());
    }
}
Also used : Arrays(java.util.Arrays) ButtonList(org.finos.symphony.toolkit.workflow.form.ButtonList) Type(org.finos.symphony.toolkit.workflow.form.Button.Type) WorkMode(org.finos.symphony.toolkit.workflow.annotations.WorkMode) Response(org.finos.symphony.toolkit.workflow.response.Response) BeansException(org.springframework.beans.BeansException) Button(org.finos.symphony.toolkit.workflow.form.Button) ChatHandlerMapping(org.finos.symphony.toolkit.workflow.java.mapping.ChatHandlerMapping) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) List(java.util.List) Optional(java.util.Optional) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ResolvableType(org.springframework.core.ResolvableType) Collections(java.util.Collections) ApplicationContextAware(org.springframework.context.ApplicationContextAware) StringUtils(org.springframework.util.StringUtils) Button(org.finos.symphony.toolkit.workflow.form.Button) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton) ButtonList(org.finos.symphony.toolkit.workflow.form.ButtonList) WorkMode(org.finos.symphony.toolkit.workflow.annotations.WorkMode)

Aggregations

Response (org.finos.symphony.toolkit.workflow.response.Response)4 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 ChatButton (org.finos.symphony.toolkit.workflow.annotations.ChatButton)2 WorkMode (org.finos.symphony.toolkit.workflow.annotations.WorkMode)2 Addressable (org.finos.symphony.toolkit.workflow.content.Addressable)2 WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ZoneId (java.time.ZoneId)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Map (java.util.Map)1 SimpleMessageAction (org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)1 ChatRequest (org.finos.symphony.toolkit.workflow.annotations.ChatRequest)1 ChatResponseBody (org.finos.symphony.toolkit.workflow.annotations.ChatResponseBody)1 ChatVariable (org.finos.symphony.toolkit.workflow.annotations.ChatVariable)1