Package org.jbpm.designer.expressioneditor.marshalling

Examples of org.jbpm.designer.expressioneditor.marshalling.ExpressionEditorMessageJSONMarshaller


    }

    @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\"," +
                "\"parameters\":[\"variableName1\",\"param1.1\"]" +
                "}," +
                "{" +
                "\"condition\":\"isBetween\"," +
                "\"parameters\":[\"variableName2\",\"param2.1\",\"param2.2\"]" +
                "}" +
                "]," +
                "\"script\":\"return true;\"," +
                "\"errorCode\":\"The error code\"," +
                "\"errorMessage\":\"The error message\"" +
                "}";

        String result = marshaller.marshall(message);

        assertEquals(expectedResult, result);

    }
View Full Code Here


    public void doProcess(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        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);

            if (logger.isDebugEnabled()) {
                logger.debug("Processing request for parameters, command: " + command + ", message: " + message);
            }

            if (!isValidCommand(command)) {
                logger.error("Invalid command: " + command + " was sent to the ExpressionsEditorProcessor, " +
                        "request will be discarded.");
                return;
            }

            try {
                requestMessage = unmarshaller.unmarshall(message);
            } catch (Exception e) {
                logger.error("It was not possible to unmarshall json message, request will be discarded. message: " + message, e);
                return;
            }

            if (GENERATE_COMMAND.equals(command)) {
                responseMessage = doGenerateScript(requestMessage);
            } else if (PARSE_COMMAND.equals(command)) {
                responseMessage = doParseScript(requestMessage);
            }

            if (responseMessage != null) {
                try {
                    String jsonResponse = marshaller.marshall(responseMessage);
                    if (logger.isDebugEnabled()) {
                        logger.debug("sending response message: " + jsonResponse);
                    }
                    out.write(jsonResponse);
                } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.jbpm.designer.expressioneditor.marshalling.ExpressionEditorMessageJSONMarshaller

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.