Search in sources :

Example 16 with OpenClinicaSystemException

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

the class ExpressionTreeHelper method getDateFromddMMMyyyyDashes.

static Date getDateFromddMMMyyyyDashes(String dateString) {
    logger.info("DateString : " + dateString);
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
        Date d = sdf.parse(dateString);
        return d;
    } catch (ParseException e) {
        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 17 with OpenClinicaSystemException

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

the class ArithmeticOpNode method validate.

void validate(String l, String r, String ltext, String rtext) throws OpenClinicaSystemException {
    String t = calculateDate(l, r);
    if (t == null) {
        try {
            Double.valueOf(l);
            Double.valueOf(r);
        } catch (NumberFormatException e) {
            throw new OpenClinicaSystemException("OCRERR_0001", new Object[] { ltext, rtext, op.toString() });
        }
    }
}
Also used : OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 18 with OpenClinicaSystemException

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

the class ConditionalOpNode method validate.

void validate(String l, String r, String ltext, String rtext) throws OpenClinicaSystemException {
    try {
        Boolean.valueOf(l);
        Boolean.valueOf(r);
    } catch (NumberFormatException e) {
        throw new OpenClinicaSystemException("OCRERR_0001", new Object[] { ltext, rtext, op.toString() });
    }
}
Also used : OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 19 with OpenClinicaSystemException

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

the class RuleSetBulkRuleRunner method runRulesBulkFromRuleSetScreenOLD.

public List<RuleSetBasedViewContainer> runRulesBulkFromRuleSetScreenOLD(List<RuleSetBean> ruleSets, Boolean dryRun, StudyBean currentStudy, HashMap<String, String> variableAndValue, UserAccountBean ub) {
    if (variableAndValue == null || variableAndValue.isEmpty()) {
        logger.warn("You must be executing Rules in Batch");
        variableAndValue = new HashMap<String, String>();
    }
    List<RuleSetBasedViewContainer> ruleSetBasedView = new ArrayList<RuleSetBasedViewContainer>();
    for (RuleSetBean ruleSet : ruleSets) {
        for (ExpressionBean expressionBean : ruleSet.getExpressions()) {
            ruleSet.setTarget(expressionBean);
            for (RuleSetRuleBean ruleSetRule : ruleSet.getRuleSetRules()) {
                String result = null;
                RuleBean rule = ruleSetRule.getRuleBean();
                ExpressionObjectWrapper eow = new ExpressionObjectWrapper(ds, currentStudy, rule.getExpression(), ruleSet, variableAndValue);
                try {
                    OpenClinicaExpressionParser oep = new OpenClinicaExpressionParser(eow);
                    result = (String) oep.parseAndEvaluateExpression(rule.getExpression().getValue());
                    // HashMap<String, ArrayList<RuleActionBean>> actionsToBeExecuted = ruleSetRule.getAllActionsWithEvaluatesToAsKey(result);
                    List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result, Phase.BATCH);
                    ItemDataBean itemData = getExpressionService().getItemDataBeanFromDb(ruleSet.getTarget().getValue());
                    if (itemData != null) {
                        Iterator<RuleActionBean> itr = actionListBasedOnRuleExecutionResult.iterator();
                        while (itr.hasNext()) {
                            RuleActionBean ruleActionBean = itr.next();
                            RuleActionRunLogBean ruleActionRunLog = new RuleActionRunLogBean(ruleActionBean.getActionType(), itemData, itemData.getValue(), ruleSetRule.getRuleBean().getOid());
                            if (getRuleActionRunLogDao().findCountByRuleActionRunLogBean(ruleActionRunLog) > 0) {
                                itr.remove();
                            }
                        }
                    }
                    logger.info("RuleSet with target  : {} , Ran Rule : {}  The Result was : {} , Based on that {} action will be executed ", new Object[] { ruleSet.getTarget().getValue(), rule.getName(), result, actionListBasedOnRuleExecutionResult.size() });
                    if (actionListBasedOnRuleExecutionResult.size() > 0) {
                        for (RuleActionBean ruleAction : actionListBasedOnRuleExecutionResult) {
                            ruleAction.setCuratedMessage(curateMessage(ruleAction, ruleSetRule));
                            // getDiscrepancyNoteService().saveFieldNotes(ruleAction.getSummary(), itemDataBeanId, "ItemData", currentStudy, ub);
                            ActionProcessor ap = ActionProcessorFacade.getActionProcessor(ruleAction.getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleSet, getRuleActionRunLogDao(), ruleSetRule);
                            RuleActionBean rab = ap.execute(RuleRunnerMode.RULSET_BULK, ExecutionMode.SAVE, ruleAction, itemData, DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleSet, ruleSetRule, currentStudy, ruleAction));
                            if (rab != null) {
                                ruleSetBasedView = populateForRuleSetBasedView(ruleSetBasedView, ruleSet, rule, result, ruleAction);
                            }
                        }
                    }
                } catch (OpenClinicaSystemException osa) {
                    String errorMessage = "RuleSet with target  : " + ruleSet.getTarget().getValue() + " , Ran Rule : " + rule.getName() + " , It resulted in an error due to : " + osa.getMessage();
                    // log error
                    logger.warn(errorMessage);
                }
            }
        }
    }
    return ruleSetBasedView;
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetBasedViewContainer(org.akaza.openclinica.domain.rule.RuleSetBasedViewContainer) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) ArrayList(java.util.ArrayList) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) OpenClinicaExpressionParser(org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser) RuleActionRunLogBean(org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ActionProcessor(org.akaza.openclinica.domain.rule.action.ActionProcessor) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean)

Example 20 with OpenClinicaSystemException

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

the class ExpressionService method isExpressionValidOLD.

/**
     * Given a Complete Expression check business logic validity of each
     * component. Will throw OpenClinicaSystemException with correct
     * explanation. This might allow immediate communication of message to user
     * .
     * 
     * @param expression
     */
@Deprecated
public void isExpressionValidOLD(String expression) {
    StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpression(expression);
    CRFBean crf = getCRFFromExpression(expression);
    if (studyEventDefinition == null || crf == null)
        throw new OpenClinicaSystemException("OCRERR_0020");
    EventDefinitionCRFBean eventDefinitionCrf = getEventDefinitionCRFDao().findByStudyEventDefinitionIdAndCRFId(this.expressionWrapper.getStudyBean(), studyEventDefinition.getId(), crf.getId());
    if (eventDefinitionCrf == null || eventDefinitionCrf.getId() == 0 || eventDefinitionCrf.getStatus() != Status.AVAILABLE)
        throw new OpenClinicaSystemException("OCRERR_0021");
    ItemGroupBean itemGroup = getItemGroupExpression(expression, crf);
    if (itemGroup == null)
        throw new OpenClinicaSystemException("OCRERR_0022");
    ItemBean item = getItemExpression(expression, itemGroup);
    if (item == null)
        throw new OpenClinicaSystemException("OCRERR_0023");
    logger.debug("Study Event Definition ID : " + studyEventDefinition.getId());
    logger.debug("Crf ID : " + crf.getId());
    logger.debug("Event Definition CRF ID : " + eventDefinitionCrf.getId());
    logger.debug("Item ID : " + item.getId());
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

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