Search in sources :

Example 1 with CashTag

use of org.finos.symphony.toolkit.workflow.sources.symphony.content.CashTag 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 2 with CashTag

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

the class MessageMLParser method parse.

public Message parse(String message, EntityJson jsonObjects) {
    message = (!message.contains("<messageML>")) ? "<messageML>" + message + "</messageML>" : message;
    Content[] out = { null };
    try {
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse(new InputSource(new StringReader(message)), new DefaultHandler2() {

            Frame<?> top = null;

            @Override
            public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
                if (top instanceof CodeBlockFrame) {
                    push(new IgnoredFrame(qName));
                } else if (isStartCodeBlock(qName, attributes)) {
                    push(new CodeBlockFrame(qName));
                } else if (isStartTag(qName, attributes)) {
                    String dataEntityId = attributes.getValue("data-entity-id");
                    Object o = jsonObjects.get(dataEntityId);
                    if (o instanceof SymphonyUser) {
                        push(new TagFrame<SymphonyUser>((SymphonyUser) o));
                    } else if (o instanceof HashTag) {
                        push(new TagFrame<HashTag>((HashTag) o));
                    } else if (o instanceof CashTag) {
                        push(new TagFrame<CashTag>((CashTag) o));
                    } else if (o instanceof Taxonomy && !((Taxonomy) o).getId().isEmpty() && ((Taxonomy) o).getId().get(0) instanceof HashTag) {
                        push(new TagFrame<HashTag>((HashTag) ((Taxonomy) o).getId().get(0)));
                    } else {
                        throw new UnsupportedOperationException();
                    }
                } else if (isStartTable(qName, attributes)) {
                    push(new TableFrame());
                } else if (isStartParaListItemOrCell(qName, attributes)) {
                    push(new ParagraphFrame());
                } else if (isStartList(qName, attributes)) {
                    push(new ListFrame(qName));
                } else if (isStartRow(qName, attributes)) {
                    if (top instanceof TableFrame) {
                        ((TableFrame) top).newRow();
                    } else {
                        throw new UnsupportedOperationException();
                    }
                } else if (isStartMessage(qName, attributes)) {
                    if (top == null) {
                        push(new MessageFrame());
                    }
                }
            }

            private boolean isStartMessage(String qName, Attributes attributes) {
                return "messageML".equals(qName) || ("div".equals(qName) && "PresentationML".equals(attributes.getValue("data-format")));
            }

            private boolean isStartList(String qName, Attributes attributes) {
                return "ul".equals(qName) || "ol".equals(qName);
            }

            private boolean isStartRow(String qName, Attributes attributes) {
                return "tr".equals(qName);
            }

            private boolean isStartCodeBlock(String qName, Attributes attributes) {
                return "pre".equals(qName) || "code".equals(qName);
            }

            private <X extends Frame<?>> X push(X newFrame) {
                newFrame.parent = top;
                top = newFrame;
                return newFrame;
            }

            @Override
            public void startEntity(String name) throws SAXException {
            // do nothing
            }

            @Override
            public void endEntity(String name) throws SAXException {
            // do nothing
            }

            private boolean isStartTable(String qName, Attributes attributes) {
                return "table".equals(qName);
            }

            private boolean isStartTag(String qName, Attributes attributes) {
                return "span".equals(qName) && (attributes.getValue("class") != null) && (attributes.getValue("class").contains("entity"));
            }

            private boolean isStartParaListItemOrCell(String qName, Attributes attributes) {
                return "p".equals(qName) || "td".equals(qName) || "li".equals(qName) || "th".equals(qName);
            }

            @Override
            public void endElement(String uri, String localName, String qName) throws SAXException {
                if (top.isEnding(qName)) {
                    Frame<?> parent = top.parent;
                    Content c = top.getContents();
                    if (parent == null) {
                        out[0] = c;
                    } else {
                        top = parent;
                        top.push(c);
                    }
                }
            }

            @Override
            public void characters(char[] ch, int start, int length) throws SAXException {
                if (top instanceof TextFrame) {
                    ((TextFrame<?>) top).push(ch, start, length);
                } else {
                    String content = new String(ch, start, length);
                    if (!content.trim().isEmpty()) {
                        throw new UnsupportedOperationException("Wasn't expecting text: " + content);
                    }
                }
            }

            @Override
            public void warning(SAXParseException e) throws SAXException {
                LOG.error("SAX warning: ", e);
            }

            @Override
            public void error(SAXParseException e) throws SAXException {
                LOG.error("SAX error: ", e);
            }

            @Override
            public void fatalError(SAXParseException e) throws SAXException {
                LOG.error("SAX fatal error: ", e);
            }
        });
    } catch (Exception e) {
        throw new RuntimeException("Couldn't parse message: " + message, e);
    }
    return (Message) out[0];
}
Also used : InputSource(org.xml.sax.InputSource) Message(org.finos.symphony.toolkit.workflow.content.Message) Taxonomy(org.symphonyoss.Taxonomy) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) Attributes(org.xml.sax.Attributes) CashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.CashTag) SAXException(org.xml.sax.SAXException) SAXParseException(org.xml.sax.SAXParseException) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) DefaultHandler2(org.xml.sax.ext.DefaultHandler2) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) Content(org.finos.symphony.toolkit.workflow.content.Content) OrderedContent(org.finos.symphony.toolkit.workflow.content.OrderedContent)

Example 3 with CashTag

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

the class TestFormMessageML method createWeirdFieldsWorkResponse.

protected WorkResponse createWeirdFieldsWorkResponse(WorkMode wm) {
    SymphonyRoom theRoom = new SymphonyRoom("tesxt room", "abc123");
    SymphonyUser someUser = new SymphonyUser(2678l, "bob", "bob@example.com");
    WeirdObject to4 = new WeirdObject();
    to4.setTheId(new HashTag("adf360dd-06fe-43a4-9a62-2c17fe2deefa"));
    to4.setC(Choice.C);
    to4.setSomeUser(someUser);
    to4.setCashTag(new CashTag("rameses"));
    to4.setB(true);
    to4.setC(Choice.B);
    Button submit = new Button("submit", Type.ACTION, "GO");
    WorkResponse wr = new WorkResponse(theRoom, to4, wm);
    ButtonList bl = (ButtonList) wr.getData().get(ButtonList.KEY);
    bl.add(submit);
    return wr;
}
Also used : WeirdObject(org.finos.symphony.toolkit.workflow.fixture.WeirdObject) Button(org.finos.symphony.toolkit.workflow.form.Button) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) CashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.CashTag) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) ButtonList(org.finos.symphony.toolkit.workflow.form.ButtonList) SymphonyRoom(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)

Aggregations

CashTag (org.finos.symphony.toolkit.workflow.sources.symphony.content.CashTag)3 HashTag (org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag)3 SymphonyUser (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser)3 Message (org.finos.symphony.toolkit.workflow.content.Message)2 SymphonyRoom (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)2 StringReader (java.io.StringReader)1 UUID (java.util.UUID)1 SAXParser (javax.xml.parsers.SAXParser)1 Content (org.finos.symphony.toolkit.workflow.content.Content)1 OrderedContent (org.finos.symphony.toolkit.workflow.content.OrderedContent)1 Paragraph (org.finos.symphony.toolkit.workflow.content.Paragraph)1 Word (org.finos.symphony.toolkit.workflow.content.Word)1 WeirdObject (org.finos.symphony.toolkit.workflow.fixture.WeirdObject)1 Button (org.finos.symphony.toolkit.workflow.form.Button)1 ButtonList (org.finos.symphony.toolkit.workflow.form.ButtonList)1 WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)1 Test (org.junit.jupiter.api.Test)1 Taxonomy (org.symphonyoss.Taxonomy)1 Attributes (org.xml.sax.Attributes)1 InputSource (org.xml.sax.InputSource)1