Search in sources :

Example 31 with RuleSetBean

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

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

the class ViewRuleSetAuditServlet 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);
        List<RuleSetAuditBean> ruleSetAudits = getRuleSetAuditDao().findAllByRuleSet(ruleSetBean);
        List<RuleSetRuleAuditBean> ruleSetRuleAudits = getRuleSetRuleAuditDao().findAllByRuleSet(ruleSetBean);
        for (RuleSetRuleAuditBean ruleSetRuleAuditBean : ruleSetRuleAudits) {
            ruleSetRuleAuditBean.setUpdater((UserAccountBean) getUserAccountDAO().findByPK(ruleSetRuleAuditBean.getUpdaterId()));
        }
        for (RuleSetAuditBean ruleSetAudit : ruleSetAudits) {
            ruleSetAudit.setUpdater((UserAccountBean) getUserAccountDAO().findByPK(ruleSetAudit.getUpdaterId()));
        }
        request.setAttribute(RULESET, ruleSetBean);
        request.setAttribute(RULESETAUDITS, ruleSetAudits);
        request.setAttribute(RULESETRULEAUDITS, ruleSetRuleAudits);
        forwardPage(Page.VIEW_RULESET_AUDITS);
    }
}
Also used : RuleSetAuditBean(org.akaza.openclinica.domain.rule.RuleSetAuditBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleSetRuleAuditBean(org.akaza.openclinica.domain.rule.RuleSetRuleAuditBean)

Example 33 with RuleSetBean

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

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

Example 35 with RuleSetBean

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

the class RuleController method create.

@RequestMapping(value = "/studies/{study}/validateRule", method = RequestMethod.POST)
@ResponseBody
public Response create(@RequestBody org.openclinica.ns.rules.v31.Rules rules, Model model, HttpSession session, @PathVariable("study") String studyOid) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    RulesPostImportContainer rpic = mapRulesToRulesPostImportContainer(rules);
    StudyDAO studyDao = new StudyDAO(dataSource);
    StudyBean currentStudy = studyDao.findByOid(studyOid);
    UserAccountBean userAccount = getUserAccount();
    mayProceed(userAccount, currentStudy);
    getRulePostImportContainerService(currentStudy, userAccount);
    rpic = getRulePostImportContainerService(currentStudy, userAccount).validateRuleDefs(rpic);
    rpic = getRulePostImportContainerService(currentStudy, userAccount).validateRuleSetDefs(rpic);
    Response response = new Response();
    response.setValid(Boolean.TRUE);
    if (rpic.getInValidRuleDefs().size() > 0 || rpic.getInValidRuleSetDefs().size() > 0) {
        response.setValid(Boolean.FALSE);
        for (AuditableBeanWrapper<RuleBean> beanWrapper : rpic.getInValidRuleDefs()) {
            for (String error : beanWrapper.getImportErrors()) {
                org.openclinica.ns.response.v31.MessagesType messageType = new MessagesType();
                messageType.setMessage(error);
                response.getMessages().add(messageType);
            }
        }
        for (AuditableBeanWrapper<RuleSetBean> beanWrapper : rpic.getInValidRuleSetDefs()) {
            for (String error : beanWrapper.getImportErrors()) {
                org.openclinica.ns.response.v31.MessagesType messageType = new MessagesType();
                messageType.setMessage(error);
                response.getMessages().add(messageType);
            }
        }
    }
    logger.debug("RPIC READY");
    return response;
}
Also used : Locale(java.util.Locale) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) MessagesType(org.openclinica.ns.response.v31.MessagesType) RulesTestMessagesType(org.openclinica.ns.rules_test.v31.RulesTestMessagesType) MessagesType(org.openclinica.ns.response.v31.MessagesType) Response(org.openclinica.ns.response.v31.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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