Package org.jbpm.designer.expressioneditor.model

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


        LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(ExpressionEditorMessageMarshallingTest.class.getResourceAsStream("OneScriptPerLine.txt") ));
        String line = null;

        List<ConditionExpression> expectedExpressions = new ArrayList<ConditionExpression>();

        ConditionExpression expression = new ConditionExpression(ConditionExpression.AND_OPERATOR);
        Condition condition = new Condition("between");
        condition.addParam("a");
        condition.addParam("o\"ne");
        condition.addParam("two");
        expression.getConditions().add(condition);
        expectedExpressions.add(expression);

        expression = new ConditionExpression(ConditionExpression.AND_OPERATOR);
        condition = new Condition("isNull");
        condition.addParam("variable1");
        expression.getConditions().add(condition);
        expectedExpressions.add(expression);

        expression = new ConditionExpression(ConditionExpression.AND_OPERATOR);
        condition = new Condition("greaterThan");
        condition.addParam("variable2");
        condition.addParam(" the value ");
        expression.getConditions().add(condition);
        expectedExpressions.add(expression);

        expression = new ConditionExpression(ConditionExpression.AND_OPERATOR);
        condition = new Condition("isNull");
        condition.addParam("a");
        expression.getConditions().add(condition);
        expectedExpressions.add(expression);

        expression = new ConditionExpression(ConditionExpression.AND_OPERATOR);
        condition = new Condition("greaterOrEqualThan");
        condition.addParam("v");
        condition.addParam("one");
        expression.getConditions().add(condition);
        expectedExpressions.add(expression);


        while ((line = lineReader.readLine()) != null) {

            logger.debug("line(" + lineReader.getLineNumber() + ") :" + line);

            ExpressionParser parser = new ExpressionParser(line);

            ConditionExpression conditionExpression = parser.parse();
            assertEqualsExpression(expectedExpressions.get(lineReader.getLineNumber()-1) , conditionExpression);
        }

    }
View Full Code Here


    @Test
    public void testScript1() throws Exception {

        String script = readFile("Script1.txt");

        ConditionExpression expectedExpression = new ConditionExpression(ConditionExpression.AND_OPERATOR);
        Condition expectedCondition = new Condition("greaterOrEqualThan");
        expectedCondition.addParam("variable");
        expectedCondition.addParam("o\\náéö great! \"\n   áéíóúñÑ @|#~!·$%&/()=?¿");
        expectedExpression.getConditions().add(expectedCondition);

        ExpressionParser parser = new ExpressionParser(script);
        ConditionExpression actualExpression = parser.parse();

        System.out.println(actualExpression.getOperator());
        for (Condition condition : actualExpression.getConditions()) {
            System.out.println("condition: " + condition.getFunction());
            for (String param : condition.getParameters()) {
                System.out.println("\""+param+"\"");
            }
        }
View Full Code Here

    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");
View Full Code Here

        JsonFactory jsonFactory = new JsonFactory();
        JsonGenerator generator = jsonFactory.createJsonGenerator(outputStream, JsonEncoding.UTF8);

        generator.writeStartObject();

        if (message.getExpression() == null) message.setExpression(new ConditionExpression());

        if (message.getExpression() != null) {

            generator.writeFieldName(ExpressionEditorMessageTokens.OPERATOR_TOKEN);
            if (message.getExpression().getOperator() != null) {
View Full Code Here

    }


    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));
View Full Code Here

    private ExpressionEditorMessage doParseScript(ExpressionEditorMessage requestMessage) {

        //TODO add more fine grained controls.
        String script = requestMessage.getScript();
        ConditionExpression conditionExpression = null;

        if (logger.isDebugEnabled()) logger.debug("parsing script: " + script);

        try {
            ExpressionParser parser = new ExpressionParser(script);
            conditionExpression = parser.parse();
            requestMessage.setExpression(conditionExpression);
            requestMessage.setErrorCode(null);
            requestMessage.setErrorMessage(null);
        } catch (ParseException e) {
            logger.warn("Script sent to server couldn't be parsed: " + script + " due to the following error: " + e.getMessage());
            requestMessage.setErrorCode(ExpressionEditorErrors.SCRIPT_PARSING_ERROR);
            requestMessage.setErrorMessage(e.getMessage());
            requestMessage.setExpression(new ConditionExpression());
        }
        return requestMessage;
    }
View Full Code Here

        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);
View Full Code Here

        this.parseIndex = expression != null ? 0 : -1;
    }

    public ConditionExpression parse() throws ParseException {

        ConditionExpression conditionExpression = new ConditionExpression();
        Condition condition = null;
        FunctionDef functionDef = null;

        parseReturnSentence();

        functionName = parseFunctionName();
        functionName = functionName.substring(KIE_FUNCTIONS.length(), functionName.length());
        functionDef = functionsRegistry.get(functionName);

        if (functionDef == null) throw new ParseException(errorMessage(FUNCTION_NAME_NOT_RECOGNIZED_ERROR, functionName), parseIndex);

        conditionExpression.setOperator(ConditionExpression.AND_OPERATOR);
        condition = new Condition(functionName);
        conditionExpression.getConditions().add(condition);

        String param = null;
        boolean first = true;

        for (ParamDef paramDef : functionDef.getParams()) {
View Full Code Here

TOP

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

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.