Search in sources :

Example 1 with Word

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

the class InRoomAddressingChecker method filter.

public Action filter(Action a) {
    if (a.getAddressable() instanceof User) {
        // direct message to bot
        return a;
    }
    if (a instanceof SimpleMessageAction) {
        SimpleMessageAction sma = (SimpleMessageAction) a;
        Optional<User> firstUserMention = sma.getMessage().getNth(User.class, 0);
        if ((firstUserMention.isPresent()) && (theBot.matches(firstUserMention.get()))) {
            // bot is mentioned, so return the action, stripping out the bot mention
            Message changedMessage = (Message) ((SimpleMessageAction) a).getMessage().removeAtStart(firstUserMention.get());
            return new SimpleMessageAction(a.getAddressable(), a.getUser(), changedMessage, sma.getData());
        }
        Optional<Word> firstWord = sma.getMessage().getNth(Word.class, 0);
        if (allowSlash && firstWord.isPresent() && firstWord.get().getText().startsWith("/")) {
            // we don't actually remove the slash - words will match anyway.
            return a;
        }
        return null;
    } else {
        // forms, everything else - let them through
        return a;
    }
}
Also used : User(org.finos.symphony.toolkit.workflow.content.User) Word(org.finos.symphony.toolkit.workflow.content.Word) Message(org.finos.symphony.toolkit.workflow.content.Message) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)

Example 2 with Word

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

the class TestContents method testContents.

@Test
public void testContents() {
    // tag def
    doAssertsOnContent(new CashTag("id123"), new CashTag("id123"));
    doAssertsOnContent(new HashTag("id123"), new HashTag("id123"));
    // room def
    doAssertsOnObject(new SymphonyRoom("abc", "abc123"), new SymphonyRoom("abc", "abc123"));
    doAssertsOnObject(new SymphonyRoom(null, "abc123"), new SymphonyRoom(null, "abc123"));
    doAssertsOnObject(new SymphonyRoom("abc", "abc123"), new SymphonyRoom("abc", "abc123"));
    doAssertsOnObject(new SymphonyRoom("abc", null), new SymphonyRoom("abc", null));
    // user def
    doAssertsOnObject(new SymphonyUser(123l, "rob", "rob@example.com"), new SymphonyUser(123l, "rob", "rob@example.com"));
    doAssertsOnObject(new SymphonyUser("rob", "rob@example.com"), new SymphonyUser("rob", "rob@example.com"));
    doAssertsOnObject(new SymphonyUser(null, "rob@example.com"), new SymphonyUser(null, "rob@example.com"));
    doAssertsOnObject(new SymphonyUser(123l, "rob", null), new SymphonyUser(123l, "rob", null));
    // id
    UUID some = UUID.randomUUID();
    doAssertsOnContent(HashTag.createID(some), HashTag.createID(some));
    // wordx
    Word w1 = Word.of("hello");
    Word w2 = Word.of("bye");
    doAssertsOnContent(w1, Word.of("hello"));
    // paragraph
    Paragraph p1 = Paragraph.of(Arrays.asList(w1, w2));
    Paragraph p2 = Paragraph.of(Arrays.asList(w1, w2));
    doAssertsOnContent(p1, p2);
    doAssertsOnContent(p1.getNth(Word.class, 0).get(), p2.getNth(Word.class, 0).get());
    // message
    Message m1 = Message.of(Arrays.asList(p1, p2));
    Message m2 = Message.of(Arrays.asList(p1, p2));
    doAssertsOnContent(m1, m2);
}
Also used : Word(org.finos.symphony.toolkit.workflow.content.Word) Message(org.finos.symphony.toolkit.workflow.content.Message) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) CashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.CashTag) UUID(java.util.UUID) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) SymphonyRoom(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom) Paragraph(org.finos.symphony.toolkit.workflow.content.Paragraph) Test(org.junit.jupiter.api.Test)

Example 3 with Word

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

the class TestMessageMLParser method testRemoveStart.

@Test
public void testRemoveStart() {
    Word one = Word.of("one");
    Word two = Word.of("two");
    Word three = Word.of("three");
    Paragraph p1 = Paragraph.of(Arrays.asList(one, two, three));
    Paragraph p1_ = Paragraph.of(Arrays.asList(two, three));
    Message m1 = Message.of(Arrays.asList(p1));
    Message m2 = Message.of(Arrays.asList(p1_));
    Assertions.assertEquals(m1.removeAtStart(one), m2);
}
Also used : Word(org.finos.symphony.toolkit.workflow.content.Word) Message(org.finos.symphony.toolkit.workflow.content.Message) Paragraph(org.finos.symphony.toolkit.workflow.content.Paragraph) Test(org.junit.jupiter.api.Test)

Example 4 with Word

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

the class TestMessageMLParser method testWithout.

@Test
public void testWithout() {
    Word one = Word.of("one");
    Word two = Word.of("two");
    Word three = Word.of("three");
    Paragraph p1 = Paragraph.of(Arrays.asList(one, two, three));
    Paragraph p2 = Paragraph.of(Arrays.asList(one, three));
    Paragraph p1_ = Paragraph.of(Arrays.asList(one, two));
    Paragraph p2_ = Paragraph.of(Arrays.asList(one));
    Message m1 = Message.of(Arrays.asList(p1, p2));
    Message m2 = Message.of(Arrays.asList(p1_, p2_));
    Assertions.assertEquals(m1.without(three), m2);
}
Also used : Word(org.finos.symphony.toolkit.workflow.content.Word) Message(org.finos.symphony.toolkit.workflow.content.Message) Paragraph(org.finos.symphony.toolkit.workflow.content.Paragraph) Test(org.junit.jupiter.api.Test)

Aggregations

Message (org.finos.symphony.toolkit.workflow.content.Message)4 Word (org.finos.symphony.toolkit.workflow.content.Word)4 Paragraph (org.finos.symphony.toolkit.workflow.content.Paragraph)3 Test (org.junit.jupiter.api.Test)3 UUID (java.util.UUID)1 SimpleMessageAction (org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)1 User (org.finos.symphony.toolkit.workflow.content.User)1 CashTag (org.finos.symphony.toolkit.workflow.sources.symphony.content.CashTag)1 HashTag (org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag)1 SymphonyRoom (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)1 SymphonyUser (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser)1