Search in sources :

Example 1 with ExpressionObjectWrapper

use of org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper in project OpenClinica by OpenClinica.

the class RulesPostImportContainerService method getExpressionService.

private ExpressionService getExpressionService() {
    expressionService = this.expressionService != null ? expressionService : new ExpressionService(new ExpressionObjectWrapper(ds, currentStudy, (ExpressionBean) null, (RuleSetBean) null));
    expressionService.setExpressionWrapper(new ExpressionObjectWrapper(ds, currentStudy, (ExpressionBean) null, (RuleSetBean) null));
    return expressionService;
}
Also used : ExpressionService(org.akaza.openclinica.service.rule.expression.ExpressionService) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 2 with ExpressionObjectWrapper

use of org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper in project OpenClinica by OpenClinica.

the class RulesPostImportContainerService method isStratificationExpressionValid.

public boolean isStratificationExpressionValid(ExpressionBean expBean, AuditableBeanWrapper<RuleSetBean> beanWrapper) {
    boolean isValid = true;
    ExpressionBean expressionBean = isExpressionValid(expBean, beanWrapper);
    ExpressionObjectWrapper eow = new ExpressionObjectWrapper(ds, currentStudy, expressionBean, ExpressionObjectWrapper.CONTEXT_TARGET);
    ExpressionProcessor ep = ExpressionProcessorFactory.createExpressionProcessor(eow);
    ep.setRespage(respage);
    // String errorString = ep.isRuleExpressionValid();
    String errorString = ep.isRuleAssignmentExpressionValid();
    if (errorString != null) {
        beanWrapper.error(errorString);
        isValid = false;
    }
    return isValid;
}
Also used : ExpressionProcessor(org.akaza.openclinica.domain.rule.expression.ExpressionProcessor) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean)

Example 3 with ExpressionObjectWrapper

use of org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper in project OpenClinica by OpenClinica.

the class EventActionValidator method isEventActionValueExpressionValid.

private boolean isEventActionValueExpressionValid(PropertyBean property, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper) {
    StudyDAO studyDAO = new StudyDAO<String, ArrayList>(getDataSource());
    StudyBean study = (StudyBean) studyDAO.findByPK(ruleSetBeanWrapper.getAuditableBean().getStudyId());
    ExpressionBean expressionBean = isExpressionValid(property.getValueExpression(), ruleSetBeanWrapper);
    ExpressionObjectWrapper eow = new ExpressionObjectWrapper(dataSource, study, expressionBean, ruleSetBeanWrapper.getAuditableBean(), ExpressionObjectWrapper.CONTEXT_VALUE_EXPRESSION);
    ExpressionProcessor ep = ExpressionProcessorFactory.createExpressionProcessor(eow);
    ep.setRespage(respage);
    String errorString = ep.isRuleExpressionValid();
    if (errorString != null) {
        ruleSetBeanWrapper.error(errorString);
        return false;
    }
    // Verify expression generates a valid date string.
    try {
        SimpleDateFormat df = new SimpleDateFormat(VALUE_EXPRESSION_DATE_FORMAT);
        df.setLenient(false);
        String valueExpression = ep.testEvaluateExpression();
        Date valueExpressionDate = df.parse(valueExpression);
        // date that was entered, if it's not, we assume that the date is invalid
        if (!df.format(valueExpressionDate).equals(valueExpression)) {
            return false;
        }
    } catch (ParseException ex) {
        return false;
    }
    return true;
}
Also used : ExpressionProcessor(org.akaza.openclinica.domain.rule.expression.ExpressionProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ParseException(java.text.ParseException) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) SimpleDateFormat(java.text.SimpleDateFormat) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) Date(java.util.Date)

Example 4 with ExpressionObjectWrapper

use of org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper 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 5 with ExpressionObjectWrapper

use of org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper in project OpenClinica by OpenClinica.

the class RulesPostImportContainerService method isRuleExpressionValid.

private boolean isRuleExpressionValid(AuditableBeanWrapper<RuleBean> ruleBeanWrapper, RuleSetBean ruleSet) {
    boolean isValid = true;
    ExpressionBean expressionBean = isExpressionValid(ruleBeanWrapper.getAuditableBean().getExpression(), ruleBeanWrapper);
    ExpressionObjectWrapper eow = new ExpressionObjectWrapper(ds, currentStudy, expressionBean, ruleSet, ExpressionObjectWrapper.CONTEXT_EXPRESSION);
    ExpressionProcessor ep = ExpressionProcessorFactory.createExpressionProcessor(eow);
    ep.setRespage(respage);
    String errorString = ep.isRuleExpressionValid();
    if (errorString != null) {
        ruleBeanWrapper.error(errorString);
        isValid = false;
    }
    return isValid;
}
Also used : ExpressionProcessor(org.akaza.openclinica.domain.rule.expression.ExpressionProcessor) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean)

Aggregations

ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)15 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)14 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)11 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)8 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)8 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)8 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)8 HashMap (java.util.HashMap)7 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)7 ArrayList (java.util.ArrayList)6 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)6 RuleActionRunLogBean (org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean)6 ExpressionProcessor (org.akaza.openclinica.domain.rule.expression.ExpressionProcessor)6 Map (java.util.Map)5 ActionProcessor (org.akaza.openclinica.domain.rule.action.ActionProcessor)5 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)3 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashSet (java.util.HashSet)2