Search in sources :

Example 1 with ViewRuleAssignmentFilter

use of org.akaza.openclinica.dao.hibernate.ViewRuleAssignmentFilter 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 2 with ViewRuleAssignmentFilter

use of org.akaza.openclinica.dao.hibernate.ViewRuleAssignmentFilter in project OpenClinica by OpenClinica.

the class ViewRuleAssignmentTableFactory method getViewRuleAssignmentFilter.

/**
     * A very custom way to filter the items. The AuditUserLoginFilter acts as a command for the Hibernate criteria object.
     * Take the Limit information and filter the rows.
     *
     * @param limit The Limit to use.
     */
protected ViewRuleAssignmentFilter getViewRuleAssignmentFilter(Limit limit) {
    ViewRuleAssignmentFilter viewRuleAssignmentFilter = new ViewRuleAssignmentFilter();
    FilterSet filterSet = limit.getFilterSet();
    Collection<Filter> filters = filterSet.getFilters();
    for (Filter filter : filters) {
        String property = filter.getProperty();
        String value = filter.getValue();
        if ("ruleSetRuleStatus".equals(property)) {
            Status s = Status.getByI18nDescription(value, locale);
            int code = s != null ? s.getCode() : -1;
            value = code > 0 ? Status.getByCode(code).getCode() + "" : "0";
        } else if ("actionType".equals(property)) {
            ActionType a = ActionType.getByDescription(value);
            value = a != null ? a.getCode() + "" : value;
        }
        viewRuleAssignmentFilter.addFilter(property, value);
    }
    return viewRuleAssignmentFilter;
}
Also used : Status(org.akaza.openclinica.domain.Status) LoginStatus(org.akaza.openclinica.domain.technicaladmin.LoginStatus) FilterSet(org.jmesa.limit.FilterSet) ActionType(org.akaza.openclinica.domain.rule.action.ActionType) Filter(org.jmesa.limit.Filter) ViewRuleAssignmentFilter(org.akaza.openclinica.dao.hibernate.ViewRuleAssignmentFilter) ViewRuleAssignmentFilter(org.akaza.openclinica.dao.hibernate.ViewRuleAssignmentFilter)

Aggregations

ViewRuleAssignmentFilter (org.akaza.openclinica.dao.hibernate.ViewRuleAssignmentFilter)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ViewRuleAssignmentSort (org.akaza.openclinica.dao.hibernate.ViewRuleAssignmentSort)1 Status (org.akaza.openclinica.domain.Status)1 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)1 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)1 ActionType (org.akaza.openclinica.domain.rule.action.ActionType)1 LoginStatus (org.akaza.openclinica.domain.technicaladmin.LoginStatus)1 Filter (org.jmesa.limit.Filter)1 FilterSet (org.jmesa.limit.FilterSet)1 Limit (org.jmesa.limit.Limit)1