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();
}
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();
}
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;
}
}
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;
}
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);
}
Aggregations