From 4c9df3f7b4f2dfd960818cced6e3c4f354050e12 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 25 Jan 2021 11:25:47 -0500 Subject: [PATCH 1/4] Add string mimetype to resourceoperationemssage --- .../email/SubscriptionDeliveringEmailSubscriber.java | 2 +- .../rest/server/messaging/BaseResourceMessage.java | 12 ++++++++++++ .../server/messaging/ResourceOperationMessage.java | 2 ++ .../messaging/BaseResourceModifiedMessageTest.java | 5 ++++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/email/SubscriptionDeliveringEmailSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/email/SubscriptionDeliveringEmailSubscriber.java index 80750c11ecc..383b00a747b 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/email/SubscriptionDeliveringEmailSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/email/SubscriptionDeliveringEmailSubscriber.java @@ -55,7 +55,7 @@ public class SubscriptionDeliveringEmailSubscriber extends BaseSubscriptionDeliv @Override public void handleMessage(ResourceDeliveryMessage theMessage) throws Exception { CanonicalSubscription subscription = theMessage.getSubscription(); - + // The Subscription.endpoint is treated as the email "to" String endpointUrl = subscription.getEndpointUrl(); List destinationAddresses = new ArrayList<>(); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceMessage.java index 2126e27f3c8..0f4a4e5e124 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceMessage.java @@ -24,6 +24,7 @@ package ca.uhn.fhir.rest.server.messaging; import ca.uhn.fhir.model.api.IModelJson; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.net.MediaType; import org.apache.commons.lang3.Validate; import javax.annotation.Nullable; @@ -43,6 +44,9 @@ public abstract class BaseResourceMessage implements IResourceMessage, IModelJso @JsonProperty("transactionId") private String myTransactionId; + @JsonProperty("mimeType") + private String myMimeType; + /** * Returns an attribute stored in this message. *

@@ -145,6 +149,14 @@ public abstract class BaseResourceMessage implements IResourceMessage, IModelJso myTransactionId = theTransactionId; } + public String getMimeType() { + return myMimeType; + } + + public void setMimeType(String theMimeType) { + myMimeType = theMimeType; + } + public enum OperationTypeEnum { CREATE, UPDATE, diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceOperationMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceOperationMessage.java index 52c1574b7a6..1540e9f7180 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceOperationMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceOperationMessage.java @@ -25,6 +25,8 @@ import ca.uhn.fhir.rest.api.server.RequestDetails; import org.hl7.fhir.instance.model.api.IBaseResource; public class ResourceOperationMessage extends BaseResourceModifiedMessage { + + public ResourceOperationMessage() { } diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java index 82a6f558a7c..ce78c325b9c 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java @@ -3,6 +3,7 @@ package ca.uhn.fhir.rest.server.messaging; import ca.uhn.fhir.rest.server.messaging.json.ResourceOperationJsonMessage; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.net.MediaType; import org.junit.jupiter.api.Test; import static ca.uhn.fhir.rest.server.messaging.json.HapiMessageHeaders.FIRST_FAILURE_KEY; @@ -17,7 +18,9 @@ class ResourceOperationMessageTest { @Test public void testSerializationAndDeserializationOfResourceModifiedMessage() throws JsonProcessingException { ResourceOperationJsonMessage jsonMessage = new ResourceOperationJsonMessage(); - jsonMessage.setPayload(new ResourceOperationMessage()); + ResourceOperationMessage payload = new ResourceOperationMessage(); + payload.setMimeType("application/json+fhir"); + jsonMessage.setPayload(payload); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(jsonMessage); jsonMessage = mapper.readValue(serialized, ResourceOperationJsonMessage.class); From 5c0b3ea90538191a7ae9614af28b85e1688e82d6 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 25 Jan 2021 12:20:38 -0500 Subject: [PATCH 2/4] Add mutator for payload --- .../email/SubscriptionDeliveringEmailSubscriber.java | 2 +- .../rest/server/messaging/ResourceOperationMessage.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/email/SubscriptionDeliveringEmailSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/email/SubscriptionDeliveringEmailSubscriber.java index 383b00a747b..80750c11ecc 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/email/SubscriptionDeliveringEmailSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/email/SubscriptionDeliveringEmailSubscriber.java @@ -55,7 +55,7 @@ public class SubscriptionDeliveringEmailSubscriber extends BaseSubscriptionDeliv @Override public void handleMessage(ResourceDeliveryMessage theMessage) throws Exception { CanonicalSubscription subscription = theMessage.getSubscription(); - + // The Subscription.endpoint is treated as the email "to" String endpointUrl = subscription.getEndpointUrl(); List destinationAddresses = new ArrayList<>(); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceOperationMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceOperationMessage.java index 1540e9f7180..9b5252662f9 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceOperationMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceOperationMessage.java @@ -37,4 +37,12 @@ public class ResourceOperationMessage extends BaseResourceModifiedMessage { public ResourceOperationMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) { super(theFhirContext, theNewResource, theOperationType, theRequest); } + + /** + * If you are using a non-fhir-resource payload, you may set the payload directly here instead of using the constructor. + * @param thePayload the payload of the message. + */ + public void setPayload(String thePayload) { + this.myPayload = thePayload; + } } From 5e36d71e4182a3d9d79440ee1ceb1cea363bb337 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 1 Feb 2021 13:43:47 -0500 Subject: [PATCH 3/4] fix mimetype --- .../rest/server/messaging/BaseResourceModifiedMessageTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java index ce78c325b9c..a97e89f2282 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java @@ -3,7 +3,6 @@ package ca.uhn.fhir.rest.server.messaging; import ca.uhn.fhir.rest.server.messaging.json.ResourceOperationJsonMessage; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.net.MediaType; import org.junit.jupiter.api.Test; import static ca.uhn.fhir.rest.server.messaging.json.HapiMessageHeaders.FIRST_FAILURE_KEY; @@ -19,7 +18,7 @@ class ResourceOperationMessageTest { public void testSerializationAndDeserializationOfResourceModifiedMessage() throws JsonProcessingException { ResourceOperationJsonMessage jsonMessage = new ResourceOperationJsonMessage(); ResourceOperationMessage payload = new ResourceOperationMessage(); - payload.setMimeType("application/json+fhir"); + payload.setMimeType("application/fhir+json"); jsonMessage.setPayload(payload); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(jsonMessage); From c5299df4d3e2186cebbcaf2326ed10f0c9b5ba6a Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 1 Feb 2021 16:31:35 -0500 Subject: [PATCH 4/4] Use constant --- .../rest/server/messaging/BaseResourceModifiedMessageTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java index a97e89f2282..3683c1facba 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java @@ -1,5 +1,6 @@ package ca.uhn.fhir.rest.server.messaging; +import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.server.messaging.json.ResourceOperationJsonMessage; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -18,7 +19,7 @@ class ResourceOperationMessageTest { public void testSerializationAndDeserializationOfResourceModifiedMessage() throws JsonProcessingException { ResourceOperationJsonMessage jsonMessage = new ResourceOperationJsonMessage(); ResourceOperationMessage payload = new ResourceOperationMessage(); - payload.setMimeType("application/fhir+json"); + payload.setMimeType(Constants.CT_FHIR_JSON_NEW); jsonMessage.setPayload(payload); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(jsonMessage);