From ea64bea1b03fe4823cb45bcef30eb837af93b00e Mon Sep 17 00:00:00 2001 From: Tadgh Date: Tue, 15 Sep 2020 15:27:21 -0400 Subject: [PATCH] Refactor to use concrete class instead of parent --- .../ca/uhn/fhir/interceptor/api/Pointcut.java | 4 +- .../jpa/empi/broker/EmpiMessageHandler.java | 8 ++- .../empi/broker/EmpiQueueConsumerLoader.java | 4 +- ...bscriptionDeliveringMessageSubscriber.java | 1 - .../BaseResourceModifiedMessage.java | 2 +- .../ConcreteResourceModifiedMessage.java | 18 +++++++ .../json/BaseResourceModifiedJsonMessage.java | 49 ------------------- .../ConcreteResourceModifiedJsonMessage.java | 49 +++++++++++++++++++ .../BaseResourceModifiedMessageTest.java | 10 ++-- 9 files changed, 83 insertions(+), 62 deletions(-) create mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ConcreteResourceModifiedMessage.java delete mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseResourceModifiedJsonMessage.java create mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ConcreteResourceModifiedJsonMessage.java diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/interceptor/api/Pointcut.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/interceptor/api/Pointcut.java index b027997a100..7eb538f4490 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/interceptor/api/Pointcut.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/interceptor/api/Pointcut.java @@ -1620,7 +1620,7 @@ public enum Pointcut { *

* Hooks may accept the following parameters: *

*

@@ -1628,7 +1628,7 @@ public enum Pointcut { * Hooks should return void. *

*/ - EMPI_AFTER_PERSISTED_RESOURCE_CHECKED(void.class, "ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage", "ca.uhn.fhir.rest.server.TransactionLogMessages"), + EMPI_AFTER_PERSISTED_RESOURCE_CHECKED(void.class, "ca.uhn.fhir.rest.server.messaging.ConcreteResourceModifiedMessage", "ca.uhn.fhir.rest.server.TransactionLogMessages"), /** * Performance Tracing Hook: 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 2662a2a2e5e..585f88aa5c3 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 @@ -33,7 +33,7 @@ import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.server.TransactionLogMessages; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.ConcreteResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IAnyResource; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -94,10 +94,14 @@ public class EmpiMessageHandler implements MessageHandler { }catch (Exception e) { log(empiContext, "Failure during EMPI processing: " + e.getMessage()); } finally { + // Interceptor call: EMPI_AFTER_PERSISTED_RESOURCE_CHECKED + ConcreteResourceModifiedMessage outgoingMsg = new ConcreteResourceModifiedMessage(myFhirContext, theMsg.getPayload(myFhirContext), theMsg.getOperationType()); + outgoingMsg.setTransactionId(theMsg.getTransactionId()); + HookParams params = new HookParams() //Janky upcast. - .add(BaseResourceModifiedMessage.class, (BaseResourceModifiedMessage) theMsg) + .add(ConcreteResourceModifiedMessage.class,outgoingMsg) .add(TransactionLogMessages.class, empiContext.getTransactionLogMessages()); myInterceptorBroadcaster.callHooks(Pointcut.EMPI_AFTER_PERSISTED_RESOURCE_CHECKED, params); } diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/broker/EmpiQueueConsumerLoader.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/broker/EmpiQueueConsumerLoader.java index a620eb7eb10..647a5b2b9c4 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/broker/EmpiQueueConsumerLoader.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/broker/EmpiQueueConsumerLoader.java @@ -5,7 +5,7 @@ import ca.uhn.fhir.empi.log.Logs; import ca.uhn.fhir.jpa.subscription.channel.api.ChannelConsumerSettings; import ca.uhn.fhir.jpa.subscription.channel.api.IChannelFactory; import ca.uhn.fhir.jpa.subscription.channel.api.IChannelReceiver; -import ca.uhn.fhir.rest.server.messaging.json.BaseResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.json.ConcreteResourceModifiedJsonMessage; import com.google.common.annotations.VisibleForTesting; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -52,7 +52,7 @@ public class EmpiQueueConsumerLoader { if (myEmpiChannel == null) { ChannelConsumerSettings config = new ChannelConsumerSettings(); config.setConcurrentConsumers(myEmpiSettings.getConcurrentConsumers()); - myEmpiChannel = myChannelFactory.getOrCreateReceiver(IEmpiSettings.EMPI_CHANNEL_NAME, BaseResourceModifiedJsonMessage.class, config); + myEmpiChannel = myChannelFactory.getOrCreateReceiver(IEmpiSettings.EMPI_CHANNEL_NAME, ConcreteResourceModifiedJsonMessage.class, config); } if (myEmpiChannel != null) { 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 2239958ba10..916957f07be 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 @@ -63,7 +63,6 @@ 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.setTransactionId(theMsg.getTransactionId()); ResourceModifiedJsonMessage message = new ResourceModifiedJsonMessage(payload); 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 ff90ae5b4b9..a3b9303cebe 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 @@ -17,7 +17,7 @@ import java.util.List; import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; -public class BaseResourceModifiedMessage extends BaseResourceMessage implements IResourceMessage, IModelJson { +public abstract class BaseResourceModifiedMessage extends BaseResourceMessage implements IResourceMessage, IModelJson { @JsonProperty("resourceId") protected String myId; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ConcreteResourceModifiedMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ConcreteResourceModifiedMessage.java new file mode 100644 index 00000000000..e2ff33f00ac --- /dev/null +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ConcreteResourceModifiedMessage.java @@ -0,0 +1,18 @@ +package ca.uhn.fhir.rest.server.messaging; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import org.hl7.fhir.instance.model.api.IBaseResource; + +public class ConcreteResourceModifiedMessage extends BaseResourceModifiedMessage { + public ConcreteResourceModifiedMessage() { + } + + public ConcreteResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) { + super(theFhirContext, theResource, theOperationType); + } + + public ConcreteResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) { + super(theFhirContext, theNewResource, theOperationType, theRequest); + } +} diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseResourceModifiedJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseResourceModifiedJsonMessage.java deleted file mode 100644 index ee1e9f47876..00000000000 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseResourceModifiedJsonMessage.java +++ /dev/null @@ -1,49 +0,0 @@ -package ca.uhn.fhir.rest.server.messaging.json; - -import ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.ToStringBuilder; - -public class BaseResourceModifiedJsonMessage extends BaseJsonMessage { - - - @JsonProperty("payload") - private BaseResourceModifiedMessage myPayload; - - /** - * Constructor - */ - public BaseResourceModifiedJsonMessage() { - super(); - } - - /** - * Constructor - */ - public BaseResourceModifiedJsonMessage(BaseResourceModifiedMessage thePayload) { - myPayload = thePayload; - setDefaultRetryHeaders(); - } - - public BaseResourceModifiedJsonMessage(HapiMessageHeaders theRetryMessageHeaders, BaseResourceModifiedMessage thePayload) { - myPayload = thePayload; - setHeaders(theRetryMessageHeaders); - } - - - @Override - public BaseResourceModifiedMessage getPayload() { - return myPayload; - } - - public void setPayload(BaseResourceModifiedMessage thePayload) { - myPayload = thePayload; - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("myPayload", myPayload) - .toString(); - } -} diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ConcreteResourceModifiedJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ConcreteResourceModifiedJsonMessage.java new file mode 100644 index 00000000000..80f91391eaf --- /dev/null +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ConcreteResourceModifiedJsonMessage.java @@ -0,0 +1,49 @@ +package ca.uhn.fhir.rest.server.messaging.json; + +import ca.uhn.fhir.rest.server.messaging.ConcreteResourceModifiedMessage; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.ToStringBuilder; + +public class ConcreteResourceModifiedJsonMessage extends BaseJsonMessage { + + + @JsonProperty("payload") + private ConcreteResourceModifiedMessage myPayload; + + /** + * Constructor + */ + public ConcreteResourceModifiedJsonMessage() { + super(); + } + + /** + * Constructor + */ + public ConcreteResourceModifiedJsonMessage(ConcreteResourceModifiedMessage thePayload) { + myPayload = thePayload; + setDefaultRetryHeaders(); + } + + public ConcreteResourceModifiedJsonMessage(HapiMessageHeaders theRetryMessageHeaders, ConcreteResourceModifiedMessage thePayload) { + myPayload = thePayload; + setHeaders(theRetryMessageHeaders); + } + + + @Override + public ConcreteResourceModifiedMessage getPayload() { + return myPayload; + } + + public void setPayload(ConcreteResourceModifiedMessage thePayload) { + myPayload = thePayload; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("myPayload", myPayload) + .toString(); + } +} 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 d8529fcd671..dbf775a864a 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,6 +1,6 @@ package ca.uhn.fhir.rest.server.messaging; -import ca.uhn.fhir.rest.server.messaging.json.BaseResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.json.ConcreteResourceModifiedJsonMessage; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; @@ -12,15 +12,15 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class BaseResourceModifiedMessageTest { +class ConcreteResourceModifiedMessageTest { @Test public void testSerializationAndDeserializationOfResourceModifiedMessage() throws JsonProcessingException { - BaseResourceModifiedJsonMessage jsonMessage = new BaseResourceModifiedJsonMessage(); - jsonMessage.setPayload(new BaseResourceModifiedMessage()); + ConcreteResourceModifiedJsonMessage jsonMessage = new ConcreteResourceModifiedJsonMessage(); + jsonMessage.setPayload(new ConcreteResourceModifiedMessage()); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(jsonMessage); - jsonMessage = mapper.readValue(serialized, BaseResourceModifiedJsonMessage.class); + jsonMessage = mapper.readValue(serialized, ConcreteResourceModifiedJsonMessage.class); assertThat(jsonMessage.getHapiHeaders().getRetryCount(), is(equalTo(0))); assertThat(jsonMessage.getHapiHeaders().getFirstFailureDate(), is(equalTo(null)));