diff --git a/midpoint-client-api/pom.xml b/midpoint-client-api/pom.xml index f8aa824..51e3977 100644 --- a/midpoint-client-api/pom.xml +++ b/midpoint-client-api/pom.xml @@ -33,5 +33,9 @@ schema-pure-jaxb ${midpoint.version} + + jakarta.ws.rs + jakarta.ws.rs-api + diff --git a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/GetOptionSupport.java b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/GetOptionSupport.java index 9245b62..a5d1e46 100644 --- a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/GetOptionSupport.java +++ b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/GetOptionSupport.java @@ -48,6 +48,8 @@ default S resolveNames() { S exclude(String path); + S returnTotalCount(); + default S distinct() { option(GetOption.DISTINCT); return self(); diff --git a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/GetOptionsBuilder.java b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/GetOptionsBuilder.java index c90ae58..efb9496 100644 --- a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/GetOptionsBuilder.java +++ b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/GetOptionsBuilder.java @@ -23,6 +23,7 @@ public class GetOptionsBuilder> implements GetOpti List options = new ArrayList<>(); List include = new ArrayList<>(); List exclude = new ArrayList<>(); + Boolean returnTotalCount = false; @Override public F include(String path) { @@ -51,6 +52,12 @@ public F removeOption(GetOption option) { return self(); } + @Override + public F returnTotalCount() { + this.returnTotalCount = true; + return self(); + } + public List getExclude() { return exclude; } @@ -59,6 +66,10 @@ public List getInclude() { return include; } + public Boolean getReturnTotalCount() { + return returnTotalCount; + } + public List optionsAsStringList() { List ret = new ArrayList<>(options.size()); for (var opt : options) { diff --git a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResult.java b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResult.java index fc77e0c..911848f 100644 --- a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResult.java +++ b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResult.java @@ -19,10 +19,12 @@ import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; +import jakarta.ws.rs.core.MultivaluedMap; + /** * @author semancik * */ public interface SearchResult extends List { - + MultivaluedMap getHeaders(); } diff --git a/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/JaxbSearchResult.java b/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/JaxbSearchResult.java index 9450202..9095355 100644 --- a/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/JaxbSearchResult.java +++ b/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/JaxbSearchResult.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.ListIterator; +import jakarta.ws.rs.core.MultivaluedMap; import org.apache.cxf.common.util.CollectionUtils; import com.evolveum.midpoint.client.api.SearchResult; @@ -34,6 +35,7 @@ public class JaxbSearchResult implements SearchResult { private List list = null; + private MultivaluedMap headers; public JaxbSearchResult() { } @@ -43,6 +45,16 @@ public JaxbSearchResult(List list) { this.list = list; } + public JaxbSearchResult(List list, MultivaluedMap headers) { + this.list = list; + this.headers = headers; + } + + @Override + public MultivaluedMap getHeaders() { + return headers; + } + @Override public int size() { if (list == null) { diff --git a/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/RestJaxbSearchService.java b/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/RestJaxbSearchService.java index a5e6f2c..6a9fbe4 100644 --- a/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/RestJaxbSearchService.java +++ b/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/RestJaxbSearchService.java @@ -15,6 +15,7 @@ */ package com.evolveum.midpoint.client.impl.restjaxb; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -81,10 +82,13 @@ public SearchResult get() throws ObjectNotFoundException { if (!options.getExclude().isEmpty()) { queryParams.put("exclude", options.getExclude()); } + if (options.getReturnTotalCount()) { + queryParams.put("returnTotalCount", Collections.singletonList(Boolean.toString(options.getReturnTotalCount()))); + } Response response = getService().post(path, query, queryParams); if (Status.OK.getStatusCode() == response.getStatus()) { - return new JaxbSearchResult<>(getSearchResultList(response)); + return new JaxbSearchResult<>(getSearchResultList(response), response.getHeaders()); } if (Status.NOT_FOUND.getStatusCode() == response.getStatus()) { diff --git a/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestBasic.java b/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestBasic.java index 1fb8957..5af3f9f 100644 --- a/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestBasic.java +++ b/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestBasic.java @@ -25,6 +25,7 @@ import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType; import com.evolveum.prism.xml.ns._public.types_3.ItemPathType; +import jakarta.ws.rs.core.MultivaluedMap; import org.apache.cxf.endpoint.Server; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -227,6 +228,15 @@ public void test014UserFilterQuerySearchMock() throws Exception { assertEquals(result.size(), 0); } + @Test + public void test015SearchResultResponseHeaders() throws Exception { + Service service = getService(); + + SearchResult searchResult = service.users().search().get(); + + MultivaluedMap responseHeaders = searchResult.getHeaders(); + assertNotNull(responseHeaders); + } @Test public void test011ValuePolicyGet() throws Exception { diff --git a/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestIntegrationBasic.java b/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestIntegrationBasic.java index 902e94b..09a7632 100644 --- a/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestIntegrationBasic.java +++ b/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestIntegrationBasic.java @@ -25,6 +25,7 @@ import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType; import com.evolveum.prism.xml.ns._public.types_3.ItemPathType; +import jakarta.ws.rs.core.MultivaluedMap; import org.apache.commons.lang3.StringUtils; import org.testng.AssertJUnit; import org.testng.annotations.BeforeClass; @@ -414,6 +415,31 @@ public void test610searchUserFilterQuery() throws Exception { assertEquals(users.size(), 1); } + @Test + public void test615SearchResultResponseHeaders() throws Exception { + SearchResult searchResult = service.users().search().queryFor(UserType.class).get(); + + MultivaluedMap responseHeaders = searchResult.getHeaders(); + assertNotNull(responseHeaders); + } + + /** + * Currently this test will pass with only with midpoint branch Z14tk0:feature/rest-search-total-count-header (currently found in this PR https://github.com/Evolveum/midpoint/pull/232) + */ + @Test + public void test620UserSearchWithTotalCount() throws Exception { + SearchResult searchResult = service.users().search().queryFor(UserType.class).build() + .options() + .returnTotalCount() + .get(); + + MultivaluedMap headers = searchResult.getHeaders(); + assertNotNull(headers); + assertTrue(headers.containsKey("X-Total-Count")); + + String totalCountHeader = headers.getFirst("X-Total-Count").toString(); + assertNotNull(totalCountHeader); + } @Test public void test700addSecurityPolicy() throws Exception { diff --git a/pom.xml b/pom.xml index 97dbcfb..317469d 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,7 @@ 3.5.2 3.0.0 3.17.0 + 4.0.0 @@ -137,6 +138,11 @@ jakarta.xml.bind-impl ${jaxb.version} + + jakarta.ws.rs + jakarta.ws.rs-api + ${jakarta.ws.rs-api.version} + com.sun.xml.bind jaxb-core