Search in sources :

Example 6 with RuleActionBean

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

the class ViewCRFServlet method html.

private String html(TableFacade tableFacade) {
    // set the column properties
    tableFacade.setColumnProperties("versionName", "ruleName", "ruleExpression", "executeOnPlaceHolder", "actionTypePlaceHolder", "actionSummaryPlaceHolder", "link");
    HtmlTable table = (HtmlTable) tableFacade.getTable();
    table.setCaption(resword.getString("rule_rules"));
    table.getTableRenderer().setWidth("800px");
    HtmlRow row = table.getRow();
    HtmlColumn versionName = row.getColumn("versionName");
    versionName.setTitle(resword.getString("CRF_version"));
    HtmlColumn ruleName = row.getColumn("ruleName");
    ruleName.setTitle(resword.getString("rule_name"));
    HtmlColumn career = row.getColumn("ruleExpression");
    career.setWidth("100px");
    career.setTitle(resword.getString("rule_expression"));
    HtmlColumn executeOn = row.getColumn("executeOnPlaceHolder");
    executeOn.setSortable(false);
    executeOn.setFilterable(false);
    executeOn.setTitle(resword.getString("rule_execute_on"));
    executeOn.getCellRenderer().setCellEditor(new CellEditor() {

        @SuppressWarnings("unchecked")
        public Object getValue(Object item, String property, int rowcount) {
            String value = "";
            List<RuleActionBean> ruleActions = (List<RuleActionBean>) new BasicCellEditor().getValue(item, "actions", rowcount);
            for (int i = 0; i < ruleActions.size(); i++) {
                value += ruleActions.get(i).getExpressionEvaluatesTo();
                // Do not add horizontal line after last Summary
                if (i != ruleActions.size() - 1) {
                    value += "<hr>";
                }
            }
            return value;
        }
    });
    HtmlColumn actionTypePlaceHolder = row.getColumn("actionTypePlaceHolder");
    actionTypePlaceHolder.setSortable(false);
    actionTypePlaceHolder.setFilterable(false);
    actionTypePlaceHolder.setTitle(resword.getString("rule_action_type"));
    actionTypePlaceHolder.getCellRenderer().setCellEditor(new CellEditor() {

        @SuppressWarnings("unchecked")
        public Object getValue(Object item, String property, int rowcount) {
            String value = "";
            List<RuleActionBean> ruleActions = (List<RuleActionBean>) new BasicCellEditor().getValue(item, "actions", rowcount);
            for (int i = 0; i < ruleActions.size(); i++) {
                value += ruleActions.get(i).getActionType().name();
                // Do not add horizontal line after last Summary
                if (i != ruleActions.size() - 1) {
                    value += "<hr>";
                }
            }
            return value;
        }
    });
    HtmlColumn actionSummaryPlaceHolder = row.getColumn("actionSummaryPlaceHolder");
    actionSummaryPlaceHolder.setSortable(false);
    actionSummaryPlaceHolder.setFilterable(false);
    actionSummaryPlaceHolder.setTitle(resword.getString("rule_action_summary"));
    actionSummaryPlaceHolder.getCellRenderer().setCellEditor(new CellEditor() {

        @SuppressWarnings("unchecked")
        public Object getValue(Object item, String property, int rowcount) {
            String value = "";
            List<RuleActionBean> ruleActions = (List<RuleActionBean>) new BasicCellEditor().getValue(item, "actions", rowcount);
            for (int i = 0; i < ruleActions.size(); i++) {
                value += ruleActions.get(i).getSummary();
                // Do not add horizontal line after last Summary
                if (i != ruleActions.size() - 1) {
                    value += "<hr>";
                }
            }
            return value;
        }
    });
    HtmlColumn link = row.getColumn("link");
    link.setSortable(false);
    link.setFilterable(false);
    link.setTitle(resword.getString("action"));
    link.getCellRenderer().setCellEditor(new CellEditor() {

        @SuppressWarnings("unchecked")
        public Object getValue(Object item, String property, int rowcount) {
            String param1 = (String) new BasicCellEditor().getValue(item, "ruleSetRuleId", rowcount);
            String param2 = (String) new BasicCellEditor().getValue(item, "versionId", rowcount);
            HtmlBuilder html = new HtmlBuilder();
            html.a().href().quote().append(request.getContextPath() + "/RunRule?ruleSetRuleId=" + param1 + "&versionId=" + param2 + "&action=dryRun").quote().close();
            html.img().name("bt_View1").src("images/bt_ExexuteRules.gif").border("0").end();
            html.aEnd();
            return html.toString();
        }
    });
    // Return the Html.
    return tableFacade.render();
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) BasicCellEditor(org.jmesa.view.editor.BasicCellEditor) HtmlTable(org.jmesa.view.html.component.HtmlTable) CellEditor(org.jmesa.view.editor.CellEditor) BasicCellEditor(org.jmesa.view.editor.BasicCellEditor) HtmlBuilder(org.jmesa.view.html.HtmlBuilder) HtmlRow(org.jmesa.view.html.component.HtmlRow) ArrayList(java.util.ArrayList) List(java.util.List) HtmlColumn(org.jmesa.view.html.component.HtmlColumn)

Example 7 with RuleActionBean

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

the class TestRuleServlet method putDummyActionInSession.

void putDummyActionInSession() {
    ArrayList<RuleActionBean> actions = new ArrayList<RuleActionBean>();
    DiscrepancyNoteActionBean discNoteAction = new DiscrepancyNoteActionBean();
    discNoteAction.setExpressionEvaluatesTo(true);
    discNoteAction.setMessage("TEST DISCREPANCY");
    actions.add(discNoteAction);
    session.setAttribute("testRuleActions", actions);
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) DiscrepancyNoteActionBean(org.akaza.openclinica.domain.rule.action.DiscrepancyNoteActionBean) ArrayList(java.util.ArrayList)

Example 8 with RuleActionBean

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

the class RulesPostImportContainerService method addNewRuleSetBeanInList.

private void addNewRuleSetBeanInList(String target, String destination, List<RuleSetBean> eventActionsRuleSetBean) {
    ExpressionBean expression = new ExpressionBean();
    expression.setValue(target);
    RuleSetBean ruleSetBean = new RuleSetBean();
    ruleSetBean.setOriginalTarget(expression);
    EventActionBean eventActionBean = new EventActionBean();
    eventActionBean.setOc_oid_reference(destination);
    List<RuleActionBean> listRuleActionBean = new ArrayList<RuleActionBean>();
    listRuleActionBean.add(eventActionBean);
    RuleSetRuleBean ruleSetRuleBean = new RuleSetRuleBean();
    ruleSetRuleBean.setActions(listRuleActionBean);
    ruleSetBean.addRuleSetRule(ruleSetRuleBean);
    eventActionsRuleSetBean.add(ruleSetBean);
}
Also used : EventActionBean(org.akaza.openclinica.domain.rule.action.EventActionBean) RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) ArrayList(java.util.ArrayList) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 9 with RuleActionBean

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

the class RulesPostImportContainerService method runValidationInList.

public void runValidationInList(String target, String destination, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper, List<RuleSetBean> eventActionsRuleSetBean) {
    // eventActionsRuleSetBean is the list of all events from rule set table
    Boolean isDestinationATarget = false;
    RuleSetBean isDestination = null;
    for (RuleSetBean ruleSetBean : eventActionsRuleSetBean) {
        if (isDestinationAndTargetMatch(parseTarget(ruleSetBean.getOriginalTarget().getValue()), parseDestination(destination)) || isDestinationAndTargetAcceptable(parseTarget(ruleSetBean.getOriginalTarget().getValue()), parseDestination(destination))) {
            isDestinationATarget = true;
            isDestination = ruleSetBean;
            break;
        }
    }
    if (isDestinationATarget == true && isDestination != null) {
        List<RuleActionBean> ruleActions = getAllRuleActions(isDestination);
        for (RuleActionBean ruleActionBean : ruleActions) {
            if (ruleActionBean.getActionType().getCode() == 6) {
                if (isDestinationAndTargetMatch(parseTarget(target), parseDestination(((EventActionBean) ruleActionBean).getOc_oid_reference() + ".STARTDATE"))) {
                    ruleSetBeanWrapper.error(createError("OCRERR_0042"));
                    break;
                }
                if (isDestinationAndTargetAcceptable(parseTarget(target), parseDestination(((EventActionBean) ruleActionBean).getOc_oid_reference()))) {
                    ruleSetBeanWrapper.error(createError("OCRERR_0043"));
                    break;
                }
                runValidationInList(target, ((EventActionBean) ruleActionBean).getOc_oid_reference(), ruleSetBeanWrapper, eventActionsRuleSetBean);
            }
        }
    } else {
        addNewRuleSetBeanInList(target, destination, eventActionsRuleSetBean);
    }
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) EventActionBean(org.akaza.openclinica.domain.rule.action.EventActionBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 10 with RuleActionBean

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

the class RuleSetBulkRuleRunner method runRulesBulkFromRuleSetScreen.

public List<RuleSetBasedViewContainer> runRulesBulkFromRuleSetScreen(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>();
    }
    List<RuleSetBasedViewContainer> ruleSetBasedView = new ArrayList<RuleSetBasedViewContainer>();
    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);
            System.out.println("tg expression:" + ruleSet.getTarget().getValue());
            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());
                    System.out.println("The result: " + result);
                    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());
        for (RuleActionContainer ruleActionContainer : entry.getValue()) {
            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());
            RuleActionBean rab = ap.execute(RuleRunnerMode.RULSET_BULK, executionMode, ruleActionContainer.getRuleAction(), ruleActionContainer.getItemDataBean(), DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule(), currentStudy, ruleActionContainer.getRuleAction()));
            System.out.println(" Action Trigger: " + ap.toString());
            if (rab != null) {
                ruleSetBasedView = populateForRuleSetBasedView(ruleSetBasedView, ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule().getRuleBean(), ruleActionContainer.getRuleAction().getExpressionEvaluatesTo().toString(), ruleActionContainer.getRuleAction());
            }
        }
    }
    return ruleSetBasedView;
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetBasedViewContainer(org.akaza.openclinica.domain.rule.RuleSetBasedViewContainer) 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) 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

RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)20 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)10 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)10 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)10 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)10 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)8 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)8 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)8 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)7 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)7 ActionProcessor (org.akaza.openclinica.domain.rule.action.ActionProcessor)6 RuleActionRunLogBean (org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean)6 Map (java.util.Map)5 List (java.util.List)4 EventActionBean (org.akaza.openclinica.domain.rule.action.EventActionBean)4 Transient (javax.persistence.Transient)3 ShowActionBean (org.akaza.openclinica.domain.rule.action.ShowActionBean)3 Transactional (org.springframework.transaction.annotation.Transactional)3 HashSet (java.util.HashSet)2