From f94502362f7edd68c424a0dd5964a8ab8851ca8e Mon Sep 17 00:00:00 2001 From: Peter Stieglecker Date: Wed, 18 Dec 2024 12:19:29 +0100 Subject: [PATCH] APS-231 GitHub 73: fixed handling of desc order in search filters --- .../test/dao/SearchFilterTest.java | 19 +++++++++++++++++++ persistence-utils-product/README.md | 5 +++++ persistence-utils-product/README_DE.md | 5 +++++ .../utils/persistence/dao/GenericDAO.java | 4 ++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/persistence-utils-demo-test/src_test/com/axonivy/utils/persistence/test/dao/SearchFilterTest.java b/persistence-utils-demo-test/src_test/com/axonivy/utils/persistence/test/dao/SearchFilterTest.java index 12aee6b..de10f9f 100644 --- a/persistence-utils-demo-test/src_test/com/axonivy/utils/persistence/test/dao/SearchFilterTest.java +++ b/persistence-utils-demo-test/src_test/com/axonivy/utils/persistence/test/dao/SearchFilterTest.java @@ -5,6 +5,7 @@ import java.math.BigDecimal; import java.util.Collection; +import java.util.Comparator; import java.util.Date; import java.util.HashSet; import java.util.List; @@ -193,6 +194,24 @@ private List uniqueMaritalStatus(Collection tuples) { return tuples.stream().map(t -> (MaritalStatus)t.get(0)).distinct().sorted().toList(); } + @Test + public void testSortingAsc() { + var ascIvyUserFilter = SearchFilter.create() + .add(PersonSearchField.IVY_USER_NAME) + .addSort(PersonSearchField.IVY_USER_NAME, true); + var asc = PersonDAO.getInstance().findBySearchFilter(ascIvyUserFilter); + assertThat(asc.stream().map(t -> t.get(0, String.class))).isSorted(); + } + + @Test + public void testSortingDesc() { + var descIvyUserFilter = SearchFilter.create() + .add(PersonSearchField.IVY_USER_NAME) + .addSort(PersonSearchField.IVY_USER_NAME, false); + var desc = PersonDAO.getInstance().findBySearchFilter(descIvyUserFilter); + assertThat(desc.stream().map(t -> t.get(0, String.class))).isSortedAccordingTo(Comparator.reverseOrder()); + } + @Test public void testEnumList() { var filter = SearchFilter.create() diff --git a/persistence-utils-product/README.md b/persistence-utils-product/README.md index 90ef610..cca57b3 100644 --- a/persistence-utils-product/README.md +++ b/persistence-utils-product/README.md @@ -14,6 +14,11 @@ Axon Ivy's JPA Persistence Lib utility helps you accelerate process automation i ## Release Notes +### 11.3.2-SNAPSHOT +*Changes* + +- [APS-232](https://1ivy.atlassian.net/browse/APS-232) Fix GitHub issue 73 (SearchFilter descending sort) + ### 10.0.8 *Changes* diff --git a/persistence-utils-product/README_DE.md b/persistence-utils-product/README_DE.md index f291f30..924cda1 100644 --- a/persistence-utils-product/README_DE.md +++ b/persistence-utils-product/README_DE.md @@ -16,6 +16,11 @@ Axon Ivy's JPA Persistence Lib unterstützt dich dabei, Prozessautomatisierungsi ## Release Notes +### 11.3.2-SNAPSHOT +*Änderungen* + +- [APS-231](https://1ivy.atlassian.net/browse/APS-231) Fix GitHub issue 73 (SearchFilter descending sort) + ### 10.0.8 *Änderungen* - [APS-224](https://1ivy.atlassian.net/browse/APS-224) Behebung des Handlings von leeren Listen oder Null-Werten in Enum-Suchfiltern. diff --git a/persistence-utils/src/com/axonivy/utils/persistence/dao/GenericDAO.java b/persistence-utils/src/com/axonivy/utils/persistence/dao/GenericDAO.java index 7ea57be..7d46499 100644 --- a/persistence-utils/src/com/axonivy/utils/persistence/dao/GenericDAO.java +++ b/persistence-utils/src/com/axonivy/utils/persistence/dao/GenericDAO.java @@ -1497,7 +1497,7 @@ protected AttributePredicates searchFilterToAttributePredicates(SearchFilter sea } // Add all needed orders. - for (FilterOrder filterOrder : searchFilter.getFilterOrders()) { + for (var filterOrder : searchFilter.getFilterOrders()) { var orders = orderMap.get(filterOrder.getSearchEnum()); if(orders == null) { @@ -1518,7 +1518,7 @@ protected AttributePredicates searchFilterToAttributePredicates(SearchFilter sea // whether multi-select filters will even be used, will be seen. // At the moment all filters produce a single selection, so this all // does not really matter. - orders.stream().forEach(o -> o.reverse()); + orders = orders.stream().map(Order::reverse).toList(); } // Add all orders. attributePredicates.addOrders(orders);