Search in sources :

Example 1 with RuleBean

use of org.akaza.openclinica.domain.rule.RuleBean 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 2 with RuleBean

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

the class RuleSetService method saveImportFromDesigner.

@Transactional
public void saveImportFromDesigner(RulesPostImportContainer rulesContainer) {
    HashMap<String, RuleBean> ruleBeans = new HashMap<String, RuleBean>();
    for (AuditableBeanWrapper<RuleBean> ruleBeanWrapper : rulesContainer.getValidRuleDefs()) {
        RuleBean r = getRuleDao().saveOrUpdate(ruleBeanWrapper.getAuditableBean());
        ruleBeans.put(r.getOid(), r);
    }
    for (AuditableBeanWrapper<RuleBean> ruleBeanWrapper : rulesContainer.getDuplicateRuleDefs()) {
        RuleBean r = getRuleDao().saveOrUpdate(ruleBeanWrapper.getAuditableBean());
        ruleBeans.put(r.getOid(), r);
    }
    for (AuditableBeanWrapper<RuleSetBean> ruleBeanWrapper : rulesContainer.getValidRuleSetDefs()) {
        loadRuleSetRuleWithPersistentRules(ruleBeanWrapper.getAuditableBean());
        saveRuleSet(ruleBeanWrapper.getAuditableBean());
    }
    for (AuditableBeanWrapper<RuleSetBean> ruleBeanWrapper : rulesContainer.getDuplicateRuleSetDefs()) {
        loadRuleSetRuleWithPersistentRulesWithHashMap(ruleBeanWrapper.getAuditableBean(), ruleBeans);
        replaceRuleSet(ruleBeanWrapper.getAuditableBean());
    }
}
Also used : HashMap(java.util.HashMap) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with RuleBean

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

the class RulesPostImportContainerService method isRuleSetRuleValid.

/**
 * If the RuleSet contains any RuleSetRule object with an invalid RuleRef OID (OID that is not in DB or in the Valid Rule Lists) , Then add an error to the
 * ruleSetBeanWrapper, which in terms will make the RuleSet inValid.
 *
 * @param importContainer
 * @param ruleSetBeanWrapper
 */
private void isRuleSetRuleValid(RulesPostImportContainer importContainer, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper, List<RuleSetBean> eventActionsRuleSetBean) {
    for (RuleSetRuleBean ruleSetRuleBean : ruleSetBeanWrapper.getAuditableBean().getRuleSetRules()) {
        String ruleDefOid = ruleSetRuleBean.getOid();
        if (ruleSetRuleBean.getId() == null || ruleSetRuleBean.getRuleSetRuleBeanImportStatus() == RuleSetRuleBeanImportStatus.EXACT_DOUBLE) {
            EventDefinitionCRFBean eventDefinitionCRFBean = getExpressionService().getEventDefinitionCRF(ruleSetBeanWrapper.getAuditableBean().getTarget().getValue());
            if (eventDefinitionCRFBean != null && eventDefinitionCRFBean.getStatus().isDeleted()) {
                ruleSetBeanWrapper.error(createError("OCRERR_0026"));
            }
            if (importContainer.getInValidRules().get(ruleDefOid) != null || importContainer.getValidRules().get(ruleDefOid) == null && getRuleDao().findByOid(ruleDefOid, ruleSetBeanWrapper.getAuditableBean().getStudyId()) == null) {
                ruleSetBeanWrapper.error(createError("OCRERR_0025"));
            }
            if (importContainer.getValidRules().get(ruleDefOid) != null) {
                AuditableBeanWrapper<RuleBean> r = importContainer.getValidRules().get(ruleDefOid);
                if (!isRuleExpressionValid(r, ruleSetBeanWrapper.getAuditableBean()))
                    ruleSetBeanWrapper.error(createError("OCRERR_0027"));
            }
            if (importContainer.getValidRules().get(ruleDefOid) == null) {
                RuleBean rule = getRuleDao().findByOid(ruleDefOid, ruleSetBeanWrapper.getAuditableBean().getStudyId());
                AuditableBeanWrapper<RuleBean> r = new AuditableBeanWrapper<RuleBean>(rule);
                if (rule == null || !isRuleExpressionValid(r, ruleSetBeanWrapper.getAuditableBean()))
                    ruleSetBeanWrapper.error(createError("OCRERR_0027"));
            }
            if (ruleSetRuleBean.getActions().size() == 0) {
                ruleSetBeanWrapper.error(createError("OCRERR_0027"));
            }
            for (RuleActionBean ruleActionBean : ruleSetRuleBean.getActions()) {
                isRuleActionValid(ruleActionBean, ruleSetBeanWrapper, eventDefinitionCRFBean, eventActionsRuleSetBean);
            }
        }
    }
}
Also used : AuditableBeanWrapper(org.akaza.openclinica.domain.rule.AuditableBeanWrapper) RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean)

Example 4 with RuleBean

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

the class RuleDaoTest method testFindByOidString.

public void testFindByOidString() {
    // RuleDao ruleDao = (RuleDao) getContext().getBean("ruleDao");
    String oid = "RULE_1";
    RuleBean persistentRuleBean = ruleDao.findByOid(oid, 1);
    assertNotNull("RuleSet is null", persistentRuleBean);
    assertEquals("The id of the retrieved RuleSet should be 1", new Integer(-1), persistentRuleBean.getId());
}
Also used : RuleBean(org.akaza.openclinica.domain.rule.RuleBean)

Example 5 with RuleBean

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

the class RuleDaoTest method testFindById.

public void testFindById() {
    // RuleDao ruleDao = (RuleDao) getContext().getBean("ruleDao");
    RuleBean ruleBean = null;
    ruleBean = ruleDao.findById(-1);
    // Test Rule
    assertNotNull("RuleSet is null", ruleBean);
    assertEquals("The id of the retrieved RuleSet should be 1", new Integer(-1), ruleBean.getId());
}
Also used : RuleBean(org.akaza.openclinica.domain.rule.RuleBean)

Aggregations

RuleBean (org.akaza.openclinica.domain.rule.RuleBean)24 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)18 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)15 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)8 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)8 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)7 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)7 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)6 RuleActionRunLogBean (org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean)6 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)5 RulesPostImportContainer (org.akaza.openclinica.domain.rule.RulesPostImportContainer)5 ActionProcessor (org.akaza.openclinica.domain.rule.action.ActionProcessor)5 Map (java.util.Map)4 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)4 Locale (java.util.Locale)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)3