diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/broker/EmpiMessageHandler.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/broker/EmpiMessageHandler.java index 70fd1f39569..2662a2a2e5e 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/broker/EmpiMessageHandler.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/broker/EmpiMessageHandler.java @@ -104,7 +104,7 @@ public class EmpiMessageHandler implements MessageHandler { } private EmpiTransactionContext createEmpiContext(ResourceModifiedMessage theMsg) { - TransactionLogMessages transactionLogMessages = TransactionLogMessages.createFromTransactionGuid(theMsg.getParentTransactionGuid()); + TransactionLogMessages transactionLogMessages = TransactionLogMessages.createFromTransactionGuid(theMsg.getTransactionId()); EmpiTransactionContext.OperationType empiOperation; switch (theMsg.getOperationType()) { case CREATE: diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/message/SubscriptionDeliveringMessageSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/message/SubscriptionDeliveringMessageSubscriber.java index c953196f90d..2239958ba10 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/message/SubscriptionDeliveringMessageSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/message/SubscriptionDeliveringMessageSubscriber.java @@ -65,7 +65,7 @@ public class SubscriptionDeliveringMessageSubscriber extends BaseSubscriptionDel protected void doDelivery(ResourceDeliveryMessage theMsg, CanonicalSubscription theSubscription, IChannelProducer theChannelProducer, IBaseResource thePayloadResource) { //TODO GGG/KHS Question: is this the point at which we can use a BaseResourceModifiedMessage, since technically we no longer have need of a subscriptionId? ResourceModifiedMessage payload = new ResourceModifiedMessage(myFhirContext, thePayloadResource, theMsg.getOperationType()); - payload.setParentTransactionGuid(theMsg.getParentTransactionGuid()); + payload.setTransactionId(theMsg.getTransactionId()); ResourceModifiedJsonMessage message = new ResourceModifiedJsonMessage(payload); theChannelProducer.send(message); ourLog.debug("Delivering {} message payload {} for {}", theMsg.getOperationType(), theMsg.getPayloadId(), theSubscription.getIdElement(myFhirContext).toUnqualifiedVersionless().getValue()); diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionMatchingSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionMatchingSubscriber.java index 169a039fc94..0f0c3d03b89 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionMatchingSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionMatchingSubscriber.java @@ -163,7 +163,7 @@ public class SubscriptionMatchingSubscriber implements MessageHandler { deliveryMsg.setPayload(myFhirContext, payload, encoding); deliveryMsg.setSubscription(subscription); deliveryMsg.setOperationType(theMsg.getOperationType()); - deliveryMsg.setParentTransactionGuid(theMsg.getParentTransactionGuid()); + deliveryMsg.setTransactionId(theMsg.getTransactionId()); deliveryMsg.copyAdditionalPropertiesFrom(theMsg); // Interceptor call: SUBSCRIPTION_RESOURCE_MATCHED diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceDeliveryMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceDeliveryMessage.java index 46781aac430..8a5a6a59c5d 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceDeliveryMessage.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceDeliveryMessage.java @@ -40,22 +40,10 @@ public class ResourceDeliveryMessage extends BaseResourceMessage implements IRes private CanonicalSubscription mySubscription; @JsonProperty("payload") private String myPayloadString; - @JsonIgnore - private transient IBaseResource myPayload; @JsonProperty("payloadId") private String myPayloadId; - @JsonProperty("parentTransactionGuid") - private String myParentTransactionGuid; - @JsonProperty("operationType") - private ResourceModifiedMessage.OperationTypeEnum myOperationType; - - public String getParentTransactionGuid() { - return myParentTransactionGuid; - } - - public void setParentTransactionGuid(String theParentTransactionGuid) { - myParentTransactionGuid = theParentTransactionGuid; - } + @JsonIgnore + private transient IBaseResource myPayload; /** * Constructor @@ -64,14 +52,6 @@ public class ResourceDeliveryMessage extends BaseResourceMessage implements IRes super(); } - public ResourceModifiedMessage.OperationTypeEnum getOperationType() { - return myOperationType; - } - - public void setOperationType(ResourceModifiedMessage.OperationTypeEnum theOperationType) { - myOperationType = theOperationType; - } - public IBaseResource getPayload(FhirContext theCtx) { IBaseResource retVal = myPayload; if (retVal == null && isNotBlank(myPayloadString)) { @@ -137,7 +117,7 @@ public class ResourceDeliveryMessage extends BaseResourceMessage implements IRes .append("myPayloadString", myPayloadString) .append("myPayload", myPayload) .append("myPayloadId", myPayloadId) - .append("myOperationType", myOperationType) + .append("myOperationType", getOperationType()) .toString(); } 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 44c59fac5f7..38d8afa4033 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 @@ -6,6 +6,7 @@ import ca.uhn.fhir.model.api.IModelJson; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.Validate; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -13,9 +14,15 @@ import java.util.Optional; @SuppressWarnings("WeakerAccess") public abstract class BaseResourceMessage implements IResourceMessage, IModelJson { + @JsonProperty("operationType") + protected BaseResourceModifiedMessage.OperationTypeEnum myOperationType; + @JsonProperty("attributes") private Map myAttributes; + @JsonProperty("transactionId") + private String myTransactionId; + /** * Returns an attribute stored in this message. *

@@ -76,4 +83,52 @@ public abstract class BaseResourceMessage implements IResourceMessage, IModelJso myAttributes.putAll(theMsg.myAttributes); } } + + /** + * Returns the {@link OperationTypeEnum} that is occurring to the Resource of the message + * + * @return the operation type. + */ + public BaseResourceModifiedMessage.OperationTypeEnum getOperationType() { + return myOperationType; + } + + /** + * Sets the {@link OperationTypeEnum} occuring to the resource of the message. + * + * @param theOperationType The operation type to set. + */ + public void setOperationType(BaseResourceModifiedMessage.OperationTypeEnum theOperationType) { + myOperationType = theOperationType; + } + + /** + * Retrieve the transaction ID related to this message. + * + * @return the transaction ID, or null. + */ + @Nullable + public String getTransactionId() { + return myTransactionId; + } + + /** + * Adds a transcation ID to this message. This ID can be used for many purposes. For example, performing tracing + * across asynchronous hooks, tying data together, or downstream logging purposes. + * + * One current internal implementation uses this field to tie back EMPI processing results (which are asynchronous) + * to the original transaction log that caused the EMPI processing to occur. + * + * @param theTransactionId An ID representing a transaction of relevance to this message. + */ + public void setTransactionId(String theTransactionId) { + myTransactionId = theTransactionId; + } + + public enum OperationTypeEnum { + CREATE, + UPDATE, + DELETE, + MANUALLY_TRIGGERED + } } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessage.java index 1fb5bbfd83b..ff90ae5b4b9 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessage.java @@ -21,14 +21,10 @@ public class BaseResourceModifiedMessage extends BaseResourceMessage implements @JsonProperty("resourceId") protected String myId; - @JsonProperty("operationType") - protected OperationTypeEnum myOperationType; @JsonProperty("payload") protected String myPayload; @JsonProperty("payloadId") protected String myPayloadId; - @JsonProperty("parentTransactionGuid") - protected String myParentTransactionGuid; @JsonIgnore protected transient IBaseResource myPayloadDecoded; @@ -51,7 +47,7 @@ public class BaseResourceModifiedMessage extends BaseResourceMessage implements public BaseResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) { this(theFhirContext, theNewResource, theOperationType); if (theRequest != null) { - setParentTransactionGuid(theRequest.getTransactionGuid()); + setTransactionId(theRequest.getTransactionGuid()); } } @@ -97,14 +93,6 @@ public class BaseResourceModifiedMessage extends BaseResourceMessage implements return ""; } - public OperationTypeEnum getOperationType() { - return myOperationType; - } - - public void setOperationType(OperationTypeEnum theOperationType) { - myOperationType = theOperationType; - } - public void setId(IIdType theId) { myId = null; if (theId != null) { @@ -112,14 +100,6 @@ public class BaseResourceModifiedMessage extends BaseResourceMessage implements } } - public String getParentTransactionGuid() { - return myParentTransactionGuid; - } - - public void setParentTransactionGuid(String theParentTransactionGuid) { - myParentTransactionGuid = theParentTransactionGuid; - } - protected void setNewPayload(FhirContext theCtx, IBaseResource theNewPayload) { /* * References with placeholders would be invalid by the time we get here, and @@ -141,13 +121,6 @@ public class BaseResourceModifiedMessage extends BaseResourceMessage implements myPayloadId = theNewPayload.getIdElement().toUnqualified().getValue(); } - public enum OperationTypeEnum { - CREATE, - UPDATE, - DELETE, - MANUALLY_TRIGGERED - } - protected static boolean payloadContainsNoPlaceholderReferences(FhirContext theCtx, IBaseResource theNewPayload) { List refs = theCtx.newTerser().getAllResourceReferences(theNewPayload); for (ResourceReferenceInfo next : refs) {