Search in sources :

Example 1 with ViewRuleAssignmentSort

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

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

the class ViewRuleAssignmentTableFactory method getViewRuleAssignmentSort.

/**
     * A very custom way to sort the items. The AuditUserLoginSort acts as a command for the Hibernate criteria object. Take
     * the Limit information and sort the rows.
     *
     * @param limit The Limit to use.
     */
protected ViewRuleAssignmentSort getViewRuleAssignmentSort(Limit limit) {
    ViewRuleAssignmentSort viewRuleAssignmentSort = new ViewRuleAssignmentSort();
    SortSet sortSet = limit.getSortSet();
    Collection<Sort> sorts = sortSet.getSorts();
    for (Sort sort : sorts) {
        String property = sort.getProperty();
        String order = sort.getOrder().toParam();
        viewRuleAssignmentSort.addSort(property, order);
    }
    return viewRuleAssignmentSort;
}
Also used : ViewRuleAssignmentSort(org.akaza.openclinica.dao.hibernate.ViewRuleAssignmentSort) ViewRuleAssignmentSort(org.akaza.openclinica.dao.hibernate.ViewRuleAssignmentSort) Sort(org.jmesa.limit.Sort) SortSet(org.jmesa.limit.SortSet)

Aggregations

ViewRuleAssignmentSort (org.akaza.openclinica.dao.hibernate.ViewRuleAssignmentSort)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ViewRuleAssignmentFilter (org.akaza.openclinica.dao.hibernate.ViewRuleAssignmentFilter)1 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)1 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)1 Limit (org.jmesa.limit.Limit)1 Sort (org.jmesa.limit.Sort)1 SortSet (org.jmesa.limit.SortSet)1