Search in sources :

Example 81 with Navajo

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

the class Test method createTestMessage.

public Navajo createTestMessage() throws NavajoException {
    Navajo navajo = NavajoFactory.getInstance().createNavajo();
    Message element = NavajoFactory.getInstance().createMessage(navajo, "Data", Message.MSG_TYPE_ARRAY);
    navajo.addMessage(element);
    init(element);
    navajo.write(System.err);
    return navajo;
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo)

Example 82 with Navajo

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

the class Test method processLine.

// 0060;AMELAND;681
private void processLine(String line, Message parent) throws NavajoException {
    // "5392 Maasdonk";"795";"1671";"Maasdonk"
    StringTokenizer st = new StringTokenizer(line, ";");
    String code = st.nextToken();
    st.nextToken();
    String members = st.nextToken();
    if (code == null) {
        throw new RuntimeException();
    }
    int total = Gemeente2Population.getGemeente(code);
    int member = Integer.parseInt(members);
    double res = (double) member / (double) total / 0.12;
    Navajo navajo = parent.getRootDoc();
    Message element = NavajoFactory.getInstance().createMessage(navajo, "Data", Message.MSG_TYPE_ARRAY_ELEMENT);
    parent.addMessage(element);
    Property key = NavajoFactory.getInstance().createProperty(navajo, "Key", Property.STRING_PROPERTY, code, 9, "", Property.DIR_IN);
    Property value = NavajoFactory.getInstance().createProperty(navajo, "Value", Property.STRING_PROPERTY, "" + res, 9, "", Property.DIR_IN);
    Property description = NavajoFactory.getInstance().createProperty(navajo, "Description", Property.STRING_PROPERTY, "Leden per 1000 inwoners: " + (int) (res * 1000), 99, "", Property.DIR_IN);
    element.addProperty(key);
    element.addProperty(value);
    element.addProperty(description);
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 83 with Navajo

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

the class Dispatcher method generateErrorMessage.

/**
 * Generate a Navajo error message and log the error to the Database.
 */
@Override
public final Navajo generateErrorMessage(Access access, String message, int code, int level, Throwable t) throws FatalException {
    if (message == null) {
        message = "Null pointer exception";
    }
    if (t != null) {
        logger.error("Generating error message for: ", t);
    }
    try {
        Navajo outMessage = NavajoFactory.getInstance().createNavajo();
        // Make sure empty Header is constructed
        Header h = NavajoFactory.getInstance().createHeader(outMessage, "", "", "", -1);
        outMessage.addHeader(h);
        Message errorMessage = NavajoFactory.getInstance().createMessage(outMessage, Constants.ERROR_MESSAGE);
        outMessage.addMessage(errorMessage);
        Property prop = NavajoFactory.getInstance().createProperty(outMessage, "message", Property.STRING_PROPERTY, message, 200, "Message", Property.DIR_OUT);
        errorMessage.addProperty(prop);
        prop = NavajoFactory.getInstance().createProperty(outMessage, "code", Property.INTEGER_PROPERTY, code + "", 100, "Code", Property.DIR_OUT);
        errorMessage.addProperty(prop);
        prop = NavajoFactory.getInstance().createProperty(outMessage, "level", Property.INTEGER_PROPERTY, level + "", 100, "Level", Property.DIR_OUT);
        errorMessage.addProperty(prop);
        if (access != null) {
            prop = NavajoFactory.getInstance().createProperty(outMessage, "access_id", Property.STRING_PROPERTY, access.accessID + "", 100, "Access id", Property.DIR_OUT);
            errorMessage.addProperty(prop);
            access.setException(t);
        }
        if (access != null) {
            access.setOutputDoc(outMessage);
        }
        return outMessage;
    } catch (Exception e) {
        throw new FatalException(e.getMessage(), e);
    }
}
Also used : Header(com.dexels.navajo.document.Header) Message(com.dexels.navajo.document.Message) FatalException(com.dexels.navajo.script.api.FatalException) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) FatalException(com.dexels.navajo.script.api.FatalException) NavajoException(com.dexels.navajo.document.NavajoException) AuthorizationException(com.dexels.navajo.script.api.AuthorizationException) UserException(com.dexels.navajo.script.api.UserException) TriggerException(com.dexels.navajo.server.enterprise.scheduler.TriggerException) IOException(java.io.IOException) SystemException(com.dexels.navajo.script.api.SystemException)

Example 84 with Navajo

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

the class Request method getThanksMessage.

/**
 * Generate a simple "feedback" message with only 1 property: "resultaat".
 */
public Navajo getThanksMessage(String what) throws NavajoException {
    // Create Navajo out message
    Navajo outMessage = NavajoFactory.getInstance().createNavajo();
    Message resultMessage = NavajoFactory.getInstance().createMessage(outMessage, "feedback");
    outMessage.addMessage(resultMessage);
    Property prop = NavajoFactory.getInstance().createProperty(outMessage, "resultaat", Property.STRING_PROPERTY, what, 1, "", Property.DIR_OUT);
    resultMessage.addProperty(prop);
    return outMessage;
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 85 with Navajo

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

the class Request method getInitialNavajoMesssage.

/**
 * This method returns the Navajo message that corresponds to an initial
 * service request. Initial services are always located somewhere on the filesystem.
 */
public Navajo getInitialNavajoMesssage(String service) throws IOException, NavajoException {
    Navajo outMessage = null;
    // Read the filename from koopsom properties
    String fileName = properties.get(service).toString();
    outMessage = NavajoFactory.getInstance().createNavajo(new FileInputStream(fileName));
    return outMessage;
}
Also used : Navajo(com.dexels.navajo.document.Navajo) FileInputStream(java.io.FileInputStream)

Aggregations

Navajo (com.dexels.navajo.document.Navajo)258 Message (com.dexels.navajo.document.Message)131 Test (org.junit.Test)109 Property (com.dexels.navajo.document.Property)86 NavajoException (com.dexels.navajo.document.NavajoException)31 Access (com.dexels.navajo.script.api.Access)30 IOException (java.io.IOException)28 StringWriter (java.io.StringWriter)27 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)25 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)22 Selection (com.dexels.navajo.document.Selection)22 Header (com.dexels.navajo.document.Header)20 Operand (com.dexels.navajo.document.Operand)20 InputStream (java.io.InputStream)17 UserException (com.dexels.navajo.script.api.UserException)16 Optional (java.util.Optional)16 FatalException (com.dexels.navajo.script.api.FatalException)14 SystemException (com.dexels.navajo.script.api.SystemException)14 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)13