-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#381: Support pagination and sorting in ITI-58 requests
- Loading branch information
Showing
36 changed files
with
2,155 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
commons/ihe/hpd/src/main/java/org/openehealth/ipf/commons/ihe/hpd/HpdUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2022 the original author or authors. | ||
* | ||
* 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 org.openehealth.ipf.commons.ihe.hpd; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.ErrorResponse; | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.LDAPResult; | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.ObjectFactory; | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.SearchResponse; | ||
|
||
import javax.xml.bind.JAXBElement; | ||
|
||
/** | ||
* @author Dmytro Rud | ||
* @since 4.3 | ||
*/ | ||
@UtilityClass | ||
public class HpdUtils { | ||
|
||
public static final ObjectFactory DSMLV2_OBJECT_FACTORY = new ObjectFactory(); | ||
|
||
public static JAXBElement<ErrorResponse> errorResponse(Exception exception, String requestId) { | ||
ErrorResponse error = DSMLV2_OBJECT_FACTORY.createErrorResponse(); | ||
error.setMessage(exception.getMessage()); | ||
error.setRequestID(requestId); | ||
ErrorResponse.ErrorType errorType = (exception instanceof HpdException) ? ((HpdException) exception).getType() : ErrorResponse.ErrorType.OTHER; | ||
error.setType(errorType); | ||
return DSMLV2_OBJECT_FACTORY.createBatchResponseErrorResponse(error); | ||
} | ||
|
||
public static String extractResponseRequestId(Object dsmlResponse) { | ||
if (dsmlResponse instanceof SearchResponse) { | ||
return ((SearchResponse) dsmlResponse).getRequestID(); | ||
} else if (dsmlResponse instanceof LDAPResult) { | ||
return ((LDAPResult) dsmlResponse).getRequestID(); | ||
} else if (dsmlResponse instanceof ErrorResponse) { | ||
return ((ErrorResponse) dsmlResponse).getRequestID(); | ||
} else { | ||
throw new NotImplementedException("Cannot handle HPD response type " + dsmlResponse.getClass() + ", please submit a bug report"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...he/hpd/src/main/java/org/openehealth/ipf/commons/ihe/hpd/controls/ConsumerHpdHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2022 the original author or authors. | ||
* | ||
* 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 org.openehealth.ipf.commons.ihe.hpd.controls; | ||
|
||
import org.openehealth.ipf.commons.ihe.hpd.controls.handlers.ConsumerHandler; | ||
import org.openehealth.ipf.commons.ihe.hpd.controls.handlers.ConsumerHandlerBase; | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.BatchRequest; | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.BatchResponse; | ||
|
||
import javax.xml.bind.JAXBElement; | ||
|
||
/** | ||
* @author Dmytro Rud | ||
* @since 4.3 | ||
*/ | ||
abstract public class ConsumerHpdHandler extends ConsumerHandlerBase<BatchRequest, BatchResponse> { | ||
|
||
public ConsumerHpdHandler(ConsumerHandler<BatchRequest, BatchResponse> wrappedHandler) { | ||
super(wrappedHandler); | ||
} | ||
|
||
/** | ||
* Combines the entries from the batch response with the ones computed locally. | ||
*/ | ||
protected static BatchResponse aggregateResponse(BatchRequest batchRequest, BatchResponse batchResponse, JAXBElement<?>[] localResponses) { | ||
batchResponse.setRequestID(batchRequest.getRequestID()); | ||
for (int i = 0; i < localResponses.length; ++i) { | ||
if (localResponses[i] != null) { | ||
int position = Math.min(i, batchResponse.getBatchResponses().size()); | ||
batchResponse.getBatchResponses().add(position, localResponses[i]); | ||
} | ||
} | ||
return batchResponse; | ||
} | ||
|
||
} |
101 changes: 101 additions & 0 deletions
101
commons/ihe/hpd/src/main/java/org/openehealth/ipf/commons/ihe/hpd/controls/ControlUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright 2022 the original author or authors. | ||
* | ||
* 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 org.openehealth.ipf.commons.ihe.hpd.controls; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.openehealth.ipf.commons.ihe.hpd.controls.sorting.SortControl2; | ||
import org.openehealth.ipf.commons.ihe.hpd.controls.sorting.SortResponseControl2; | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.Control; | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.DsmlMessage; | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.SearchResponse; | ||
|
||
import javax.naming.ldap.*; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Methods for mapping of Controls to and from DSMLv2 and Strings. | ||
* | ||
* @author Dmytro Rud | ||
* @since 4.3 | ||
*/ | ||
@UtilityClass | ||
public class ControlUtils { | ||
|
||
public static <T extends BasicControl> T extractControl(byte[] berBytes, String type, boolean criticality) throws IOException { | ||
switch (type) { | ||
case PagedResultsControl.OID: | ||
return (T) new PagedResultsResponseControl(PagedResultsResponseControl.OID, criticality, berBytes); | ||
case SortControl.OID: | ||
return (T) new SortControl2(berBytes, criticality); | ||
case SortResponseControl.OID: | ||
return (T) new SortResponseControl2(berBytes, criticality); | ||
default: | ||
throw new NotImplementedException("Cannot handle control type " + type); | ||
} | ||
} | ||
|
||
public static PagedResultsResponseControl convert(PagedResultsControl control) throws IOException { | ||
byte[] berBytes = control.getEncodedValue(); | ||
return new PagedResultsResponseControl(PagedResultsResponseControl.OID, control.isCritical(), berBytes); | ||
} | ||
|
||
public static <T extends BasicControl> T extractControl(List<Control> controls, String type) throws IOException { | ||
for (Control control : controls) { | ||
if (type.equals(control.getType())) { | ||
return extractControl((byte[]) control.getControlValue(), type, control.isCriticality()); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static <T extends BasicControl> T extractControl(SearchResponse searchResponse, String type) throws IOException { | ||
return ((searchResponse != null) && (searchResponse.getSearchResultDone() != null)) | ||
? extractControl(searchResponse.getSearchResultDone().getControl(), type) | ||
: null; | ||
} | ||
|
||
public static <T extends BasicControl> T extractControl(DsmlMessage dsmlMessage, String type) throws IOException { | ||
return (dsmlMessage != null) | ||
? extractControl(dsmlMessage.getControl(), type) | ||
: null; | ||
} | ||
|
||
public static Control toDsmlv2(BasicControl bc) { | ||
Control control = new Control(); | ||
control.setType(bc.getID()); | ||
control.setCriticality(bc.isCritical()); | ||
control.setControlValue(bc.getEncodedValue()); | ||
return control; | ||
} | ||
|
||
public static void setControl(SearchResponse response, BasicControl bc) { | ||
setControl(response.getSearchResultDone(), bc); | ||
} | ||
|
||
public static void setControl(DsmlMessage dsmlMessage, BasicControl bc) { | ||
List<Control> controls = dsmlMessage.getControl(); | ||
for (int i = 0; i < controls.size(); ++i) { | ||
if (bc.getID().equals(controls.get(i).getType())) { | ||
controls.set(i, toDsmlv2(bc)); | ||
return; | ||
} | ||
} | ||
controls.add(toDsmlv2(bc)); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
.../src/main/java/org/openehealth/ipf/commons/ihe/hpd/controls/handlers/ConsumerHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2022 the original author or authors. | ||
* | ||
* 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 org.openehealth.ipf.commons.ihe.hpd.controls.handlers; | ||
|
||
/** | ||
* @author Dmytro Rud | ||
* @since 4.3 | ||
*/ | ||
public interface ConsumerHandler<RequestType, ResponseType> { | ||
|
||
/** | ||
* @return Handler which is one step nearer to the Camel route. | ||
*/ | ||
ConsumerHandler<RequestType, ResponseType> getWrappedHandler(); | ||
|
||
/** | ||
* @return Response to the given request. | ||
*/ | ||
ResponseType handle(RequestType request); | ||
|
||
} |
Oops, something went wrong.