Java Code Examples for org.springframework.data.domain.Sort.Direction#DESC

The following examples show how to use org.springframework.data.domain.Sort.Direction#DESC . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskController.java    From spring4-sandbox with Apache License 2.0 6 votes vote down vote up
private List<TaskDetails> findByStatus(Status status) {
	Sort sort = new Sort(Direction.DESC, "lastModifiedDate");

	List<TaskDetails> detailsList = new ArrayList<>();
	List<Task> tasks = taskRepository.findByStatus(status, sort);

	for (Task task : tasks) {
		TaskDetails details = new TaskDetails();
		details.setId(task.getId());
		details.setName(task.getName());
		details.setDescription(task.getDescription());
		details.setCreatedDate(task.getCreatedDate());
		details.setLastModifiedDate(task.getLastModifiedDate());
		detailsList.add(details);
	}
	return detailsList;
}
 
Example 2
Source File: DictionaryServiceImpl.java    From hermes with Apache License 2.0 6 votes vote down vote up
@Override
public Page<Dictionary> queryByCondition(final Dictionary dictionary, final String id, String page, String size) throws Exception {
	 Pageable pageable = new PageRequest(Integer.valueOf(Strings.empty(page, "0")), Integer.valueOf(Strings.empty(size, "10")), new Sort(Direction.DESC,  "createTime"));
	 return  dictionaryRepository.findAll(new Specification<Dictionary>() {
		@Override
		public Predicate toPredicate(Root<Dictionary> root, CriteriaQuery<?> query,CriteriaBuilder cb) {
			List<Predicate> list = new ArrayList<Predicate>();
			if (StringUtils.isNotEmpty(dictionary.getCode())) {
				list.add(cb.like(root.<String>get("code"), "%"+dictionary.getCode().trim()+"%"));
			}
			if (StringUtils.isNotEmpty(dictionary.getName())) {
				list.add(cb.like(root.<String>get("name"), "%"+dictionary.getName().trim()+"%"));
			}
			if (StringUtils.isNotEmpty(id)) {
				list.add(cb.equal(root.<String>get("type").<String>get("id"), id));
			}
			return cb.and(list.toArray(new Predicate[list.size()]));
		}
	},pageable);
}
 
Example 3
Source File: ActionStatusBeanQuery.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Parametric Constructor.
 *
 * @param definition
 *            QueryDefinition contains the query properties.
 * @param queryConfig
 *            Implementation specific configuration.
 * @param sortPropertyIds
 *            The properties participating in sort.
 * @param sortStates
 *            The ascending or descending state of sort properties.
 */
public ActionStatusBeanQuery(final QueryDefinition definition, final Map<String, Object> queryConfig,
        final Object[] sortPropertyIds, final boolean[] sortStates) {
    super(definition, queryConfig, sortPropertyIds, sortStates);

    if (isNotNullOrEmpty(queryConfig)) {
        currentSelectedActionId = (Long) queryConfig.get(SPUIDefinitions.ACTIONSTATES_BY_ACTION);
    }

    if (sortStates != null && sortStates.length > 0) {
        // Initialize sort
        sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortPropertyIds[0]);
        // Add sort
        for (int distId = 1; distId < sortPropertyIds.length; distId++) {
            sort.and(new Sort(sortStates[distId] ? Direction.ASC : Direction.DESC,
                    (String) sortPropertyIds[distId]));
        }
    }
}
 
Example 4
Source File: TaskController.java    From spring4-sandbox with Apache License 2.0 6 votes vote down vote up
private List<TaskDetails> findByStatus(Status status) {
	Sort sort = new Sort(Direction.DESC, "lastModifiedDate");

	List<TaskDetails> detailsList = new ArrayList<>();
	List<Task> tasks = taskRepository.findByStatus(status, sort);

	for (Task task : tasks) {
		TaskDetails details = new TaskDetails();
		details.setId(task.getId());
		details.setName(task.getName());
		details.setDescription(task.getDescription());
		details.setCreatedDate(task.getCreatedDate());
		details.setLastModifiedDate(task.getLastModifiedDate());
		detailsList.add(details);
	}
	return detailsList;
}
 
Example 5
Source File: ActionBeanQuery.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Parametric Constructor.
 *
 * @param definition
 *            QueryDefinition contains the query properties.
 * @param queryConfig
 *            Implementation specific configuration.
 * @param sortPropertyIds
 *            The properties participating in sort.
 * @param sortStates
 *            The ascending or descending state of sort properties.
 */
public ActionBeanQuery(final QueryDefinition definition, final Map<String, Object> queryConfig,
        final Object[] sortPropertyIds, final boolean[] sortStates) {
    super(definition, queryConfig, sortPropertyIds, sortStates);

    if (isNotNullOrEmpty(queryConfig)) {
        currentSelectedConrollerId = (String) queryConfig.get(SPUIDefinitions.ACTIONS_BY_TARGET);
    }

    if (sortStates == null || sortStates.length <= 0) {
        return;
    }

    // Initialize sort
    sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortPropertyIds[0]);
    // Add sort
    for (int distId = 1; distId < sortPropertyIds.length; distId++) {
        sort.and(new Sort(sortStates[distId] ? Direction.ASC : Direction.DESC, (String) sortPropertyIds[distId]));
    }
}
 
Example 6
Source File: ArtifactBeanQuery.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Parametric Constructor.
 *
 * @param definition
 *            as Def
 * @param queryConfig
 *            as Config
 * @param sortIds
 *            as sort
 * @param sortStates
 *            as Sort status
 */
public ArtifactBeanQuery(final QueryDefinition definition, final Map<String, Object> queryConfig,
        final Object[] sortIds, final boolean[] sortStates) {

    super(definition, queryConfig, sortIds, sortStates);

    if (HawkbitCommonUtil.isNotNullOrEmpty(queryConfig)) {
        baseSwModuleId = (Long) queryConfig.get(SPUIDefinitions.BY_BASE_SOFTWARE_MODULE);
    }

    if (!ArrayUtils.isEmpty(sortStates)) {
        sort = new Sort(sortStates[0] ? Direction.ASC : Direction.DESC, (String) sortIds[0]);

        for (int targetId = 1; targetId < sortIds.length; targetId++) {
            sort.and(new Sort(sortStates[targetId] ? Direction.ASC : Direction.DESC, (String) sortIds[targetId]));
        }
    }
}
 
Example 7
Source File: PropertiesServiceImpl.java    From hermes with Apache License 2.0 5 votes vote down vote up
@Override
public Page<Properties> queryByCondition(final Properties properties, final String typeId,String page, String size) throws Exception {
	 Pageable pageable = new PageRequest(Integer.valueOf(Strings.empty(page, "0")), Integer.valueOf(Strings.empty(size, "10")), new Sort(Direction.DESC,  "createTime"));
	 return  propertiesRepository.findAll(new Specification<Properties>() {
		@Override
		public Predicate toPredicate(Root<Properties> root, CriteriaQuery<?> query,CriteriaBuilder cb) {
			List<Predicate> list = new ArrayList<Predicate>();
			if (StringUtils.isNotEmpty(properties.getCode())) {
				list.add(cb.like(root.<String>get("code"), "%"+properties.getCode().trim()+"%"));
			}
			if (StringUtils.isNotEmpty(properties.getName())) {
				list.add(cb.like(root.<String>get("name"), "%"+properties.getName().trim()+"%"));
			}
			if (StringUtils.isNotEmpty(properties.getStatus())) {
				list.add(cb.equal(root.<String>get("status"), properties.getStatus().trim()));
			}
			if (StringUtils.isNotEmpty(typeId)) {
				list.add(cb.equal(root.<String>get("type").<String>get("id"), typeId));
			}
			Dictionary  dict = dictionaryRepository.findByCodeAndStatus(HermesConstants.PLAT_TYPE,HermesConstants.CODE_00);
			if(dict != null){
			     list.add(cb.notEqual(root.<String>get("type").<String>get("id"), dict.getId()));
			}
			return cb.and(list.toArray(new Predicate[list.size()]));
		}
	},pageable);
}
 
Example 8
Source File: UsersController.java    From cloudstreetmarket.com with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping(value="/leaderboard", method=GET)
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Leaderboard", notes = "")
public Page<UserDTO> getLeaders(
           @ApiIgnore @PageableDefault(size=9, page=0, sort={"balanceUSD"}, direction=Direction.DESC) Pageable pageable){
	return communityService.getLeaders(pageable);
}
 
Example 9
Source File: UsersController.java    From cloudstreetmarket.com with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping(method=GET)
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "List user accounts", notes = "")
public Page<UserDTO> search(
		@Or({
               @Spec(params="cn", path="id", spec=LikeIgnoreCase.class)}	
		) @ApiIgnore Specification<User> spec,
           @ApiParam(value="Contains filter") @RequestParam(value="cn", defaultValue="", required=false) String contain, 
           @ApiIgnore @PageableDefault(size=10, page=0, sort={"balance"}, direction=Direction.DESC) Pageable pageable){
	return communityService.search(spec, pageable);
}
 
Example 10
Source File: AccountSummaryController.java    From cloudstreetmarket.com with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping(value="/wallets/{userName}", method=GET)
@ApiOperation(value = "Gets all wallet-items per user", notes = "Return a page of user-activities")
public List<WalletItemDTO> getWallet(
		@PathVariable String userName,
		@ApiIgnore @PageableDefault(size=10, page=0, direction=Direction.DESC) Pageable pageable){
	return walletService.findBy(userName);
}
 
Example 11
Source File: LikeActionController.java    From cloudstreetmarket.com with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping(method=GET)
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Search for likes", notes = "")
public PagedResources<LikeActionResource> search(
		@ApiParam(value="Action Id: 123") @RequestParam(value="action", required=true) Long actionId,
		@ApiIgnore @PageableDefault(size=10, page=0, sort={"id"}, direction=Direction.DESC) Pageable pageable){
	return pagedAssembler.toResource(likeActionService.findBy(pageable, actionId), assembler);
}
 
Example 12
Source File: ApiLogServiceImpl.java    From hermes with Apache License 2.0 5 votes vote down vote up
/**
 * 外围日志列表
 * @param page
 * @param size
 */
@Override
public Page<ApiLog> queryByCondition(final ApiLogVo apiLogVo, String page, String size) throws Exception {
	 Pageable pageable = new PageRequest(Integer.valueOf(Strings.empty(page, "0")), Integer.valueOf(Strings.empty(size, "10")), new Sort(Direction.DESC,  "createTime"));
	 return  apiLogRepository.findAll(new Specification<ApiLog>() {
		@Override
		public Predicate toPredicate(Root<ApiLog> root, CriteriaQuery<?> query,CriteriaBuilder cb) {
			List<Predicate> list = new ArrayList<Predicate>();
			if (StringUtils.isNotEmpty(apiLogVo.getSerialNo())) {
				list.add(cb.like(root.<String>get("serialNo"), "%"+apiLogVo.getSerialNo().trim()+"%"));
			}
			if (StringUtils.isNotEmpty(apiLogVo.getInterfaceName())) {
				list.add(cb.like(root.<String>get("interfaceName"), "%"+apiLogVo.getInterfaceName().trim()+"%"));
			}
			if (StringUtils.isNotEmpty(apiLogVo.getStatus())) {
				list.add(cb.equal(root.<String>get("dealFlag"), apiLogVo.getStatus().trim()));
			}
			if(StringUtils.isNotEmpty(apiLogVo.getBeginDate()) && StringUtils.isNotEmpty(apiLogVo.getEndDate())){
				Date beginDate = null, endDate = null;
				try{
						beginDate = Calendars.parse("yyyy-MM-dd HH:mm:ss", apiLogVo.getBeginDate());
						endDate = Calendars.parse("yyyy-MM-dd HH:mm:ss", apiLogVo.getEndDate());
				}catch(Exception e){
					Logger.error("日志列表查询:格式化导入开始时间["+beginDate+"],结束时间["+endDate+"],异常,忽略时间查询条件");
				}
				list.add(cb.greaterThanOrEqualTo(root.<Date> get("requestTime"), beginDate));
				list.add(cb.lessThanOrEqualTo(root.<Date> get("requestTime"), endDate));
			}
			return cb.and(list.toArray(new Predicate[list.size()]));
		}
	},pageable);
}
 
Example 13
Source File: PersonService.java    From init-spring with Apache License 2.0 5 votes vote down vote up
@Transactional(readOnly = true)
public Page<Person> findAllForPagination(int page, int size)
{
	Pageable pageable = new PageRequest(page, size, new Sort(Direction.DESC, "id"));
	Page<Person> persons = personRepository.findAll(pageable);
	return persons;
}
 
Example 14
Source File: FileServiceImpl.java    From mongodb-file-server with MIT License 5 votes vote down vote up
@Override
public List<File> listFilesByPage(int pageIndex, int pageSize) {
	Page<File> page = null;
	List<File> list = null;
	
	Sort sort = new Sort(Direction.DESC,"uploadDate"); 
	Pageable pageable = PageRequest.of(pageIndex, pageSize, sort);
	
	page = fileRepository.findAll(pageable);
	list = page.getContent();
	return list;
}
 
Example 15
Source File: BulkImportController.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String detail(Model model, @PathVariable("id") ImportJob importJob, @PageableDefault(size = PAGE_SIZE, sort="createdDate", direction=Direction.DESC) Pageable pageable) {
    ImportJobDto importJobDto = createImportJobDto(importJob);
    model.addAttribute("importJobDto", importJobDto);
    
    return "bulk/detail";
}
 
Example 16
Source File: IndexController.java    From cloudstreetmarket.com with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping(method=GET)
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Get overviews of indices", notes = "Return a page of index-overviews")
public PagedResources<IndexResource> getSeveral(
		@RequestParam(value="exchange", required=false) String exchangeId,
		@RequestParam(value="market", required=false) MarketId marketId,
		@ApiIgnore @PageableDefault(size=10, page=0, sort={"previousClose"}, direction=Direction.DESC) Pageable pageable){
	return pagedAssembler.toResource(indexService.gather(exchangeId, marketId, pageable), assembler);
}
 
Example 17
Source File: AbstractModelsResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected Sort getSort(String sort, boolean prefixWithProcessModel) {
  String propName;
  Direction direction;
  if (SORT_NAME_ASC.equals(sort)) {
    if (prefixWithProcessModel) {
      propName = "model.name";
    } else {
      propName = "name";
    }
    direction = Direction.ASC;
  } else if (SORT_NAME_DESC.equals(sort)) {
    if (prefixWithProcessModel) {
      propName = "model.name";
    } else {
      propName = "name";
    }
    direction = Direction.DESC;
  } else if (SORT_MODIFIED_ASC.equals(sort)) {
    if (prefixWithProcessModel) {
      propName = "model.lastUpdated";
    } else {
      propName = "lastUpdated";
    }
    direction = Direction.ASC;
  } else {
    // Default sorting
    if (prefixWithProcessModel) {
      propName = "model.lastUpdated";
    } else {
      propName = "lastUpdated";
    }
    direction = Direction.DESC;
  }
  return new Sort(direction, propName);
}
 
Example 18
Source File: CmsController.java    From hermes with Apache License 2.0 5 votes vote down vote up
@RequestMapping("notice/{cid}")
public String noticeArticleCategory(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer size, @PathVariable String cid, Model model) {
	Pageable pageable = new PageRequest(page, size, new Sort(Direction.DESC, "order", "updateTime"));
	Page<Article> dataBox = articleService.find(cid, pageable);
	if (dataBox.getContent().size() == 1) {
		return "redirect:/notice/" + cid + "/" + dataBox.getContent().get(0).getId();
	} else {
		model.addAttribute("nav", articleCategoryRepository.findByCode(helpCenterCode));
		model.addAttribute("sel", articleCategoryRepository.findOne(cid));
		model.addAttribute("aeli", dataBox);
		return "cms/notice_li";
	}
}
 
Example 19
Source File: PaginationSortDescAttrProcessor.java    From thymeleaf-spring-data-dialect with Apache License 2.0 4 votes vote down vote up
protected Direction getForcedDirection() {
    return Direction.DESC;
}
 
Example 20
Source File: OrderService.java    From jcart with MIT License 4 votes vote down vote up
public List<Order> getAllOrders()
{
	Sort sort = new Sort(Direction.DESC, "createdOn");
	return orderRepository.findAll(sort);
}