From 9f3c25410c71bd899ee64e4ddf0130c279aabc8c Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Thu, 11 Apr 2024 13:22:37 +0000 Subject: [PATCH] polish --- .../envers/services/CustomerService.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/jpa/boot-data-envers/src/main/java/com/example/envers/services/CustomerService.java b/jpa/boot-data-envers/src/main/java/com/example/envers/services/CustomerService.java index 1b15f654b..0fa9ba516 100644 --- a/jpa/boot-data-envers/src/main/java/com/example/envers/services/CustomerService.java +++ b/jpa/boot-data-envers/src/main/java/com/example/envers/services/CustomerService.java @@ -58,13 +58,13 @@ public Optional findCustomerById(Long id) { } public List findCustomerRevisionsById(Long id) { - List> revisionDtoCF = customerRepository + List> revisionCFList = customerRepository .findRevisions(id) .get() .map(customerRevision -> CompletableFuture.supplyAsync( () -> customerRevisionToRevisionDTOMapper.convert(customerRevision))) .toList(); - return revisionDtoCF.stream().map(CompletableFuture::join).toList(); + return revisionCFList.stream().map(CompletableFuture::join).toList(); } public PagedResult findCustomerHistoryById(Long id, Pageable pageRequest) { @@ -72,18 +72,17 @@ public PagedResult findCustomerHistoryById(Long id, Pageable pag throw new CustomerNotFoundException(id); } - RevisionSort sortDir; - Optional direction = - pageRequest.getSort().stream().map(Sort.Order::getDirection).findFirst(); - if (direction.isPresent()) { - if (Sort.Direction.ASC.name().equalsIgnoreCase(direction.get().name())) { - sortDir = RevisionSort.asc(); - } else { - sortDir = RevisionSort.desc(); - } - } else { - sortDir = RevisionSort.desc(); - } + RevisionSort sortDir = pageRequest.getSort().stream() + .map(Sort.Order::getDirection) + .findFirst() + .map(direction -> { + if (Sort.Direction.ASC.name().equalsIgnoreCase(direction.name())) { + return RevisionSort.asc(); + } else { + return RevisionSort.desc(); + } + }) + .orElse(RevisionSort.desc()); Pageable pageable = PageRequest.of(pageRequest.getPageNumber(), pageRequest.getPageSize(), sortDir); Page> customerRevisions = customerRepository.findRevisions(id, pageable);