Search in sources :

Example 91 with Message

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

the class SetAllProperties method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    // input (ArrayList, Object).
    if (this.getOperands().size() != 3)
        throw new TMLExpressionException("SetAllProperties(Message, String, Object) expected");
    Object a = this.getOperands().get(0);
    if (!(a instanceof Message))
        throw new TMLExpressionException("SetAllProperties(Message, String, Object) expected");
    Object b = this.getOperands().get(1);
    if (!(b instanceof String))
        throw new TMLExpressionException("SetAllProperties(Message, String, Object) expected");
    Object c = this.getOperands().get(2);
    Message source = (Message) a;
    String propertyName = (String) b;
    for (Iterator<Message> iter = source.getAllMessages().iterator(); iter.hasNext(); ) {
        Message element = iter.next();
        Property p = element.getProperty(propertyName);
        if (p != null) {
            p.setAnyValue(c);
        }
    }
    return null;
}
Also used : Message(com.dexels.navajo.document.Message) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

Example 92 with Message

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

the class ServiceCommand method appendTokenAttributes.

private void appendTokenAttributes(ArticleRuntime runtime, Navajo n) {
    Map<String, Object> extraParams = new HashMap<String, Object>();
    if (runtime.getToken() != null && runtime.getToken().getUser() != null) {
        extraParams.put("USERID", runtime.getToken().getUser().getUserId());
        extraParams.put("USERNAME", runtime.getToken().getUser().getUsername());
    } else {
        extraParams.put("USERID", -1);
        extraParams.put("USERNAME", runtime.getUsername());
    }
    extraParams.put("TENANT", runtime.getInstance());
    extraParams.put("PERSONID", "");
    extraParams.put("DOMAIN", "");
    extraParams.put("UNIONID", "");
    GlobalManagerImpl.appendMapToAAA(n, extraParams);
    if (n.getMessage(Message.MSG_TOKEN_BLOCK) == null) {
        Message tokenMsg = NavajoFactory.getInstance().createMessage(n, Message.MSG_TOKEN_BLOCK);
        n.addMessage(tokenMsg);
    }
    Message tokenMsg = n.getMessage(Message.MSG_TOKEN_BLOCK);
    // Add attributes
    for (String key : runtime.getUserAttributes().keySet()) {
        Object value = runtime.getUserAttributes().get(key);
        Property p2 = NavajoFactory.getInstance().createProperty(n, key, "", "", Property.DIR_OUT);
        p2.setAnyValue(value);
        tokenMsg.addProperty(p2);
    }
}
Also used : Message(com.dexels.navajo.document.Message) HashMap(java.util.HashMap) Property(com.dexels.navajo.document.Property)

Example 93 with Message

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

the class ServiceCommand method handleError.

private void handleError(Navajo result) throws UserException, AuthorizationException, ConditionErrorException {
    Message error = result.getMessage("error");
    if (error != null) {
        String errMsg = error.getProperty("message").getValue();
        String errCode = error.getProperty("code").getValue();
        int errorCode = -1;
        try {
            errorCode = Integer.parseInt(errCode);
        } catch (NumberFormatException e) {
            logger.error("Error: ", e);
        }
        throw new UserException(errorCode, errMsg);
    }
    boolean authenticationError = false;
    Message aaaError = result.getMessage(AuthorizationException.AUTHENTICATION_ERROR_MESSAGE);
    if (aaaError == null) {
        aaaError = result.getMessage(AuthorizationException.AUTHORIZATION_ERROR_MESSAGE);
    } else {
        authenticationError = true;
    }
    if (aaaError != null) {
        throw new AuthorizationException(authenticationError, !authenticationError, aaaError.getProperty("User").getValue(), aaaError.getProperty("Message").getValue());
    }
    if (result.getMessage("ConditionErrors") != null) {
        throw new ConditionErrorException(result);
    }
}
Also used : ConditionErrorException(com.dexels.navajo.server.ConditionErrorException) Message(com.dexels.navajo.document.Message) AuthorizationException(com.dexels.navajo.script.api.AuthorizationException) UserException(com.dexels.navajo.script.api.UserException)

Example 94 with Message

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

the class MessageMapTest method test4.

@Test
public void test4() throws Exception {
    // message1 array and message2 array test
    /* building message 1 array*/
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Message array = NavajoFactory.getInstance().createMessage(n, "productArray");
    n.addMessage(array);
    array.setType(Message.MSG_TYPE_ARRAY);
    /*Creating the first element of the message array productArray*/
    Message c1e1 = NavajoFactory.getInstance().createMessage(n, "productArray");
    c1e1.setIndex(0);
    c1e1.setType(Message.MSG_TYPE_ARRAY_ELEMENT);
    array.addElement(c1e1);
    Property c1e1p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
    Property c1e1p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Laptop", 0, "", "out");
    Property c1e1p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, (0) + "", 0, "", "out");
    c1e1.addProperty(c1e1p1);
    c1e1.addProperty(c1e1p1a);
    c1e1.addProperty(c1e1p2);
    /*Creating the second element of the message array productArray */
    Message c1e2 = NavajoFactory.getInstance().createMessage(n, "productArray");
    c1e2.setIndex(1);
    c1e2.setType(Message.MSG_TYPE_ARRAY_ELEMENT);
    array.addElement(c1e2);
    Property c1e2p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
    Property c1e2p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Desktop", 0, "", "out");
    Property c1e2p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, (20) + "", 0, "", "out");
    c1e2.addProperty(c1e2p1);
    c1e2.addProperty(c1e2p1a);
    c1e2.addProperty(c1e2p2);
    n.write(System.err);
    /* building message 2 array*/
    Navajo n2 = NavajoFactory.getInstance().createNavajo();
    Message array2 = NavajoFactory.getInstance().createMessage(n2, "coreArray");
    n2.addMessage(array2);
    array2.setType(Message.MSG_TYPE_ARRAY);
    /*Creating the first element of the message array coreArray */
    Message c2e1 = NavajoFactory.getInstance().createMessage(n2, "coreArray");
    c2e1.setIndex(0);
    c2e1.setType(Message.MSG_TYPE_ARRAY_ELEMENT);
    array2.addElement(c2e1);
    Property c2e1p1 = NavajoFactory.getInstance().createProperty(n2, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
    Property c2e1p2 = NavajoFactory.getInstance().createProperty(n2, "Sub", Property.STRING_PROPERTY, "Laptop", 0, "", "out");
    Property c2e1p3 = NavajoFactory.getInstance().createProperty(n2, "Core", Property.STRING_PROPERTY, "I", 0, "", "out");
    c2e1.addProperty(c2e1p1);
    c2e1.addProperty(c2e1p2);
    c2e1.addProperty(c2e1p3);
    /*Creating the second element of the message array coreArray */
    Message c2e2 = NavajoFactory.getInstance().createMessage(n2, "coreArray");
    c2e2.setIndex(0);
    c2e2.setType(Message.MSG_TYPE_ARRAY_ELEMENT);
    array2.addElement(c2e2);
    Property c2e2p1 = NavajoFactory.getInstance().createProperty(n2, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
    Property c2e2p2 = NavajoFactory.getInstance().createProperty(n2, "Sub", Property.STRING_PROPERTY, "Laptop", 0, "", "out");
    Property c2e2p3 = NavajoFactory.getInstance().createProperty(n2, "Core", Property.STRING_PROPERTY, "A", 0, "", "out");
    c2e2.addProperty(c2e2p1);
    c2e2.addProperty(c2e2p2);
    c2e2.addProperty(c2e2p3);
    n2.write(System.err);
    Access a = new Access();
    a.setOutputDoc(n);
    MessageMap mm = new MessageMap();
    mm.load(a);
    mm.setJoinMessage1("productArray");
    /*for the 2nd message*/
    a.setOutputDoc(n2);
    mm.load(a);
    mm.setJoinMessage2("coreArray");
    mm.setJoinType("inner");
    mm.setJoinCondition("Sub=Sub");
    Message resultMessage = NavajoFactory.getInstance().createMessage(n, "ResultingMessage");
    resultMessage.setType("array");
    n.addMessage(resultMessage);
    a.setCurrentOutMessage(resultMessage);
    ResultMessage[] result = mm.getResultMessage();
    a.setCurrentOutMessage(null);
    mm.store();
    for (int l = 0; l < result.length; l++) {
        assertEquals("Laptop", result[l].getProperty("Sub"));
    }
}
Also used : Message(com.dexels.navajo.document.Message) ResultMessage(com.dexels.navajo.adapter.messagemap.ResultMessage) Access(com.dexels.navajo.script.api.Access) Navajo(com.dexels.navajo.document.Navajo) ResultMessage(com.dexels.navajo.adapter.messagemap.ResultMessage) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 95 with Message

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

the class MessageMapTest method test2.

@Test
public void test2() throws Exception {
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Message array = NavajoFactory.getInstance().createMessage(n, "Array");
    n.addMessage(array);
    array.setType(Message.MSG_TYPE_ARRAY);
    for (int i = 0; i < 10; i++) {
        Message c = NavajoFactory.getInstance().createMessage(n, "Array");
        array.addElement(c);
        if (i % 2 == 0) {
            Property p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
            Property p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Laptop", 0, "", "out");
            Property p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, (i * 10) + "", 0, "", "out");
            String d3 = "2012-01-" + ((i + 1) < 10 ? "0" + (i + 1) : i);
            Property p3 = NavajoFactory.getInstance().createProperty(n, "Date", Property.DATE_PROPERTY, d3, 0, "", "out");
            Property p4 = NavajoFactory.getInstance().createProperty(n, "Gender", "1", "Geslacht", "");
            p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Man", "Man", false));
            p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Vrouw", "Vrouw", true));
            c.addProperty(p1);
            c.addProperty(p1a);
            c.addProperty(p2);
            c.addProperty(p3);
            c.addProperty(p4);
        } else {
            Property p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
            Property p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Desktop", 0, "", "out");
            Property p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, (i * 20) + "", 0, "", "out");
            String d3 = "2012-01-" + ((i + 1) < 10 ? "0" + (i + 1) : (i + 1));
            Property p3 = NavajoFactory.getInstance().createProperty(n, "Date", Property.DATE_PROPERTY, d3, 0, "", "out");
            Property p4 = NavajoFactory.getInstance().createProperty(n, "Gender", "1", "Geslacht", "");
            p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Man", "Man", false));
            p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Vrouw", "Vrouw", true));
            c.addProperty(p1);
            c.addProperty(p1a);
            c.addProperty(p2);
            c.addProperty(p3);
            c.addProperty(p4);
        }
    }
    n.write(System.err);
    Access a = new Access();
    a.setOutputDoc(n);
    MessageMap mm = new MessageMap();
    mm.load(a);
    // mm.setGroupBy("Product,Sub");
    mm.setJoinMessage1("Array");
    mm.setJoinType("outer");
    // mm.setRemoveSource(true);
    Message resultMessage = NavajoFactory.getInstance().createMessage(n, "ResultingMessage");
    resultMessage.setType("array");
    n.addMessage(resultMessage);
    a.setCurrentOutMessage(resultMessage);
    ResultMessage[] result = mm.getResultMessage();
    a.setCurrentOutMessage(null);
    mm.store();
    assertEquals("Vrouw", result[0].getProperty("Gender"));
// n.write(System.err);
}
Also used : Message(com.dexels.navajo.document.Message) ResultMessage(com.dexels.navajo.adapter.messagemap.ResultMessage) Access(com.dexels.navajo.script.api.Access) Navajo(com.dexels.navajo.document.Navajo) ResultMessage(com.dexels.navajo.adapter.messagemap.ResultMessage) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Aggregations

Message (com.dexels.navajo.document.Message)312 Property (com.dexels.navajo.document.Property)149 Navajo (com.dexels.navajo.document.Navajo)127 Test (org.junit.Test)95 NavajoException (com.dexels.navajo.document.NavajoException)39 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)35 Access (com.dexels.navajo.script.api.Access)27 UserException (com.dexels.navajo.script.api.UserException)27 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 Selection (com.dexels.navajo.document.Selection)25 Operand (com.dexels.navajo.document.Operand)22 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)19 MappableException (com.dexels.navajo.script.api.MappableException)18 Ignore (org.junit.Ignore)17 SystemException (com.dexels.navajo.script.api.SystemException)16 Optional (java.util.Optional)15 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)13 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)13 HashMap (java.util.HashMap)13