-
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.
#422: Support JSON representation of the HPD DSMLv2 data model
- Loading branch information
Showing
12 changed files
with
362 additions
and
15 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
27 changes: 27 additions & 0 deletions
27
...d/src/main/java/org/openehealth/ipf/commons/ihe/hpd/stub/dsmlv2/BatchResponseElement.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,27 @@ | ||
/* | ||
* Copyright 2023 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.stub.dsmlv2; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
|
||
/** | ||
* Marker interface for whatever can appear in {@link BatchResponse#batchResponses}. | ||
* | ||
* @author Dmytro Rud | ||
*/ | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS) | ||
public interface BatchResponseElement { | ||
} |
93 changes: 93 additions & 0 deletions
93
.../main/java/org/openehealth/ipf/commons/ihe/hpd/stub/dsmlv2/BatchResponseIntermediary.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,93 @@ | ||
/* | ||
* Copyright 2023 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.stub.dsmlv2; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Intermediary representation of an HPD {@link BatchResponse} required because the JSON deserializer cannot handle lists of JAXBElements. | ||
* <p> | ||
* Usage: | ||
* <pre> | ||
* ObjectMapper mapper = new ObjectMapper(); | ||
* BatchResponseIntermediary intermediary = mapper.readValue(json1, BatchResponseIntermediary.class); | ||
* BatchResponse batchResponse = batchResponseIntermediary.toBatchResponse(); | ||
* </pre> | ||
* | ||
* @author Dmytro Rud | ||
*/ | ||
public class BatchResponseIntermediary { | ||
|
||
private static final ObjectFactory OBJECT_FACTORY = new ObjectFactory(); | ||
|
||
@Getter | ||
@Setter | ||
private List<BatchResponseElement> batchResponses; | ||
|
||
@Getter | ||
@Setter | ||
private String requestID; | ||
|
||
/** | ||
* Transforms this intermediary representation into a proper JAXB POJO. | ||
*/ | ||
public BatchResponse toBatchResponse() { | ||
BatchResponse batchResponse = new BatchResponse(); | ||
batchResponse.setRequestID(requestID); | ||
if (batchResponses != null) { | ||
for (Object response : batchResponses) { | ||
if (response instanceof ExtendedResponse) { | ||
batchResponse.getBatchResponses().add(OBJECT_FACTORY.createBatchResponseExtendedResponse((ExtendedResponse) response)); | ||
} else if (response instanceof SearchResponse) { | ||
batchResponse.getBatchResponses().add(OBJECT_FACTORY.createBatchResponseSearchResponse((SearchResponse) response)); | ||
} else if (response instanceof ErrorResponse) { | ||
batchResponse.getBatchResponses().add(OBJECT_FACTORY.createBatchResponseErrorResponse((ErrorResponse) response)); | ||
} else if (response instanceof LDAPResult) { | ||
LDAPResult ldapResult = (LDAPResult) response; | ||
switch (ldapResult.getElementName()) { | ||
case "modDNResponse": | ||
batchResponse.getBatchResponses().add(OBJECT_FACTORY.createBatchResponseModDNResponse(ldapResult)); | ||
break; | ||
case "compareResponse": | ||
batchResponse.getBatchResponses().add(OBJECT_FACTORY.createBatchResponseCompareResponse(ldapResult)); | ||
break; | ||
case "delResponse": | ||
batchResponse.getBatchResponses().add(OBJECT_FACTORY.createBatchResponseDelResponse(ldapResult)); | ||
break; | ||
case "modifyResponse": | ||
batchResponse.getBatchResponses().add(OBJECT_FACTORY.createBatchResponseModifyResponse(ldapResult)); | ||
break; | ||
case "authResponse": | ||
batchResponse.getBatchResponses().add(OBJECT_FACTORY.createBatchResponseAuthResponse(ldapResult)); | ||
break; | ||
case "addResponse": | ||
batchResponse.getBatchResponses().add(OBJECT_FACTORY.createBatchResponseAddResponse(ldapResult)); | ||
break; | ||
default: | ||
throw new IllegalStateException("Cannot handle LDAPResult element name " + ldapResult.getElementName()); | ||
} | ||
} else { | ||
throw new IllegalStateException("Cannot handle class " + response.getClass().getName()); | ||
} | ||
} | ||
} | ||
return batchResponse; | ||
} | ||
|
||
} |
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
56 changes: 56 additions & 0 deletions
56
.../main/java/org/openehealth/ipf/commons/ihe/hpd/stub/dsmlv2/JaxbElementListSerializer.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,56 @@ | ||
/* | ||
* Copyright 2023 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.stub.dsmlv2; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.jsontype.TypeSerializer; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
import com.fasterxml.jackson.databind.type.SimpleType; | ||
|
||
import javax.xml.bind.JAXBElement; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* JSON serializer for {@link List}<{@link JAXBElement}>. | ||
* | ||
* @author Dmytro Rud | ||
*/ | ||
public class JaxbElementListSerializer extends StdSerializer<List> { | ||
|
||
public JaxbElementListSerializer() { | ||
super(List.class); | ||
} | ||
|
||
@Override | ||
public void serialize(List list, JsonGenerator gen, SerializerProvider provider) throws IOException { | ||
gen.writeStartArray(list); | ||
for (Object object : list) { | ||
JAXBElement<?> jaxbElement = (JAXBElement<?>) object; | ||
Object value = jaxbElement.getValue(); | ||
if (value instanceof LDAPResult) { | ||
((LDAPResult) value).setElementName(jaxbElement.getName().getLocalPart()); | ||
} | ||
JsonSerializer<Object> valueSerializer = provider.findValueSerializer(value.getClass()); | ||
TypeSerializer typeSerializer = provider.findTypeSerializer(SimpleType.constructUnsafe(value.getClass())); | ||
valueSerializer.serializeWithType(value, gen, provider, typeSerializer); | ||
} | ||
gen.writeEndArray(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.