Search in sources :

Example 1 with RuleActionRunLogBean

use of org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean 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 RuleActionRunLogBean

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

the class RuleActionRunLogDao method findAllItemData.

public List<RuleActionRunLogBean> findAllItemData(int itemDataId) {
    String query = "from RuleActionRunLogBean logbean where " + "logbean.itemDataId =:itemDataId ";
    Query q = getCurrentSession().createQuery(query);
    q.setInteger("itemDataId", itemDataId);
    List<RuleActionRunLogBean> list = (List<RuleActionRunLogBean>) q.list();
    return list;
}
Also used : Query(org.hibernate.Query) RuleActionRunLogBean(org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean) List(java.util.List)

Example 3 with RuleActionRunLogBean

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

the class Key method runRulesBulk.

public HashMap<RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>> runRulesBulk(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>>>();
    HashMap<String, ArrayList<RuleActionContainer>> toBeExecuted = new HashMap<String, ArrayList<RuleActionContainer>>();
    for (RuleSetBean ruleSet : ruleSets) {
        String key = getExpressionService().getItemOid(ruleSet.getOriginalTarget().getValue());
        List<RuleActionContainer> allActionContainerListBasedOnRuleExecutionResult = null;
        if (toBeExecuted.containsKey(key)) {
            allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
        } else {
            toBeExecuted.put(key, new ArrayList<RuleActionContainer>());
            allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
        }
        ItemDataBean itemData = null;
        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());
                    itemData = getExpressionService().getItemDataBeanFromDb(ruleSet.getTarget().getValue());
                    // Actions
                    List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result, Phase.BATCH);
                    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();
                            }
                        }
                    }
                    for (RuleActionBean ruleActionBean : actionListBasedOnRuleExecutionResult) {
                        RuleActionContainer ruleActionContainer = new RuleActionContainer(ruleActionBean, expressionBean, itemData, ruleSet);
                        allActionContainerListBasedOnRuleExecutionResult.add(ruleActionContainer);
                    }
                    logger.info("RuleSet with target  : {} , Ran Rule : {}  The Result was : {} , Based on that {} action will be executed in {} mode. ", new Object[] { ruleSet.getTarget().getValue(), rule.getName(), result, actionListBasedOnRuleExecutionResult.size(), executionMode.name() });
                } catch (OpenClinicaSystemException osa) {
                // TODO: report something useful
                }
            }
        }
    }
    for (Map.Entry<String, ArrayList<RuleActionContainer>> entry : toBeExecuted.entrySet()) {
        // Sort the list of actions
        Collections.sort(entry.getValue(), new RuleActionContainerComparator());
        HashMap<Key, List<RuleActionBean>> hms = new HashMap<Key, List<RuleActionBean>>();
        for (RuleActionContainer ruleActionContainer : entry.getValue()) {
            // ruleSet.setTarget(ruleAction.getRuleSetExpression());
            ruleActionContainer.getRuleAction().setCuratedMessage(curateMessage(ruleActionContainer.getRuleAction(), ruleActionContainer.getRuleAction().getRuleSetRule()));
            ActionProcessor ap = ActionProcessorFacade.getActionProcessor(ruleActionContainer.getRuleAction().getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleActionContainer.getRuleSetBean(), getRuleActionRunLogDao(), ruleActionContainer.getRuleAction().getRuleSetRule());
            RuleActionBean rab = null;
            ap.execute(RuleRunnerMode.RULSET_BULK, executionMode, ruleActionContainer.getRuleAction(), ruleActionContainer.getItemDataBean(), DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule(), currentStudy, ruleActionContainer.getRuleAction()));
            if (rab != null) {
                Key k = new Key(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getExpressionEvaluatesTo().toString(), ruleActionContainer.getRuleAction().getRuleSetRule().getRuleBean());
                if (hms.containsKey(k)) {
                    hms.get(k).add(ruleActionContainer.getRuleAction());
                } else {
                    List<RuleActionBean> theActionBeansToShow = new ArrayList<RuleActionBean>();
                    theActionBeansToShow.add(ruleActionContainer.getRuleAction());
                    hms.put(k, theActionBeansToShow);
                }
            }
        }
        for (Map.Entry<Key, List<RuleActionBean>> theEntry : hms.entrySet()) {
            Key key = theEntry.getKey();
            List<RuleActionBean> value = theEntry.getValue();
            crfViewSpecificOrderedObjects = populateForCrfBasedRulesView(crfViewSpecificOrderedObjects, key.getRuleSet(), key.getRule(), key.getResult(), currentStudy, value);
        }
    }
    // 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) ArrayList(java.util.ArrayList) OpenClinicaExpressionParser(org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser) RuleActionRunLogBean(org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList) List(java.util.List) RuleBulkExecuteContainer(org.akaza.openclinica.domain.rule.RuleBulkExecuteContainer) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) RuleBulkExecuteContainerTwo(org.akaza.openclinica.domain.rule.RuleBulkExecuteContainerTwo) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ActionProcessor(org.akaza.openclinica.domain.rule.action.ActionProcessor) HashMap(java.util.HashMap) Map(java.util.Map) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean)

Example 4 with RuleActionRunLogBean

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

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

the class DataEntryRuleRunner method runRules.

public MessageContainer runRules(List<RuleSetBean> ruleSets, ExecutionMode executionMode, StudyBean currentStudy, HashMap<String, String> variableAndValue, UserAccountBean ub, Phase phase, HttpServletRequest request) {
    if (variableAndValue == null || variableAndValue.isEmpty()) {
        logger.warn("You must be executing Rules in Batch");
        variableAndValue = new HashMap<String, String>();
    }
    HashMap allItemDatasHm = new HashMap();
    MessageContainer messageContainer = new MessageContainer();
    HashMap<String, ArrayList<RuleActionContainer>> toBeExecuted = new HashMap<String, ArrayList<RuleActionContainer>>();
    switch(executionMode) {
        case SAVE:
            {
                toBeExecuted = (HashMap<String, ArrayList<RuleActionContainer>>) request.getAttribute("toBeExecuted");
                if (// Break only if the action is insertAction;
                request.getAttribute("insertAction") == null) {
                    break;
                } else {
                    toBeExecuted = new HashMap<String, ArrayList<RuleActionContainer>>();
                }
            }
        case DRY_RUN:
            {
                for (RuleSetBean ruleSet : ruleSets) {
                    String key = getExpressionService().getItemOid(ruleSet.getOriginalTarget().getValue());
                    List<RuleActionContainer> allActionContainerListBasedOnRuleExecutionResult = null;
                    if (toBeExecuted.containsKey(key)) {
                        allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
                    } else {
                        toBeExecuted.put(key, new ArrayList<RuleActionContainer>());
                        allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
                    }
                    /**
                     *  OC-12523, this is a performance issue, user reported when update one subject form data
                     */
                    String itemOid = key;
                    String itemGroupOid = getExpressionService().getItemGroupOid(ruleSet.getExpressions().get(0).getValue());
                    int studySubjectId = ((StudySubjectBean) request.getAttribute("studySubject")).getSubjectId();
                    HashMap itemDatasHm = getItemDataDao().findByStudySubjectAndOids(ruleSet.getStudyId(), itemOid, itemGroupOid, studySubjectId);
                    allItemDatasHm.putAll(itemDatasHm);
                    ItemDataBean itemData = null;
                    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, ecb);
                            try {
                                OpenClinicaExpressionParser oep = new OpenClinicaExpressionParser(eow);
                                result = (String) oep.parseAndEvaluateExpression(rule.getExpression().getValue());
                                String studyEventId = getExpressionService().getStudyEventDefinitionOrdninalCurated(expressionBean.getValue());
                                itemOid = getExpressionService().getItemOid(expressionBean.getValue());
                                itemGroupOid = getExpressionService().getItemGroupOid(expressionBean.getValue());
                                String itemDataKey = studyEventId + itemGroupOid + itemOid;
                                itemData = (ItemDataBean) itemDatasHm.get(itemDataKey);
                                // Actions
                                List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result, phase);
                                if (itemData != null) {
                                    Iterator<RuleActionBean> itr = actionListBasedOnRuleExecutionResult.iterator();
                                    String firstDDE = "firstDDEInsert_" + ruleSetRule.getOid() + "_" + itemData.getId();
                                    while (itr.hasNext()) {
                                        RuleActionBean ruleActionBean = itr.next();
                                        if (ruleActionBean.getActionType() == ActionType.INSERT) {
                                            request.setAttribute("insertAction", true);
                                            if (phase == Phase.DOUBLE_DATA_ENTRY && itemData.getStatus().getId() == 4 && request.getAttribute(firstDDE) == null) {
                                                request.setAttribute(firstDDE, true);
                                            }
                                        }
                                        if (request.getAttribute(firstDDE) == Boolean.TRUE) {
                                        } else {
                                            String itemDataValueFromForm = "";
                                            if (variableAndValue.containsKey(key)) {
                                                itemDataValueFromForm = variableAndValue.get(key);
                                            } else {
                                                logger.info("Cannot find value from variableAndValue for item=" + key + ". " + "Used itemData.getValue()");
                                                itemDataValueFromForm = itemData.getValue();
                                            }
                                            RuleActionRunLogBean ruleActionRunLog = new RuleActionRunLogBean(ruleActionBean.getActionType(), itemData, itemDataValueFromForm, ruleSetRule.getRuleBean().getOid());
                                            if (getRuleActionRunLogDao().findCountByRuleActionRunLogBean(ruleActionRunLog) > 0) {
                                                itr.remove();
                                            }
                                        }
                                    }
                                }
                                for (RuleActionBean ruleActionBean : actionListBasedOnRuleExecutionResult) {
                                    RuleActionContainer ruleActionContainer = new RuleActionContainer(ruleActionBean, expressionBean, itemData, ruleSet);
                                    allActionContainerListBasedOnRuleExecutionResult.add(ruleActionContainer);
                                }
                                logger.info("RuleSet with target  : {} , Ran Rule : {}  The Result was : {} , Based on that {} action will be executed in {} mode. ", new Object[] { ruleSet.getTarget().getValue(), rule.getName(), result, actionListBasedOnRuleExecutionResult.size(), executionMode.name() });
                            } catch (OpenClinicaSystemException osa) {
                            // TODO: report something useful
                            }
                        }
                    }
                }
                request.setAttribute("toBeExecuted", toBeExecuted);
                break;
            }
    }
    for (Map.Entry<String, ArrayList<RuleActionContainer>> entry : toBeExecuted.entrySet()) {
        // Sort the list of actions
        Collections.sort(entry.getValue(), new RuleActionContainerComparator());
        for (RuleActionContainer ruleActionContainer : entry.getValue()) {
            logger.info("START Expression is : {} , RuleAction : {} , ExecutionMode : {} ", new Object[] { ruleActionContainer.getExpressionBean().getValue(), ruleActionContainer.getRuleAction().toString(), executionMode });
            ruleActionContainer.getRuleSetBean().setTarget(ruleActionContainer.getExpressionBean());
            ruleActionContainer.getRuleAction().setCuratedMessage(curateMessage(ruleActionContainer.getRuleAction(), ruleActionContainer.getRuleAction().getRuleSetRule()));
            ActionProcessor ap = ActionProcessorFacade.getActionProcessor(ruleActionContainer.getRuleAction().getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleActionContainer.getRuleSetBean(), getRuleActionRunLogDao(), ruleActionContainer.getRuleAction().getRuleSetRule());
            String expression = ruleActionContainer.getRuleSetBean().getTarget().getValue();
            String studyEventId = getExpressionService().getStudyEventDefinitionOidOrdinalFromExpression(expression);
            String itemOid = getExpressionService().getItemOidFromExpression(expression);
            String itemGroupOid = getExpressionService().getItemGroupOidFromExpression(expression);
            String itemDataKey = studyEventId + itemGroupOid + itemOid;
            ItemDataBean itemData = (ItemDataBean) allItemDatasHm.get(itemDataKey);
            // may not from dry run first, so still need to diuble check
            if (itemData == null) {
                itemData = getExpressionService().getItemDataBeanFromDb(ruleActionContainer.getRuleSetBean().getTarget().getValue());
            }
            RuleActionBean rab = ap.execute(RuleRunnerMode.DATA_ENTRY, executionMode, ruleActionContainer.getRuleAction(), itemData, DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule(), currentStudy, ruleActionContainer.getRuleAction()));
            if (rab != null) {
                if (rab instanceof ShowActionBean) {
                    messageContainer.add(getExpressionService().getGroupOidOrdinal(ruleActionContainer.getRuleSetBean().getTarget().getValue()), rab);
                } else {
                    messageContainer.add(getExpressionService().getGroupOrdninalConcatWithItemOid(ruleActionContainer.getRuleSetBean().getTarget().getValue()), ruleActionContainer.getRuleAction());
                }
            }
            logger.info("END Expression is : {} , RuleAction : {} , ExecutionMode : {} ", new Object[] { ruleActionContainer.getExpressionBean().getValue(), ruleActionContainer.getRuleAction().toString(), executionMode });
        }
    }
    return messageContainer;
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OpenClinicaExpressionParser(org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser) RuleActionRunLogBean(org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ShowActionBean(org.akaza.openclinica.domain.rule.action.ShowActionBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) ActionProcessor(org.akaza.openclinica.domain.rule.action.ActionProcessor) HashMap(java.util.HashMap) Map(java.util.Map) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean)

Aggregations

RuleActionRunLogBean (org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean)7 ArrayList (java.util.ArrayList)6 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)6 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)6 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)6 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)6 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)6 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)6 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)6 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)6 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)6 HashMap (java.util.HashMap)5 ActionProcessor (org.akaza.openclinica.domain.rule.action.ActionProcessor)5 List (java.util.List)3 Map (java.util.Map)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 RuleBulkExecuteContainer (org.akaza.openclinica.domain.rule.RuleBulkExecuteContainer)2 RuleBulkExecuteContainerTwo (org.akaza.openclinica.domain.rule.RuleBulkExecuteContainerTwo)2 RuleSetBasedViewContainer (org.akaza.openclinica.domain.rule.RuleSetBasedViewContainer)2