Search in sources :

Example 41 with RuleSetBean

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

the class Key method runRulesBulkOLD.

@Deprecated
public HashMap<RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>> runRulesBulkOLD(List<RuleSetBean> ruleSets, ExecutionMode executionMode, 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>();
    }
    HashMap<RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>> crfViewSpecificOrderedObjects = new HashMap<RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>>();
    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());
                    // Actions
                    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();
                            }
                        }
                    }
                    List<RuleActionBean> actionBeansToShow = new ArrayList<RuleActionBean>();
                    if (actionListBasedOnRuleExecutionResult.size() > 0) {
                        //if (!dryRun) {
                        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, ruleAction, itemData, DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleSet, ruleSetRule, currentStudy, ruleAction));
                            if (rab != null) {
                                actionBeansToShow.add(ruleAction);
                            }
                        }
                        if (actionBeansToShow.size() > 0) {
                            crfViewSpecificOrderedObjects = populateForCrfBasedRulesView(crfViewSpecificOrderedObjects, ruleSet, rule, result, currentStudy, actionBeansToShow);
                        }
                    }
                } 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);
                }
            }
        }
    }
    logCrfViewSpecificOrderedObjects(crfViewSpecificOrderedObjects);
    return crfViewSpecificOrderedObjects;
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) 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) RuleBulkExecuteContainerTwo(org.akaza.openclinica.domain.rule.RuleBulkExecuteContainerTwo) 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) RuleBulkExecuteContainer(org.akaza.openclinica.domain.rule.RuleBulkExecuteContainer) 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 42 with RuleSetBean

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

the class RestoreRuleSetServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String ruleSetId = request.getParameter(RULESET_ID);
    String action = request.getParameter(ACTION);
    if (ruleSetId == null) {
        addPageMessage(respage.getString("please_choose_a_CRF_to_view"));
        forwardPage(Page.CRF_LIST);
    } else {
        RuleSetBean ruleSetBean = null;
        // ruleSetBean = getRuleSetService().getRuleSetById(currentStudy, ruleSetId, null);
        ruleSetBean = getRuleSetService().getRuleSetById(currentStudy, ruleSetId);
        if (action.equals("confirm")) {
            request.setAttribute(RULESET, ruleSetBean);
            forwardPage(Page.RESTORE_RULE_SET);
        } else {
            // getRuleSetDao().restore(ruleSetBean, ub);
            // getRuleSetService().restore(ruleSetBean, ub);
            getRuleSetService().updateRuleSet(ruleSetBean, ub, Status.AVAILABLE);
            forwardPage(Page.LIST_RULE_SETS_SERVLET);
        }
    }
}
Also used : RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 43 with RuleSetBean

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

the class RunRuleSetServlet method getRuleSetBean.

private RuleSetBean getRuleSetBean(String ruleSetId, String ruleId) {
    RuleSetBean ruleSetBean = null;
    if (ruleId != null && ruleSetId != null && ruleId.length() > 0 && ruleSetId.length() > 0) {
        ruleSetBean = getRuleSetService().getRuleSetById(currentStudy, ruleSetId);
        ruleSetBean = ruleSetService.filterByRules(ruleSetBean, Integer.valueOf(ruleId));
    } else if (ruleSetId != null && ruleSetId.length() > 0) {
        // getRuleSetService().getRuleSetById(currentStudy, ruleSetId);
        // ruleSetBean = getRuleSetService().getRuleSetById(currentStudy, ruleSetId, null);
        ruleSetBean = getRuleSetService().getRuleSetById(currentStudy, ruleSetId);
    }
    return ruleSetBean;
}
Also used : RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 44 with RuleSetBean

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

the class RemoveRuleSetServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String ruleSetId = request.getParameter(RULESET_ID);
    String action = request.getParameter(ACTION);
    if (ruleSetId == null) {
        addPageMessage(respage.getString("please_choose_a_CRF_to_view"));
        forwardPage(Page.CRF_LIST);
    } else {
        RuleSetBean ruleSetBean = null;
        ruleSetBean = getRuleSetService().getRuleSetById(currentStudy, ruleSetId);
        if (action != null && action.equals("confirm")) {
            request.setAttribute(RULESET, ruleSetBean);
            forwardPage(Page.REMOVE_RULE_SET);
        } else {
            for (RuleSetRuleBean ruleSetRuleBean : ruleSetBean.getRuleSetRules()) {
                if (ruleSetRuleBean.getStatus() != Status.DELETED) {
                    ruleSetRuleBean.setStatus(Status.DELETED);
                    ruleSetRuleBean.setUpdater(ub);
                    ruleSetRuleBean = getRuleSetRuleDao().saveOrUpdate(ruleSetRuleBean);
                    createRuleSetRuleAuditBean(ruleSetRuleBean, ub, Status.DELETED);
                }
            }
            forwardPage(Page.LIST_RULE_SETS_SERVLET);
        }
    }
}
Also used : RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 45 with RuleSetBean

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

the class RuleSetDaoTest method testFindByCrfEmptyResultSet.

public void testFindByCrfEmptyResultSet() {
    CRFBean crfBean = new CRFBean();
    crfBean.setId(4);
    StudyBean studyBean = new StudyBean();
    studyBean.setId(1);
    // RuleSetDao ruleSetDao = (RuleSetDao) getContext().getBean("ruleSetDao");
    crfBean.setId(4);
    List<RuleSetBean> persistentRuleSets = ruleSetDao.findByCrf(crfBean, studyBean);
    assertNotNull("The returned ruleSet was null", persistentRuleSets);
    assertEquals("The List size of ruleset objects should be 0 ", persistentRuleSets.size(), 0);
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Aggregations

RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)67 ArrayList (java.util.ArrayList)28 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)26 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)19 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)15 HashMap (java.util.HashMap)13 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)11 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)9 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)9 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)8 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)7 Map (java.util.Map)6 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)6 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)6 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)6 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)5 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)5 RulesPostImportContainer (org.akaza.openclinica.domain.rule.RulesPostImportContainer)5 RuleActionRunLogBean (org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean)5 Locale (java.util.Locale)4