Search in sources :

Example 1 with ListSubjectSort

use of org.akaza.openclinica.dao.submit.ListSubjectSort in project OpenClinica by OpenClinica.

the class ListSubjectTableFactory method setDataAndLimitVariables.

@SuppressWarnings("unchecked")
@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
    // initialize i18n
    resword = ResourceBundleProvider.getWordsBundle(getLocale());
    resformat = ResourceBundleProvider.getFormatBundle(getLocale());
    Limit limit = tableFacade.getLimit();
    ListSubjectFilter listSubjectFilter = getListSubjectFilter(limit);
    if (!limit.isComplete()) {
        Integer totalRows = getSubjectDao().getCountWithFilter(listSubjectFilter, getCurrentStudy());
        if (totalRows == null) {
            totalRows = 0;
        }
        tableFacade.setTotalRows(totalRows.intValue());
    }
    ListSubjectSort listSubjectSort = getListSubjectSort(limit);
    int rowStart = limit.getRowSelect().getRowStart();
    int rowEnd = limit.getRowSelect().getRowEnd();
    Collection<SubjectBean> items = getSubjectDao().getWithFilterAndSort(getCurrentStudy(), listSubjectFilter, listSubjectSort, rowStart, rowEnd);
    Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
    for (SubjectBean subject : items) {
        UserAccountBean owner = (UserAccountBean) getUserAccountDao().findByPK(subject.getOwnerId());
        UserAccountBean updater = subject.getUpdaterId() == 0 ? null : (UserAccountBean) getUserAccountDao().findByPK(subject.getUpdaterId());
        HashMap<Object, Object> h = new HashMap<Object, Object>();
        String studySubjectIdAndStudy = "";
        List<StudySubjectBean> studySubjects = getStudySubjectDao().findAllBySubjectId(subject.getId());
        for (StudySubjectBean studySubjectBean : studySubjects) {
            StudyBean study = (StudyBean) getStudyDao().findByPK(studySubjectBean.getStudyId());
            studySubjectIdAndStudy += studySubjectIdAndStudy.length() == 0 ? "" : ",";
            studySubjectIdAndStudy += study.getIdentifier() + "-" + studySubjectBean.getLabel();
        }
        h.put("studySubjectIdAndStudy", studySubjectIdAndStudy);
        h.put("subject", subject);
        h.put("subject.uniqueIdentifier", subject.getUniqueIdentifier());
        h.put("subject.gender", subject.getGender());
        Date tempDate = subject.getCreatedDate();
        String tempDateStr = tempDate == null ? "" : I18nFormatUtil.getDateFormat(getLocale()).format(tempDate);
        h.put("subject.createdDate", tempDateStr);
        h.put("subject.owner", owner);
        tempDate = subject.getUpdatedDate();
        tempDateStr = tempDate == null ? "" : I18nFormatUtil.getDateFormat(getLocale()).format(tempDate);
        h.put("subject.updatedDate", tempDateStr);
        h.put("subject.updater", updater);
        h.put("subject.status", subject.getStatus());
        theItems.add(h);
    }
    tableFacade.setItems(theItems);
}
Also used : ListSubjectFilter(org.akaza.openclinica.dao.submit.ListSubjectFilter) HashMap(java.util.HashMap) ListSubjectSort(org.akaza.openclinica.dao.submit.ListSubjectSort) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) Date(java.util.Date) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Limit(org.jmesa.limit.Limit)

Example 2 with ListSubjectSort

use of org.akaza.openclinica.dao.submit.ListSubjectSort in project OpenClinica by OpenClinica.

the class ListSubjectTableFactory method getListSubjectSort.

/**
 * 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 ListSubjectSort getListSubjectSort(Limit limit) {
    ListSubjectSort listSubjectSort = new ListSubjectSort();
    SortSet sortSet = limit.getSortSet();
    Collection<Sort> sorts = sortSet.getSorts();
    for (Sort sort : sorts) {
        String property = sort.getProperty();
        String order = sort.getOrder().toParam();
        listSubjectSort.addSort(property, order);
    }
    return listSubjectSort;
}
Also used : ListSubjectSort(org.akaza.openclinica.dao.submit.ListSubjectSort) Sort(org.jmesa.limit.Sort) ListSubjectSort(org.akaza.openclinica.dao.submit.ListSubjectSort) SortSet(org.jmesa.limit.SortSet)

Aggregations

ListSubjectSort (org.akaza.openclinica.dao.submit.ListSubjectSort)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)1 SubjectBean (org.akaza.openclinica.bean.submit.SubjectBean)1 ListSubjectFilter (org.akaza.openclinica.dao.submit.ListSubjectFilter)1 Limit (org.jmesa.limit.Limit)1 Sort (org.jmesa.limit.Sort)1 SortSet (org.jmesa.limit.SortSet)1