Search in sources :

Example 61 with OpenClinicaSystemException

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 });
    }
}
Also used : ParseException(java.text.ParseException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 62 with OpenClinicaSystemException

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 });
}
Also used : OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 63 with OpenClinicaSystemException

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();
}
Also used : OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 64 with OpenClinicaSystemException

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);
    }
}
Also used : OpenClinicaExpressionParser(org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser) MessageFormat(java.text.MessageFormat) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 65 with OpenClinicaSystemException

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);
    }
}
Also used : OpenClinicaExpressionParser(org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser) ExpressionService(org.akaza.openclinica.service.rule.expression.ExpressionService) MessageFormat(java.text.MessageFormat) 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