Search in sources :

Example 71 with Property

use of com.dexels.navajo.document.Property in project navajo by Dexels.

the class JsonTmlConverterImpl method toNode.

/* (non-Javadoc)
	 * @see com.dexels.navajo.document.json.impl.JsonTmlConferter#toNode(com.dexels.navajo.document.Message, java.lang.String)
	 */
@Override
public ObjectNode toNode(Message m, final String primaryKeys) {
    ObjectNode result = createTopLevel(primaryKeys);
    ObjectNode columnValuesList = objectMapper.createObjectNode();
    result.set("Columns", columnValuesList);
    List<Property> allProperties = m.getAllProperties();
    if (allProperties != null) {
        for (Property p : allProperties) {
            ObjectNode o = objectMapper.createObjectNode();
            o.put("Type", p.getType());
            o.put("Value", p.getValue());
            columnValuesList.set(p.getName(), o);
        }
    }
    for (Message submessage : m.getAllMessages()) {
        String name = submessage.getName();
        if (Message.MSG_TYPE_ARRAY.equals((submessage.getType()))) {
            ArrayNode node = objectMapper.createArrayNode();
            for (Message element : submessage.getAllMessages()) {
                node.add(toNode(element, primaryKeys));
            }
            ObjectNode submessages = ensureSub("SubMessage", result);
            submessages.set(name, node);
        } else {
            ObjectNode submsg = ensureSub("SubMessage", result);
            submsg.set(name, toNode(submessage, primaryKeys));
        }
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Message(com.dexels.navajo.document.Message) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Property(com.dexels.navajo.document.Property)

Example 72 with Property

use of com.dexels.navajo.document.Property in project navajo by Dexels.

the class NavajoDomStreamer method emitBinaryProperties.

private static void emitBinaryProperties(Message m, List<NavajoStreamEvent> list) {
    for (Property p : m.getAllProperties()) {
        if (Property.BINARY_PROPERTY.equals(p.getType())) {
            list.add(Events.binaryStarted(p.getName(), p.getLength(), Optional.ofNullable(p.getDescription()), Optional.ofNullable(p.getDirection()), Optional.ofNullable(p.getSubType())));
            Binary b = (Binary) p.getTypedValue();
            if (b != null) {
                try {
                    b.writeBase64(new Writer() {

                        @Override
                        public void write(char[] cbuf, int off, int len) throws IOException {
                            list.add(Events.binaryContent(new String(cbuf, off, len)));
                        }

                        @Override
                        public void flush() throws IOException {
                        }

                        @Override
                        public void close() throws IOException {
                        }
                    });
                } catch (IOException e) {
                    logger.error("Error: ", e);
                }
            }
            list.add(Events.binaryDone());
        }
    }
}
Also used : Binary(com.dexels.navajo.document.types.Binary) IOException(java.io.IOException) Property(com.dexels.navajo.document.Property) Writer(java.io.Writer)

Example 73 with Property

use of com.dexels.navajo.document.Property in project navajo by Dexels.

the class NavajoDomStreamer method messageProperties.

private static List<Prop> messageProperties(Message msg) {
    List<Property> all = msg.getAllProperties();
    final List<Prop> result = new ArrayList<>();
    for (Property property : all) {
        result.add(create(property));
    }
    return Collections.unmodifiableList(result);
}
Also used : Prop(com.dexels.navajo.document.stream.api.Prop) ArrayList(java.util.ArrayList) Property(com.dexels.navajo.document.Property)

Example 74 with Property

use of com.dexels.navajo.document.Property in project navajo by Dexels.

the class NavajoStreamCollector method createTmlProperty.

private Property createTmlProperty(Prop p) {
    Property result;
    if (Property.SELECTION_PROPERTY.equals(p.type())) {
        result = NavajoFactory.getInstance().createProperty(assemble, p.name(), p.cardinality().orElse(null), p.description(), p.direction().orElse(null));
        for (Select s : p.selections()) {
            Selection sel = NavajoFactory.getInstance().createSelection(assemble, s.name(), s.value(), s.selected());
            result.addSelection(sel);
        }
    } else {
        result = NavajoFactory.getInstance().createProperty(assemble, p.name(), p.type() == null ? Property.STRING_PROPERTY : p.type(), null, p.length(), p.description(), p.direction().orElse(null));
        if (p.value() != null) {
            result.setAnyValue(p.value());
        }
        if (p.type() != null) {
            result.setType(p.type());
        }
    }
    return result;
}
Also used : Selection(com.dexels.navajo.document.Selection) Select(com.dexels.navajo.document.stream.api.Select) Property(com.dexels.navajo.document.Property)

Example 75 with Property

use of com.dexels.navajo.document.Property in project navajo by Dexels.

the class NavajoStreamCollector method createBinaryProperty.

private Property createBinaryProperty(String name, Binary value) {
    Property result = this.binaryProperties.get(name);
    // Property result = NavajoFactory.getInstance().createProperty(assemble, name, Property.BINARY_PROPERTY, null,0,"", Property.DIR_IN);
    if (result == null) {
        logger.warn("Missing binary property with name " + name);
    } else {
        result.setAnyValue(value);
        return result;
    }
    Property res = NavajoFactory.getInstance().createProperty(assemble, name, Property.BINARY_PROPERTY, null, 0, "", Property.DIR_IN);
    return res;
}
Also used : Property(com.dexels.navajo.document.Property)

Aggregations

Property (com.dexels.navajo.document.Property)253 Message (com.dexels.navajo.document.Message)148 Test (org.junit.Test)88 Navajo (com.dexels.navajo.document.Navajo)84 Selection (com.dexels.navajo.document.Selection)36 NavajoException (com.dexels.navajo.document.NavajoException)30 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)17 ArrayList (java.util.ArrayList)17 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)16 Binary (com.dexels.navajo.document.types.Binary)16 UserException (com.dexels.navajo.script.api.UserException)16 Access (com.dexels.navajo.script.api.Access)15 StringWriter (java.io.StringWriter)13 List (java.util.List)11 Operand (com.dexels.navajo.document.Operand)10 MappableException (com.dexels.navajo.script.api.MappableException)9 IOException (java.io.IOException)9 Writer (java.io.Writer)9 StringTokenizer (java.util.StringTokenizer)9 JSONTML (com.dexels.navajo.document.json.JSONTML)8