Search in sources :

Example 51 with Property

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

the class BaseMessageImpl method addProperty.

@Override
public final void addProperty(Property q, boolean preferExistingPropertyValue) {
    if (this.getType().equals(Message.MSG_TYPE_ARRAY)) {
        logger.warn("Adding property {} to array instead of array_element!", q.getName());
    }
    if (q == null) {
        throw new NullPointerException("Message: can not add null property");
    }
    if (propertyMap == null) {
        propertyMap = new TreeMap<>();
    }
    if (propertyList == null) {
        propertyList = new ArrayList<>();
    }
    BasePropertyImpl p = (BasePropertyImpl) q;
    Property oldProperty = propertyMap.get(p.getName());
    if (oldProperty == q) {
        // ignore
        return;
    }
    if (oldProperty == null) {
        propertyList.add(q);
        propertyMap.put(p.getName(), p);
        p.setParent(this);
    } else if (!preferExistingPropertyValue) {
        this.removeProperty(oldProperty);
        propertyList.add(q);
        propertyMap.put(p.getName(), p);
    }
}
Also used : Property(com.dexels.navajo.document.Property)

Example 52 with Property

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

the class BasePropertyImpl method clone.

@Override
public Object clone() {
    Property p = cloneWithoutValue();
    p.setName(getName());
    if (BINARY_PROPERTY.equals(p.getType())) {
        p.setValue(myBinary);
    } else {
        p.setValue(getValue());
    }
    return p;
}
Also used : Property(com.dexels.navajo.document.Property)

Example 53 with Property

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

the class BasePropertyImpl method getEvaluatedValue.

public final Object getEvaluatedValue() {
    Operand o;
    // No evaluator present.
    if (NavajoFactory.getInstance().getExpressionEvaluator() == null) {
        return null;
    }
    try {
        try {
            if (!EXPRESSION_PROPERTY.equals(getType())) {
                throw NavajoFactory.getInstance().createNavajoException("Can only evaluate expression type properties!");
            }
            try {
                o = NavajoFactory.getInstance().getExpressionEvaluator().evaluate(getValue(), getRootDoc(), null, getParentMessage(), null);
                evaluatedType = o.type;
                return o.value;
            } catch (Throwable e) {
                logger.info("Exception while evaluating property: {} expression: {}", getFullPropertyName(), getValue());
                return null;
            }
        } catch (NavajoException ex) {
            logger.error("Error: ", ex);
            if (myParent != null) {
                Message pp = myParent.getArrayParentMessage();
                if (pp != null && Message.MSG_TYPE_ARRAY.equals(pp.getType())) {
                    Message def = pp.getDefinitionMessage();
                    if (def != null) {
                        Property ppp = def.getProperty(getName());
                        if (ppp != null) {
                            evaluatedType = ppp.getType();
                            return null;
                        }
                    }
                }
            }
            evaluatedType = "string";
            return null;
        }
    } catch (Throwable ex1) {
        evaluatedType = "string";
        return null;
    }
}
Also used : Message(com.dexels.navajo.document.Message) Operand(com.dexels.navajo.document.Operand) NavajoException(com.dexels.navajo.document.NavajoException) Property(com.dexels.navajo.document.Property)

Example 54 with Property

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

the class BaseNavajoImpl method getProperties.

@Override
public List<Property> getProperties(String s) {
    List<Property> props = new ArrayList<>();
    Property prop = null;
    List<Message> messages = null;
    String property = null;
    Message message = null;
    StringTokenizer tok = new StringTokenizer(s, Navajo.MESSAGE_SEPARATOR);
    String messageList = "";
    int count = tok.countTokens();
    for (int i = 0; i < count - 1; i++) {
        property = tok.nextToken();
        messageList += property;
        if ((i + 1) < count - 1)
            messageList += Navajo.MESSAGE_SEPARATOR;
    }
    String realProperty = tok.nextToken();
    messages = this.getMessages(messageList);
    for (int i = 0; i < messages.size(); i++) {
        message = messages.get(i);
        prop = message.getProperty(realProperty);
        if (prop != null)
            props.add(prop);
    }
    return props;
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(com.dexels.navajo.document.Message) ArrayList(java.util.ArrayList) Property(com.dexels.navajo.document.Property)

Example 55 with Property

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

the class BirtUtils method createResultSet.

private void createResultSet(Document d, Element odaDataSetTag, Message sourceObject, String service) {
    Message first = null;
    if (sourceObject == null) {
        return;
    }
    if (sourceObject.getType().equals(Message.MSG_TYPE_ARRAY)) {
        first = sourceObject.getMessage(0);
        if (first == null) {
            return;
        }
    } else {
        first = sourceObject;
    }
    List<Property> props = first.getAllProperties();
    Element listprop = addProperty(d, odaDataSetTag, "list-property", "resultSet", null);
    for (int i = 0; i < props.size(); i++) {
        Property current = props.get(i);
        Element s = d.createElement("structure");
        listprop.appendChild(s);
        addProperty(d, s, "property", "position", "" + (i + 1));
        addProperty(d, s, "property", "name", current.getName());
        addProperty(d, s, "property", "nativeName", current.getName());
        addProperty(d, s, "property", "dataType", getPropertyType(current, false));
        if (Property.BINARY_PROPERTY.equals(current.getType())) {
            Element n = (Element) XMLutils.findNode(odaDataSetTag, "computedColumns");
            if (n == null) {
                n = addProperty(d, odaDataSetTag, "list-property", "computedColumns", null);
            }
            Element struc = addProperty(d, n, "structure", null, null);
            addProperty(d, struc, "property", "name", current.getName() + "_Data");
            addProperty(d, struc, "expression", "expression", "importPackage(Packages.org.dexels.utils); Base64.decode(dataSetRow[\"" + current.getName() + "\"])");
            addProperty(d, struc, "property", "dataType", "any");
        }
    }
    addProperty(d, odaDataSetTag, "property", "queryText", createArrayMessageQueryText(props, service, sourceObject));
}
Also used : Message(com.dexels.navajo.document.Message) Element(org.w3c.dom.Element) 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