Revert "fixed the issue of meta.source field inconsistently populated in subscription messages for different requests (#4524)" (#4535)
This reverts commit 53252b8d15
.
This commit is contained in:
parent
f3847b1d0b
commit
e99aebd2ca
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
type: fix
|
|
||||||
issue: 4523
|
|
||||||
title: "Previously, meta source field in subscription messages was inconsistently populated regarding different requests.
|
|
||||||
Now, this has been fixed and meta source will be included in all subscription messages."
|
|
|
@ -34,9 +34,7 @@ import ca.uhn.fhir.jpa.subscription.match.registry.ActiveSubscription;
|
||||||
import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry;
|
import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry;
|
||||||
import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription;
|
import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription;
|
||||||
import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage;
|
import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage;
|
||||||
import ca.uhn.fhir.rest.api.Constants;
|
|
||||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||||
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
|
|
||||||
import ca.uhn.fhir.util.BundleBuilder;
|
import ca.uhn.fhir.util.BundleBuilder;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import org.apache.commons.text.StringSubstitutor;
|
import org.apache.commons.text.StringSubstitutor;
|
||||||
|
@ -141,14 +139,6 @@ public abstract class BaseSubscriptionDeliverySubscriber implements MessageHandl
|
||||||
return builder.getBundle();
|
return builder.getBundle();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IBaseResource updateDeliveryResourceWithMetaSource(IBaseResource thePayloadResource) {
|
|
||||||
String resType = thePayloadResource.fhirType();
|
|
||||||
IFhirResourceDao<?> dao = myDaoRegistry.getResourceDao(resType);
|
|
||||||
IBaseResource resourceWithMetaSource = dao.read(thePayloadResource.getIdElement(), new SystemRequestDetails());
|
|
||||||
|
|
||||||
return resourceWithMetaSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void setFhirContextForUnitTest(FhirContext theCtx) {
|
public void setFhirContextForUnitTest(FhirContext theCtx) {
|
||||||
myFhirContext = theCtx;
|
myFhirContext = theCtx;
|
||||||
|
|
|
@ -32,7 +32,6 @@ import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage;
|
||||||
import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage;
|
import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage;
|
||||||
import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage;
|
import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage;
|
||||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||||
import ca.uhn.fhir.util.HapiExtensions;
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -60,14 +59,8 @@ public class SubscriptionDeliveringMessageSubscriber extends BaseSubscriptionDel
|
||||||
|
|
||||||
protected void doDelivery(ResourceDeliveryMessage theSourceMessage, CanonicalSubscription theSubscription, IChannelProducer theChannelProducer, ResourceModifiedJsonMessage theWrappedMessageToSend) {
|
protected void doDelivery(ResourceDeliveryMessage theSourceMessage, CanonicalSubscription theSubscription, IChannelProducer theChannelProducer, ResourceModifiedJsonMessage theWrappedMessageToSend) {
|
||||||
String payloadId = theSourceMessage.getPayloadId();
|
String payloadId = theSourceMessage.getPayloadId();
|
||||||
IBaseResource payloadResource = null;
|
|
||||||
if (isNotBlank(theSubscription.getPayloadSearchCriteria())) {
|
if (isNotBlank(theSubscription.getPayloadSearchCriteria())) {
|
||||||
payloadResource = createDeliveryBundleForPayloadSearchCriteria(theSubscription, theWrappedMessageToSend.getPayload().getPayload(myFhirContext));
|
IBaseResource payloadResource = createDeliveryBundleForPayloadSearchCriteria(theSubscription, theWrappedMessageToSend.getPayload().getPayload(myFhirContext));
|
||||||
} else if (! theWrappedMessageToSend.getPayload().getPayloadString().contains(HapiExtensions.EXT_META_SOURCE)){
|
|
||||||
payloadResource = updateDeliveryResourceWithMetaSource(theWrappedMessageToSend.getPayload().getPayload(myFhirContext));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (payloadResource != null) {
|
|
||||||
ResourceModifiedJsonMessage newWrappedMessageToSend = convertDeliveryMessageToResourceModifiedMessage(theSourceMessage, payloadResource);
|
ResourceModifiedJsonMessage newWrappedMessageToSend = convertDeliveryMessageToResourceModifiedMessage(theSourceMessage, payloadResource);
|
||||||
theWrappedMessageToSend.setPayload(newWrappedMessageToSend.getPayload());
|
theWrappedMessageToSend.setPayload(newWrappedMessageToSend.getPayload());
|
||||||
payloadId = payloadResource.getIdElement().toUnqualifiedVersionless().getValue();
|
payloadId = payloadResource.getIdElement().toUnqualifiedVersionless().getValue();
|
||||||
|
|
|
@ -27,6 +27,7 @@ import ca.uhn.fhir.rest.client.api.IRestfulClientFactory;
|
||||||
import ca.uhn.fhir.rest.server.SimpleBundleProvider;
|
import ca.uhn.fhir.rest.server.SimpleBundleProvider;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.r4.model.Bundle;
|
import org.hl7.fhir.r4.model.Bundle;
|
||||||
import org.hl7.fhir.r4.model.IdType;
|
import org.hl7.fhir.r4.model.IdType;
|
||||||
import org.hl7.fhir.r4.model.Patient;
|
import org.hl7.fhir.r4.model.Patient;
|
||||||
|
@ -58,7 +59,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.eq;
|
import static org.mockito.Mockito.eq;
|
||||||
|
@ -208,7 +208,6 @@ public class BaseSubscriptionDeliverySubscriberTest {
|
||||||
});
|
});
|
||||||
when(myInterceptorBroadcaster.callHooks(eq(Pointcut.SUBSCRIPTION_AFTER_MESSAGE_DELIVERY), any())).thenReturn(false);
|
when(myInterceptorBroadcaster.callHooks(eq(Pointcut.SUBSCRIPTION_AFTER_MESSAGE_DELIVERY), any())).thenReturn(false);
|
||||||
when(myChannelFactory.getOrCreateProducer(any(), any(), any())).thenReturn(myChannelProducer);
|
when(myChannelFactory.getOrCreateProducer(any(), any(), any())).thenReturn(myChannelProducer);
|
||||||
when(myDaoRegistry.getResourceDao(anyString())).thenReturn(myResourceDao);
|
|
||||||
|
|
||||||
CanonicalSubscription subscription = generateSubscription();
|
CanonicalSubscription subscription = generateSubscription();
|
||||||
Patient patient = generatePatient();
|
Patient patient = generatePatient();
|
||||||
|
@ -346,7 +345,6 @@ public class BaseSubscriptionDeliverySubscriberTest {
|
||||||
when(myInterceptorBroadcaster.callHooks(eq(Pointcut.SUBSCRIPTION_BEFORE_MESSAGE_DELIVERY), any())).thenReturn(true);
|
when(myInterceptorBroadcaster.callHooks(eq(Pointcut.SUBSCRIPTION_BEFORE_MESSAGE_DELIVERY), any())).thenReturn(true);
|
||||||
when(myInterceptorBroadcaster.callHooks(eq(Pointcut.SUBSCRIPTION_AFTER_MESSAGE_DELIVERY), any())).thenReturn(false);
|
when(myInterceptorBroadcaster.callHooks(eq(Pointcut.SUBSCRIPTION_AFTER_MESSAGE_DELIVERY), any())).thenReturn(false);
|
||||||
when(myChannelFactory.getOrCreateProducer(any(), any(), any())).thenReturn(myChannelProducer);
|
when(myChannelFactory.getOrCreateProducer(any(), any(), any())).thenReturn(myChannelProducer);
|
||||||
when(myDaoRegistry.getResourceDao(anyString())).thenReturn(myResourceDao);
|
|
||||||
|
|
||||||
CanonicalSubscription subscription = generateSubscription();
|
CanonicalSubscription subscription = generateSubscription();
|
||||||
Patient patient = generatePatient();
|
Patient patient = generatePatient();
|
||||||
|
@ -403,40 +401,6 @@ public class BaseSubscriptionDeliverySubscriberTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSubscriptionMessageContainsMetaSourceField() throws URISyntaxException {
|
|
||||||
//Given: we have a subscription message that contains a patient resource
|
|
||||||
Patient p1 = generatePatient();
|
|
||||||
p1.addName().setFamily("p1-family");
|
|
||||||
|
|
||||||
CanonicalSubscription subscription = generateSubscription();
|
|
||||||
subscription.setCriteriaString("[*]");
|
|
||||||
|
|
||||||
ResourceDeliveryMessage payload = new ResourceDeliveryMessage();
|
|
||||||
payload.setSubscription(subscription);
|
|
||||||
payload.setPayload(myCtx, p1, EncodingEnum.JSON);
|
|
||||||
payload.setOperationType(ResourceModifiedMessage.OperationTypeEnum.CREATE);
|
|
||||||
|
|
||||||
//When
|
|
||||||
when(myInterceptorBroadcaster.callHooks(eq(Pointcut.SUBSCRIPTION_BEFORE_MESSAGE_DELIVERY), ArgumentMatchers.any(HookParams.class))).thenReturn(true);
|
|
||||||
when(myInterceptorBroadcaster.callHooks(eq(Pointcut.SUBSCRIPTION_AFTER_MESSAGE_DELIVERY), any())).thenReturn(false);
|
|
||||||
when(myChannelFactory.getOrCreateProducer(any(), any(), any())).thenReturn(myChannelProducer);
|
|
||||||
when(myDaoRegistry.getResourceDao(anyString())).thenReturn(myResourceDao);
|
|
||||||
|
|
||||||
p1.getMeta().setSource("#example-source");
|
|
||||||
when(myResourceDao.read(any(), any())).thenReturn(p1);
|
|
||||||
|
|
||||||
//Then: meta.source field will be included in the message
|
|
||||||
myMessageSubscriber.handleMessage(payload);
|
|
||||||
|
|
||||||
ArgumentCaptor<ResourceModifiedJsonMessage> captor = ArgumentCaptor.forClass(ResourceModifiedJsonMessage.class);
|
|
||||||
verify(myChannelProducer).send(captor.capture());
|
|
||||||
List<ResourceModifiedJsonMessage> messages = captor.getAllValues();
|
|
||||||
|
|
||||||
ResourceModifiedMessage receivedMessage = messages.get(0).getPayload();
|
|
||||||
assertTrue(receivedMessage.getPayloadString().contains("\"source\":\"#example-source\""));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private Patient generatePatient() {
|
private Patient generatePatient() {
|
||||||
Patient patient = new Patient();
|
Patient patient = new Patient();
|
||||||
|
|
Loading…
Reference in New Issue