Search in sources :

Example 11 with RuleSetRuleBean

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

the class TestRuleServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    String action = request.getParameter("action");
    Validator v = new Validator(request);
    if (StringUtil.isBlank(action)) {
        request.setAttribute("result", resword.getString("test_rule_default_result"));
        Integer ruleSetRuleId = fp.getInt("ruleSetRuleId");
        if (ruleSetRuleId != 0) {
            // If testing an existing ruleSetRule
            RuleSetRuleBean rsr = getRuleSetRuleDao().findById(ruleSetRuleId);
            rsr.getActions().size();
            HashMap presetValues = new HashMap();
            presetValues.put(TARGET, rsr.getRuleSetBean().getTarget().getValue());
            presetValues.put(RULE, rsr.getRuleBean().getExpression().getValue());
            presetValues.put(RULE_SET_RULE_ID, String.valueOf(ruleSetRuleId));
            fp.setPresetValues(presetValues);
            setPresetValues(presetValues);
            session.setAttribute("testRuleActions", rsr.getActions());
            session.setAttribute("testRulesTarget", rsr.getRuleSetBean().getTarget().getValue());
            request.setAttribute("ruleSetRuleId", ruleSetRuleId);
            request.setAttribute("ruleSetId", rsr.getRuleSetBean().getId());
            ItemBean item = getExpressionService().getItemBeanFromExpression(rsr.getRuleSetBean().getTarget().getValue());
            if (item != null) {
                request.setAttribute("itemName", item.getName());
                request.setAttribute("itemDefinition", item.getDescription());
            } else {
                StudyEventDefinitionBean studyEventDef = getExpressionService().getStudyEventDefinitionFromExpressionForEvents(rsr.getRuleSetBean().getTarget().getValue(), this.currentStudy);
                request.setAttribute("itemName", studyEventDef.getName());
                request.setAttribute("itemDefinition", studyEventDef.getDescription());
            }
            request.setAttribute("ruleSetRuleAvailable", true);
        } else {
            // free form testing
            putDummyActionInSession();
        }
        session.removeAttribute("testValues");
        request.setAttribute("action", "validate");
        forwardPage(Page.TEST_RULES);
    } else if (action.equals("validate")) {
        HashMap<String, String> result = validate(v);
        if (result.get("ruleValidation").equals("rule_valid")) {
            addPageMessage(resword.getString("test_rules_message_valid"));
        } else {
            addPageMessage(resword.getString("test_rules_message_invalid"));
        }
        request.setAttribute("ruleValidation", result.get("ruleValidation"));
        request.setAttribute("validate", "on");
        request.setAttribute("ruleEvaluatesTo", resword.getString("test_rules_validate_message"));
        request.setAttribute("ruleValidationFailMessage", result.get("ruleValidationFailMessage"));
        request.setAttribute("action", result.get("ruleValidation").equals("rule_valid") ? "test" : "validate");
        result.remove("result");
        result.remove("ruleValidation");
        result.remove("ruleEvaluatesTo");
        result.remove("ruleValidationFailMessage");
        populateTooltip(result);
        session.setAttribute("testValues", result);
        populteFormFields(fp);
        forwardPage(Page.TEST_RULES);
    } else if (action.equals("test")) {
        HashMap<String, String> result = validate(v);
        HashMap errors = v.validate();
        if (!errors.isEmpty()) {
            setInputMessages(errors);
            if (result.get("ruleValidation").equals("rule_valid")) {
                addPageMessage(resword.getString("test_rules_message_valid"));
            } else {
                addPageMessage(resword.getString("test_rules_message_invalid"));
            }
            request.setAttribute("ruleValidation", result.get("ruleValidation"));
            request.setAttribute("validate", "on");
            request.setAttribute("ruleEvaluatesTo", resword.getString("test_rules_rule_fail_invalid_data_type") + " " + resword.getString("test_rules_rule_fail_invalid_data_type_desc"));
            request.setAttribute("ruleValidationFailMessage", result.get("ruleValidationFailMessage"));
            request.setAttribute("action", "test");
        } else {
            if (result.get("ruleValidation").equals("rule_valid")) {
                addPageMessage(resword.getString("test_rules_message_valid"));
            } else {
                addPageMessage(resword.getString("test_rules_message_invalid"));
            }
            request.setAttribute("action", result.get("ruleValidation").equals("rule_valid") ? "test" : "validate");
            request.setAttribute("ruleValidation", result.get("ruleValidation"));
            request.setAttribute("ruleEvaluatesTo", result.get("ruleEvaluatesTo"));
            request.setAttribute("ruleValidationFailMessage", result.get("ruleValidationFailMessage"));
        }
        if (result.get("ruleValidation").equals("rule_invalid")) {
            session.setAttribute("testValues", new HashMap<String, String>());
        } else {
            session.setAttribute("testValues", result);
        }
        result.remove("result");
        result.remove("ruleValidation");
        result.remove("ruleEvaluatesTo");
        result.remove("ruleValidationFailMessage");
        populateTooltip(result);
        populteFormFields(fp);
        forwardPage(Page.TEST_RULES);
    }
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) Validator(org.akaza.openclinica.control.form.Validator)

Example 12 with RuleSetRuleBean

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

the class ViewRuleAssignmentTableFactory method setDataAndLimitVariables.

@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
    // initialize i18n
    resword = ResourceBundleProvider.getWordsBundle(getLocale());
    Limit limit = tableFacade.getLimit();
    ViewRuleAssignmentFilter viewRuleAssignmentFilter = getViewRuleAssignmentFilter(limit);
    ViewRuleAssignmentSort viewRuleAssignmentSort = getViewRuleAssignmentSort(limit);
    viewRuleAssignmentFilter.addFilter("studyId", currentStudy.getId());
    if (viewRuleAssignmentSort.getSorts().size() == 0) {
        viewRuleAssignmentSort.addSort("itemName", "asc");
    }
    Boolean ruleSetRuleStatusFilterNotSelected = true;
    for (ViewRuleAssignmentFilter.Filter filter : viewRuleAssignmentFilter.getFilters()) {
        if (filter.getProperty().equals("ruleSetRuleStatus")) {
            ruleSetRuleStatusFilterNotSelected = false;
        }
    }
    if (ruleSetRuleStatusFilterNotSelected) {
        viewRuleAssignmentFilter.addFilter("ruleSetRuleStatus", "1");
    }
    /*
         * Because we are using the State feature (via stateAttr) we can do a check to see if we have a complete limit
         * already. See the State feature for more details Very important to set the totalRow before trying to get the row
         * start and row end variables. Very important to set the totalRow before trying to get the row start and row end
         * variables.
         */
    if (!limit.isComplete()) {
        int totalRows = getRuleSetService().getCountWithFilter(viewRuleAssignmentFilter);
        tableFacade.setTotalRows(totalRows);
    }
    int rowStart = limit.getRowSelect().getRowStart();
    int rowEnd = limit.getRowSelect().getRowEnd();
    Collection<RuleSetRuleBean> items = getRuleSetService().getWithFilterAndSort(viewRuleAssignmentFilter, viewRuleAssignmentSort, rowStart, rowEnd);
    HashMap<Integer, RuleSetBean> ruleSets = new HashMap<Integer, RuleSetBean>();
    Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
    ruleSetRuleIds = new ArrayList<Integer>();
    for (RuleSetRuleBean ruleSetRuleBean : items) {
        RuleSetBean ruleSetBean = null;
        ruleSetRuleIds.add(ruleSetRuleBean.getId());
        if (ruleSets.containsKey(ruleSetRuleBean.getRuleSetBean().getId())) {
            ruleSetBean = ruleSets.get(ruleSetRuleBean.getRuleSetBean().getId());
        } else {
            ruleSetBean = ruleSetRuleBean.getRuleSetBean();
            getRuleSetService().getObjects(ruleSetBean);
            ruleSets.put(ruleSetBean.getId(), ruleSetBean);
        }
        HashMap<Object, Object> theItem = new HashMap<Object, Object>();
        theItem.put("ruleSetRunSchedule", ruleSetBean.isRunSchedule());
        theItem.put("ruleSetRunTime", ruleSetBean.getRunTime());
        theItem.put("ruleSetId", ruleSetBean.getId());
        theItem.put("ruleSetRuleId", ruleSetRuleBean.getId());
        theItem.put("ruleId", ruleSetRuleBean.getRuleBean().getId());
        theItem.put("ruleSetRule", ruleSetRuleBean);
        theItem.put("targetValue", ruleSetBean.getTarget().getValue());
        theItem.put("studyEventDefinitionName", ruleSetBean.getStudyEventDefinitionName());
        theItem.put("crf", ruleSetBean.getCrf());
        theItem.put("crfVersion", ruleSetBean.getCrfVersion());
        theItem.put("item", ruleSetBean.getItem());
        theItem.put("crfName", ruleSetBean.getCrfName());
        theItem.put("crfVersionName", ruleSetBean.getCrfVersionName());
        theItem.put("groupLabel", ruleSetBean.getGroupLabel());
        theItem.put("itemName", ruleSetBean.getItemName());
        theItem.put("ruleSetRules", ruleSetBean.getRuleSetRules());
        theItem.put("ruleName", ruleSetRuleBean.getRuleBean().getName());
        theItem.put("ruleExpressionValue", ruleSetRuleBean.getRuleBean().getExpression().getValue());
        theItem.put("ruleOid", ruleSetRuleBean.getRuleBean().getOid());
        theItem.put("ruleDescription", ruleSetRuleBean.getRuleBean().getDescription());
        theItem.put("theActions", ruleSetRuleBean.getActions());
        theItem.put("ruleSetRuleStatus", "");
        theItem.put("validations", "");
        theItem.put("actionExecuteOn", "");
        theItem.put("actionType", "XXXXXXXXX");
        theItem.put("actionSummary", "");
        theItems.add(theItem);
    }
    // Do not forget to set the items back on the tableFacade.
    tableFacade.setItems(theItems);
}
Also used : RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ViewRuleAssignmentSort(org.akaza.openclinica.dao.hibernate.ViewRuleAssignmentSort) ViewRuleAssignmentFilter(org.akaza.openclinica.dao.hibernate.ViewRuleAssignmentFilter) Limit(org.jmesa.limit.Limit) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 13 with RuleSetRuleBean

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

the class ViewRuleSetServlet method orderRuleSetRulesByStatus.

List<RuleSetRuleBean> orderRuleSetRulesByStatus(RuleSetBean ruleSet) {
    ArrayList<RuleSetRuleBean> availableRuleSetRules = new ArrayList<RuleSetRuleBean>();
    ArrayList<RuleSetRuleBean> nonAvailableRuleSetRules = new ArrayList<RuleSetRuleBean>();
    for (RuleSetRuleBean ruleSetRuleBean : ruleSet.getRuleSetRules()) {
        if (ruleSetRuleBean.getStatus() == Status.AVAILABLE) {
            availableRuleSetRules.add(ruleSetRuleBean);
        } else {
            nonAvailableRuleSetRules.add(ruleSetRuleBean);
        }
    }
    availableRuleSetRules.addAll(nonAvailableRuleSetRules);
    return availableRuleSetRules;
}
Also used : RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) ArrayList(java.util.ArrayList)

Example 14 with RuleSetRuleBean

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

the class ViewRuleSetServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String ruleSetId = request.getParameter(RULESET_ID);
    if (ruleSetId == null) {
        addPageMessage(respage.getString("please_choose_a_CRF_to_view"));
        forwardPage(Page.CRF_LIST);
    } else {
        RuleSetBean ruleSetBean = getRuleSetService().getRuleSetById(currentStudy, ruleSetId);
        Boolean firstTime = true;
        String validRuleSetRuleIds = "";
        for (int j = 0; j < ruleSetBean.getRuleSetRules().size(); j++) {
            RuleSetRuleBean rsr = ruleSetBean.getRuleSetRules().get(j);
            if (rsr.getStatus() == Status.AVAILABLE) {
                if (firstTime) {
                    validRuleSetRuleIds += rsr.getId();
                    firstTime = false;
                } else {
                    validRuleSetRuleIds += "," + rsr.getId();
                }
            }
        }
        CoreResources core = (CoreResources) SpringServletAccess.getApplicationContext(context).getBean("coreResources");
        String designerUrl = core.getField("designer.url") + "access?host=" + getHostPathFromSysUrl(core.getField("sysURL.base"), request.getContextPath()) + "&app=" + getContextPath(request);
        UserAccountBean currentUser = (UserAccountBean) request.getSession().getAttribute("userBean");
        request.setAttribute("designerUrl", designerUrl);
        request.setAttribute("currentStudy", currentStudy.getOid());
        request.setAttribute("providerUser", currentUser.getName());
        request.setAttribute("validRuleSetRuleIds", validRuleSetRuleIds);
        request.setAttribute("ruleSetRuleBeans", orderRuleSetRulesByStatus(ruleSetBean));
        request.setAttribute(RULESET, ruleSetBean);
        forwardPage(Page.VIEW_RULES);
    }
}
Also used : RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) CoreResources(org.akaza.openclinica.dao.core.CoreResources) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 15 with RuleSetRuleBean

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

the class UpdateRuleSetRuleServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String ruleSetId = request.getParameter(RULESET_ID);
    String ruleSetRuleId = request.getParameter(RULESETRULE_ID);
    String source = request.getParameter("source");
    String action = request.getParameter(ACTION);
    Status status = null;
    String pageMessage = "";
    if (ruleSetRuleId != null) {
        RuleSetRuleBean ruleSetRule = getRuleSetRuleDao().findById(Integer.valueOf(ruleSetRuleId));
        if (ruleSetRuleId != null && action.equals("remove")) {
            status = Status.DELETED;
            updateRuleSetRule(ruleSetRule, status);
            pageMessage = "view_rules_remove_confirmation";
        } else if (ruleSetRuleId != null && action.equals("restore")) {
            status = Status.AVAILABLE;
            ruleSetRule.getRuleSetBean().setStatus(Status.AVAILABLE);
            updateRuleSetRule(ruleSetRule, status);
            pageMessage = "view_rules_restore_confirmation";
        }
    }
    if (ruleSetRuleId == null && ruleSetId != null && action.equals("remove")) {
        RuleSetBean rs = getRuleSetDao().findById(Integer.valueOf(ruleSetId));
        for (RuleSetRuleBean theRuleSetRule : rs.getRuleSetRules()) {
            if (theRuleSetRule.getStatus() != Status.DELETED) {
                status = Status.DELETED;
                updateRuleSetRule(theRuleSetRule, status);
            }
        }
        pageMessage = "view_rules_remove_confirmation";
    }
    addPageMessage(resword.getString(pageMessage));
    if (source != null && source.equals("ViewRuleSet")) {
        context.getRequestDispatcher("/ViewRuleSet?ruleSetId=" + ruleSetId).forward(request, response);
    } else {
        forwardPage(Page.LIST_RULE_SETS_SERVLET);
    }
}
Also used : Status(org.akaza.openclinica.domain.Status) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Aggregations

RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)33 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)20 ArrayList (java.util.ArrayList)12 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)10 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)10 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)9 HashMap (java.util.HashMap)7 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)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 ActionProcessor (org.akaza.openclinica.domain.rule.action.ActionProcessor)5 EventActionBean (org.akaza.openclinica.domain.rule.action.EventActionBean)5 Map (java.util.Map)3 AuditableBeanWrapper (org.akaza.openclinica.domain.rule.AuditableBeanWrapper)3 ShowActionBean (org.akaza.openclinica.domain.rule.action.ShowActionBean)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2