Moved more into parent class, added javadocs for transactionId

This commit is contained in:
Tadgh 2020-09-14 16:44:50 -04:00
parent 2871b721a2
commit a9fb849d49
6 changed files with 62 additions and 54 deletions

View File

@ -104,7 +104,7 @@ public class EmpiMessageHandler implements MessageHandler {
} }
private EmpiTransactionContext createEmpiContext(ResourceModifiedMessage theMsg) { private EmpiTransactionContext createEmpiContext(ResourceModifiedMessage theMsg) {
TransactionLogMessages transactionLogMessages = TransactionLogMessages.createFromTransactionGuid(theMsg.getParentTransactionGuid()); TransactionLogMessages transactionLogMessages = TransactionLogMessages.createFromTransactionGuid(theMsg.getTransactionId());
EmpiTransactionContext.OperationType empiOperation; EmpiTransactionContext.OperationType empiOperation;
switch (theMsg.getOperationType()) { switch (theMsg.getOperationType()) {
case CREATE: case CREATE:

View File

@ -65,7 +65,7 @@ public class SubscriptionDeliveringMessageSubscriber extends BaseSubscriptionDel
protected void doDelivery(ResourceDeliveryMessage theMsg, CanonicalSubscription theSubscription, IChannelProducer theChannelProducer, IBaseResource thePayloadResource) { 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? //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()); ResourceModifiedMessage payload = new ResourceModifiedMessage(myFhirContext, thePayloadResource, theMsg.getOperationType());
payload.setParentTransactionGuid(theMsg.getParentTransactionGuid()); payload.setTransactionId(theMsg.getTransactionId());
ResourceModifiedJsonMessage message = new ResourceModifiedJsonMessage(payload); ResourceModifiedJsonMessage message = new ResourceModifiedJsonMessage(payload);
theChannelProducer.send(message); theChannelProducer.send(message);
ourLog.debug("Delivering {} message payload {} for {}", theMsg.getOperationType(), theMsg.getPayloadId(), theSubscription.getIdElement(myFhirContext).toUnqualifiedVersionless().getValue()); ourLog.debug("Delivering {} message payload {} for {}", theMsg.getOperationType(), theMsg.getPayloadId(), theSubscription.getIdElement(myFhirContext).toUnqualifiedVersionless().getValue());

View File

@ -163,7 +163,7 @@ public class SubscriptionMatchingSubscriber implements MessageHandler {
deliveryMsg.setPayload(myFhirContext, payload, encoding); deliveryMsg.setPayload(myFhirContext, payload, encoding);
deliveryMsg.setSubscription(subscription); deliveryMsg.setSubscription(subscription);
deliveryMsg.setOperationType(theMsg.getOperationType()); deliveryMsg.setOperationType(theMsg.getOperationType());
deliveryMsg.setParentTransactionGuid(theMsg.getParentTransactionGuid()); deliveryMsg.setTransactionId(theMsg.getTransactionId());
deliveryMsg.copyAdditionalPropertiesFrom(theMsg); deliveryMsg.copyAdditionalPropertiesFrom(theMsg);
// Interceptor call: SUBSCRIPTION_RESOURCE_MATCHED // Interceptor call: SUBSCRIPTION_RESOURCE_MATCHED

View File

@ -40,22 +40,10 @@ public class ResourceDeliveryMessage extends BaseResourceMessage implements IRes
private CanonicalSubscription mySubscription; private CanonicalSubscription mySubscription;
@JsonProperty("payload") @JsonProperty("payload")
private String myPayloadString; private String myPayloadString;
@JsonIgnore
private transient IBaseResource myPayload;
@JsonProperty("payloadId") @JsonProperty("payloadId")
private String myPayloadId; private String myPayloadId;
@JsonProperty("parentTransactionGuid") @JsonIgnore
private String myParentTransactionGuid; private transient IBaseResource myPayload;
@JsonProperty("operationType")
private ResourceModifiedMessage.OperationTypeEnum myOperationType;
public String getParentTransactionGuid() {
return myParentTransactionGuid;
}
public void setParentTransactionGuid(String theParentTransactionGuid) {
myParentTransactionGuid = theParentTransactionGuid;
}
/** /**
* Constructor * Constructor
@ -64,14 +52,6 @@ public class ResourceDeliveryMessage extends BaseResourceMessage implements IRes
super(); super();
} }
public ResourceModifiedMessage.OperationTypeEnum getOperationType() {
return myOperationType;
}
public void setOperationType(ResourceModifiedMessage.OperationTypeEnum theOperationType) {
myOperationType = theOperationType;
}
public IBaseResource getPayload(FhirContext theCtx) { public IBaseResource getPayload(FhirContext theCtx) {
IBaseResource retVal = myPayload; IBaseResource retVal = myPayload;
if (retVal == null && isNotBlank(myPayloadString)) { if (retVal == null && isNotBlank(myPayloadString)) {
@ -137,7 +117,7 @@ public class ResourceDeliveryMessage extends BaseResourceMessage implements IRes
.append("myPayloadString", myPayloadString) .append("myPayloadString", myPayloadString)
.append("myPayload", myPayload) .append("myPayload", myPayload)
.append("myPayloadId", myPayloadId) .append("myPayloadId", myPayloadId)
.append("myOperationType", myOperationType) .append("myOperationType", getOperationType())
.toString(); .toString();
} }

View File

@ -6,6 +6,7 @@ import ca.uhn.fhir.model.api.IModelJson;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import javax.annotation.Nullable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@ -13,9 +14,15 @@ import java.util.Optional;
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
public abstract class BaseResourceMessage implements IResourceMessage, IModelJson { public abstract class BaseResourceMessage implements IResourceMessage, IModelJson {
@JsonProperty("operationType")
protected BaseResourceModifiedMessage.OperationTypeEnum myOperationType;
@JsonProperty("attributes") @JsonProperty("attributes")
private Map<String, String> myAttributes; private Map<String, String> myAttributes;
@JsonProperty("transactionId")
private String myTransactionId;
/** /**
* Returns an attribute stored in this message. * Returns an attribute stored in this message.
* <p> * <p>
@ -76,4 +83,52 @@ public abstract class BaseResourceMessage implements IResourceMessage, IModelJso
myAttributes.putAll(theMsg.myAttributes); 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
}
} }

View File

@ -21,14 +21,10 @@ public class BaseResourceModifiedMessage extends BaseResourceMessage implements
@JsonProperty("resourceId") @JsonProperty("resourceId")
protected String myId; protected String myId;
@JsonProperty("operationType")
protected OperationTypeEnum myOperationType;
@JsonProperty("payload") @JsonProperty("payload")
protected String myPayload; protected String myPayload;
@JsonProperty("payloadId") @JsonProperty("payloadId")
protected String myPayloadId; protected String myPayloadId;
@JsonProperty("parentTransactionGuid")
protected String myParentTransactionGuid;
@JsonIgnore @JsonIgnore
protected transient IBaseResource myPayloadDecoded; protected transient IBaseResource myPayloadDecoded;
@ -51,7 +47,7 @@ public class BaseResourceModifiedMessage extends BaseResourceMessage implements
public BaseResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) { public BaseResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) {
this(theFhirContext, theNewResource, theOperationType); this(theFhirContext, theNewResource, theOperationType);
if (theRequest != null) { if (theRequest != null) {
setParentTransactionGuid(theRequest.getTransactionGuid()); setTransactionId(theRequest.getTransactionGuid());
} }
} }
@ -97,14 +93,6 @@ public class BaseResourceModifiedMessage extends BaseResourceMessage implements
return ""; return "";
} }
public OperationTypeEnum getOperationType() {
return myOperationType;
}
public void setOperationType(OperationTypeEnum theOperationType) {
myOperationType = theOperationType;
}
public void setId(IIdType theId) { public void setId(IIdType theId) {
myId = null; myId = null;
if (theId != 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) { protected void setNewPayload(FhirContext theCtx, IBaseResource theNewPayload) {
/* /*
* References with placeholders would be invalid by the time we get here, and * 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(); myPayloadId = theNewPayload.getIdElement().toUnqualified().getValue();
} }
public enum OperationTypeEnum {
CREATE,
UPDATE,
DELETE,
MANUALLY_TRIGGERED
}
protected static boolean payloadContainsNoPlaceholderReferences(FhirContext theCtx, IBaseResource theNewPayload) { protected static boolean payloadContainsNoPlaceholderReferences(FhirContext theCtx, IBaseResource theNewPayload) {
List<ResourceReferenceInfo> refs = theCtx.newTerser().getAllResourceReferences(theNewPayload); List<ResourceReferenceInfo> refs = theCtx.newTerser().getAllResourceReferences(theNewPayload);
for (ResourceReferenceInfo next : refs) { for (ResourceReferenceInfo next : refs) {