Package org.jbpm.designer.expressioneditor.model

Examples of org.jbpm.designer.expressioneditor.model.ExpressionEditorMessage


    @Test
    public void testUnmarshalling() throws Exception {

        ExpressionEditorMessageJSONUnmarshaller unmarshaller = new ExpressionEditorMessageJSONUnmarshaller();
        ExpressionEditorMessage message = unmarshaller.unmarshall(ExpressionEditorMessageMarshallingTest.class.getResourceAsStream("condition_editor_message.json"));

        assertNotNull("json message was not marshalled", message);
        assertNotNull("condition expression was not marshalled", message.getExpression());

        assertEquals("OR", message.getExpression().getOperator());
        assertEquals(2, message.getExpression().getConditions().size());

        assertEquals("isEquals", message.getExpression().getConditions().get(0).getFunction());
        assertEquals("variableName1", message.getExpression().getConditions().get(0).getParameters().get(0));
        assertEquals("param1.1", message.getExpression().getConditions().get(0).getParameters().get(1));

        assertEquals("isBetween", message.getExpression().getConditions().get(1).getFunction());
        assertEquals("variableName2", message.getExpression().getConditions().get(1).getParameters().get(0));
        assertEquals("param2.1", message.getExpression().getConditions().get(1).getParameters().get(1));
        assertEquals("param2.2", message.getExpression().getConditions().get(1).getParameters().get(2));

        assertEquals("return true;", message.getScript());
        assertEquals("The error code", message.getErrorCode());
        assertEquals("The error message", message.getErrorMessage());

    }
View Full Code Here


    @Test
    public void testMarshalling() throws Exception {
        ExpressionEditorMessageJSONMarshaller marshaller = new ExpressionEditorMessageJSONMarshaller();

        ExpressionEditorMessage message = new ExpressionEditorMessage();

        ConditionExpression expression = new ConditionExpression("OR");
        message.setExpression(expression);

        Condition condition1 = new Condition();
        condition1.setFunction("isEquals");
        condition1.getParameters().add("variableName1");
        condition1.getParameters().add("param1.1");

        expression.getConditions().add(condition1);


        Condition condition2 = new Condition();
        condition2.setFunction("isBetween");
        condition2.getParameters().add("variableName2");
        condition2.getParameters().add("param2.1");
        condition2.getParameters().add("param2.2");

        expression.getConditions().add(condition2);

        message.setScript("return true;");
        message.setErrorCode("The error code");
        message.setErrorMessage("The error message");

        String expectedResult = "{\"operator\":\"OR\"," +
                "\"conditions\":[" +
                "{" +
                "\"condition\":\"isEquals\"," +
View Full Code Here

        return unmarshall(parser);
    }


    private ExpressionEditorMessage unmarshall(JsonParser parser) throws Exception {
        ExpressionEditorMessage message = new ExpressionEditorMessage();
        ConditionExpression expression = new ConditionExpression();

        try {
            String currentField;

            while (parser.nextToken() != JsonToken.END_OBJECT) {

                currentField = parser.getCurrentName();

                if (ExpressionEditorMessageTokens.OPERATOR_TOKEN.equals(currentField)) {
                    parser.nextToken();
                    expression.setOperator(parseText(parser));
                    message.setExpression(expression);
                } else if (ExpressionEditorMessageTokens.CONDITIONS_TOKEN.equals(currentField)) {
                    List<Condition> conditions = parseConditions(parser);
                    if (conditions.size() > 0) {
                        expression.setConditions(conditions);
                        message.setExpression(expression);
                    }
                } else if (ExpressionEditorMessageTokens.SCRIPT_TOKEN.equals(currentField)) {
                    parser.nextToken();
                    message.setScript(parseText(parser));
                } else if (ExpressionEditorMessageTokens.ERROR_CODE_TOKEN.equals(currentField)) {
                    parser.nextToken();
                    message.setErrorCode(parseText(parser));
                } else if (ExpressionEditorMessageTokens.ERROR_MESSAGE_TOKEN.equals(currentField)) {
                    parser.nextToken();
                    message.setErrorMessage(parseText(parser));
                }
            }
        } catch (IOException e) {
            logger.error("An error was produced during json message parsing. " + e);
            throw e;
View Full Code Here

        res.setContentType("application/json");
        try {

            ExpressionEditorMessageJSONMarshaller marshaller = new ExpressionEditorMessageJSONMarshaller();
            ExpressionEditorMessageJSONUnmarshaller unmarshaller = new ExpressionEditorMessageJSONUnmarshaller();
            ExpressionEditorMessage requestMessage = null;
            ExpressionEditorMessage responseMessage = null;

            PrintWriter out = res.getWriter();

            String command = req.getParameter(COMMAND_PARAM);
            String message = req.getParameter(MESSAGE_PARAM);
View Full Code Here

        }
        return requestMessage;
    }

    private ExpressionEditorMessage doGenerateScript(ExpressionEditorMessage requestMessage) {
        ExpressionEditorMessage responseMessage = new ExpressionEditorMessage();
        List<String> errors = new ArrayList<String>();
        ExpressionScriptGenerator generator = new ExpressionScriptGenerator();

        if (isValidMessageForCommand(GENERATE_COMMAND, requestMessage)) {
            ConditionExpression expression = requestMessage.getExpression();
            String script = generator.generateScript(expression, errors);

            if (script == null) {
                //process the errors.
                requestMessage.setErrorCode(ExpressionEditorErrors.SCRIPT_GENERATION_ERROR);
                responseMessage.setErrorMessage(concat(errors));
            }
            responseMessage.setScript(script);

        } else {
            responseMessage.setErrorCode(ExpressionEditorErrors.INVALID_MESSAGE_ERROR);
        }
        return responseMessage;
    }
View Full Code Here

TOP

Related Classes of org.jbpm.designer.expressioneditor.model.ExpressionEditorMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.