Search in sources :

Example 26 with WorkResponse

use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.

the class SchedulerTests method handleFeedLeaderTest.

@SuppressWarnings("unchecked")
@Test
public void handleFeedLeaderTest() {
    when(history.getLastFromHistory(Mockito.any(Class.class), Mockito.any(Addressable.class))).thenReturn(reminderList());
    when(leaderService.isLeader(Mockito.any())).thenReturn(true);
    when(rooms.getAllConversations()).thenReturn(createStreams());
    scheduler.everyFiveMinutesWeekday();
    verify(responseHandlers).accept(Mockito.any(WorkResponse.class));
    ArgumentCaptor<WorkResponse> argumentCaptor = ArgumentCaptor.forClass(WorkResponse.class);
    verify(responseHandlers).accept(argumentCaptor.capture());
    WorkResponse fr = argumentCaptor.getValue();
    Reminder r = (Reminder) fr.getFormObject();
    Assertions.assertEquals(r.getLocalTime(), expectedTime);
// reminder timefinder tests to chck formresponse
}
Also used : Addressable(org.finos.symphony.toolkit.workflow.content.Addressable) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) Test(org.junit.jupiter.api.Test)

Example 27 with WorkResponse

use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.

the class EditActionElementsConsumer method acceptFormAction.

@Override
public void acceptFormAction(FormAction u) {
    if (u.getAction().equals(EDIT)) {
        Object o = u.getData().get(WorkResponse.OBJECT_KEY);
        rh.accept(new WorkResponse(u.getAddressable(), o, WorkMode.EDIT));
    }
}
Also used : WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse)

Example 28 with WorkResponse

use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.

the class TableEditRow method updateData.

protected void updateData(FormAction in, String verb) {
    String tableLocation = verb.substring(0, verb.length() - UPDATE_SUFFIX.length() - 1);
    tableLocation = fixSpel(tableLocation);
    int lastBracket = tableLocation.lastIndexOf('[');
    int row = Integer.parseInt(tableLocation.substring(lastBracket + 1, tableLocation.length() - 1));
    tableLocation = tableLocation.substring(0, lastBracket);
    Object updated = in.getFormData();
    Expression e = spel.parseExpression(tableLocation);
    Object data = in.getData().get(WORKFLOW_001);
    @SuppressWarnings("unchecked") List<Object> listToUpdate = (List<Object>) e.getValue(data);
    listToUpdate.set(row, updated);
    WorkResponse wr = new WorkResponse(in.getAddressable(), data, WorkMode.EDIT);
    rh.accept(wr);
}
Also used : Expression(org.springframework.expression.Expression) List(java.util.List) ButtonList(org.finos.symphony.toolkit.workflow.form.ButtonList) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse)

Example 29 with WorkResponse

use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.

the class TableEditRow method createEditForm.

protected void createEditForm(FormAction in, String verb) {
    String tableLocation = verb.substring(0, verb.length() - EDIT_SUFFIX.length() - 1);
    tableLocation = fixSpel(tableLocation);
    Expression e = spel.parseExpression(tableLocation);
    Object data = in.getData().get(WorkResponse.OBJECT_KEY);
    Object o = e.getValue(data);
    Class<?> c = o.getClass();
    Map<String, Object> json = WorkResponse.createEntityMap(o, ButtonList.of(new Button(tableLocation + "." + UPDATE_SUFFIX, Type.ACTION, "Update")), null);
    json.put(WORKFLOW_001, data);
    WorkResponse wr = new WorkResponse(in.getAddressable(), json, WorkResponse.getTemplateNameForClass(WorkMode.EDIT, c), WorkMode.EDIT, c);
    rh.accept(wr);
}
Also used : Expression(org.springframework.expression.Expression) Button(org.finos.symphony.toolkit.workflow.form.Button) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse)

Example 30 with WorkResponse

use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.

the class TableDeleteRows method acceptFormAction.

@SuppressWarnings("unchecked")
@Override
public void acceptFormAction(FormAction ea) {
    String verb = ea.getAction();
    if (verb == null) {
        return;
    }
    if (verb.endsWith(ACTION_SUFFIX)) {
        Object data = ea.getData().get(WorkResponse.OBJECT_KEY);
        // get the table to modify
        String tableLocation = verb.substring(0, verb.length() - ACTION_SUFFIX.length() - 1);
        tableLocation = TableEditRow.fixSpel(tableLocation);
        Expression e = spel.parseExpression(tableLocation);
        List<Object> table = (List<Object>) e.getValue(data);
        Object deleteStructure = ((FormSubmission) ea.getFormData()).structure;
        String mapLocation = convertSpelToMapSpel(tableLocation);
        e = spel.parseExpression(mapLocation);
        List<Integer> toRemove = getRowsToDelete((List<Object>) e.getValue(deleteStructure));
        for (Integer i : toRemove) {
            table.remove((int) i);
        }
        WorkResponse out = new WorkResponse(ea.getAddressable(), data, WorkMode.EDIT);
        rh.accept(out);
    }
}
Also used : Expression(org.springframework.expression.Expression) FormSubmission(org.finos.symphony.toolkit.workflow.form.FormSubmission) List(java.util.List) 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