Skip to content

Commit

Permalink
Feature - returning response headers in SearchResult
Browse files Browse the repository at this point in the history
  • Loading branch information
Z14tk0 authored and a921966 committed Nov 4, 2024
1 parent 6f26d17 commit f1ba901
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 2 deletions.
4 changes: 4 additions & 0 deletions midpoint-client-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@
<artifactId>schema-pure-jaxb</artifactId>
<version>${midpoint.version}</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
* @author semancik
*
*/
public interface SearchResult<O extends ObjectType> extends List<O> {
public interface SearchResult<O extends ObjectType> extends List<O>, SearchResultMetadata {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2017-2020 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.client.api;

import jakarta.ws.rs.core.MultivaluedMap;

public interface SearchResultMetadata {
MultivaluedMap<String, Object> getHeaders();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,7 @@
public class JaxbSearchResult<O extends ObjectType> implements SearchResult<O> {

private List<O> list = null;
private MultivaluedMap<String, Object> headers;

public JaxbSearchResult() {
}
Expand All @@ -43,6 +45,16 @@ public JaxbSearchResult(List<O> list) {
this.list = list;
}

public JaxbSearchResult(List<O> list, MultivaluedMap<String, Object> headers) {
this.list = list;
this.headers = headers;
}

@Override
public MultivaluedMap<String, Object> getHeaders() {
return headers;
}

@Override
public int size() {
if (list == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public SearchResult<O> get() throws ObjectNotFoundException {
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -227,6 +228,15 @@ public void test014UserFilterQuerySearchMock() throws Exception {
assertEquals(result.size(), 0);
}

@Test
public void test015SearchResultResponseHeaders() throws Exception {
Service service = getService();

SearchResult<? extends ObjectType> searchResult = service.users().search().get();

MultivaluedMap<String, Object> responseHeaders = searchResult.getHeaders();
assertNotNull(responseHeaders);
}

@Test
public void test011ValuePolicyGet() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -414,6 +415,13 @@ public void test610searchUserFilterQuery() throws Exception {
assertEquals(users.size(), 1);
}

@Test
public void test615SearchResultResponseHeaders() throws Exception {
SearchResult<? extends ObjectType> searchResult = service.users().search().queryFor(UserType.class).get();

MultivaluedMap<String, Object> responseHeaders = searchResult.getHeaders();
assertNotNull(responseHeaders);
}

@Test
public void test700addSecurityPolicy() throws Exception {
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<surefire.version>3.5.2</surefire.version>
<jakarta.annotation.version>3.0.0</jakarta.annotation.version>
<commons-lang3.version>3.17.0</commons-lang3.version>
<jakarta.ws.rs-api.version>4.0.0</jakarta.ws.rs-api.version>
</properties>

<scm>
Expand Down Expand Up @@ -137,6 +138,11 @@
<artifactId>jakarta.xml.bind-impl</artifactId>
<version>${jaxb.version}</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>${jakarta.ws.rs-api.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
Expand Down

0 comments on commit f1ba901

Please sign in to comment.