Search in sources :

Example 11 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class OpenClinicaExpressionParser method parseAndTestEvaluateExpression.

public String parseAndTestEvaluateExpression(String expression) throws OpenClinicaSystemException {
    if (expression.length() > 2040)
        throw new OpenClinicaSystemException("OCRERR_0052");
    getTextIO().fillBuffer(expression);
    getTextIO().skipBlanks();
    ExpressionNode exp = expressionTree();
    if (getTextIO().peek() != '\n')
        throw new OpenClinicaSystemException(ERROR_MESSAGE_KEY);
    return exp.testValue();
}
Also used : OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 12 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class OpenClinicaExpressionParser method parseAndEvaluateExpression.

public Object parseAndEvaluateExpression(String expression) throws OpenClinicaSystemException {
    getTextIO().fillBuffer(expression);
    getTextIO().skipBlanks();
    ExpressionNode exp = expressionTree();
    if (getTextIO().peek() != '\n')
        throw new OpenClinicaSystemException(ERROR_MESSAGE_KEY);
    return exp.value();
}
Also used : OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 13 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class OpenClinicaExpressionParser method expressionTree.

/**
     * Reads an expression from the current line of input and builds an expression tree that represents the expression.
     * 
     * @return an ExpNode which is a pointer to the root node of the expression tree
     * @throws OpenClinicaSystemException
     *             if a syntax error is found in the input
     */
private ExpressionNode expressionTree() throws OpenClinicaSystemException {
    try {
        textIO.skipBlanks();
        // True if there is a leading minus sign.
        boolean negative;
        negative = false;
        if (textIO.peek() == '-') {
            textIO.getAnyChar();
            negative = true;
        }
        // The expression tree for the expression.
        ExpressionNode exp;
        // Start with the first term.
        exp = termTree3();
        if (negative)
            exp = new UnaryMinusNode(exp);
        textIO.skipBlanks();
        while (textIO.peek() == 'o' && textIO.peek(3).matches("or ") || textIO.peek() == 'a' && textIO.peek(4).matches("and ")) {
            // Read the next term and combine it with the
            // previous terms into a bigger expression tree.
            // char op = textIO.getAnyChar();
            String op = textIO.peek() == 'o' ? textIO.getAnyString(3) : textIO.getAnyString(4);
            logger.debug("Operator" + op);
            ExpressionNode nextTerm = termTree3();
            exp = ExpressionNodeFactory.getExpNode(Operator.getByDescription(op), exp, nextTerm);
            textIO.skipBlanks();
        }
        return exp;
    } catch (NullPointerException e) {
        throw new OpenClinicaSystemException(ERROR_MESSAGE_KEY);
    } catch (OpenClinicaSystemException e) {
        throw e;
    }
}
Also used : OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 14 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class OpenClinicaExpressionParser method parseAndTestEvaluateExpression.

public HashMap<String, String> parseAndTestEvaluateExpression(String expression, HashMap<String, String> h) throws OpenClinicaSystemException {
    getTextIO().fillBuffer(expression);
    getTextIO().skipBlanks();
    ExpressionNode exp = expressionTree();
    if (getTextIO().peek() != '\n')
        throw new OpenClinicaSystemException(ERROR_MESSAGE_KEY);
    setTestValues(h);
    // HashMap<String, String> theTestValues = getTestValues();
    HashMap<String, String> theTestValues = getResponseTestValues();
    theTestValues.put("result", exp.testValue());
    return theTestValues;
}
Also used : OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 15 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class EqualityOpNode method testCalculate.

@Override
String testCalculate() throws OpenClinicaSystemException {
    String x = null;
    String y = null;
    String l = left.testValue();
    String r = right.testValue();
    try {
        Float fx = Float.valueOf(l);
        Float fy = Float.valueOf(r);
        x = fx.toString();
        y = fy.toString();
    } catch (NumberFormatException nfe) {
    // Don't do anything cause we were just testing above.
    }
    if (x == null && y == null) {
        x = String.valueOf(l);
        y = String.valueOf(r);
    }
    boolean isEventStatusParamExist = left.getNumber().endsWith(STATUS);
    if ((isEventStatusParamExist) && !y.equals("not_scheduled") && !y.equals("data_entry_started") && !y.equals("completed") && !y.equals("stopped") && !y.equals("skipped") && !y.equals("locked") && !y.equals("signed") && !y.equals("scheduled"))
        throw new OpenClinicaSystemException("OCRERR_0038", new String[] { y });
    return calc(x, y);
}
Also used : OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Aggregations

OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)76 IOException (java.io.IOException)19 File (java.io.File)13 HashMap (java.util.HashMap)11 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)11 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)11 ArrayList (java.util.ArrayList)10 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)10 FileNotFoundException (java.io.FileNotFoundException)8 MessageFormat (java.text.MessageFormat)8 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)7 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)7 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)7 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)7 FileOutputStream (java.io.FileOutputStream)6 Date (java.util.Date)6 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)6 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)6 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)6 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)6