From df20a04b53488942f9231af446de8da80d79d2f6 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Wed, 9 Sep 2020 12:07:22 -0400 Subject: [PATCH 01/25] Add test to ensure Messageheaders are serializable --- .../cache/SubscriptionRegistrySharedTest.java | 1 - .../InMemorySubscriptionMatcherR3Test.java | 36 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistrySharedTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistrySharedTest.java index bec37133e26..b7fa0f3df6a 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistrySharedTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistrySharedTest.java @@ -33,7 +33,6 @@ public class SubscriptionRegistrySharedTest extends BaseSubscriptionRegistryTest return "shared"; } } - } @Test diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java index 5198c1b7236..743be4dc972 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java @@ -10,16 +10,40 @@ import ca.uhn.fhir.jpa.subscription.module.BaseSubscriptionDstu3Test; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.server.SimpleBundleProvider; import ca.uhn.fhir.util.UrlUtil; -import org.hl7.fhir.dstu3.model.*; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.hl7.fhir.dstu3.model.BodySite; +import org.hl7.fhir.dstu3.model.CodeableConcept; +import org.hl7.fhir.dstu3.model.Coding; +import org.hl7.fhir.dstu3.model.CommunicationRequest; +import org.hl7.fhir.dstu3.model.DateTimeType; +import org.hl7.fhir.dstu3.model.Dosage; +import org.hl7.fhir.dstu3.model.Enumerations; +import org.hl7.fhir.dstu3.model.EpisodeOfCare; +import org.hl7.fhir.dstu3.model.IdType; +import org.hl7.fhir.dstu3.model.Location; +import org.hl7.fhir.dstu3.model.MedicationRequest; +import org.hl7.fhir.dstu3.model.Observation; +import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.Procedure; +import org.hl7.fhir.dstu3.model.ProcedureRequest; +import org.hl7.fhir.dstu3.model.Provenance; +import org.hl7.fhir.dstu3.model.QuestionnaireResponse; +import org.hl7.fhir.dstu3.model.Reference; +import org.hl7.fhir.dstu3.model.SearchParameter; +import org.hl7.fhir.dstu3.model.Timing; import org.hl7.fhir.dstu3.model.codesystems.MedicationRequestCategory; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.messaging.MessageHeaders; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -92,6 +116,16 @@ public class InMemorySubscriptionMatcherR3Test extends BaseSubscriptionDstu3Test } + @Test + public void testSerializationOfMessageHeaders() throws JsonProcessingException { + Map headers = new HashMap<>(); + headers.put("zoop", "zoop"); + MessageHeaders mh = new MessageHeaders(headers); + + ObjectMapper mapper = new ObjectMapper(); + //Test that serialization of MessageHeaders works. + mapper.writeValueAsString(mh); + } @Test public void testResourceById() { From 222923374987cba9118f8e3a176815a6f185c708 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Wed, 9 Sep 2020 15:58:41 -0400 Subject: [PATCH 02/25] Move subscription models to legacy, except the ones that are subscription specific --- .../InMemorySubscriptionMatcherR4Test.java | 5 +- .../RestHookWithInterceptorR4Test.java | 2 +- .../jpa/empi/broker/EmpiMessageHandler.java | 4 +- .../empi/broker/EmpiQueueConsumerLoader.java | 2 +- .../empi/svc/EmpiChannelSubmitterSvcImpl.java | 4 +- .../SubscriptionChannelFactory.java | 2 +- ...bscriptionDeliveringMessageSubscriber.java | 4 +- ...mpositeInMemoryDaoSubscriptionMatcher.java | 2 +- .../matching/DaoSubscriptionMatcher.java | 7 +- .../matching/IResourceModifiedConsumer.java | 2 +- .../matching/ISubscriptionMatcher.java | 3 +- .../matching/InMemorySubscriptionMatcher.java | 2 +- ...aseSubscriberForSubscriptionResources.java | 2 +- .../SubscriptionActivatingSubscriber.java | 6 +- .../SubscriptionMatchingSubscriber.java | 15 +- .../SubscriptionRegisteringSubscriber.java | 4 +- .../model/LegacyBaseResourceMessage.java | 97 +++++++++ .../LegacyResourceModifiedJsonMessage.java | 60 ++++++ .../model/LegacyResourceModifiedMessage.java | 198 ++++++++++++++++++ .../model/ResourceDeliveryMessage.java | 2 + .../SubscriptionMatcherInterceptor.java | 4 +- .../SubscriptionTriggeringSvcImpl.java | 7 +- .../util/SubscriptionDebugLogInterceptor.java | 2 +- ...castingSubscribableChannelWrapperTest.java | 4 +- ...aseSubscriptionDeliverySubscriberTest.java | 16 +- .../module/ResourceModifiedTest.java | 2 +- .../InMemorySubscriptionMatcherR3Test.java | 1 - ...kingQueueSubscribableChannelDstu3Test.java | 4 +- hapi-fhir-server/pom.xml | 6 +- .../messaging}/BaseResourceMessage.java | 2 +- .../server/messaging/IResourceMessage.java | 25 +++ .../messaging}/ResourceModifiedMessage.java | 38 +--- .../ResourceModifiedSubscriptionMessage.java | 36 ++++ .../messaging/json/BaseJsonMessage.java | 49 +++++ .../json}/ResourceModifiedJsonMessage.java | 3 +- ...sourceModifiedSubscriptionJsonMessage.java | 61 ++++++ 36 files changed, 595 insertions(+), 88 deletions(-) create mode 100644 hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyBaseResourceMessage.java create mode 100644 hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedJsonMessage.java create mode 100644 hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedMessage.java rename {hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model => hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging}/BaseResourceMessage.java (98%) create mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/IResourceMessage.java rename {hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model => hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging}/ResourceModifiedMessage.java (81%) create mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedSubscriptionMessage.java create mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java rename {hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model => hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json}/ResourceModifiedJsonMessage.java (92%) create mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedSubscriptionJsonMessage.java diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR4Test.java index 439f51a2a19..c930738ecb8 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR4Test.java @@ -11,7 +11,6 @@ import ca.uhn.fhir.jpa.subscription.match.matcher.matching.InMemorySubscriptionM import ca.uhn.fhir.jpa.subscription.match.matcher.matching.SubscriptionMatchingStrategy; import ca.uhn.fhir.jpa.subscription.match.matcher.matching.SubscriptionStrategyEvaluator; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.util.CoordCalculatorTest; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.rest.param.CompositeParam; @@ -30,6 +29,8 @@ import ca.uhn.fhir.rest.param.TokenOrListParam; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.param.TokenParamModifier; import ca.uhn.fhir.rest.param.UriParam; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedSubscriptionMessage; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -465,7 +466,7 @@ public class InMemorySubscriptionMatcherR4Test { CanonicalSubscription subscription = new CanonicalSubscription(); subscription.setCriteriaString(criteria); subscription.setIdElement(new IdType("Subscription", 123L)); - ResourceModifiedMessage msg = new ResourceModifiedMessage(myFhirContext, patient, ResourceModifiedMessage.OperationTypeEnum.CREATE); + ResourceModifiedSubscriptionMessage msg = new ResourceModifiedSubscriptionMessage(myFhirContext, patient, ResourceModifiedMessage.OperationTypeEnum.CREATE); msg.setSubscriptionId("123"); msg.setId(new IdType("Patient/ABC")); InMemoryMatchResult result = myInMemorySubscriptionMatcher.match(subscription, msg); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithInterceptorR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithInterceptorR4Test.java index faa775e0771..cc79578577c 100755 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithInterceptorR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithInterceptorR4Test.java @@ -10,10 +10,10 @@ import ca.uhn.fhir.jpa.config.StoppableSubscriptionDeliveringRestHookSubscriber; import ca.uhn.fhir.jpa.subscription.BaseSubscriptionsR4Test; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.util.SubscriptionDebugLogInterceptor; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.apache.commons.lang3.Validate; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Observation; 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 9b05e2793b5..94d18540f75 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 @@ -29,10 +29,10 @@ import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.api.Pointcut; import ca.uhn.fhir.jpa.empi.svc.EmpiMatchLinkSvc; import ca.uhn.fhir.jpa.empi.svc.EmpiResourceFilteringSvc; -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.json.ResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IAnyResource; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; 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 fc9f4eb005c..1e83444a464 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.jpa.subscription.model.ResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; import com.google.common.annotations.VisibleForTesting; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiChannelSubmitterSvcImpl.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiChannelSubmitterSvcImpl.java index 05ae109316a..6ebd4747e9f 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiChannelSubmitterSvcImpl.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiChannelSubmitterSvcImpl.java @@ -24,8 +24,8 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.empi.api.IEmpiChannelSubmitterSvc; import ca.uhn.fhir.jpa.subscription.channel.api.ChannelProducerSettings; import ca.uhn.fhir.jpa.subscription.channel.api.IChannelFactory; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/channel/subscription/SubscriptionChannelFactory.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/channel/subscription/SubscriptionChannelFactory.java index a8abc0394eb..fe0b18020e8 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/channel/subscription/SubscriptionChannelFactory.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/channel/subscription/SubscriptionChannelFactory.java @@ -27,7 +27,7 @@ import ca.uhn.fhir.jpa.subscription.channel.api.IChannelProducer; import ca.uhn.fhir.jpa.subscription.channel.api.IChannelReceiver; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionConstants; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryJsonMessage; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; import org.apache.commons.lang3.Validate; public class SubscriptionChannelFactory { 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 561904a423f..ccf096bb7f9 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 @@ -28,9 +28,9 @@ import ca.uhn.fhir.jpa.subscription.channel.api.IChannelProducer; import ca.uhn.fhir.jpa.subscription.match.deliver.BaseSubscriptionDeliverySubscriber; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IBaseResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/CompositeInMemoryDaoSubscriptionMatcher.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/CompositeInMemoryDaoSubscriptionMatcher.java index 18351b3b5e7..b9833dc1b1e 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/CompositeInMemoryDaoSubscriptionMatcher.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/CompositeInMemoryDaoSubscriptionMatcher.java @@ -23,7 +23,7 @@ package ca.uhn.fhir.jpa.subscription.match.matcher.matching; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryMatchResult; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/DaoSubscriptionMatcher.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/DaoSubscriptionMatcher.java index 35e0d01e3d9..057eda8a377 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/DaoSubscriptionMatcher.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/DaoSubscriptionMatcher.java @@ -28,8 +28,8 @@ import ca.uhn.fhir.jpa.searchparam.MatchUrlService; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryMatchResult; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.slf4j.Logger; @@ -37,11 +37,14 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; public class DaoSubscriptionMatcher implements ISubscriptionMatcher { + private Logger ourLog = LoggerFactory.getLogger(DaoSubscriptionMatcher.class); + @Autowired DaoRegistry myDaoRegistry; + @Autowired MatchUrlService myMatchUrlService; - private Logger ourLog = LoggerFactory.getLogger(DaoSubscriptionMatcher.class); + @Autowired private FhirContext myCtx; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/IResourceModifiedConsumer.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/IResourceModifiedConsumer.java index e02a5bdd82d..2de668f2bdc 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/IResourceModifiedConsumer.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/IResourceModifiedConsumer.java @@ -20,8 +20,8 @@ package ca.uhn.fhir.jpa.subscription.match.matcher.matching; * #L% */ -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IBaseResource; public interface IResourceModifiedConsumer { diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/ISubscriptionMatcher.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/ISubscriptionMatcher.java index 0880bbadfb9..091202c2730 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/ISubscriptionMatcher.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/ISubscriptionMatcher.java @@ -22,8 +22,9 @@ package ca.uhn.fhir.jpa.subscription.match.matcher.matching; import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryMatchResult; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; public interface ISubscriptionMatcher { + //TODO GGG convert this to a ResourceModifiedSubscriptionMessage InMemoryMatchResult match(CanonicalSubscription subscription, ResourceModifiedMessage msg); } diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/InMemorySubscriptionMatcher.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/InMemorySubscriptionMatcher.java index 5eb0d304e9b..159d579cd7e 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/InMemorySubscriptionMatcher.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/InMemorySubscriptionMatcher.java @@ -24,8 +24,8 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryMatchResult; import ca.uhn.fhir.jpa.searchparam.matcher.SearchParamMatcher; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/BaseSubscriberForSubscriptionResources.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/BaseSubscriberForSubscriptionResources.java index c54a6b93113..419be6b1c8e 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/BaseSubscriberForSubscriptionResources.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/BaseSubscriberForSubscriptionResources.java @@ -21,8 +21,8 @@ package ca.uhn.fhir.jpa.subscription.match.matcher.subscriber; */ import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.model.dstu2.valueset.ResourceTypeEnum; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionActivatingSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionActivatingSubscriber.java index 93246cbd2bd..cb4bc02f3f1 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionActivatingSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionActivatingSubscriber.java @@ -23,14 +23,14 @@ package ca.uhn.fhir.jpa.subscription.match.matcher.subscriber; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; -import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscriptionChannelType; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.match.matcher.matching.SubscriptionStrategyEvaluator; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionCanonicalizer; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionConstants; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; +import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscriptionChannelType; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import ca.uhn.fhir.util.SubscriptionUtil; import org.hl7.fhir.instance.model.api.IBaseResource; import org.slf4j.Logger; 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 435da9b40a9..da896a6c32f 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 @@ -12,9 +12,10 @@ import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryJsonMessage; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedSubscriptionJsonMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedSubscriptionMessage; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; @@ -79,17 +80,17 @@ public class SubscriptionMatchingSubscriber implements MessageHandler { public void handleMessage(@Nonnull Message theMessage) throws MessagingException { ourLog.trace("Handling resource modified message: {}", theMessage); - if (!(theMessage instanceof ResourceModifiedJsonMessage)) { + //TODO ADD BACKPORT FOR HANDLING OLD LEGACY SUBSCRIPTIONS HERE + if (!(theMessage instanceof ResourceModifiedSubscriptionJsonMessage)) { ourLog.warn("Unexpected message payload type: {}", theMessage); return; } - ResourceModifiedMessage msg = ((ResourceModifiedJsonMessage) theMessage).getPayload(); + ResourceModifiedSubscriptionMessage msg = ((ResourceModifiedSubscriptionJsonMessage) theMessage).getPayload(); matchActiveSubscriptionsAndDeliver(msg); - } - public void matchActiveSubscriptionsAndDeliver(ResourceModifiedMessage theMsg) { + public void matchActiveSubscriptionsAndDeliver(ResourceModifiedSubscriptionMessage theMsg) { switch (theMsg.getOperationType()) { case CREATE: case UPDATE: @@ -117,7 +118,7 @@ public class SubscriptionMatchingSubscriber implements MessageHandler { } } - private void doMatchActiveSubscriptionsAndDeliver(ResourceModifiedMessage theMsg) { + private void doMatchActiveSubscriptionsAndDeliver(ResourceModifiedSubscriptionMessage theMsg) { IIdType resourceId = theMsg.getId(myFhirContext); Collection subscriptions = mySubscriptionRegistry.getAll(); diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionRegisteringSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionRegisteringSubscriber.java index 7684d0d760f..cff765be02f 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionRegisteringSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionRegisteringSubscriber.java @@ -21,10 +21,10 @@ package ca.uhn.fhir.jpa.subscription.match.matcher.subscriber; */ import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionCanonicalizer; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IBaseResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyBaseResourceMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyBaseResourceMessage.java new file mode 100644 index 00000000000..dfe55214cd4 --- /dev/null +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyBaseResourceMessage.java @@ -0,0 +1,97 @@ +package ca.uhn.fhir.jpa.subscription.model; + +/*- + * #%L + * HAPI FHIR Subscription Server + * %% + * Copyright (C) 2014 - 2020 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import ca.uhn.fhir.model.api.IModelJson; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.Validate; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +@SuppressWarnings("WeakerAccess") +public abstract class LegacyBaseResourceMessage implements IResourceMessage, IModelJson { + + @JsonProperty("attributes") + private Map myAttributes; + + /** + * Returns an attribute stored in this message. + *

+ * Attributes are just a spot for user data of any kind to be + * added to the message for pasing along the subscription processing + * pipeline (typically by interceptors). Values will be carried from the beginning to the end. + *

+ *

+ * Note that messages are designed to be passed into queueing systems + * and serialized as JSON. As a result, only strings are currently allowed + * as values. + *

+ */ + public Optional getAttribute(String theKey) { + Validate.notBlank(theKey); + if (myAttributes == null) { + return Optional.empty(); + } + return Optional.ofNullable(myAttributes.get(theKey)); + } + + /** + * Sets an attribute stored in this message. + *

+ * Attributes are just a spot for user data of any kind to be + * added to the message for passing along the subscription processing + * pipeline (typically by interceptors). Values will be carried from the beginning to the end. + *

+ *

+ * Note that messages are designed to be passed into queueing systems + * and serialized as JSON. As a result, only strings are currently allowed + * as values. + *

+ * + * @param theKey The key (must not be null or blank) + * @param theValue The value (must not be null) + */ + public void setAttribute(String theKey, String theValue) { + Validate.notBlank(theKey); + Validate.notNull(theValue); + if (myAttributes == null) { + myAttributes = new HashMap<>(); + } + myAttributes.put(theKey, theValue); + } + + /** + * Copies any attributes from the given message into this messsage. + * + * @see #setAttribute(String, String) + * @see #getAttribute(String) + */ + public void copyAdditionalPropertiesFrom(LegacyBaseResourceMessage theMsg) { + if (theMsg.myAttributes != null) { + if (myAttributes == null) { + myAttributes = new HashMap<>(); + } + myAttributes.putAll(theMsg.myAttributes); + } + } +} diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedJsonMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedJsonMessage.java new file mode 100644 index 00000000000..821af831bbc --- /dev/null +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedJsonMessage.java @@ -0,0 +1,60 @@ +package ca.uhn.fhir.jpa.subscription.model; + +/*- + * #%L + * HAPI FHIR Subscription Server + * %% + * Copyright (C) 2014 - 2020 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.ToStringBuilder; + +public class LegacyResourceModifiedJsonMessage extends BaseJsonMessage { + + @JsonProperty("payload") + private LegacyResourceModifiedMessage myPayload; + + /** + * Constructor + */ + public LegacyResourceModifiedJsonMessage() { + super(); + } + + /** + * Constructor + */ + public LegacyResourceModifiedJsonMessage(LegacyResourceModifiedMessage thePayload) { + myPayload = thePayload; + } + + @Override + public LegacyResourceModifiedMessage getPayload() { + return myPayload; + } + + public void setPayload(LegacyResourceModifiedMessage thePayload) { + myPayload = thePayload; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("myPayload", myPayload) + .toString(); + } +} diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedMessage.java new file mode 100644 index 00000000000..f2e8c543889 --- /dev/null +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedMessage.java @@ -0,0 +1,198 @@ +package ca.uhn.fhir.jpa.subscription.model; + +/*- + * #%L + * HAPI FHIR Subscription Server + * %% + * Copyright (C) 2014 - 2020 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.IModelJson; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.util.ResourceReferenceInfo; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; + +import java.util.List; + +import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isNotBlank; + +public class LegacyResourceModifiedMessage extends LegacyBaseResourceMessage implements IResourceMessage, IModelJson { + + @JsonProperty("resourceId") + private String myId; + @JsonProperty("operationType") + private OperationTypeEnum myOperationType; + /** + * This will only be set if the resource is being triggered for a specific + * subscription + */ + @JsonProperty(value = "subscriptionId", required = false) + private String mySubscriptionId; + @JsonProperty("payload") + private String myPayload; + @JsonProperty("payloadId") + private String myPayloadId; + @JsonProperty("parentTransactionGuid") + private String myParentTransactionGuid; + @JsonIgnore + private transient IBaseResource myPayloadDecoded; + + /** + * Constructor + */ + public LegacyResourceModifiedMessage() { + super(); + } + + public LegacyResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) { + this(); + setId(theResource.getIdElement()); + setOperationType(theOperationType); + if (theOperationType != OperationTypeEnum.DELETE) { + setNewPayload(theFhirContext, theResource); + } + } + + public LegacyResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) { + this(theFhirContext, theNewResource, theOperationType); + if (theRequest != null) { + setParentTransactionGuid(theRequest.getTransactionGuid()); + } + } + + @Override + public String getPayloadId() { + return myPayloadId; + } + + public String getSubscriptionId() { + return mySubscriptionId; + } + + public void setSubscriptionId(String theSubscriptionId) { + mySubscriptionId = theSubscriptionId; + } + + public String getId() { + return myId; + } + + public IIdType getId(FhirContext theCtx) { + IIdType retVal = null; + if (myId != null) { + retVal = theCtx.getVersion().newIdType().setValue(myId); + } + return retVal; + } + + public IBaseResource getNewPayload(FhirContext theCtx) { + if (myPayloadDecoded == null && isNotBlank(myPayload)) { + myPayloadDecoded = theCtx.newJsonParser().parseResource(myPayload); + } + return myPayloadDecoded; + } + + public OperationTypeEnum getOperationType() { + return myOperationType; + } + + public void setOperationType(OperationTypeEnum theOperationType) { + myOperationType = theOperationType; + } + + public void setId(IIdType theId) { + myId = null; + if (theId != null) { + myId = theId.getValue(); + } + } + + public String getParentTransactionGuid() { + return myParentTransactionGuid; + } + + public void setParentTransactionGuid(String theParentTransactionGuid) { + myParentTransactionGuid = theParentTransactionGuid; + } + + private void setNewPayload(FhirContext theCtx, IBaseResource theNewPayload) { + /* + * References with placeholders would be invalid by the time we get here, and + * would be caught before we even get here. This check is basically a last-ditch + * effort to make sure nothing has broken in the various safeguards that + * should prevent this from happening (hence it only being an assert as + * opposed to something executed all the time). + */ + assert payloadContainsNoPlaceholderReferences(theCtx, theNewPayload); + + /* + * Note: Don't set myPayloadDecoded in here- This is a false optimization since + * it doesn't actually get used if anyone is doing subscriptions at any + * scale using a queue engine, and not going through the serialize/deserialize + * as we would in a queue engine can mask bugs. + * -JA + */ + myPayload = theCtx.newJsonParser().encodeResourceToString(theNewPayload); + myPayloadId = theNewPayload.getIdElement().toUnqualified().getValue(); + } + + public enum OperationTypeEnum { + CREATE, + UPDATE, + DELETE, + MANUALLY_TRIGGERED + } + + private static boolean payloadContainsNoPlaceholderReferences(FhirContext theCtx, IBaseResource theNewPayload) { + List refs = theCtx.newTerser().getAllResourceReferences(theNewPayload); + for (ResourceReferenceInfo next : refs) { + String ref = next.getResourceReference().getReferenceElement().getValue(); + if (isBlank(ref)) { + IBaseResource resource = next.getResourceReference().getResource(); + if (resource != null) { + ref = resource.getIdElement().getValue(); + } + } + if (isNotBlank(ref)) { + if (ref.startsWith("#")) { + continue; + } + if (ref.startsWith("urn:uuid:")) { + throw new AssertionError("Reference at " + next.getName() + " is invalid: " + ref); + } + } + } + return true; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("myId", myId) + .append("myOperationType", myOperationType) + .append("mySubscriptionId", mySubscriptionId) +// .append("myPayload", myPayload) + .append("myPayloadId", myPayloadId) +// .append("myPayloadDecoded", myPayloadDecoded) + .toString(); + } +} 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 9d990f53bca..aff2b34ed65 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 @@ -23,6 +23,8 @@ package ca.uhn.fhir.jpa.subscription.model; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.server.messaging.BaseResourceMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.builder.ToStringBuilder; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionMatcherInterceptor.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionMatcherInterceptor.java index 51e01bd6c69..a147fe9da12 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionMatcherInterceptor.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionMatcherInterceptor.java @@ -10,10 +10,10 @@ import ca.uhn.fhir.jpa.subscription.channel.impl.LinkedBlockingChannel; import ca.uhn.fhir.jpa.subscription.channel.subscription.SubscriptionChannelFactory; import ca.uhn.fhir.jpa.subscription.match.matcher.matching.IResourceModifiedConsumer; import ca.uhn.fhir.jpa.subscription.match.matcher.subscriber.SubscriptionMatchingSubscriber; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.util.JpaInterceptorBroadcaster; import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import com.google.common.annotations.VisibleForTesting; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IBaseResource; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/triggering/SubscriptionTriggeringSvcImpl.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/triggering/SubscriptionTriggeringSvcImpl.java index 36723118bfb..f966ed90655 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/triggering/SubscriptionTriggeringSvcImpl.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/triggering/SubscriptionTriggeringSvcImpl.java @@ -26,21 +26,22 @@ import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.api.svc.ISearchCoordinatorSvc; -import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.jpa.model.sched.HapiJob; import ca.uhn.fhir.jpa.model.sched.ISchedulerService; import ca.uhn.fhir.jpa.model.sched.ScheduledJobDefinition; import ca.uhn.fhir.jpa.searchparam.MatchUrlService; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.subscription.match.matcher.matching.IResourceModifiedConsumer; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.model.dstu2.valueset.ResourceTypeEnum; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.api.CacheControlDirective; import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedSubscriptionMessage; import ca.uhn.fhir.util.ParametersUtil; import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.util.UrlUtil; @@ -306,7 +307,7 @@ public class SubscriptionTriggeringSvcImpl implements ISubscriptionTriggeringSvc ourLog.info("Submitting resource {} to subscription {}", theResourceToTrigger.getIdElement().toUnqualifiedVersionless().getValue(), theSubscriptionId); - ResourceModifiedMessage msg = new ResourceModifiedMessage(myFhirContext, theResourceToTrigger, ResourceModifiedMessage.OperationTypeEnum.UPDATE); + ResourceModifiedSubscriptionMessage msg = new ResourceModifiedSubscriptionMessage(myFhirContext, theResourceToTrigger, ResourceModifiedMessage.OperationTypeEnum.UPDATE); msg.setSubscriptionId(theSubscriptionId); return myExecutorService.submit(() -> { diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/util/SubscriptionDebugLogInterceptor.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/util/SubscriptionDebugLogInterceptor.java index 288ad03b2d5..1f14b47f494 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/util/SubscriptionDebugLogInterceptor.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/util/SubscriptionDebugLogInterceptor.java @@ -25,8 +25,8 @@ import ca.uhn.fhir.interceptor.api.Interceptor; import ca.uhn.fhir.interceptor.api.Pointcut; import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryMatchResult; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscriptionChannelType; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import ca.uhn.fhir.util.StopWatch; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/channel/subscription/BroadcastingSubscribableChannelWrapperTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/channel/subscription/BroadcastingSubscribableChannelWrapperTest.java index 4c29d2b86ad..a48f44b12dd 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/channel/subscription/BroadcastingSubscribableChannelWrapperTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/channel/subscription/BroadcastingSubscribableChannelWrapperTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.jpa.subscription.channel.subscription; import ca.uhn.fhir.jpa.subscription.channel.api.IChannelReceiver; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java index 512bb0a42a8..f1aee3f5541 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java @@ -3,33 +3,35 @@ package ca.uhn.fhir.jpa.subscription.match.deliver; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.api.Pointcut; +import ca.uhn.fhir.jpa.subscription.match.deliver.resthook.SubscriptionDeliveringRestHookSubscriber; +import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryJsonMessage; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; -import ca.uhn.fhir.jpa.subscription.match.deliver.resthook.SubscriptionDeliveringRestHookSubscriber; -import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.IRestfulClientFactory; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Patient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Answers; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; import org.springframework.messaging.support.GenericMessage; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) public class BaseSubscriptionDeliverySubscriberTest { diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/ResourceModifiedTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/ResourceModifiedTest.java index ebe2b40c684..728510cf7a2 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/ResourceModifiedTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/ResourceModifiedTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.jpa.subscription.module; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.r4.model.Organization; import org.junit.jupiter.api.Test; diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java index 743be4dc972..6a5a10dc7bd 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java @@ -113,7 +113,6 @@ public class InMemorySubscriptionMatcherR3Test extends BaseSubscriptionDstu3Test pr.setSubject(new Reference("Patient/")); assertMatched(pr, "ProcedureRequest?intent=original-order"); assertNotMatched(pr, "ProcedureRequest?subject=Patient/123"); - } @Test diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java index aaa6e1c0276..c2bdd952529 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java @@ -11,8 +11,6 @@ import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionLoader; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscriptionChannelType; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; -import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.module.BaseSubscriptionDstu3Test; import ca.uhn.fhir.jpa.subscription.module.subscriber.SubscriptionMatchingSubscriberTest; import ca.uhn.fhir.model.primitive.IdDt; @@ -23,6 +21,8 @@ import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.test.concurrency.IPointcutLatch; import ca.uhn.test.concurrency.PointcutLatch; diff --git a/hapi-fhir-server/pom.xml b/hapi-fhir-server/pom.xml index e57afa70464..bcbf3a23dc0 100644 --- a/hapi-fhir-server/pom.xml +++ b/hapi-fhir-server/pom.xml @@ -73,8 +73,12 @@ org.apache.commons commons-collections4 + + org.springframework + spring-messaging + - + diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/BaseResourceMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceMessage.java similarity index 98% rename from hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/BaseResourceMessage.java rename to hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceMessage.java index ba753078243..0b778c76521 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/BaseResourceMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceMessage.java @@ -1,4 +1,4 @@ -package ca.uhn.fhir.jpa.subscription.model; +package ca.uhn.fhir.rest.server.messaging; /*- * #%L diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/IResourceMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/IResourceMessage.java new file mode 100644 index 00000000000..d06e6e51789 --- /dev/null +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/IResourceMessage.java @@ -0,0 +1,25 @@ +package ca.uhn.fhir.rest.server.messaging; + +/*- + * #%L + * HAPI FHIR Subscription Server + * %% + * Copyright (C) 2014 - 2020 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +public interface IResourceMessage { + String getPayloadId(); +} diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedMessage.java similarity index 81% rename from hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedMessage.java rename to hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedMessage.java index 28bd066cb02..8767e7e5895 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedMessage.java @@ -1,24 +1,4 @@ -package ca.uhn.fhir.jpa.subscription.model; - -/*- - * #%L - * HAPI FHIR Subscription Server - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ +package ca.uhn.fhir.rest.server.messaging; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IModelJson; @@ -41,12 +21,6 @@ public class ResourceModifiedMessage extends BaseResourceMessage implements IRes private String myId; @JsonProperty("operationType") private OperationTypeEnum myOperationType; - /** - * This will only be set if the resource is being triggered for a specific - * subscription - */ - @JsonProperty(value = "subscriptionId", required = false) - private String mySubscriptionId; @JsonProperty("payload") private String myPayload; @JsonProperty("payloadId") @@ -84,14 +58,6 @@ public class ResourceModifiedMessage extends BaseResourceMessage implements IRes return myPayloadId; } - public String getSubscriptionId() { - return mySubscriptionId; - } - - public void setSubscriptionId(String theSubscriptionId) { - mySubscriptionId = theSubscriptionId; - } - public String getId() { return myId; } @@ -189,10 +155,10 @@ public class ResourceModifiedMessage extends BaseResourceMessage implements IRes return new ToStringBuilder(this) .append("myId", myId) .append("myOperationType", myOperationType) - .append("mySubscriptionId", mySubscriptionId) // .append("myPayload", myPayload) .append("myPayloadId", myPayloadId) // .append("myPayloadDecoded", myPayloadDecoded) .toString(); } } + diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedSubscriptionMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedSubscriptionMessage.java new file mode 100644 index 00000000000..9fe55618f7e --- /dev/null +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedSubscriptionMessage.java @@ -0,0 +1,36 @@ +package ca.uhn.fhir.rest.server.messaging; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.hl7.fhir.instance.model.api.IBaseResource; + +public class ResourceModifiedSubscriptionMessage extends ResourceModifiedMessage { + + /** + * This will only be set if the resource is being triggered for a specific + * subscription + */ + @JsonProperty(value = "subscriptionId", required = false) + private String mySubscriptionId; + + public ResourceModifiedSubscriptionMessage() { + } + + public ResourceModifiedSubscriptionMessage(FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) { + super(theFhirContext, theResource, theOperationType); + } + + public ResourceModifiedSubscriptionMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) { + super(theFhirContext, theNewResource, theOperationType, theRequest); + } + + public String getSubscriptionId() { + return mySubscriptionId; + } + + public void setSubscriptionId(String theSubscriptionId) { + mySubscriptionId = theSubscriptionId; + } + +} diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java new file mode 100644 index 00000000000..40d7d7e487e --- /dev/null +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java @@ -0,0 +1,49 @@ +package ca.uhn.fhir.rest.server.messaging.json; + +/*- + * #%L + * HAPI FHIR Subscription Server + * %% + * Copyright (C) 2014 - 2020 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import ca.uhn.fhir.model.api.IModelJson; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHeaders; + +public abstract class BaseJsonMessage implements Message, IModelJson { + + private static final long serialVersionUID = 1L; + @JsonProperty("headers") + private MessageHeaders myHeaders; + + /** + * Constructor + */ + public BaseJsonMessage() { + super(); + } + + @Override + public MessageHeaders getHeaders() { + return myHeaders; + } + + public void setHeaders(MessageHeaders theHeaders) { + myHeaders = theHeaders; + } +} diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedJsonMessage.java similarity index 92% rename from hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedJsonMessage.java rename to hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedJsonMessage.java index f8b8407d686..59ce15b7425 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedJsonMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedJsonMessage.java @@ -1,4 +1,4 @@ -package ca.uhn.fhir.jpa.subscription.model; +package ca.uhn.fhir.rest.server.messaging.json; /*- * #%L @@ -20,6 +20,7 @@ package ca.uhn.fhir.jpa.subscription.model; * #L% */ +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.builder.ToStringBuilder; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedSubscriptionJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedSubscriptionJsonMessage.java new file mode 100644 index 00000000000..7f19ee426b1 --- /dev/null +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedSubscriptionJsonMessage.java @@ -0,0 +1,61 @@ +package ca.uhn.fhir.rest.server.messaging.json; + +/*- + * #%L + * HAPI FHIR Subscription Server + * %% + * Copyright (C) 2014 - 2020 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import ca.uhn.fhir.rest.server.messaging.ResourceModifiedSubscriptionMessage; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.ToStringBuilder; + +public class ResourceModifiedSubscriptionJsonMessage extends BaseJsonMessage { + + @JsonProperty("payload") + private ResourceModifiedSubscriptionMessage myPayload; + + /** + * Constructor + */ + public ResourceModifiedSubscriptionJsonMessage() { + super(); + } + + /** + * Constructor + */ + public ResourceModifiedSubscriptionJsonMessage(ResourceModifiedSubscriptionMessage thePayload) { + myPayload = thePayload; + } + + @Override + public ResourceModifiedSubscriptionMessage getPayload() { + return myPayload; + } + + public void setPayload(ResourceModifiedSubscriptionMessage thePayload) { + myPayload = thePayload; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("myPayload", myPayload) + .toString(); + } +} From 28a9a53917d324c71910c3dca50c7dfd6afe7270 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Thu, 10 Sep 2020 16:05:56 -0400 Subject: [PATCH 03/25] Rework to keep several things in subscription --- .../ca/uhn/fhir/interceptor/api/Pointcut.java | 4 +- .../InMemorySubscriptionMatcherR4Test.java | 5 +- .../RestHookWithInterceptorR4Test.java | 2 +- .../jpa/empi/broker/EmpiMessageHandler.java | 9 +- .../empi/broker/EmpiQueueConsumerLoader.java | 4 +- .../empi/svc/EmpiChannelSubmitterSvcImpl.java | 4 +- .../SubscriptionChannelFactory.java | 2 +- ...bscriptionDeliveringMessageSubscriber.java | 5 +- ...mpositeInMemoryDaoSubscriptionMatcher.java | 2 +- .../matching/DaoSubscriptionMatcher.java | 2 +- .../matching/IResourceModifiedConsumer.java | 2 +- .../matching/ISubscriptionMatcher.java | 3 +- .../matching/InMemorySubscriptionMatcher.java | 2 +- ...aseSubscriberForSubscriptionResources.java | 2 +- .../SubscriptionActivatingSubscriber.java | 4 +- .../SubscriptionMatchingSubscriber.java | 13 +- .../SubscriptionRegisteringSubscriber.java | 4 +- .../subscription/model/BaseJsonMessage.java | 49 ----- .../subscription/model/IResourceMessage.java | 25 --- .../model/LegacyBaseResourceMessage.java | 97 --------- .../LegacyResourceModifiedJsonMessage.java | 60 ------ .../model/LegacyResourceModifiedMessage.java | 198 ------------------ .../model/ResourceDeliveryJsonMessage.java | 1 + .../model/ResourceDeliveryMessage.java | 2 +- .../model}/ResourceModifiedJsonMessage.java | 4 +- .../model/ResourceModifiedMessage.java | 78 +++++++ .../SubscriptionMatcherInterceptor.java | 4 +- .../SubscriptionTriggeringSvcImpl.java | 5 +- .../util/SubscriptionDebugLogInterceptor.java | 2 +- ...castingSubscribableChannelWrapperTest.java | 4 +- ...aseSubscriptionDeliverySubscriberTest.java | 2 +- .../module/ResourceModifiedTest.java | 2 +- ...kingQueueSubscribableChannelDstu3Test.java | 4 +- ....java => BaseResourceModifiedMessage.java} | 44 ++-- .../ResourceModifiedSubscriptionMessage.java | 36 ---- .../messaging/json/BaseJsonMessage.java | 34 +++ ...a => BaseResourceModifiedJsonMessage.java} | 23 +- 37 files changed, 210 insertions(+), 533 deletions(-) delete mode 100644 hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/BaseJsonMessage.java delete mode 100644 hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/IResourceMessage.java delete mode 100644 hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyBaseResourceMessage.java delete mode 100644 hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedJsonMessage.java delete mode 100644 hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedMessage.java rename {hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json => hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model}/ResourceModifiedJsonMessage.java (92%) create mode 100644 hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedMessage.java rename hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/{ResourceModifiedMessage.java => BaseResourceModifiedMessage.java} (75%) delete mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedSubscriptionMessage.java rename hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/{ResourceModifiedSubscriptionJsonMessage.java => BaseResourceModifiedJsonMessage.java} (61%) 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 ec6bf9ee932..b027997a100 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: *

    - *
  • ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage - This parameter should not be modified as processing is complete when this hook is invoked.
  • + *
  • ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage- This parameter should not be modified as processing is complete when this hook is invoked.
  • *
  • ca.uhn.fhir.empi.model.TransactionLogMessages - This parameter is for informational messages provided by the EMPI module during EMPI procesing. .
  • *
*

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

*/ - EMPI_AFTER_PERSISTED_RESOURCE_CHECKED(void.class, "ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage", "ca.uhn.fhir.rest.server.TransactionLogMessages"), + EMPI_AFTER_PERSISTED_RESOURCE_CHECKED(void.class, "ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage", "ca.uhn.fhir.rest.server.TransactionLogMessages"), /** * Performance Tracing Hook: diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR4Test.java index c930738ecb8..439f51a2a19 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR4Test.java @@ -11,6 +11,7 @@ import ca.uhn.fhir.jpa.subscription.match.matcher.matching.InMemorySubscriptionM import ca.uhn.fhir.jpa.subscription.match.matcher.matching.SubscriptionMatchingStrategy; import ca.uhn.fhir.jpa.subscription.match.matcher.matching.SubscriptionStrategyEvaluator; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.util.CoordCalculatorTest; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.rest.param.CompositeParam; @@ -29,8 +30,6 @@ import ca.uhn.fhir.rest.param.TokenOrListParam; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.param.TokenParamModifier; import ca.uhn.fhir.rest.param.UriParam; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedSubscriptionMessage; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -466,7 +465,7 @@ public class InMemorySubscriptionMatcherR4Test { CanonicalSubscription subscription = new CanonicalSubscription(); subscription.setCriteriaString(criteria); subscription.setIdElement(new IdType("Subscription", 123L)); - ResourceModifiedSubscriptionMessage msg = new ResourceModifiedSubscriptionMessage(myFhirContext, patient, ResourceModifiedMessage.OperationTypeEnum.CREATE); + ResourceModifiedMessage msg = new ResourceModifiedMessage(myFhirContext, patient, ResourceModifiedMessage.OperationTypeEnum.CREATE); msg.setSubscriptionId("123"); msg.setId(new IdType("Patient/ABC")); InMemoryMatchResult result = myInMemorySubscriptionMatcher.match(subscription, msg); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithInterceptorR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithInterceptorR4Test.java index cc79578577c..faa775e0771 100755 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithInterceptorR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithInterceptorR4Test.java @@ -10,10 +10,10 @@ import ca.uhn.fhir.jpa.config.StoppableSubscriptionDeliveringRestHookSubscriber; import ca.uhn.fhir.jpa.subscription.BaseSubscriptionsR4Test; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.util.SubscriptionDebugLogInterceptor; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.apache.commons.lang3.Validate; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Observation; 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 94d18540f75..15e7aebc5f4 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 @@ -29,10 +29,11 @@ import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.api.Pointcut; import ca.uhn.fhir.jpa.empi.svc.EmpiMatchLinkSvc; import ca.uhn.fhir.jpa.empi.svc.EmpiResourceFilteringSvc; +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.json.ResourceModifiedJsonMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IAnyResource; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -58,6 +59,7 @@ public class EmpiMessageHandler implements MessageHandler { public void handleMessage(Message theMessage) throws MessagingException { ourLog.info("Handling resource modified message: {}", theMessage); + //TODO GGG TEST THAT THE MESSAGE HEADERS COME IN HERE if (!(theMessage instanceof ResourceModifiedJsonMessage)) { ourLog.warn("Unexpected message payload type: {}", theMessage); return; @@ -95,7 +97,8 @@ public class EmpiMessageHandler implements MessageHandler { } finally { // Interceptor call: EMPI_AFTER_PERSISTED_RESOURCE_CHECKED HookParams params = new HookParams() - .add(ResourceModifiedMessage.class, theMsg) + //Janky upcast. + .add(BaseResourceModifiedMessage.class, (BaseResourceModifiedMessage) theMsg) .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 1e83444a464..a620eb7eb10 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.ResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.json.BaseResourceModifiedJsonMessage; 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, ResourceModifiedJsonMessage.class, config); + myEmpiChannel = myChannelFactory.getOrCreateReceiver(IEmpiSettings.EMPI_CHANNEL_NAME, BaseResourceModifiedJsonMessage.class, config); } if (myEmpiChannel != null) { diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiChannelSubmitterSvcImpl.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiChannelSubmitterSvcImpl.java index 6ebd4747e9f..05ae109316a 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiChannelSubmitterSvcImpl.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiChannelSubmitterSvcImpl.java @@ -24,8 +24,8 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.empi.api.IEmpiChannelSubmitterSvc; import ca.uhn.fhir.jpa.subscription.channel.api.ChannelProducerSettings; import ca.uhn.fhir.jpa.subscription.channel.api.IChannelFactory; -import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/channel/subscription/SubscriptionChannelFactory.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/channel/subscription/SubscriptionChannelFactory.java index fe0b18020e8..a8abc0394eb 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/channel/subscription/SubscriptionChannelFactory.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/channel/subscription/SubscriptionChannelFactory.java @@ -27,7 +27,7 @@ import ca.uhn.fhir.jpa.subscription.channel.api.IChannelProducer; import ca.uhn.fhir.jpa.subscription.channel.api.IChannelReceiver; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionConstants; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryJsonMessage; -import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; import org.apache.commons.lang3.Validate; public class SubscriptionChannelFactory { 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 ccf096bb7f9..9b47757d8aa 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 @@ -28,9 +28,9 @@ import ca.uhn.fhir.jpa.subscription.channel.api.IChannelProducer; import ca.uhn.fhir.jpa.subscription.match.deliver.BaseSubscriptionDeliverySubscriber; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.api.EncodingEnum; -import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IBaseResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,6 +63,7 @@ public class SubscriptionDeliveringMessageSubscriber extends BaseSubscriptionDel } protected void doDelivery(ResourceDeliveryMessage theMsg, CanonicalSubscription theSubscription, IChannelProducer theChannelProducer, IBaseResource thePayloadResource) { + //TODO GGG 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()); ResourceModifiedJsonMessage message = new ResourceModifiedJsonMessage(payload); diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/CompositeInMemoryDaoSubscriptionMatcher.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/CompositeInMemoryDaoSubscriptionMatcher.java index b9833dc1b1e..18351b3b5e7 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/CompositeInMemoryDaoSubscriptionMatcher.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/CompositeInMemoryDaoSubscriptionMatcher.java @@ -23,7 +23,7 @@ package ca.uhn.fhir.jpa.subscription.match.matcher.matching; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryMatchResult; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/DaoSubscriptionMatcher.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/DaoSubscriptionMatcher.java index 057eda8a377..87a69f109ca 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/DaoSubscriptionMatcher.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/DaoSubscriptionMatcher.java @@ -28,8 +28,8 @@ import ca.uhn.fhir.jpa.searchparam.MatchUrlService; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryMatchResult; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.slf4j.Logger; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/IResourceModifiedConsumer.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/IResourceModifiedConsumer.java index 2de668f2bdc..e02a5bdd82d 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/IResourceModifiedConsumer.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/IResourceModifiedConsumer.java @@ -20,8 +20,8 @@ package ca.uhn.fhir.jpa.subscription.match.matcher.matching; * #L% */ +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IBaseResource; public interface IResourceModifiedConsumer { diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/ISubscriptionMatcher.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/ISubscriptionMatcher.java index 091202c2730..0880bbadfb9 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/ISubscriptionMatcher.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/ISubscriptionMatcher.java @@ -22,9 +22,8 @@ package ca.uhn.fhir.jpa.subscription.match.matcher.matching; import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryMatchResult; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; public interface ISubscriptionMatcher { - //TODO GGG convert this to a ResourceModifiedSubscriptionMessage InMemoryMatchResult match(CanonicalSubscription subscription, ResourceModifiedMessage msg); } diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/InMemorySubscriptionMatcher.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/InMemorySubscriptionMatcher.java index 159d579cd7e..5eb0d304e9b 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/InMemorySubscriptionMatcher.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/InMemorySubscriptionMatcher.java @@ -24,8 +24,8 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryMatchResult; import ca.uhn.fhir.jpa.searchparam.matcher.SearchParamMatcher; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/BaseSubscriberForSubscriptionResources.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/BaseSubscriberForSubscriptionResources.java index 419be6b1c8e..c54a6b93113 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/BaseSubscriberForSubscriptionResources.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/BaseSubscriberForSubscriptionResources.java @@ -21,8 +21,8 @@ package ca.uhn.fhir.jpa.subscription.match.matcher.subscriber; */ import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.model.dstu2.valueset.ResourceTypeEnum; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionActivatingSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionActivatingSubscriber.java index cb4bc02f3f1..2a61ee8a1d0 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionActivatingSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionActivatingSubscriber.java @@ -28,9 +28,9 @@ import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionCanonicalizer; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionConstants; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscriptionChannelType; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import ca.uhn.fhir.util.SubscriptionUtil; import org.hl7.fhir.instance.model.api.IBaseResource; import org.slf4j.Logger; 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 da896a6c32f..d54f94020fc 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 @@ -12,10 +12,9 @@ import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryJsonMessage; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.api.EncodingEnum; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; -import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedSubscriptionJsonMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedSubscriptionMessage; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; @@ -81,16 +80,16 @@ public class SubscriptionMatchingSubscriber implements MessageHandler { ourLog.trace("Handling resource modified message: {}", theMessage); //TODO ADD BACKPORT FOR HANDLING OLD LEGACY SUBSCRIPTIONS HERE - if (!(theMessage instanceof ResourceModifiedSubscriptionJsonMessage)) { + if (!(theMessage instanceof ResourceModifiedJsonMessage)) { ourLog.warn("Unexpected message payload type: {}", theMessage); return; } - ResourceModifiedSubscriptionMessage msg = ((ResourceModifiedSubscriptionJsonMessage) theMessage).getPayload(); + ResourceModifiedMessage msg = ((ResourceModifiedJsonMessage) theMessage).getPayload(); matchActiveSubscriptionsAndDeliver(msg); } - public void matchActiveSubscriptionsAndDeliver(ResourceModifiedSubscriptionMessage theMsg) { + public void matchActiveSubscriptionsAndDeliver(ResourceModifiedMessage theMsg) { switch (theMsg.getOperationType()) { case CREATE: case UPDATE: @@ -118,7 +117,7 @@ public class SubscriptionMatchingSubscriber implements MessageHandler { } } - private void doMatchActiveSubscriptionsAndDeliver(ResourceModifiedSubscriptionMessage theMsg) { + private void doMatchActiveSubscriptionsAndDeliver(ResourceModifiedMessage theMsg) { IIdType resourceId = theMsg.getId(myFhirContext); Collection subscriptions = mySubscriptionRegistry.getAll(); diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionRegisteringSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionRegisteringSubscriber.java index cff765be02f..a8b6208fd44 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionRegisteringSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/matcher/subscriber/SubscriptionRegisteringSubscriber.java @@ -23,8 +23,8 @@ package ca.uhn.fhir.jpa.subscription.match.matcher.subscriber; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionCanonicalizer; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; -import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import org.hl7.fhir.instance.model.api.IBaseResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/BaseJsonMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/BaseJsonMessage.java deleted file mode 100644 index 1bb28358726..00000000000 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/BaseJsonMessage.java +++ /dev/null @@ -1,49 +0,0 @@ -package ca.uhn.fhir.jpa.subscription.model; - -/*- - * #%L - * HAPI FHIR Subscription Server - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.model.api.IModelJson; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHeaders; - -public abstract class BaseJsonMessage implements Message, IModelJson { - - private static final long serialVersionUID = 1L; - @JsonProperty("headers") - private MessageHeaders myHeaders; - - /** - * Constructor - */ - public BaseJsonMessage() { - super(); - } - - @Override - public MessageHeaders getHeaders() { - return myHeaders; - } - - public void setHeaders(MessageHeaders theHeaders) { - myHeaders = theHeaders; - } -} diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/IResourceMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/IResourceMessage.java deleted file mode 100644 index 0881b8021c5..00000000000 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/IResourceMessage.java +++ /dev/null @@ -1,25 +0,0 @@ -package ca.uhn.fhir.jpa.subscription.model; - -/*- - * #%L - * HAPI FHIR Subscription Server - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -public interface IResourceMessage { - String getPayloadId(); -} diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyBaseResourceMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyBaseResourceMessage.java deleted file mode 100644 index dfe55214cd4..00000000000 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyBaseResourceMessage.java +++ /dev/null @@ -1,97 +0,0 @@ -package ca.uhn.fhir.jpa.subscription.model; - -/*- - * #%L - * HAPI FHIR Subscription Server - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.model.api.IModelJson; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.Validate; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -@SuppressWarnings("WeakerAccess") -public abstract class LegacyBaseResourceMessage implements IResourceMessage, IModelJson { - - @JsonProperty("attributes") - private Map myAttributes; - - /** - * Returns an attribute stored in this message. - *

- * Attributes are just a spot for user data of any kind to be - * added to the message for pasing along the subscription processing - * pipeline (typically by interceptors). Values will be carried from the beginning to the end. - *

- *

- * Note that messages are designed to be passed into queueing systems - * and serialized as JSON. As a result, only strings are currently allowed - * as values. - *

- */ - public Optional getAttribute(String theKey) { - Validate.notBlank(theKey); - if (myAttributes == null) { - return Optional.empty(); - } - return Optional.ofNullable(myAttributes.get(theKey)); - } - - /** - * Sets an attribute stored in this message. - *

- * Attributes are just a spot for user data of any kind to be - * added to the message for passing along the subscription processing - * pipeline (typically by interceptors). Values will be carried from the beginning to the end. - *

- *

- * Note that messages are designed to be passed into queueing systems - * and serialized as JSON. As a result, only strings are currently allowed - * as values. - *

- * - * @param theKey The key (must not be null or blank) - * @param theValue The value (must not be null) - */ - public void setAttribute(String theKey, String theValue) { - Validate.notBlank(theKey); - Validate.notNull(theValue); - if (myAttributes == null) { - myAttributes = new HashMap<>(); - } - myAttributes.put(theKey, theValue); - } - - /** - * Copies any attributes from the given message into this messsage. - * - * @see #setAttribute(String, String) - * @see #getAttribute(String) - */ - public void copyAdditionalPropertiesFrom(LegacyBaseResourceMessage theMsg) { - if (theMsg.myAttributes != null) { - if (myAttributes == null) { - myAttributes = new HashMap<>(); - } - myAttributes.putAll(theMsg.myAttributes); - } - } -} diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedJsonMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedJsonMessage.java deleted file mode 100644 index 821af831bbc..00000000000 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedJsonMessage.java +++ /dev/null @@ -1,60 +0,0 @@ -package ca.uhn.fhir.jpa.subscription.model; - -/*- - * #%L - * HAPI FHIR Subscription Server - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.ToStringBuilder; - -public class LegacyResourceModifiedJsonMessage extends BaseJsonMessage { - - @JsonProperty("payload") - private LegacyResourceModifiedMessage myPayload; - - /** - * Constructor - */ - public LegacyResourceModifiedJsonMessage() { - super(); - } - - /** - * Constructor - */ - public LegacyResourceModifiedJsonMessage(LegacyResourceModifiedMessage thePayload) { - myPayload = thePayload; - } - - @Override - public LegacyResourceModifiedMessage getPayload() { - return myPayload; - } - - public void setPayload(LegacyResourceModifiedMessage thePayload) { - myPayload = thePayload; - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("myPayload", myPayload) - .toString(); - } -} diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedMessage.java deleted file mode 100644 index f2e8c543889..00000000000 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/LegacyResourceModifiedMessage.java +++ /dev/null @@ -1,198 +0,0 @@ -package ca.uhn.fhir.jpa.subscription.model; - -/*- - * #%L - * HAPI FHIR Subscription Server - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IModelJson; -import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.util.ResourceReferenceInfo; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.instance.model.api.IIdType; - -import java.util.List; - -import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.apache.commons.lang3.StringUtils.isNotBlank; - -public class LegacyResourceModifiedMessage extends LegacyBaseResourceMessage implements IResourceMessage, IModelJson { - - @JsonProperty("resourceId") - private String myId; - @JsonProperty("operationType") - private OperationTypeEnum myOperationType; - /** - * This will only be set if the resource is being triggered for a specific - * subscription - */ - @JsonProperty(value = "subscriptionId", required = false) - private String mySubscriptionId; - @JsonProperty("payload") - private String myPayload; - @JsonProperty("payloadId") - private String myPayloadId; - @JsonProperty("parentTransactionGuid") - private String myParentTransactionGuid; - @JsonIgnore - private transient IBaseResource myPayloadDecoded; - - /** - * Constructor - */ - public LegacyResourceModifiedMessage() { - super(); - } - - public LegacyResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) { - this(); - setId(theResource.getIdElement()); - setOperationType(theOperationType); - if (theOperationType != OperationTypeEnum.DELETE) { - setNewPayload(theFhirContext, theResource); - } - } - - public LegacyResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) { - this(theFhirContext, theNewResource, theOperationType); - if (theRequest != null) { - setParentTransactionGuid(theRequest.getTransactionGuid()); - } - } - - @Override - public String getPayloadId() { - return myPayloadId; - } - - public String getSubscriptionId() { - return mySubscriptionId; - } - - public void setSubscriptionId(String theSubscriptionId) { - mySubscriptionId = theSubscriptionId; - } - - public String getId() { - return myId; - } - - public IIdType getId(FhirContext theCtx) { - IIdType retVal = null; - if (myId != null) { - retVal = theCtx.getVersion().newIdType().setValue(myId); - } - return retVal; - } - - public IBaseResource getNewPayload(FhirContext theCtx) { - if (myPayloadDecoded == null && isNotBlank(myPayload)) { - myPayloadDecoded = theCtx.newJsonParser().parseResource(myPayload); - } - return myPayloadDecoded; - } - - public OperationTypeEnum getOperationType() { - return myOperationType; - } - - public void setOperationType(OperationTypeEnum theOperationType) { - myOperationType = theOperationType; - } - - public void setId(IIdType theId) { - myId = null; - if (theId != null) { - myId = theId.getValue(); - } - } - - public String getParentTransactionGuid() { - return myParentTransactionGuid; - } - - public void setParentTransactionGuid(String theParentTransactionGuid) { - myParentTransactionGuid = theParentTransactionGuid; - } - - private void setNewPayload(FhirContext theCtx, IBaseResource theNewPayload) { - /* - * References with placeholders would be invalid by the time we get here, and - * would be caught before we even get here. This check is basically a last-ditch - * effort to make sure nothing has broken in the various safeguards that - * should prevent this from happening (hence it only being an assert as - * opposed to something executed all the time). - */ - assert payloadContainsNoPlaceholderReferences(theCtx, theNewPayload); - - /* - * Note: Don't set myPayloadDecoded in here- This is a false optimization since - * it doesn't actually get used if anyone is doing subscriptions at any - * scale using a queue engine, and not going through the serialize/deserialize - * as we would in a queue engine can mask bugs. - * -JA - */ - myPayload = theCtx.newJsonParser().encodeResourceToString(theNewPayload); - myPayloadId = theNewPayload.getIdElement().toUnqualified().getValue(); - } - - public enum OperationTypeEnum { - CREATE, - UPDATE, - DELETE, - MANUALLY_TRIGGERED - } - - private static boolean payloadContainsNoPlaceholderReferences(FhirContext theCtx, IBaseResource theNewPayload) { - List refs = theCtx.newTerser().getAllResourceReferences(theNewPayload); - for (ResourceReferenceInfo next : refs) { - String ref = next.getResourceReference().getReferenceElement().getValue(); - if (isBlank(ref)) { - IBaseResource resource = next.getResourceReference().getResource(); - if (resource != null) { - ref = resource.getIdElement().getValue(); - } - } - if (isNotBlank(ref)) { - if (ref.startsWith("#")) { - continue; - } - if (ref.startsWith("urn:uuid:")) { - throw new AssertionError("Reference at " + next.getName() + " is invalid: " + ref); - } - } - } - return true; - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("myId", myId) - .append("myOperationType", myOperationType) - .append("mySubscriptionId", mySubscriptionId) -// .append("myPayload", myPayload) - .append("myPayloadId", myPayloadId) -// .append("myPayloadDecoded", myPayloadDecoded) - .toString(); - } -} diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceDeliveryJsonMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceDeliveryJsonMessage.java index 81bd263ec23..06d0e9a0b99 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceDeliveryJsonMessage.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceDeliveryJsonMessage.java @@ -20,6 +20,7 @@ package ca.uhn.fhir.jpa.subscription.model; * #L% */ +import ca.uhn.fhir.rest.server.messaging.json.BaseJsonMessage; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.builder.ToStringBuilder; 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 aff2b34ed65..46781aac430 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 @@ -24,7 +24,7 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.server.messaging.BaseResourceMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.IResourceMessage; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.builder.ToStringBuilder; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedJsonMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedJsonMessage.java similarity index 92% rename from hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedJsonMessage.java rename to hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedJsonMessage.java index 59ce15b7425..53affa50f14 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedJsonMessage.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedJsonMessage.java @@ -1,4 +1,4 @@ -package ca.uhn.fhir.rest.server.messaging.json; +package ca.uhn.fhir.jpa.subscription.model; /*- * #%L @@ -20,7 +20,7 @@ package ca.uhn.fhir.rest.server.messaging.json; * #L% */ -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.json.BaseJsonMessage; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.builder.ToStringBuilder; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedMessage.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedMessage.java new file mode 100644 index 00000000000..957fa561eec --- /dev/null +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/model/ResourceModifiedMessage.java @@ -0,0 +1,78 @@ +package ca.uhn.fhir.jpa.subscription.model; + +/*- + * #%L + * HAPI FHIR Subscription Server + * %% + * Copyright (C) 2014 - 2020 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.hl7.fhir.instance.model.api.IBaseResource; + +/** + * Most of this class has been moved to ResourceModifiedMessage in the hapi-fhir-server project, for a reusable channel ResourceModifiedMessage + * that doesn't require knowledge of subscriptions. + */ +public class ResourceModifiedMessage extends BaseResourceModifiedMessage { + + /** + * This will only be set if the resource is being triggered for a specific + * subscription + */ + @JsonProperty(value = "subscriptionId", required = false) + private String mySubscriptionId; + + /** + * Constructor + */ + public ResourceModifiedMessage() { + super(); + } + + public ResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) { + super(theFhirContext, theResource, theOperationType); + } + + public ResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) { + super(theFhirContext, theNewResource, theOperationType, theRequest); + } + + + public String getSubscriptionId() { + return mySubscriptionId; + } + + public void setSubscriptionId(String theSubscriptionId) { + mySubscriptionId = theSubscriptionId; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("myId", myId) + .append("myOperationType", myOperationType) + .append("mySubscriptionId", mySubscriptionId) +// .append("myPayload", myPayload) + .append("myPayloadId", myPayloadId) +// .append("myPayloadDecoded", myPayloadDecoded) + .toString(); + } +} diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionMatcherInterceptor.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionMatcherInterceptor.java index a147fe9da12..51e01bd6c69 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionMatcherInterceptor.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionMatcherInterceptor.java @@ -10,10 +10,10 @@ import ca.uhn.fhir.jpa.subscription.channel.impl.LinkedBlockingChannel; import ca.uhn.fhir.jpa.subscription.channel.subscription.SubscriptionChannelFactory; import ca.uhn.fhir.jpa.subscription.match.matcher.matching.IResourceModifiedConsumer; import ca.uhn.fhir.jpa.subscription.match.matcher.subscriber.SubscriptionMatchingSubscriber; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.util.JpaInterceptorBroadcaster; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import com.google.common.annotations.VisibleForTesting; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IBaseResource; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/triggering/SubscriptionTriggeringSvcImpl.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/triggering/SubscriptionTriggeringSvcImpl.java index f966ed90655..84a2d36dd36 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/triggering/SubscriptionTriggeringSvcImpl.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/triggering/SubscriptionTriggeringSvcImpl.java @@ -32,6 +32,7 @@ import ca.uhn.fhir.jpa.model.sched.ScheduledJobDefinition; import ca.uhn.fhir.jpa.searchparam.MatchUrlService; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.subscription.match.matcher.matching.IResourceModifiedConsumer; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.model.dstu2.valueset.ResourceTypeEnum; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.api.CacheControlDirective; @@ -40,8 +41,6 @@ import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedSubscriptionMessage; import ca.uhn.fhir.util.ParametersUtil; import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.util.UrlUtil; @@ -307,7 +306,7 @@ public class SubscriptionTriggeringSvcImpl implements ISubscriptionTriggeringSvc ourLog.info("Submitting resource {} to subscription {}", theResourceToTrigger.getIdElement().toUnqualifiedVersionless().getValue(), theSubscriptionId); - ResourceModifiedSubscriptionMessage msg = new ResourceModifiedSubscriptionMessage(myFhirContext, theResourceToTrigger, ResourceModifiedMessage.OperationTypeEnum.UPDATE); + ResourceModifiedMessage msg = new ResourceModifiedMessage(myFhirContext, theResourceToTrigger, ResourceModifiedMessage.OperationTypeEnum.UPDATE); msg.setSubscriptionId(theSubscriptionId); return myExecutorService.submit(() -> { diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/util/SubscriptionDebugLogInterceptor.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/util/SubscriptionDebugLogInterceptor.java index 1f14b47f494..23083343a0a 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/util/SubscriptionDebugLogInterceptor.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/util/SubscriptionDebugLogInterceptor.java @@ -26,7 +26,7 @@ import ca.uhn.fhir.interceptor.api.Pointcut; import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryMatchResult; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscriptionChannelType; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.util.StopWatch; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/channel/subscription/BroadcastingSubscribableChannelWrapperTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/channel/subscription/BroadcastingSubscribableChannelWrapperTest.java index a48f44b12dd..4c29d2b86ad 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/channel/subscription/BroadcastingSubscribableChannelWrapperTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/channel/subscription/BroadcastingSubscribableChannelWrapperTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.jpa.subscription.channel.subscription; import ca.uhn.fhir.jpa.subscription.channel.api.IChannelReceiver; -import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java index f1aee3f5541..17e3f471021 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java @@ -8,11 +8,11 @@ import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryJsonMessage; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.IRestfulClientFactory; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Patient; import org.junit.jupiter.api.BeforeEach; diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/ResourceModifiedTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/ResourceModifiedTest.java index 728510cf7a2..ebe2b40c684 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/ResourceModifiedTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/ResourceModifiedTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.jpa.subscription.module; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import org.hl7.fhir.r4.model.Organization; import org.junit.jupiter.api.Test; diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java index c2bdd952529..aaa6e1c0276 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java @@ -11,6 +11,8 @@ import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionLoader; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscriptionChannelType; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.module.BaseSubscriptionDstu3Test; import ca.uhn.fhir.jpa.subscription.module.subscriber.SubscriptionMatchingSubscriberTest; import ca.uhn.fhir.model.primitive.IdDt; @@ -21,8 +23,6 @@ import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; -import ca.uhn.fhir.rest.server.messaging.json.ResourceModifiedJsonMessage; -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedMessage; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.test.concurrency.IPointcutLatch; import ca.uhn.test.concurrency.PointcutLatch; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessage.java similarity index 75% rename from hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedMessage.java rename to hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessage.java index 8767e7e5895..1fb5bbfd83b 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessage.java @@ -2,6 +2,8 @@ package ca.uhn.fhir.rest.server.messaging; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IModelJson; +import ca.uhn.fhir.parser.IParser; +import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.util.ResourceReferenceInfo; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -15,29 +17,29 @@ import java.util.List; import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; -public class ResourceModifiedMessage extends BaseResourceMessage implements IResourceMessage, IModelJson { +public class BaseResourceModifiedMessage extends BaseResourceMessage implements IResourceMessage, IModelJson { @JsonProperty("resourceId") - private String myId; + protected String myId; @JsonProperty("operationType") - private OperationTypeEnum myOperationType; + protected OperationTypeEnum myOperationType; @JsonProperty("payload") - private String myPayload; + protected String myPayload; @JsonProperty("payloadId") - private String myPayloadId; + protected String myPayloadId; @JsonProperty("parentTransactionGuid") - private String myParentTransactionGuid; + protected String myParentTransactionGuid; @JsonIgnore - private transient IBaseResource myPayloadDecoded; + protected transient IBaseResource myPayloadDecoded; /** * Constructor */ - public ResourceModifiedMessage() { + public BaseResourceModifiedMessage() { super(); } - public ResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) { + public BaseResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) { this(); setId(theResource.getIdElement()); setOperationType(theOperationType); @@ -46,7 +48,7 @@ public class ResourceModifiedMessage extends BaseResourceMessage implements IRes } } - public ResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) { + public BaseResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) { this(theFhirContext, theNewResource, theOperationType); if (theRequest != null) { setParentTransactionGuid(theRequest.getTransactionGuid()); @@ -77,6 +79,24 @@ public class ResourceModifiedMessage extends BaseResourceMessage implements IRes return myPayloadDecoded; } + public IBaseResource getPayload(FhirContext theCtx) { + IBaseResource retVal = myPayloadDecoded; + if (retVal == null && isNotBlank(myPayload)) { + IParser parser = EncodingEnum.detectEncoding(myPayload).newParser(theCtx); + retVal = parser.parseResource(myPayload); + myPayloadDecoded = retVal; + } + return retVal; + } + + public String getPayloadString() { + if (this.myPayload != null) { + return this.myPayload; + } + + return ""; + } + public OperationTypeEnum getOperationType() { return myOperationType; } @@ -100,7 +120,7 @@ public class ResourceModifiedMessage extends BaseResourceMessage implements IRes myParentTransactionGuid = theParentTransactionGuid; } - private 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 * would be caught before we even get here. This check is basically a last-ditch @@ -128,7 +148,7 @@ public class ResourceModifiedMessage extends BaseResourceMessage implements IRes MANUALLY_TRIGGERED } - private static boolean payloadContainsNoPlaceholderReferences(FhirContext theCtx, IBaseResource theNewPayload) { + protected static boolean payloadContainsNoPlaceholderReferences(FhirContext theCtx, IBaseResource theNewPayload) { List refs = theCtx.newTerser().getAllResourceReferences(theNewPayload); for (ResourceReferenceInfo next : refs) { String ref = next.getResourceReference().getReferenceElement().getValue(); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedSubscriptionMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedSubscriptionMessage.java deleted file mode 100644 index 9fe55618f7e..00000000000 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceModifiedSubscriptionMessage.java +++ /dev/null @@ -1,36 +0,0 @@ -package ca.uhn.fhir.rest.server.messaging; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.rest.api.server.RequestDetails; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.hl7.fhir.instance.model.api.IBaseResource; - -public class ResourceModifiedSubscriptionMessage extends ResourceModifiedMessage { - - /** - * This will only be set if the resource is being triggered for a specific - * subscription - */ - @JsonProperty(value = "subscriptionId", required = false) - private String mySubscriptionId; - - public ResourceModifiedSubscriptionMessage() { - } - - public ResourceModifiedSubscriptionMessage(FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) { - super(theFhirContext, theResource, theOperationType); - } - - public ResourceModifiedSubscriptionMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) { - super(theFhirContext, theNewResource, theOperationType, theRequest); - } - - public String getSubscriptionId() { - return mySubscriptionId; - } - - public void setSubscriptionId(String theSubscriptionId) { - mySubscriptionId = theSubscriptionId; - } - -} diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java index 40d7d7e487e..0edf77cf96f 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java @@ -25,23 +25,57 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + public abstract class BaseJsonMessage implements Message, IModelJson { private static final long serialVersionUID = 1L; @JsonProperty("headers") private MessageHeaders myHeaders; + private String RETRY_COUNT_HEADER = "retryCount"; + private String FIRST_FAILURE_HEADER = "firstFailure"; + private String LAST_FAILURE_HEADER = "lastFailure"; + /** * Constructor */ public BaseJsonMessage() { super(); + setDefaultRetryHeaders(); + } + + protected void setDefaultRetryHeaders() { + Map headers = new HashMap<>(); + headers.put(RETRY_COUNT_HEADER, 0); + headers.put(FIRST_FAILURE_HEADER, null); + headers.put(LAST_FAILURE_HEADER, null); + MessageHeaders messageHeaders = new MessageHeaders(headers); + setHeaders(messageHeaders); } @Override public MessageHeaders getHeaders() { return myHeaders; } + public final Integer getRetryCount() { + //TODO GGG this is not NPE-safe + return (Integer)this.getHeaders().get(RETRY_COUNT_HEADER); + } + + public final Date getFirstFailureDate() { + //TODO GGG this is not NPE-safe + return (Date)this.getHeaders().get(FIRST_FAILURE_HEADER); + + } + + public final Date getLastFailureDate() { + //TODO GGG this is not NPE-safe + return (Date)this.getHeaders().get(LAST_FAILURE_HEADER); + + } public void setHeaders(MessageHeaders theHeaders) { myHeaders = theHeaders; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedSubscriptionJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseResourceModifiedJsonMessage.java similarity index 61% rename from hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedSubscriptionJsonMessage.java rename to hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseResourceModifiedJsonMessage.java index 7f19ee426b1..df43b0f9970 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceModifiedSubscriptionJsonMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseResourceModifiedJsonMessage.java @@ -20,35 +20,44 @@ package ca.uhn.fhir.rest.server.messaging.json; * #L% */ -import ca.uhn.fhir.rest.server.messaging.ResourceModifiedSubscriptionMessage; +import ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.builder.ToStringBuilder; +import org.springframework.messaging.MessageHeaders; + +public class BaseResourceModifiedJsonMessage extends BaseJsonMessage { -public class ResourceModifiedSubscriptionJsonMessage extends BaseJsonMessage { @JsonProperty("payload") - private ResourceModifiedSubscriptionMessage myPayload; + private BaseResourceModifiedMessage myPayload; /** * Constructor */ - public ResourceModifiedSubscriptionJsonMessage() { + public BaseResourceModifiedJsonMessage() { super(); } /** * Constructor */ - public ResourceModifiedSubscriptionJsonMessage(ResourceModifiedSubscriptionMessage thePayload) { + public BaseResourceModifiedJsonMessage(BaseResourceModifiedMessage thePayload) { myPayload = thePayload; + setDefaultRetryHeaders(); } + public BaseResourceModifiedJsonMessage(MessageHeaders theRetryMessageHeaders, BaseResourceModifiedMessage thePayload) { + myPayload = thePayload; + setHeaders(theRetryMessageHeaders); + } + + @Override - public ResourceModifiedSubscriptionMessage getPayload() { + public BaseResourceModifiedMessage getPayload() { return myPayload; } - public void setPayload(ResourceModifiedSubscriptionMessage thePayload) { + public void setPayload(BaseResourceModifiedMessage thePayload) { myPayload = thePayload; } From c3ddf59d6fd699d35471ce31968ca66a8a4c4ae5 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 14 Sep 2020 13:02:32 -0400 Subject: [PATCH 04/25] Add HapiMessageHeaders to BaseJsonMessage class --- .../InMemorySubscriptionMatcherR3Test.java | 16 ---- .../messaging/json/BaseJsonMessage.java | 86 ++++++++++++++++++- .../json/BaseResourceModifiedJsonMessage.java | 3 +- .../json/MessageHeaderDeserializer.java | 24 ++++++ 4 files changed, 108 insertions(+), 21 deletions(-) create mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/MessageHeaderDeserializer.java diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java index 6a5a10dc7bd..c5eb62b95ec 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java @@ -10,8 +10,6 @@ import ca.uhn.fhir.jpa.subscription.module.BaseSubscriptionDstu3Test; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.server.SimpleBundleProvider; import ca.uhn.fhir.util.UrlUtil; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import org.hl7.fhir.dstu3.model.BodySite; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Coding; @@ -38,12 +36,9 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.messaging.MessageHeaders; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; -import java.util.Map; import java.util.Set; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -115,17 +110,6 @@ public class InMemorySubscriptionMatcherR3Test extends BaseSubscriptionDstu3Test assertNotMatched(pr, "ProcedureRequest?subject=Patient/123"); } - @Test - public void testSerializationOfMessageHeaders() throws JsonProcessingException { - Map headers = new HashMap<>(); - headers.put("zoop", "zoop"); - MessageHeaders mh = new MessageHeaders(headers); - - ObjectMapper mapper = new ObjectMapper(); - //Test that serialization of MessageHeaders works. - mapper.writeValueAsString(mh); - } - @Test public void testResourceById() { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java index 0edf77cf96f..ae9cb3ced38 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java @@ -25,15 +25,17 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Set; public abstract class BaseJsonMessage implements Message, IModelJson { private static final long serialVersionUID = 1L; @JsonProperty("headers") - private MessageHeaders myHeaders; + private HapiMessageHeaders myHeaders; private String RETRY_COUNT_HEADER = "retryCount"; private String FIRST_FAILURE_HEADER = "firstFailure"; @@ -46,20 +48,98 @@ public abstract class BaseJsonMessage implements Message, IModelJson { super(); setDefaultRetryHeaders(); } + public static class HapiMessageHeaders implements Map{ + + private final Map headers; + + public HapiMessageHeaders(Map theHeaders) { + headers = theHeaders; + } + + public HapiMessageHeaders() { + headers = new HashMap<>(); + } + + + @Override + public int size() { + return this.headers.size(); + } + + @Override + public boolean isEmpty() { + return this.headers.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return this.headers.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return this.headers.containsValue(value); + } + + @Override + public Object get(Object key) { + return this.headers.get(key); + } + + @Override + public Object put(String key, Object value) { + return this.headers.put(key, value); + } + + @Override + public Object remove(Object key) { + return this.headers.remove(key); + } + + @Override + public void putAll(Map m) { + this.headers.putAll(m); + } + + @Override + public void clear() { + this.headers.clear(); + } + + @Override + public Set keySet() { + return this.headers.keySet(); + } + + @Override + public Collection values() { + return this.headers.values(); + } + + @Override + public Set> entrySet() { + return this.headers.entrySet(); + } + } protected void setDefaultRetryHeaders() { Map headers = new HashMap<>(); headers.put(RETRY_COUNT_HEADER, 0); headers.put(FIRST_FAILURE_HEADER, null); headers.put(LAST_FAILURE_HEADER, null); - MessageHeaders messageHeaders = new MessageHeaders(headers); + HapiMessageHeaders messageHeaders = new HapiMessageHeaders(headers); setHeaders(messageHeaders); } @Override public MessageHeaders getHeaders() { + return new MessageHeaders(myHeaders); + } + + public HapiMessageHeaders getHapiHeaders() { return myHeaders; } + public final Integer getRetryCount() { //TODO GGG this is not NPE-safe return (Integer)this.getHeaders().get(RETRY_COUNT_HEADER); @@ -77,7 +157,7 @@ public abstract class BaseJsonMessage implements Message, IModelJson { } - public void setHeaders(MessageHeaders theHeaders) { + public void setHeaders(HapiMessageHeaders theHeaders) { myHeaders = theHeaders; } } 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 index df43b0f9970..2cdf57b1b6a 100644 --- 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 @@ -23,7 +23,6 @@ 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; -import org.springframework.messaging.MessageHeaders; public class BaseResourceModifiedJsonMessage extends BaseJsonMessage { @@ -46,7 +45,7 @@ public class BaseResourceModifiedJsonMessage extends BaseJsonMessage { + @Override + public MessageHeaders deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { + JsonNode node = p.getCodec().readTree(p); + return null; + } + + @Override + public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException { + return super.deserializeWithType(p, ctxt, typeDeserializer); + } +} From 2e1f2a662a44944b68677f5b4d4f6ce3dfc72e9d Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 14 Sep 2020 13:20:01 -0400 Subject: [PATCH 05/25] Move class to top level, add tests --- .../messaging/json/BaseJsonMessage.java | 105 +---------------- .../messaging/json/HapiMessageHeaders.java | 108 ++++++++++++++++++ .../BaseResourceModifiedMessageTest.java | 33 ++++++ 3 files changed, 143 insertions(+), 103 deletions(-) create mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java create mode 100644 hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java index ae9cb3ced38..bb422fc25c2 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java @@ -25,21 +25,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - public abstract class BaseJsonMessage implements Message, IModelJson { private static final long serialVersionUID = 1L; @JsonProperty("headers") private HapiMessageHeaders myHeaders; - private String RETRY_COUNT_HEADER = "retryCount"; - private String FIRST_FAILURE_HEADER = "firstFailure"; - private String LAST_FAILURE_HEADER = "lastFailure"; /** * Constructor @@ -48,86 +39,10 @@ public abstract class BaseJsonMessage implements Message, IModelJson { super(); setDefaultRetryHeaders(); } - public static class HapiMessageHeaders implements Map{ - - private final Map headers; - - public HapiMessageHeaders(Map theHeaders) { - headers = theHeaders; - } - - public HapiMessageHeaders() { - headers = new HashMap<>(); - } - - - @Override - public int size() { - return this.headers.size(); - } - - @Override - public boolean isEmpty() { - return this.headers.isEmpty(); - } - - @Override - public boolean containsKey(Object key) { - return this.headers.containsKey(key); - } - - @Override - public boolean containsValue(Object value) { - return this.headers.containsValue(value); - } - - @Override - public Object get(Object key) { - return this.headers.get(key); - } - - @Override - public Object put(String key, Object value) { - return this.headers.put(key, value); - } - - @Override - public Object remove(Object key) { - return this.headers.remove(key); - } - - @Override - public void putAll(Map m) { - this.headers.putAll(m); - } - - @Override - public void clear() { - this.headers.clear(); - } - - @Override - public Set keySet() { - return this.headers.keySet(); - } - - @Override - public Collection values() { - return this.headers.values(); - } - - @Override - public Set> entrySet() { - return this.headers.entrySet(); - } - } protected void setDefaultRetryHeaders() { - Map headers = new HashMap<>(); - headers.put(RETRY_COUNT_HEADER, 0); - headers.put(FIRST_FAILURE_HEADER, null); - headers.put(LAST_FAILURE_HEADER, null); - HapiMessageHeaders messageHeaders = new HapiMessageHeaders(headers); + HapiMessageHeaders messageHeaders = new HapiMessageHeaders(); + messageHeaders.initializeDefaultRetryValues(); setHeaders(messageHeaders); } @@ -140,22 +55,6 @@ public abstract class BaseJsonMessage implements Message, IModelJson { return myHeaders; } - public final Integer getRetryCount() { - //TODO GGG this is not NPE-safe - return (Integer)this.getHeaders().get(RETRY_COUNT_HEADER); - } - - public final Date getFirstFailureDate() { - //TODO GGG this is not NPE-safe - return (Date)this.getHeaders().get(FIRST_FAILURE_HEADER); - - } - - public final Date getLastFailureDate() { - //TODO GGG this is not NPE-safe - return (Date)this.getHeaders().get(LAST_FAILURE_HEADER); - - } public void setHeaders(HapiMessageHeaders theHeaders) { myHeaders = theHeaders; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java new file mode 100644 index 00000000000..17bf3488270 --- /dev/null +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java @@ -0,0 +1,108 @@ +package ca.uhn.fhir.rest.server.messaging.json; + +import ca.uhn.fhir.model.api.IModelJson; + +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class HapiMessageHeaders implements Map, IModelJson { + public static String RETRY_COUNT_HEADER = "retryCount"; + public static String FIRST_FAILURE_HEADER = "firstFailure"; + public static String LAST_FAILURE_HEADER = "lastFailure"; + + private final Map headers; + + public HapiMessageHeaders(Map theHeaders) { + headers = theHeaders; + } + + public HapiMessageHeaders() { + headers = new HashMap<>(); + } + + + @Override + public int size() { + return this.headers.size(); + } + + @Override + public boolean isEmpty() { + return this.headers.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return this.headers.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return this.headers.containsValue(value); + } + + @Override + public Object get(Object key) { + return this.headers.get(key); + } + + @Override + public Object put(String key, Object value) { + return this.headers.put(key, value); + } + + @Override + public Object remove(Object key) { + return this.headers.remove(key); + } + + @Override + public void putAll(Map m) { + this.headers.putAll(m); + } + + @Override + public void clear() { + this.headers.clear(); + } + + @Override + public Set keySet() { + return this.headers.keySet(); + } + + @Override + public Collection values() { + return this.headers.values(); + } + + @Override + public Set> entrySet() { + return this.headers.entrySet(); + } + + public Integer getRetryCount() { + return (Integer)this.getHeaders().get(RETRY_COUNT_HEADER); + } + + public Date getFirstFailureDate() { + return (Date)this.getHeaders().get(FIRST_FAILURE_HEADER); + + } + + public Date getLastFailureDate() { + return (Date)this.getHeaders().get(LAST_FAILURE_HEADER); + + } + public Map getHeaders() { + return this.headers; + } + public void initializeDefaultRetryValues() { + headers.put(RETRY_COUNT_HEADER, 0); + headers.put(FIRST_FAILURE_HEADER, null); + headers.put(LAST_FAILURE_HEADER, null); + } +} 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 new file mode 100644 index 00000000000..f001236e0e1 --- /dev/null +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/messaging/BaseResourceModifiedMessageTest.java @@ -0,0 +1,33 @@ +package ca.uhn.fhir.rest.server.messaging; + +import ca.uhn.fhir.rest.server.messaging.json.BaseResourceModifiedJsonMessage; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +import static ca.uhn.fhir.rest.server.messaging.json.HapiMessageHeaders.FIRST_FAILURE_HEADER; +import static ca.uhn.fhir.rest.server.messaging.json.HapiMessageHeaders.LAST_FAILURE_HEADER; +import static ca.uhn.fhir.rest.server.messaging.json.HapiMessageHeaders.RETRY_COUNT_HEADER; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class BaseResourceModifiedMessageTest { + + @Test + public void testSerializationAndDeserializationOfResourceModifiedMessage() throws JsonProcessingException { + BaseResourceModifiedJsonMessage jsonMessage = new BaseResourceModifiedJsonMessage(); + jsonMessage.setPayload(new BaseResourceModifiedMessage()); + ObjectMapper mapper = new ObjectMapper(); + String serialized = mapper.writeValueAsString(jsonMessage); + jsonMessage = mapper.readValue(serialized, BaseResourceModifiedJsonMessage.class); + + assertThat(jsonMessage.getHapiHeaders().getRetryCount(), is(equalTo(0))); + assertThat(jsonMessage.getHapiHeaders().getFirstFailureDate(), is(equalTo(null))); + assertThat(jsonMessage.getHapiHeaders().getLastFailureDate(), is(equalTo(null))); + + assertThat(jsonMessage.getHeaders().get(RETRY_COUNT_HEADER), is(equalTo(0))); + assertThat(jsonMessage.getHeaders().get(FIRST_FAILURE_HEADER), is(equalTo(null))); + assertThat(jsonMessage.getHeaders().get(LAST_FAILURE_HEADER), is(equalTo(null))); + } +} From 3e324355f26f6c11d4ab96fa575f590dfee289f8 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 14 Sep 2020 13:28:36 -0400 Subject: [PATCH 06/25] Add javadocs --- .../server/messaging/json/HapiMessageHeaders.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java index 17bf3488270..e4e6d847621 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java @@ -8,6 +8,12 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +/** + * This class is for holding headers for BaseJsonMessages. Any serializable data can be thrown into + * the header map. There are also three special headers, defined by the constants in this class, which are for use + * in message handling retrying. There are also matching helper functions for fetching those special variables; however + * they can also be accessed in standard map fashion with a `get` on the map. + */ public class HapiMessageHeaders implements Map, IModelJson { public static String RETRY_COUNT_HEADER = "retryCount"; public static String FIRST_FAILURE_HEADER = "firstFailure"; @@ -100,7 +106,11 @@ public class HapiMessageHeaders implements Map, IModelJson { public Map getHeaders() { return this.headers; } - public void initializeDefaultRetryValues() { + + /** + * Sets deffault values for the special headers that HAPI cares about during retry. + */ + public void initializeDefaultRetryValues() { headers.put(RETRY_COUNT_HEADER, 0); headers.put(FIRST_FAILURE_HEADER, null); headers.put(LAST_FAILURE_HEADER, null); From 9a09a8abf3a0f3b24804553bed52b1a80b74a6be Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 14 Sep 2020 13:41:11 -0400 Subject: [PATCH 07/25] Update todos --- .../java/ca/uhn/fhir/jpa/empi/broker/EmpiMessageHandler.java | 1 - .../message/SubscriptionDeliveringMessageSubscriber.java | 2 +- .../ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) 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 15e7aebc5f4..70fd1f39569 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 @@ -59,7 +59,6 @@ public class EmpiMessageHandler implements MessageHandler { public void handleMessage(Message theMessage) throws MessagingException { ourLog.info("Handling resource modified message: {}", theMessage); - //TODO GGG TEST THAT THE MESSAGE HEADERS COME IN HERE if (!(theMessage instanceof ResourceModifiedJsonMessage)) { ourLog.warn("Unexpected message payload type: {}", theMessage); return; 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 9b47757d8aa..c953196f90d 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,7 @@ public class SubscriptionDeliveringMessageSubscriber extends BaseSubscriptionDel } protected void doDelivery(ResourceDeliveryMessage theMsg, CanonicalSubscription theSubscription, IChannelProducer theChannelProducer, IBaseResource thePayloadResource) { - //TODO GGG 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()); payload.setParentTransactionGuid(theMsg.getParentTransactionGuid()); ResourceModifiedJsonMessage message = new ResourceModifiedJsonMessage(payload); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java index bb422fc25c2..40e87c76a24 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java @@ -31,7 +31,6 @@ public abstract class BaseJsonMessage implements Message, IModelJson { @JsonProperty("headers") private HapiMessageHeaders myHeaders; - /** * Constructor */ From f20c42a8bd92167c322950f98ce2fa29361124f6 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 14 Sep 2020 13:48:44 -0400 Subject: [PATCH 08/25] Remove license claims, remove dead class --- .../server/messaging/BaseResourceMessage.java | 20 +--------------- .../server/messaging/IResourceMessage.java | 20 +--------------- .../messaging/json/BaseJsonMessage.java | 19 --------------- .../json/BaseResourceModifiedJsonMessage.java | 20 ---------------- .../json/MessageHeaderDeserializer.java | 24 ------------------- 5 files changed, 2 insertions(+), 101 deletions(-) delete mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/MessageHeaderDeserializer.java 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 0b778c76521..44c59fac5f7 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 @@ -1,24 +1,6 @@ package ca.uhn.fhir.rest.server.messaging; -/*- - * #%L - * HAPI FHIR Subscription Server - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ + import ca.uhn.fhir.model.api.IModelJson; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/IResourceMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/IResourceMessage.java index d06e6e51789..d2432451091 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/IResourceMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/IResourceMessage.java @@ -1,24 +1,6 @@ package ca.uhn.fhir.rest.server.messaging; -/*- - * #%L - * HAPI FHIR Subscription Server - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ + public interface IResourceMessage { String getPayloadId(); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java index 40e87c76a24..6d73558cddc 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java @@ -1,24 +1,5 @@ package ca.uhn.fhir.rest.server.messaging.json; -/*- - * #%L - * HAPI FHIR Subscription Server - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ import ca.uhn.fhir.model.api.IModelJson; import com.fasterxml.jackson.annotation.JsonProperty; 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 index 2cdf57b1b6a..ee1e9f47876 100644 --- 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 @@ -1,25 +1,5 @@ package ca.uhn.fhir.rest.server.messaging.json; -/*- - * #%L - * HAPI FHIR Subscription Server - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - import ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.builder.ToStringBuilder; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/MessageHeaderDeserializer.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/MessageHeaderDeserializer.java deleted file mode 100644 index f1ca5e3010b..00000000000 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/MessageHeaderDeserializer.java +++ /dev/null @@ -1,24 +0,0 @@ -package ca.uhn.fhir.rest.server.messaging.json; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.jsontype.TypeDeserializer; -import org.springframework.messaging.MessageHeaders; - -import java.io.IOException; - -public class MessageHeaderDeserializer extends JsonDeserializer { - @Override - public MessageHeaders deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { - JsonNode node = p.getCodec().readTree(p); - return null; - } - - @Override - public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException { - return super.deserializeWithType(p, ctxt, typeDeserializer); - } -} From 6e0ef035e935cbd47ba843616d9977ebfe0cddd5 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 14 Sep 2020 15:35:58 -0400 Subject: [PATCH 09/25] Rename constants. Remove dead comment --- .../SubscriptionMatchingSubscriber.java | 1 - .../messaging/json/HapiMessageHeaders.java | 18 +++++++++--------- .../BaseResourceModifiedMessageTest.java | 12 ++++++------ 3 files changed, 15 insertions(+), 16 deletions(-) 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 d54f94020fc..169a039fc94 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 @@ -79,7 +79,6 @@ public class SubscriptionMatchingSubscriber implements MessageHandler { public void handleMessage(@Nonnull Message theMessage) throws MessagingException { ourLog.trace("Handling resource modified message: {}", theMessage); - //TODO ADD BACKPORT FOR HANDLING OLD LEGACY SUBSCRIPTIONS HERE if (!(theMessage instanceof ResourceModifiedJsonMessage)) { ourLog.warn("Unexpected message payload type: {}", theMessage); return; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java index e4e6d847621..58e5819ed41 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java @@ -15,9 +15,9 @@ import java.util.Set; * they can also be accessed in standard map fashion with a `get` on the map. */ public class HapiMessageHeaders implements Map, IModelJson { - public static String RETRY_COUNT_HEADER = "retryCount"; - public static String FIRST_FAILURE_HEADER = "firstFailure"; - public static String LAST_FAILURE_HEADER = "lastFailure"; + public static String RETRY_COUNT_KEY = "retryCount"; + public static String FIRST_FAILURE_KEY = "firstFailure"; + public static String LAST_FAILURE_KEY = "lastFailure"; private final Map headers; @@ -91,16 +91,16 @@ public class HapiMessageHeaders implements Map, IModelJson { } public Integer getRetryCount() { - return (Integer)this.getHeaders().get(RETRY_COUNT_HEADER); + return (Integer)this.getHeaders().get(RETRY_COUNT_KEY); } public Date getFirstFailureDate() { - return (Date)this.getHeaders().get(FIRST_FAILURE_HEADER); + return (Date)this.getHeaders().get(FIRST_FAILURE_KEY); } public Date getLastFailureDate() { - return (Date)this.getHeaders().get(LAST_FAILURE_HEADER); + return (Date)this.getHeaders().get(LAST_FAILURE_KEY); } public Map getHeaders() { @@ -111,8 +111,8 @@ public class HapiMessageHeaders implements Map, IModelJson { * Sets deffault values for the special headers that HAPI cares about during retry. */ public void initializeDefaultRetryValues() { - headers.put(RETRY_COUNT_HEADER, 0); - headers.put(FIRST_FAILURE_HEADER, null); - headers.put(LAST_FAILURE_HEADER, null); + headers.put(RETRY_COUNT_KEY, 0); + headers.put(FIRST_FAILURE_KEY, null); + headers.put(LAST_FAILURE_KEY, null); } } 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 f001236e0e1..d8529fcd671 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 @@ -5,9 +5,9 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; -import static ca.uhn.fhir.rest.server.messaging.json.HapiMessageHeaders.FIRST_FAILURE_HEADER; -import static ca.uhn.fhir.rest.server.messaging.json.HapiMessageHeaders.LAST_FAILURE_HEADER; -import static ca.uhn.fhir.rest.server.messaging.json.HapiMessageHeaders.RETRY_COUNT_HEADER; +import static ca.uhn.fhir.rest.server.messaging.json.HapiMessageHeaders.FIRST_FAILURE_KEY; +import static ca.uhn.fhir.rest.server.messaging.json.HapiMessageHeaders.LAST_FAILURE_KEY; +import static ca.uhn.fhir.rest.server.messaging.json.HapiMessageHeaders.RETRY_COUNT_KEY; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -26,8 +26,8 @@ class BaseResourceModifiedMessageTest { assertThat(jsonMessage.getHapiHeaders().getFirstFailureDate(), is(equalTo(null))); assertThat(jsonMessage.getHapiHeaders().getLastFailureDate(), is(equalTo(null))); - assertThat(jsonMessage.getHeaders().get(RETRY_COUNT_HEADER), is(equalTo(0))); - assertThat(jsonMessage.getHeaders().get(FIRST_FAILURE_HEADER), is(equalTo(null))); - assertThat(jsonMessage.getHeaders().get(LAST_FAILURE_HEADER), is(equalTo(null))); + assertThat(jsonMessage.getHeaders().get(RETRY_COUNT_KEY), is(equalTo(0))); + assertThat(jsonMessage.getHeaders().get(FIRST_FAILURE_KEY), is(equalTo(null))); + assertThat(jsonMessage.getHeaders().get(LAST_FAILURE_KEY), is(equalTo(null))); } } From a9fb849d497226c331c9b6dfdc7a2f0af32e49cf Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 14 Sep 2020 16:44:50 -0400 Subject: [PATCH 10/25] Moved more into parent class, added javadocs for transactionId --- .../jpa/empi/broker/EmpiMessageHandler.java | 2 +- ...bscriptionDeliveringMessageSubscriber.java | 2 +- .../SubscriptionMatchingSubscriber.java | 2 +- .../model/ResourceDeliveryMessage.java | 26 +-------- .../server/messaging/BaseResourceMessage.java | 55 +++++++++++++++++++ .../BaseResourceModifiedMessage.java | 29 +--------- 6 files changed, 62 insertions(+), 54 deletions(-) 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) { From 5744f7035ff9ad34b18f97869a62a0c629efdebe Mon Sep 17 00:00:00 2001 From: Tadgh Date: Mon, 14 Sep 2020 16:54:09 -0400 Subject: [PATCH 11/25] Rename to match names across classes --- .../jpa/subscription/model/ResourceDeliveryMessage.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 8a5a6a59c5d..5f9f5b57223 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 @@ -43,7 +43,7 @@ public class ResourceDeliveryMessage extends BaseResourceMessage implements IRes @JsonProperty("payloadId") private String myPayloadId; @JsonIgnore - private transient IBaseResource myPayload; + private transient IBaseResource myPayloadDecoded; /** * Constructor @@ -53,11 +53,11 @@ public class ResourceDeliveryMessage extends BaseResourceMessage implements IRes } public IBaseResource getPayload(FhirContext theCtx) { - IBaseResource retVal = myPayload; + IBaseResource retVal = myPayloadDecoded; if (retVal == null && isNotBlank(myPayloadString)) { IParser parser = EncodingEnum.detectEncoding(myPayloadString).newParser(theCtx); retVal = parser.parseResource(myPayloadString); - myPayload = retVal; + myPayloadDecoded = retVal; } return retVal; } @@ -115,7 +115,7 @@ public class ResourceDeliveryMessage extends BaseResourceMessage implements IRes return new ToStringBuilder(this) .append("mySubscription", mySubscription) .append("myPayloadString", myPayloadString) - .append("myPayload", myPayload) + .append("myPayload", myPayloadDecoded) .append("myPayloadId", myPayloadId) .append("myOperationType", getOperationType()) .toString(); From ea64bea1b03fe4823cb45bcef30eb837af93b00e Mon Sep 17 00:00:00 2001 From: Tadgh Date: Tue, 15 Sep 2020 15:27:21 -0400 Subject: [PATCH 12/25] 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: *

    - *
  • ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage- This parameter should not be modified as processing is complete when this hook is invoked.
  • + *
  • ca.uhn.fhir.rest.server.messaging.ConcreteResourceModifiedMessage- This parameter should not be modified as processing is complete when this hook is invoked.
  • *
  • ca.uhn.fhir.empi.model.TransactionLogMessages - This parameter is for informational messages provided by the EMPI module during EMPI procesing. .
  • *
*

@@ -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))); From 3ca1a42d378cec4fee0b0b588ab2e33bd91f8407 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Tue, 15 Sep 2020 15:37:24 -0400 Subject: [PATCH 13/25] Swap EMPI channel consumer to use Subscription ResourceModifiedMessages --- .../ca/uhn/fhir/jpa/empi/broker/EmpiQueueConsumerLoader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 647a5b2b9c4..fc9f4eb005c 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.ConcreteResourceModifiedJsonMessage; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; 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, ConcreteResourceModifiedJsonMessage.class, config); + myEmpiChannel = myChannelFactory.getOrCreateReceiver(IEmpiSettings.EMPI_CHANNEL_NAME, ResourceModifiedJsonMessage.class, config); } if (myEmpiChannel != null) { From 74bba9dbcc9219fb4de00b50fa6ed4ca790524e6 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Tue, 15 Sep 2020 18:57:55 -0400 Subject: [PATCH 14/25] Rename to ResourceOperationMessage --- .../ca/uhn/fhir/interceptor/api/Pointcut.java | 4 +- .../jpa/empi/broker/EmpiMessageHandler.java | 7 ++- .../server/messaging/BaseResourceMessage.java | 2 +- .../ConcreteResourceModifiedMessage.java | 18 ------- .../messaging/ResourceOperationMessage.java | 18 +++++++ .../ConcreteResourceModifiedJsonMessage.java | 49 ------------------- .../json/ResourceOperationJsonMessage.java | 49 +++++++++++++++++++ .../BaseResourceModifiedMessageTest.java | 10 ++-- 8 files changed, 78 insertions(+), 79 deletions(-) delete mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ConcreteResourceModifiedMessage.java create mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceOperationMessage.java delete mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ConcreteResourceModifiedJsonMessage.java create mode 100644 hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceOperationJsonMessage.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 7eb538f4490..3ef6f1fd674 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: *

    - *
  • ca.uhn.fhir.rest.server.messaging.ConcreteResourceModifiedMessage- This parameter should not be modified as processing is complete when this hook is invoked.
  • + *
  • ca.uhn.fhir.rest.server.messaging.ResourceOperationMessage - This parameter should not be modified as processing is complete when this hook is invoked.
  • *
  • ca.uhn.fhir.empi.model.TransactionLogMessages - This parameter is for informational messages provided by the EMPI module during EMPI procesing. .
  • *
*

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

*/ - EMPI_AFTER_PERSISTED_RESOURCE_CHECKED(void.class, "ca.uhn.fhir.rest.server.messaging.ConcreteResourceModifiedMessage", "ca.uhn.fhir.rest.server.TransactionLogMessages"), + EMPI_AFTER_PERSISTED_RESOURCE_CHECKED(void.class, "ca.uhn.fhir.rest.server.messaging.ResourceOperationMessage", "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 585f88aa5c3..bc264cd650a 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.ConcreteResourceModifiedMessage; +import ca.uhn.fhir.rest.server.messaging.ResourceOperationMessage; import org.hl7.fhir.instance.model.api.IAnyResource; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -96,12 +96,11 @@ public class EmpiMessageHandler implements MessageHandler { } finally { // Interceptor call: EMPI_AFTER_PERSISTED_RESOURCE_CHECKED - ConcreteResourceModifiedMessage outgoingMsg = new ConcreteResourceModifiedMessage(myFhirContext, theMsg.getPayload(myFhirContext), theMsg.getOperationType()); + ResourceOperationMessage outgoingMsg = new ResourceOperationMessage(myFhirContext, theMsg.getPayload(myFhirContext), theMsg.getOperationType()); outgoingMsg.setTransactionId(theMsg.getTransactionId()); HookParams params = new HookParams() - //Janky upcast. - .add(ConcreteResourceModifiedMessage.class,outgoingMsg) + .add(ResourceOperationMessage.class, outgoingMsg) .add(TransactionLogMessages.class, empiContext.getTransactionLogMessages()); myInterceptorBroadcaster.callHooks(Pointcut.EMPI_AFTER_PERSISTED_RESOURCE_CHECKED, params); } 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 38d8afa4033..3d555b34236 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 @@ -113,7 +113,7 @@ public abstract class BaseResourceMessage implements IResourceMessage, IModelJso } /** - * Adds a transcation ID to this message. This ID can be used for many purposes. For example, performing tracing + * Adds a transaction 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) 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 deleted file mode 100644 index e2ff33f00ac..00000000000 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ConcreteResourceModifiedMessage.java +++ /dev/null @@ -1,18 +0,0 @@ -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/ResourceOperationMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceOperationMessage.java new file mode 100644 index 00000000000..529e20b41ce --- /dev/null +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/ResourceOperationMessage.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 ResourceOperationMessage extends BaseResourceModifiedMessage { + public ResourceOperationMessage() { + } + + public ResourceOperationMessage(FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) { + super(theFhirContext, theResource, theOperationType); + } + + public ResourceOperationMessage(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/ConcreteResourceModifiedJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ConcreteResourceModifiedJsonMessage.java deleted file mode 100644 index 80f91391eaf..00000000000 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ConcreteResourceModifiedJsonMessage.java +++ /dev/null @@ -1,49 +0,0 @@ -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/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceOperationJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceOperationJsonMessage.java new file mode 100644 index 00000000000..dd843293153 --- /dev/null +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/ResourceOperationJsonMessage.java @@ -0,0 +1,49 @@ +package ca.uhn.fhir.rest.server.messaging.json; + +import ca.uhn.fhir.rest.server.messaging.ResourceOperationMessage; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.ToStringBuilder; + +public class ResourceOperationJsonMessage extends BaseJsonMessage { + + + @JsonProperty("payload") + private ResourceOperationMessage myPayload; + + /** + * Constructor + */ + public ResourceOperationJsonMessage() { + super(); + } + + /** + * Constructor + */ + public ResourceOperationJsonMessage(ResourceOperationMessage thePayload) { + myPayload = thePayload; + setDefaultRetryHeaders(); + } + + public ResourceOperationJsonMessage(HapiMessageHeaders theRetryMessageHeaders, ResourceOperationMessage thePayload) { + myPayload = thePayload; + setHeaders(theRetryMessageHeaders); + } + + + @Override + public ResourceOperationMessage getPayload() { + return myPayload; + } + + public void setPayload(ResourceOperationMessage 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 dbf775a864a..2d7e3377bd4 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.ConcreteResourceModifiedJsonMessage; +import ca.uhn.fhir.rest.server.messaging.json.ResourceOperationJsonMessage; 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 ConcreteResourceModifiedMessageTest { +class ResourceOperationMessageTest { @Test public void testSerializationAndDeserializationOfResourceModifiedMessage() throws JsonProcessingException { - ConcreteResourceModifiedJsonMessage jsonMessage = new ConcreteResourceModifiedJsonMessage(); - jsonMessage.setPayload(new ConcreteResourceModifiedMessage()); + ResourceOperationJsonMessage jsonMessage = new ResourceOperationJsonMessage(); + jsonMessage.setPayload(new ResourceOperationMessage()); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(jsonMessage); - jsonMessage = mapper.readValue(serialized, ConcreteResourceModifiedJsonMessage.class); + jsonMessage = mapper.readValue(serialized, ResourceOperationJsonMessage.class); assertThat(jsonMessage.getHapiHeaders().getRetryCount(), is(equalTo(0))); assertThat(jsonMessage.getHapiHeaders().getFirstFailureDate(), is(equalTo(null))); From 6ab7a0bcfedfdaedf363695b7ac135f59567901e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 16 Sep 2020 08:02:01 -0400 Subject: [PATCH 15/25] Bump animal-sniffer-maven-plugin from 1.18 to 1.19 (#2084) Bumps [animal-sniffer-maven-plugin](https://github.com/mojohaus/animal-sniffer) from 1.18 to 1.19. - [Release notes](https://github.com/mojohaus/animal-sniffer/releases) - [Commits](https://github.com/mojohaus/animal-sniffer/compare/animal-sniffer-parent-1.18...animal-sniffer-parent-1.19) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2609efd2dcb..cb9009312e8 100644 --- a/pom.xml +++ b/pom.xml @@ -1824,7 +1824,7 @@ org.codehaus.mojo animal-sniffer-maven-plugin - 1.18 + 1.19 org.codehaus.mojo From c884f29112d1c8b73a631501d0de44bffc0e067f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tue=20Toft=20N=C3=B8rg=C3=A5rd?= Date: Wed, 16 Sep 2020 15:05:28 +0200 Subject: [PATCH 16/25] SearchCoordinatorSvcImpl gets ExecutorService from injected ThreadPoolTaskExecutor (#2083) * Get ExecutorService from injected ThreadPoolTaskExecutor which enables support of TaskDecorators (e.g. to add/clear ThreadLocal logging context (MDC) variables) * Properly initialize ThreadPoolTaskExecutor --- .../main/java/ca/uhn/fhir/jpa/config/BaseConfig.java | 8 ++++++++ .../uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java | 11 +++++------ .../fhir/jpa/search/SearchCoordinatorSvcImplTest.java | 3 ++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java index 5600f17fe04..bc84c33d677 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java @@ -262,6 +262,14 @@ public abstract class BaseConfig { return new DatabaseSearchResultCacheSvcImpl(); } + @Bean + public ThreadPoolTaskExecutor searchCoordinatorThreadFactory() { + final ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); + threadPoolTaskExecutor.setThreadNamePrefix("search_coord_"); + threadPoolTaskExecutor.initialize(); + return threadPoolTaskExecutor; + } + @Bean public TaskScheduler taskScheduler() { ConcurrentTaskScheduler retVal = new ConcurrentTaskScheduler(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java index 6e1e22b9120..eafcd442ce8 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java @@ -37,7 +37,6 @@ import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.jpa.entity.SearchInclude; import ca.uhn.fhir.jpa.entity.SearchTypeEnum; import ca.uhn.fhir.jpa.interceptor.JpaPreResourceAccessDetails; -import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.jpa.model.search.SearchRuntimeDetails; import ca.uhn.fhir.jpa.model.search.SearchStatusEnum; import ca.uhn.fhir.jpa.partition.IRequestPartitionHelperSvc; @@ -54,6 +53,7 @@ import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.IPreResourceAccessDetails; import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.server.IPagingProvider; import ca.uhn.fhir.rest.server.SimpleBundleProvider; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; @@ -80,7 +80,7 @@ import org.springframework.data.domain.Sort; import org.springframework.orm.jpa.JpaDialect; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.vendor.HibernateJpaDialect; -import org.springframework.scheduling.concurrent.CustomizableThreadFactory; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Component; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; @@ -111,7 +111,6 @@ import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; @@ -161,9 +160,9 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc { /** * Constructor */ - public SearchCoordinatorSvcImpl() { - CustomizableThreadFactory threadFactory = new CustomizableThreadFactory("search_coord_"); - myExecutor = Executors.newCachedThreadPool(threadFactory); + @Autowired + public SearchCoordinatorSvcImpl(ThreadPoolTaskExecutor searchCoordinatorThreadFactory) { + myExecutor = searchCoordinatorThreadFactory.getThreadPoolExecutor(); } @VisibleForTesting diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java index 1b74f6647f1..9c3665dd9d1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java @@ -7,6 +7,7 @@ import ca.uhn.fhir.interceptor.model.RequestPartitionId; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; +import ca.uhn.fhir.jpa.config.dstu3.BaseDstu3Config; import ca.uhn.fhir.jpa.dao.IResultIterator; import ca.uhn.fhir.jpa.dao.ISearchBuilder; import ca.uhn.fhir.jpa.dao.SearchBuilder; @@ -124,7 +125,7 @@ public class SearchCoordinatorSvcImplTest { myCurrentSearch = null; - mySvc = new SearchCoordinatorSvcImpl(); + mySvc = new SearchCoordinatorSvcImpl(new BaseDstu3Config().searchCoordinatorThreadFactory()); mySvc.setEntityManagerForUnitTest(myEntityManager); mySvc.setTransactionManagerForUnitTest(myTxManager); mySvc.setContextForUnitTest(ourCtx); From b64e982ec3a033c782fdff3fdc8a16d3ecec9176 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Wed, 16 Sep 2020 09:07:33 -0400 Subject: [PATCH 17/25] Credit for #2083 --- ...3-search-coordinator-threads-use-threadpoolexecutor.yaml | 6 ++++++ .../src/test/java/ca/uhn/fhir/jpa/packages/NpmTestR4.java | 1 + 2 files changed, 7 insertions(+) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_2_0/2083-search-coordinator-threads-use-threadpoolexecutor.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_2_0/2083-search-coordinator-threads-use-threadpoolexecutor.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_2_0/2083-search-coordinator-threads-use-threadpoolexecutor.yaml new file mode 100644 index 00000000000..81fcd2f1ec4 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_2_0/2083-search-coordinator-threads-use-threadpoolexecutor.yaml @@ -0,0 +1,6 @@ +--- +type: add +issue: 2083 +title: "The JPA search coordinator will now use worker threads sourced from a ThreadPoolTaskExecutor, in order to simplify + the addition of decorators to those threads. Thanks to Tue Toft Nørgård for the pull requets!" + diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmTestR4.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmTestR4.java index dd09c8f92d8..d646765860b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmTestR4.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmTestR4.java @@ -384,6 +384,7 @@ public class NpmTestR4 extends BaseJpaR4Test { PackageInstallationSpec spec = new PackageInstallationSpec().setName("hl7.fhir.uv.shorthand").setVersion("0.12.0").setInstallMode(PackageInstallationSpec.InstallModeEnum.STORE_ONLY); igInstaller.install(spec); + runInTransaction(() -> { NpmPackageVersionEntity versionEntity = myPackageVersionDao.findByPackageIdAndVersion("hl7.fhir.uv.shorthand", "0.12.0").orElseThrow(() -> new IllegalArgumentException()); assertEquals(true, versionEntity.isCurrentVersion()); From cdc195bd0b0e0327921b52cc384c59778af24958 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Wed, 16 Sep 2020 13:13:43 -0400 Subject: [PATCH 18/25] Change to use long type for failure timestamps --- .../messaging/json/HapiMessageHeaders.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java index 58e5819ed41..552f1d314df 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java @@ -3,7 +3,6 @@ package ca.uhn.fhir.rest.server.messaging.json; import ca.uhn.fhir.model.api.IModelJson; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -94,15 +93,24 @@ public class HapiMessageHeaders implements Map, IModelJson { return (Integer)this.getHeaders().get(RETRY_COUNT_KEY); } - public Date getFirstFailureDate() { - return (Date)this.getHeaders().get(FIRST_FAILURE_KEY); - + public Long getFirstFailureDate() { + return (Long)this.getHeaders().get(FIRST_FAILURE_KEY); } - public Date getLastFailureDate() { - return (Date)this.getHeaders().get(LAST_FAILURE_KEY); - + public Long getLastFailureDate() { + return (Long)this.getHeaders().get(LAST_FAILURE_KEY); } + + public void setRetryCount(Integer theRetryCount) { + this.getHeaders().put(RETRY_COUNT_KEY, theRetryCount); + } + + public void setLastFailureDate(Long theLastFailureDate) { + this.getHeaders().put(LAST_FAILURE_KEY, theLastFailureDate); + } + public void setFirstFailureDate(Long theFirstFailureDate) { + this.getHeaders().put(FIRST_FAILURE_KEY, theFirstFailureDate); + } public Map getHeaders() { return this.headers; } From 666113696be02f0584753d6e3d064b6e302ee051 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Wed, 16 Sep 2020 14:06:54 -0400 Subject: [PATCH 19/25] add attributes to HapiHeaders. Turns out deserialization makes a best guess, and doesnt respect types in Map --- .../messaging/json/HapiMessageHeaders.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java index 552f1d314df..271e6c68d78 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java @@ -18,6 +18,10 @@ public class HapiMessageHeaders implements Map, IModelJson { public static String FIRST_FAILURE_KEY = "firstFailure"; public static String LAST_FAILURE_KEY = "lastFailure"; + private Integer retryCount; + private Long firstFailureTimestamp; + private Long lastFailureTimestamp; + private final Map headers; public HapiMessageHeaders(Map theHeaders) { @@ -90,26 +94,32 @@ public class HapiMessageHeaders implements Map, IModelJson { } public Integer getRetryCount() { - return (Integer)this.getHeaders().get(RETRY_COUNT_KEY); + return this.retryCount; +// return (Integer)this.getHeaders().get(RETRY_COUNT_KEY); } public Long getFirstFailureDate() { - return (Long)this.getHeaders().get(FIRST_FAILURE_KEY); + return this.firstFailureTimestamp; + //return (Long)this.getHeaders().get(FIRST_FAILURE_KEY); } public Long getLastFailureDate() { - return (Long)this.getHeaders().get(LAST_FAILURE_KEY); + //return (Long)this.getHeaders().get(LAST_FAILURE_KEY); + return this.lastFailureTimestamp; } public void setRetryCount(Integer theRetryCount) { this.getHeaders().put(RETRY_COUNT_KEY, theRetryCount); + this.retryCount = theRetryCount; } public void setLastFailureDate(Long theLastFailureDate) { this.getHeaders().put(LAST_FAILURE_KEY, theLastFailureDate); + this.lastFailureTimestamp = theLastFailureDate; } public void setFirstFailureDate(Long theFirstFailureDate) { this.getHeaders().put(FIRST_FAILURE_KEY, theFirstFailureDate); + this.firstFailureTimestamp = theFirstFailureDate; } public Map getHeaders() { return this.headers; From 3189819dd5218d296c48ba318c6ba84aec82bbc4 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Wed, 16 Sep 2020 14:13:03 -0400 Subject: [PATCH 20/25] limit transaction size config (#2087) --- .../2087-limit-transaction-size-config.yaml | 5 + .../ca/uhn/fhir/jpa/api/config/DaoConfig.java | 28 +++++ .../jpa/dao/BaseTransactionProcessor.java | 16 ++- .../dstu3/FhirSystemDaoDstu3SearchTest.java | 46 -------- .../jpa/dao/dstu3/FhirSystemDaoDstu3Test.java | 102 ------------------ .../FhirSystemDaoTransactionDstu3Test.java | 78 ++++++++++++++ 6 files changed, 125 insertions(+), 150 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_2_0/2087-limit-transaction-size-config.yaml delete mode 100644 hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3SearchTest.java create mode 100644 hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoTransactionDstu3Test.java diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_2_0/2087-limit-transaction-size-config.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_2_0/2087-limit-transaction-size-config.yaml new file mode 100644 index 00000000000..db383a422f5 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_2_0/2087-limit-transaction-size-config.yaml @@ -0,0 +1,5 @@ +--- +type: add +issue: 2087 +title: "Added new DaoConfig parameter called maximumTransactionBundleSize that if not-null will throw a +PayloadTooLarge exception when the number of resources in a transaction bundle exceeds this size." diff --git a/hapi-fhir-jpaserver-api/src/main/java/ca/uhn/fhir/jpa/api/config/DaoConfig.java b/hapi-fhir-jpaserver-api/src/main/java/ca/uhn/fhir/jpa/api/config/DaoConfig.java index 03c8f3f5c5b..038a189d788 100644 --- a/hapi-fhir-jpaserver-api/src/main/java/ca/uhn/fhir/jpa/api/config/DaoConfig.java +++ b/hapi-fhir-jpaserver-api/src/main/java/ca/uhn/fhir/jpa/api/config/DaoConfig.java @@ -80,6 +80,7 @@ public class DaoConfig { * @see #setMaximumSearchResultCountInTransaction(Integer) */ private static final Integer DEFAULT_MAXIMUM_SEARCH_RESULT_COUNT_IN_TRANSACTION = null; + private static final Integer DEFAULT_MAXIMUM_TRANSACTION_BUNDLE_SIZE = null; private static final Logger ourLog = LoggerFactory.getLogger(DaoConfig.class); private static final int DEFAULT_EXPUNGE_BATCH_SIZE = 800; private IndexEnabledEnum myIndexMissingFieldsEnabled = IndexEnabledEnum.DISABLED; @@ -126,6 +127,8 @@ public class DaoConfig { private boolean myIndexContainedResources = true; private int myMaximumExpansionSize = DEFAULT_MAX_EXPANSION_SIZE; private Integer myMaximumSearchResultCountInTransaction = DEFAULT_MAXIMUM_SEARCH_RESULT_COUNT_IN_TRANSACTION; + + private Integer myMaximumTransactionBundleSize = DEFAULT_MAXIMUM_TRANSACTION_BUNDLE_SIZE; private ResourceEncodingEnum myResourceEncoding = ResourceEncodingEnum.JSONC; /** * update setter javadoc if default changes @@ -655,6 +658,31 @@ public class DaoConfig { myMaximumSearchResultCountInTransaction = theMaximumSearchResultCountInTransaction; } + /** + * Specifies the maximum number of resources permitted within a single transaction bundle. + * If a transaction bundle is submitted with more than this number of resources, it will be + * rejected with a PayloadTooLarge exception. + *

+ * The default value is null, which means that there is no limit. + *

+ */ + public Integer getMaximumTransactionBundleSize() { + return myMaximumTransactionBundleSize; + } + + /** + * Specifies the maximum number of resources permitted within a single transaction bundle. + * If a transaction bundle is submitted with more than this number of resources, it will be + * rejected with a PayloadTooLarge exception. + *

+ * The default value is null, which means that there is no limit. + *

+ */ + public DaoConfig setMaximumTransactionBundleSize(Integer theMaximumTransactionBundleSize) { + myMaximumTransactionBundleSize = theMaximumTransactionBundleSize; + return this; + } + /** * This setting controls the number of threads allocated to resource reindexing * (which is only ever used if SearchParameters change, or a manual reindex is diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java index afbfdc0c954..1135bd1e6c6 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java @@ -25,6 +25,7 @@ import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.interceptor.api.HookParams; import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.api.Pointcut; +import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.api.dao.IJpaDao; @@ -54,6 +55,7 @@ import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.NotModifiedException; +import ca.uhn.fhir.rest.server.exceptions.PayloadTooLargeException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.method.BaseMethodBinding; import ca.uhn.fhir.rest.server.method.BaseResourceReturningMethodBinding; @@ -124,6 +126,8 @@ public abstract class BaseTransactionProcessor { private MatchResourceUrlService myMatchResourceUrlService; @Autowired private HapiTransactionService myHapiTransactionService; + @Autowired + private DaoConfig myDaoConfig; @PostConstruct public void start() { @@ -342,7 +346,15 @@ public abstract class BaseTransactionProcessor { throw new InvalidRequestException("Unable to process transaction where incoming Bundle.type = " + transactionType); } - ourLog.debug("Beginning {} with {} resources", theActionName, myVersionAdapter.getEntries(theRequest).size()); + int numberOfEntries = myVersionAdapter.getEntries(theRequest).size(); + + if (myDaoConfig.getMaximumTransactionBundleSize() != null && numberOfEntries > myDaoConfig.getMaximumTransactionBundleSize()) { + throw new PayloadTooLargeException("Transaction Bundle Too large. Transaction bundle contains " + + numberOfEntries + + " which exceedes the maximum permitted transaction bundle size of " + myDaoConfig.getMaximumTransactionBundleSize()); + } + + ourLog.debug("Beginning {} with {} resources", theActionName, numberOfEntries); final TransactionDetails transactionDetails = new TransactionDetails(); final StopWatch transactionStopWatch = new StopWatch(); @@ -350,7 +362,7 @@ public abstract class BaseTransactionProcessor { List requestEntries = myVersionAdapter.getEntries(theRequest); // Do all entries have a verb? - for (int i = 0; i < myVersionAdapter.getEntries(theRequest).size(); i++) { + for (int i = 0; i < numberOfEntries; i++) { IBase nextReqEntry = requestEntries.get(i); String verb = myVersionAdapter.getEntryRequestVerb(myContext, nextReqEntry); if (verb == null || !isValidVerb(verb)) { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3SearchTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3SearchTest.java deleted file mode 100644 index fd47d44bd85..00000000000 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3SearchTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package ca.uhn.fhir.jpa.dao.dstu3; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Test; - -import ca.uhn.fhir.util.TestUtil; - -public class FhirSystemDaoDstu3SearchTest extends BaseJpaDstu3SystemTest { - - @Test - public void testSearchByParans() { - // code to come.. just here to prevent a failure - } - - /*//@formatter:off - * [ERROR] Search parameter action has conflicting types token and reference - * [ERROR] Search parameter source has conflicting types token and reference - * [ERROR] Search parameter plan has conflicting types reference and token - * [ERROR] Search parameter version has conflicting types token and string - * [ERROR] Search parameter source has conflicting types reference and uri - * [ERROR] Search parameter location has conflicting types reference and uri - * [ERROR] Search parameter title has conflicting types string and token - * [ERROR] Search parameter manufacturer has conflicting types string and reference - * [ERROR] Search parameter address has conflicting types token and string - * [ERROR] Search parameter source has conflicting types reference and string - * [ERROR] Search parameter destination has conflicting types reference and string - * [ERROR] Search parameter responsible has conflicting types reference and string - * [ERROR] Search parameter value has conflicting types token and string - * [ERROR] Search parameter address has conflicting types token and string - * [ERROR] Search parameter address has conflicting types token and string - * [ERROR] Search parameter address has conflicting types token and string - * [ERROR] Search parameter address has conflicting types token and string - * [ERROR] Search parameter action has conflicting types reference and token - * [ERROR] Search parameter version has conflicting types token and string - * [ERROR] Search parameter address has conflicting types token and string - * [ERROR] Search parameter base has conflicting types reference and token - * [ERROR] Search parameter target has conflicting types reference and token - * [ERROR] Search parameter base has conflicting types reference and uri - * [ERROR] Search parameter contact has conflicting types string and token - * [ERROR] Search parameter substance has conflicting types token and reference - * [ERROR] Search parameter provider has conflicting types reference and token - * [ERROR] Search parameter system has conflicting types token and uri - * [ERROR] Search parameter reference has conflicting types reference and uri - * //@formatter:off - */ -} diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java index 11fac06fce8..fd5d1938250 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java @@ -2888,108 +2888,6 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertEquals(1, found.size().intValue()); } - // - // - // /** - // * Issue #55 - // */ - // @Test - // public void testTransactionWithCidIds() throws Exception { - // Bundle request = new Bundle(); - // - // Patient p1 = new Patient(); - // p1.setId("cid:patient1"); - // p1.addIdentifier().setSystem("system").setValue("testTransactionWithCidIds01"); - // res.add(p1); - // - // Observation o1 = new Observation(); - // o1.setId("cid:observation1"); - // o1.getIdentifier().setSystem("system").setValue("testTransactionWithCidIds02"); - // o1.setSubject(new Reference("Patient/cid:patient1")); - // res.add(o1); - // - // Observation o2 = new Observation(); - // o2.setId("cid:observation2"); - // o2.getIdentifier().setSystem("system").setValue("testTransactionWithCidIds03"); - // o2.setSubject(new Reference("Patient/cid:patient1")); - // res.add(o2); - // - // ourSystemDao.transaction(res); - // - // assertTrue(p1.getId().getValue(), p1.getId().getIdPart().matches("^[0-9]+$")); - // assertTrue(o1.getId().getValue(), o1.getId().getIdPart().matches("^[0-9]+$")); - // assertTrue(o2.getId().getValue(), o2.getId().getIdPart().matches("^[0-9]+$")); - // - // assertThat(o1.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart())); - // assertThat(o2.getSubject().getReference().getValue(), endsWith("Patient/" + p1.getId().getIdPart())); - // - // } - // - // @Test - // public void testTransactionWithDelete() throws Exception { - // Bundle request = new Bundle(); - // - // /* - // * Create 3 - // */ - // - // List res; - // res = new ArrayList(); - // - // Patient p1 = new Patient(); - // p1.addIdentifier().setSystem("urn:system").setValue("testTransactionWithDelete"); - // res.add(p1); - // - // Patient p2 = new Patient(); - // p2.addIdentifier().setSystem("urn:system").setValue("testTransactionWithDelete"); - // res.add(p2); - // - // Patient p3 = new Patient(); - // p3.addIdentifier().setSystem("urn:system").setValue("testTransactionWithDelete"); - // res.add(p3); - // - // ourSystemDao.transaction(res); - // - // /* - // * Verify - // */ - // - // IBundleProvider results = ourPatientDao.search(Patient.SP_IDENTIFIER, new TokenParam("urn:system", - // "testTransactionWithDelete")); - // assertEquals(3, results.size()); - // - // /* - // * Now delete 2 - // */ - // - // request = new Bundle(); - // res = new ArrayList(); - // List existing = results.getResources(0, 3); - // - // p1 = new Patient(); - // p1.setId(existing.get(0).getId()); - // ResourceMetadataKeyEnum.DELETED_AT.put(p1, InstantDt.withCurrentTime()); - // res.add(p1); - // - // p2 = new Patient(); - // p2.setId(existing.get(1).getId()); - // ResourceMetadataKeyEnum.DELETED_AT.put(p2, InstantDt.withCurrentTime()); - // res.add(p2); - // - // ourSystemDao.transaction(res); - // - // /* - // * Verify - // */ - // - // IBundleProvider results2 = ourPatientDao.search(Patient.SP_IDENTIFIER, new TokenParam("urn:system", - // "testTransactionWithDelete")); - // assertEquals(1, results2.size()); - // List existing2 = results2.getResources(0, 1); - // assertEquals(existing2.get(0).getId(), existing.get(2).getId()); - // - // } - @Test public void testTransactionWithRelativeOidIds() { Bundle res = new Bundle(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoTransactionDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoTransactionDstu3Test.java new file mode 100644 index 00000000000..8db6ddc8b7b --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoTransactionDstu3Test.java @@ -0,0 +1,78 @@ +package ca.uhn.fhir.jpa.dao.dstu3; + +import ca.uhn.fhir.jpa.api.config.DaoConfig; +import ca.uhn.fhir.rest.server.exceptions.PayloadTooLargeException; +import org.hl7.fhir.dstu3.model.Bundle; +import org.hl7.fhir.dstu3.model.Bundle.BundleType; +import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb; +import org.hl7.fhir.dstu3.model.Observation; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +public class FhirSystemDaoTransactionDstu3Test extends BaseJpaDstu3SystemTest { + public static final int TEST_MAXIMUM_TRANSACTION_BUNDLE_SIZE = 5; + + @AfterEach + public void after() { + myDaoConfig.setMaximumTransactionBundleSize(new DaoConfig().getMaximumTransactionBundleSize()); + } + + @BeforeEach + public void beforeDisableResultReuse() { + myDaoConfig.setMaximumTransactionBundleSize(TEST_MAXIMUM_TRANSACTION_BUNDLE_SIZE); + } + + private Bundle createInputTransactionWithSize(int theSize) { + Bundle retval = new Bundle(); + retval.setType(BundleType.TRANSACTION); + for (int i = 0; i < theSize; ++i) { + Observation obs = new Observation(); + obs.setStatus(Observation.ObservationStatus.FINAL); + retval + .addEntry() + .setFullUrl("urn:uuid:000" + i) + .setResource(obs) + .getRequest() + .setMethod(HTTPVerb.POST); + } + + return retval; + } + + @Test + public void testTransactionTooBig() { + Bundle bundle = createInputTransactionWithSize(TEST_MAXIMUM_TRANSACTION_BUNDLE_SIZE + 1); + + try { + mySystemDao.transaction(null, bundle); + fail(); + } catch (PayloadTooLargeException e) { + assertThat(e.getMessage(), containsString("Transaction Bundle Too large. Transaction bundle contains " + + (TEST_MAXIMUM_TRANSACTION_BUNDLE_SIZE + 1) + + " which exceedes the maximum permitted transaction bundle size of " + TEST_MAXIMUM_TRANSACTION_BUNDLE_SIZE)); + } + } + + @Test + public void testTransactionSmallEnough() { + testTransactionBundleSucceedsWithSize(TEST_MAXIMUM_TRANSACTION_BUNDLE_SIZE); + testTransactionBundleSucceedsWithSize(TEST_MAXIMUM_TRANSACTION_BUNDLE_SIZE - 1); + testTransactionBundleSucceedsWithSize(1); + } + + private void testTransactionBundleSucceedsWithSize(int theSize) { + Bundle bundle = createInputTransactionWithSize(theSize); + Bundle response = mySystemDao.transaction(null, bundle); + + assertEquals(theSize, response.getEntry().size()); + assertEquals("201 Created", response.getEntry().get(0).getResponse().getStatus()); + assertEquals("201 Created", response.getEntry().get(theSize - 1).getResponse().getStatus()); + } + +} From 4c5051a5d924433ba8afbf6c0c41630a0019ef44 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Wed, 16 Sep 2020 15:05:44 -0400 Subject: [PATCH 21/25] More refactor for custom headers and top level attributes --- .../messaging/json/BaseJsonMessage.java | 3 +- .../messaging/json/HapiMessageHeaders.java | 101 +++++------------- 2 files changed, 26 insertions(+), 78 deletions(-) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java index 6d73558cddc..e3eff4e118c 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/BaseJsonMessage.java @@ -22,13 +22,12 @@ public abstract class BaseJsonMessage implements Message, IModelJson { protected void setDefaultRetryHeaders() { HapiMessageHeaders messageHeaders = new HapiMessageHeaders(); - messageHeaders.initializeDefaultRetryValues(); setHeaders(messageHeaders); } @Override public MessageHeaders getHeaders() { - return new MessageHeaders(myHeaders); + return myHeaders.toMessageHeaders(); } public HapiMessageHeaders getHapiHeaders() { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java index 271e6c68d78..a0384e36d8b 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java @@ -1,11 +1,11 @@ package ca.uhn.fhir.rest.server.messaging.json; import ca.uhn.fhir.model.api.IModelJson; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.springframework.messaging.MessageHeaders; -import java.util.Collection; import java.util.HashMap; import java.util.Map; -import java.util.Set; /** * This class is for holding headers for BaseJsonMessages. Any serializable data can be thrown into @@ -13,15 +13,19 @@ import java.util.Set; * in message handling retrying. There are also matching helper functions for fetching those special variables; however * they can also be accessed in standard map fashion with a `get` on the map. */ -public class HapiMessageHeaders implements Map, IModelJson { +public class HapiMessageHeaders implements IModelJson { public static String RETRY_COUNT_KEY = "retryCount"; public static String FIRST_FAILURE_KEY = "firstFailure"; public static String LAST_FAILURE_KEY = "lastFailure"; - private Integer retryCount; - private Long firstFailureTimestamp; - private Long lastFailureTimestamp; + @JsonProperty("retryCount") + private Integer myRetryCount; + @JsonProperty("firstFailureTimestamp") + private Long myFirstFailureTimestamp; + @JsonProperty("lastFailureTimestamp") + private Long myLastFailureTimestamp; + @JsonProperty("customHeaders") private final Map headers; public HapiMessageHeaders(Map theHeaders) { @@ -32,99 +36,44 @@ public class HapiMessageHeaders implements Map, IModelJson { headers = new HashMap<>(); } - - @Override - public int size() { - return this.headers.size(); - } - - @Override - public boolean isEmpty() { - return this.headers.isEmpty(); - } - - @Override - public boolean containsKey(Object key) { - return this.headers.containsKey(key); - } - - @Override - public boolean containsValue(Object value) { - return this.headers.containsValue(value); - } - - @Override - public Object get(Object key) { - return this.headers.get(key); - } - - @Override - public Object put(String key, Object value) { - return this.headers.put(key, value); - } - - @Override - public Object remove(Object key) { - return this.headers.remove(key); - } - - @Override - public void putAll(Map m) { - this.headers.putAll(m); - } - - @Override - public void clear() { - this.headers.clear(); - } - - @Override - public Set keySet() { - return this.headers.keySet(); - } - - @Override - public Collection values() { - return this.headers.values(); - } - - @Override - public Set> entrySet() { - return this.headers.entrySet(); - } - public Integer getRetryCount() { - return this.retryCount; -// return (Integer)this.getHeaders().get(RETRY_COUNT_KEY); + return this.myRetryCount; } public Long getFirstFailureDate() { - return this.firstFailureTimestamp; - //return (Long)this.getHeaders().get(FIRST_FAILURE_KEY); + return this.myFirstFailureTimestamp; } public Long getLastFailureDate() { - //return (Long)this.getHeaders().get(LAST_FAILURE_KEY); - return this.lastFailureTimestamp; + return this.myLastFailureTimestamp; } public void setRetryCount(Integer theRetryCount) { this.getHeaders().put(RETRY_COUNT_KEY, theRetryCount); - this.retryCount = theRetryCount; + this.myRetryCount = theRetryCount; } public void setLastFailureDate(Long theLastFailureDate) { this.getHeaders().put(LAST_FAILURE_KEY, theLastFailureDate); - this.lastFailureTimestamp = theLastFailureDate; + this.myLastFailureTimestamp = theLastFailureDate; } public void setFirstFailureDate(Long theFirstFailureDate) { this.getHeaders().put(FIRST_FAILURE_KEY, theFirstFailureDate); - this.firstFailureTimestamp = theFirstFailureDate; + this.myFirstFailureTimestamp = theFirstFailureDate; } public Map getHeaders() { return this.headers; } + public MessageHeaders toMessageHeaders() { + Map returnedHeaders = new HashMap<>(); + returnedHeaders.putAll(this.headers); + returnedHeaders.put(RETRY_COUNT_KEY, myRetryCount); + returnedHeaders.put(FIRST_FAILURE_KEY, myFirstFailureTimestamp); + returnedHeaders.put(LAST_FAILURE_KEY, myLastFailureTimestamp); + return new MessageHeaders(returnedHeaders); + } + /** * Sets deffault values for the special headers that HAPI cares about during retry. */ From 558f7a5ccf02d534e864f98679300e71f58f9d97 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Wed, 16 Sep 2020 15:21:49 -0400 Subject: [PATCH 22/25] Minor cleanup --- .../messaging/json/HapiMessageHeaders.java | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java index a0384e36d8b..09ec9aca8a2 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java @@ -49,37 +49,26 @@ public class HapiMessageHeaders implements IModelJson { } public void setRetryCount(Integer theRetryCount) { - this.getHeaders().put(RETRY_COUNT_KEY, theRetryCount); this.myRetryCount = theRetryCount; } public void setLastFailureDate(Long theLastFailureDate) { - this.getHeaders().put(LAST_FAILURE_KEY, theLastFailureDate); this.myLastFailureTimestamp = theLastFailureDate; } public void setFirstFailureDate(Long theFirstFailureDate) { - this.getHeaders().put(FIRST_FAILURE_KEY, theFirstFailureDate); this.myFirstFailureTimestamp = theFirstFailureDate; } - public Map getHeaders() { + + public Map getCustomHeaders() { return this.headers; } public MessageHeaders toMessageHeaders() { - Map returnedHeaders = new HashMap<>(); - returnedHeaders.putAll(this.headers); + Map returnedHeaders = new HashMap<>(this.headers); returnedHeaders.put(RETRY_COUNT_KEY, myRetryCount); returnedHeaders.put(FIRST_FAILURE_KEY, myFirstFailureTimestamp); returnedHeaders.put(LAST_FAILURE_KEY, myLastFailureTimestamp); return new MessageHeaders(returnedHeaders); } - /** - * Sets deffault values for the special headers that HAPI cares about during retry. - */ - public void initializeDefaultRetryValues() { - headers.put(RETRY_COUNT_KEY, 0); - headers.put(FIRST_FAILURE_KEY, null); - headers.put(LAST_FAILURE_KEY, null); - } } From 9d3a97a46f639e853e0f77066be7111798c8e357 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Wed, 16 Sep 2020 15:24:09 -0400 Subject: [PATCH 23/25] Default for int --- .../uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java index 09ec9aca8a2..8ba8d5298f9 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java @@ -19,7 +19,7 @@ public class HapiMessageHeaders implements IModelJson { public static String LAST_FAILURE_KEY = "lastFailure"; @JsonProperty("retryCount") - private Integer myRetryCount; + private Integer myRetryCount = 0; @JsonProperty("firstFailureTimestamp") private Long myFirstFailureTimestamp; @JsonProperty("lastFailureTimestamp") From ddfac72e8d83b8f3c60abf084e93cc9b06deae0b Mon Sep 17 00:00:00 2001 From: Tadgh Date: Wed, 16 Sep 2020 15:27:03 -0400 Subject: [PATCH 24/25] Clean spacing --- .../fhir/rest/server/messaging/json/HapiMessageHeaders.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java index 8ba8d5298f9..35d73adba69 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java @@ -55,7 +55,8 @@ public class HapiMessageHeaders implements IModelJson { public void setLastFailureDate(Long theLastFailureDate) { this.myLastFailureTimestamp = theLastFailureDate; } - public void setFirstFailureDate(Long theFirstFailureDate) { + + public void setFirstFailureDate(Long theFirstFailureDate) { this.myFirstFailureTimestamp = theFirstFailureDate; } From 45775c86604fb82f5a90e66f92d5900a81875c1e Mon Sep 17 00:00:00 2001 From: Tadgh Date: Wed, 16 Sep 2020 15:29:04 -0400 Subject: [PATCH 25/25] Reuse constant --- .../server/messaging/json/HapiMessageHeaders.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java index 35d73adba69..a3b81e74f61 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/messaging/json/HapiMessageHeaders.java @@ -14,15 +14,15 @@ import java.util.Map; * they can also be accessed in standard map fashion with a `get` on the map. */ public class HapiMessageHeaders implements IModelJson { - public static String RETRY_COUNT_KEY = "retryCount"; - public static String FIRST_FAILURE_KEY = "firstFailure"; - public static String LAST_FAILURE_KEY = "lastFailure"; + public static final String RETRY_COUNT_KEY = "retryCount"; + public static final String FIRST_FAILURE_KEY = "firstFailureTimestamp"; + public static final String LAST_FAILURE_KEY = "lastFailureTimestamp"; - @JsonProperty("retryCount") + @JsonProperty(RETRY_COUNT_KEY) private Integer myRetryCount = 0; - @JsonProperty("firstFailureTimestamp") + @JsonProperty(FIRST_FAILURE_KEY) private Long myFirstFailureTimestamp; - @JsonProperty("lastFailureTimestamp") + @JsonProperty(LAST_FAILURE_KEY) private Long myLastFailureTimestamp; @JsonProperty("customHeaders")