Search in sources :

Example 1 with Table

use of org.finos.symphony.toolkit.workflow.content.Table in project spring-bot by finos.

the class TestHandlerMapping method testTableMapping.

@Test
public void testTableMapping() throws Exception {
    execute("process-table <table>\n" + "      <tr>\n" + "        <th>Thing</th><th>Thang</th>\n" + "      </tr>\n" + "      <tr>\n" + "        <td>1</td><td>2</td>\n" + "      </tr>\n" + "      <tr>\n" + "        <td>3</td><td>4</td>\n" + "      </tr>\n" + "  </table> <span class=\"entity\" data-entity-id=\"1\">@gaurav</span>");
    Assertions.assertEquals("process-table", oc.lastMethod);
    Assertions.assertEquals(2, oc.lastArguments.size());
    Table firstArgument = (Table) oc.lastArguments.get(0);
    List<Paragraph> expected = Arrays.asList(Paragraph.of(Arrays.asList(Word.of("thing"))), Paragraph.of(Arrays.asList(Word.of("thang"))));
    Assertions.assertEquals(expected, firstArgument.getColumnNames());
    Assertions.assertEquals(2, firstArgument.getData().size());
}
Also used : Table(org.finos.symphony.toolkit.workflow.content.Table) Paragraph(org.finos.symphony.toolkit.workflow.content.Paragraph) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Table

use of org.finos.symphony.toolkit.workflow.content.Table 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 3 with Table

use of org.finos.symphony.toolkit.workflow.content.Table in project spring-bot by finos.

the class TestMessageMLParser method testMessageWithTable.

@Test
public void testMessageWithTable() throws Exception {
    Content c = smp.parse("<div data-format=\"PresentationML\" data-version=\"2.0\" class=\"wysiwyg\"><p><table class=\"pasted-table\"><thead><tr><th>Name</th><th>Age</th><th>Alive</th></tr></thead><tbody><tr><td>Jim</td><td>5</td><td>FALSE</td></tr><tr><td>James</td><td>7</td><td>TRUE</td></tr></tbody></table></p></div>", new EntityJson());
    Assertions.assertEquals(Paragraph.of(Arrays.asList(Word.of("Age"))), c.getNth(Table.class, 0).get().getColumnNames().get(1));
    Assertions.assertEquals(Paragraph.of(Arrays.asList(Word.of("TRUE"))), c.getNth(Table.class, 0).get().getData().get(1).get(2));
}
Also used : EntityJson(org.finos.symphony.toolkit.json.EntityJson) Table(org.finos.symphony.toolkit.workflow.content.Table) Content(org.finos.symphony.toolkit.workflow.content.Content) Test(org.junit.jupiter.api.Test)

Aggregations

Table (org.finos.symphony.toolkit.workflow.content.Table)3 Content (org.finos.symphony.toolkit.workflow.content.Content)2 Paragraph (org.finos.symphony.toolkit.workflow.content.Paragraph)2 Test (org.junit.jupiter.api.Test)2 ZoneId (java.time.ZoneId)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 EntityJson (org.finos.symphony.toolkit.json.EntityJson)1 ChatButton (org.finos.symphony.toolkit.workflow.annotations.ChatButton)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 WorkMode (org.finos.symphony.toolkit.workflow.annotations.WorkMode)1 Addressable (org.finos.symphony.toolkit.workflow.content.Addressable)1 UnorderedList (org.finos.symphony.toolkit.workflow.content.UnorderedList)1 User (org.finos.symphony.toolkit.workflow.content.User)1 Word (org.finos.symphony.toolkit.workflow.content.Word)1