use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class ExpressionTreeHelper method getDate.
static Date getDate(String dateString) {
logger.info("DateString : " + dateString);
String[] componentsOfDate = dateString.split("[/|.|-]");
if (componentsOfDate.length == 3) {
dateString = componentsOfDate[0] + "-" + componentsOfDate[1] + "-" + componentsOfDate[2];
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date d = sdf.parse(dateString);
return d;
} catch (ParseException e) {
throw new OpenClinicaSystemException("OCRERR_0004", new Object[] { dateString });
}
} else {
throw new OpenClinicaSystemException("OCRERR_0004", new Object[] { dateString });
}
}
use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class OpenClinicaExpressionParser method factorTree.
// end termValue()
/**
* Reads a factor 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 factorTree() throws OpenClinicaSystemException {
textIO.skipBlanks();
char ch = textIO.peek();
logger.debug("TheChar is : " + ch);
if (Character.isDigit(ch)) {
String dateOrNum = textIO.getDate();
if (dateOrNum == null) {
dateOrNum = String.valueOf(textIO.getDouble());
}
logger.debug("TheNum is : " + dateOrNum);
return new ConstantNode(dateOrNum);
} else if (ch == '(') {
// The factor is an expression in parentheses.
// Return a tree representing that expression.
// Read the "("
textIO.getAnyChar();
ExpressionNode exp = expressionTree();
textIO.skipBlanks();
if (textIO.peek() != ')')
throw new OpenClinicaSystemException("OCRERR_0006");
// Read the ")"
textIO.getAnyChar();
return exp;
} else if (String.valueOf(ch).matches("\\w+")) {
String k = textIO.getWord();
logger.debug("TheWord 1 is : " + k);
if (null != expressionWrapper) {
return new OpenClinicaVariableNode(k, expressionWrapper, this);
} else {
return new OpenClinicaBeanVariableNode(k, expressionBeanWrapper, this);
}
} else if (String.valueOf(ch).matches("\"")) {
String k = textIO.getDoubleQuoteWord();
logger.debug("TheWord 2 is : " + k);
return new ConstantNode(k);
} else if (ch == '\n')
throw new OpenClinicaSystemException("OCRERR_0007");
else if (ch == ')')
throw new OpenClinicaSystemException("OCRERR_0008");
else if (ch == '+' || ch == '-' || ch == '*' || ch == '/')
throw new OpenClinicaSystemException("OCRERR_0009");
else
throw new OpenClinicaSystemException("OCRERR_0010", new Object[] { ch });
}
use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class OpenClinicaExpressionParser method parseExpression.
public void parseExpression(String expression) throws OpenClinicaSystemException {
getTextIO().fillBuffer(expression);
getTextIO().skipBlanks();
ExpressionNode exp = expressionTree();
if (getTextIO().peek() != '\n')
throw new OpenClinicaSystemException(ERROR_MESSAGE_KEY);
exp.printStackCommands();
}
use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class OpenClinicaV1ExpressionProcessor method testEvaluateExpression.
public String testEvaluateExpression() {
try {
oep = new OpenClinicaExpressionParser(expressionWrapper);
String result = oep.parseAndTestEvaluateExpression(e.getValue());
logger.debug("Test Result : " + result);
return result;
} catch (OpenClinicaSystemException e) {
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString(e.getErrorCode()));
Object[] arguments = e.getErrorParams();
return "Fail - " + e.getErrorCode() + " : " + mf.format(arguments);
}
}
use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class OpenClinicaV1ExpressionProcessor method isRuleAssignmentExpressionValid.
public String isRuleAssignmentExpressionValid() {
try {
oep = new OpenClinicaExpressionParser(expressionWrapper);
oep.parseAndTestEvaluateExpression(e.getValue());
expressionService = new ExpressionService(expressionWrapper);
if (expressionService.ruleSetExpressionChecker(e.getValue())) {
return null;
} else {
MessageFormat mf = new MessageFormat("");
String errorCode = "OCRERR_0024";
mf.applyPattern(respage.getString(errorCode));
Object[] arguments = {};
return errorCode + " : " + mf.format(arguments);
}
} catch (OpenClinicaSystemException e) {
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString(e.getErrorCode()));
Object[] arguments = e.getErrorParams();
return e.getErrorCode() + " : " + mf.format(arguments);
}
}
Aggregations