List of usage examples for org.springframework.beans.support SortDefinition getProperty
String getProperty();
From source file:org.shept.beans.support.PropertyComparator.java
/** * Sort the given List according to the given sort definition. * <p>Note: Contained objects have to provide the given property * in the form of a bean property, i.e. a getXXX method. * @param source the input List//from w w w. jav a 2 s.c o m * @param sortDefinition the parameters to sort by * @throws java.lang.IllegalArgumentException in case of a missing propertyName */ public static void sort(List source, SortDefinition sortDefinition) throws BeansException { if (StringUtils.hasText(sortDefinition.getProperty())) { Collections.sort(source, new PropertyComparator(sortDefinition)); } }
From source file:org.shept.beans.support.PropertyComparator.java
/** * Sort the given source according to the given sort definition. * <p>Note: Contained objects have to provide the given property * in the form of a bean property, i.e. a getXXX method. * @param source input source/* w w w .j ava 2 s . com*/ * @param sortDefinition the parameters to sort by * @throws java.lang.IllegalArgumentException in case of a missing propertyName */ public static void sort(Object[] source, SortDefinition sortDefinition) throws BeansException { if (StringUtils.hasText(sortDefinition.getProperty())) { Arrays.sort(source, new PropertyComparator(sortDefinition)); } }
From source file:org.shept.persistence.provider.hibernate.HibernateCriteriaFilter.java
/** * @return a default criteria definition by simply return an empty entity object * @see http://stackoverflow.com/questions/1926618/hibernate-sort-by-properties-of-inner-bean * //w w w . jav a 2s . c om */ public DetachedCriteria getCriteria(SortDefinition sortDefinition) { SortDefinition sd = defaultSortDefinition; DetachedCriteria crit = DetachedCriteria.forClass(getEntityClass()); // set sort criteria from FormFilter if (null != sortDefinition && StringUtils.hasText(sortDefinition.getProperty())) { sd = sortDefinition; } if (null != sd && StringUtils.hasText(sd.getProperty())) { String prop = sd.getProperty(); String[] pathArr = StringUtils.split(prop, "."); if (pathArr == null) { pathArr = new String[] { prop }; } if (pathArr.length > 2) { throw new UnsupportedOperationException( "Sort Criteria Definition '" + prop + "' may only nest one level deep"); } if (pathArr.length == 2) { crit.createAlias(pathArr[0], pathArr[0]); } if (sortDefinition.isAscending()) crit.addOrder(Order.asc(prop)); else crit.addOrder(Order.desc(prop)); } return crit; }
From source file:org.patientview.patientview.controller.JoinRequestsController.java
/** * Deal with the URIs "/control/joinRequestList" * get the join requests list(paging and sorting) */// ww w.j a v a 2 s . c o m @RequestMapping(value = Routes.JOIN_REQUEST_LIST_URL) public String joinRequestList(HttpServletRequest request, @RequestParam(value = "page", required = false) String page) { PagedListHolder pagedListHolder; if (page == null || "".equals(page)) { pagedListHolder = getPageListData(false); } else { pagedListHolder = (PagedListHolder) request.getSession().getAttribute("joinRequests"); if ("prev".equals(page)) { if (pagedListHolder != null) { pagedListHolder.previousPage(); } else { pagedListHolder = getPageListData(null); } } else if ("next".equals(page)) { if (pagedListHolder != null) { pagedListHolder.nextPage(); } else { pagedListHolder = getPageListData(null); } } else if ("all".equals(page)) { pagedListHolder = getPageListData(null); } else if ("incomplete".equals(page)) { pagedListHolder = getPageListData(false); } else if ("complete".equals(page)) { pagedListHolder = getPageListData(true); } else if ("sort".equals(page)) { String property = (String) request.getParameter("property"); MutableSortDefinition newSort = new MutableSortDefinition(property, true, false); SortDefinition sort = pagedListHolder.getSort(); if (StringUtils.equals(sort.getProperty(), property)) { newSort.setAscending(!sort.isAscending()); } pagedListHolder.setSort(newSort); pagedListHolder.resort(); } } pagedListHolder.setPageSize(pageSize); request.getSession().setAttribute("joinRequests", pagedListHolder); request.setAttribute("specialty", getSpecialtyContext()); if (pagedListHolder.isFirstPage()) { request.setAttribute("firstPage", true); } if (pagedListHolder.isLastPage()) { request.setAttribute("lastPage", true); } List<JoinRequest> joinRequestList = LegacySpringUtils.getJoinRequestManager().getUsersJoinRequests(false); if (joinRequestList != null && joinRequestList.size() > 0) { request.setAttribute("inCompletedNumber", joinRequestList.size()); } return forwardTo(request, Routes.JOIN_REQUEST_LIST_PAGE); }
From source file:org.patientview.patientview.controller.UnitPatientsControlller.java
@RequestMapping(value = Routes.UNIT_PATIENTS_LIST_URL) public String getPatients(@RequestParam(value = "unitcode", required = false) String unitcode, @RequestParam(value = "page", required = false) String page, @RequestParam(value = "nhsno", required = false) String nhsno, @RequestParam(value = "firstname", required = false) String firstname, @RequestParam(value = "lastname", required = false) String lastname, @RequestParam(value = "showgps", required = false) boolean showgps, @RequestParam(value = "property", required = false) String property, HttpServletRequest request) { unitcode = (unitcode == null) ? "" : unitcode; PagedListHolder pagedListHolder = (PagedListHolder) request.getSession().getAttribute("patients"); //TODO So we get every patient in the database and then start paging //TODO There is probably not a single use case why you would want this many patients //TODO Pagination needs to restrict query results if (StringUtils.isEmpty(page) || pagedListHolder == null) { // Validation if (StringUtils.isEmpty(unitcode) && StringUtils.isEmpty(nhsno) && StringUtils.isEmpty(firstname + lastname)) { return "redirect:/renal/control/unitPatientsUnitSelect.do?validation=failed"; }//www .j a va 2s .com nhsno = (nhsno == null) ? "" : nhsno; firstname = (firstname == null) ? "" : firstname; lastname = (lastname == null) ? "" : lastname; List patients = null; PatientManager patientManager = LegacySpringUtils.getPatientManager(); if (StringUtils.isEmpty(unitcode)) { if (LegacySpringUtils.getSecurityUserManager().isRolePresent("superadmin")) { patients = patientManager.getAllUnitPatientsWithTreatmentIncludeHidden(nhsno, firstname, lastname, showgps); } else { patients = patientManager.getAllUnitPatientsWithTreatment(nhsno, firstname, lastname, showgps); } } else { if (LegacySpringUtils.getSecurityUserManager().isRolePresent("superadmin")) { patients = patientManager.getUnitPatientsWithTreatmentIncludeHidden(unitcode, nhsno, firstname, lastname, showgps); } else { patients = patientManager.getUnitPatientsWithTreatment(unitcode, nhsno, firstname, lastname, showgps); } } pagedListHolder = new PagedListHolder(patients); request.getSession().setAttribute("patients", pagedListHolder); } else { if ("first".equals(page)) { pagedListHolder.setPage(0); } else if ("prev".equals(page)) { pagedListHolder.previousPage(); } else if ("next".equals(page)) { pagedListHolder.nextPage(); } else if ("last".equals(page)) { pagedListHolder.setPage(pagedListHolder.getPageCount() - 1); } else if ("sort".equals(page)) { MutableSortDefinition newSort = new MutableSortDefinition(property, true, false); SortDefinition sort = pagedListHolder.getSort(); if (StringUtils.equals(sort.getProperty(), property)) { newSort.setAscending(!sort.isAscending()); } pagedListHolder.setSort(newSort); pagedListHolder.resort(); } } //Reset the unit selection on the first page if (page == null) { request.getSession().setAttribute("unit", null); } if (StringUtils.isNotEmpty(unitcode)) { Unit unit = LegacySpringUtils.getUnitManager().get(unitcode); request.getSession().setAttribute("unit", unit); } return forwardTo(request, Routes.UNIT_PATIENTS_LIST_PAGE); }
From source file:org.patientview.patientview.controller.UnitUsersController.java
@RequestMapping(value = Routes.UNIT_USERS_LIST_URL) public String getUsers(@RequestParam(value = "unitcode", required = false) String unitcode, @RequestParam(value = "page", required = false) String page, @RequestParam(value = "property", required = false) String property, HttpServletRequest request) { if (StringUtils.isNotEmpty(unitcode)) { Unit unit = LegacySpringUtils.getUnitManager().get(unitcode); request.setAttribute("unit", unit); }//from ww w .ja v a 2s .c o m PagedListHolder pagedListHolder = (PagedListHolder) request.getSession().getAttribute("unitUsers"); if (StringUtils.isEmpty(page) || pagedListHolder == null) { List unitUsers = null; if (StringUtils.isEmpty(unitcode)) { unitUsers = LegacySpringUtils.getUnitManager().getAllUnitUsers(); } else { unitUsers = LegacySpringUtils.getUnitManager().getUnitUsers(unitcode); } pagedListHolder = new PagedListHolder(unitUsers); request.getSession().setAttribute("unitUsers", pagedListHolder); } else { if ("prev".equals(page)) { pagedListHolder.previousPage(); } else if ("next".equals(page)) { pagedListHolder.nextPage(); } else if ("sort".equals(page)) { MutableSortDefinition newSort = new MutableSortDefinition(property, true, false); SortDefinition sort = pagedListHolder.getSort(); if (StringUtils.equals(sort.getProperty(), property)) { newSort.setAscending(!sort.isAscending()); } pagedListHolder.setSort(newSort); pagedListHolder.resort(); } } return forwardTo(request, Routes.UNIT_USERS_LIST_PAGE); }
From source file:org.springframework.beans.support.PropertyComparator.java
/** * Sort the given List according to the given sort definition. * <p>Note: Contained objects have to provide the given property * in the form of a bean property, i.e. a getXXX method. * @param source the input List//from www . jav a 2 s . co m * @param sortDefinition the parameters to sort by * @throws java.lang.IllegalArgumentException in case of a missing propertyName */ public static void sort(List<?> source, SortDefinition sortDefinition) throws BeansException { if (StringUtils.hasText(sortDefinition.getProperty())) { Collections.sort(source, new PropertyComparator<>(sortDefinition)); } }
From source file:org.springframework.beans.support.PropertyComparator.java
/** * Sort the given source according to the given sort definition. * <p>Note: Contained objects have to provide the given property * in the form of a bean property, i.e. a getXXX method. * @param source input source/* w w w . j ava 2 s.co m*/ * @param sortDefinition the parameters to sort by * @throws java.lang.IllegalArgumentException in case of a missing propertyName */ public static void sort(Object[] source, SortDefinition sortDefinition) throws BeansException { if (StringUtils.hasText(sortDefinition.getProperty())) { Arrays.sort(source, new PropertyComparator<>(sortDefinition)); } }