From cffe4c9df268378beda1b3046d6d8efda975c0ba Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Mon, 30 Jul 2018 21:22:00 -0400 Subject: [PATCH 1/3] License header updates --- .../fhir/rest/server/exceptions/ResourceGoneException.java | 4 ++-- .../src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java | 4 ++-- .../java/ca/uhn/fhir/jpa/dao/BaseSearchParamExtractor.java | 4 ++-- .../src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java | 4 ++-- .../java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu2.java | 4 ++-- .../main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptDao.java | 4 ++-- .../ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3.java | 4 ++-- .../java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4.java | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/ResourceGoneException.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/ResourceGoneException.java index f9494cdb9e5..ea495641181 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/ResourceGoneException.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/ResourceGoneException.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.rest.server.exceptions; * 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. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index cc0c919dc94..92a9dbca55c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -91,9 +91,9 @@ import static org.apache.commons.lang3.StringUtils.*; * 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. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseSearchParamExtractor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseSearchParamExtractor.java index 92216d40b71..cfd452fe6bc 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseSearchParamExtractor.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseSearchParamExtractor.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.dao; * 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. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java index 57fed5b50f1..6d86ce24f82 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java @@ -20,9 +20,9 @@ import java.util.*; * 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. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu2.java index d6ce2ffc65a..cbcc69cec68 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParamExtractorDstu2.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.dao; * 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. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptDao.java index d0f519b2729..f64059eeb8f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptDao.java @@ -21,9 +21,9 @@ import java.util.List; * 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. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3.java index b956134c75a..a9fb3f13995 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.dao.dstu3; * 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. diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4.java index 7a7a71982a0..e08680761f5 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.dao.r4; * 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. From d07fd76d605a4e6ce5f0f92c93e8a60c43043c8f Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Fri, 3 Aug 2018 10:44:15 -0400 Subject: [PATCH 2/3] Dont keep resource bodies in the queue for JPA subscription delivery --- .../BaseSubscriptionDeliverySubscriber.java | 41 ++++++++----------- .../subscription/ResourceDeliveryMessage.java | 8 +--- pom.xml | 2 +- src/changes/changes.xml | 5 +++ 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionDeliverySubscriber.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionDeliverySubscriber.java index 800d88b1b48..cec5fb5134f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionDeliverySubscriber.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionDeliverySubscriber.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.subscription; * 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. @@ -27,12 +27,12 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Subscription; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.lang.NonNullApi; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; public abstract class BaseSubscriptionDeliverySubscriber extends BaseSubscriptionSubscriber { private static final Logger ourLog = LoggerFactory.getLogger(BaseSubscriptionDeliverySubscriber.class); - private boolean myReloadResourceBeforeDelivery = true; public BaseSubscriptionDeliverySubscriber(IFhirResourceDao theSubscriptionDao, Subscription.SubscriptionChannelType theChannelType, BaseSubscriptionInterceptor theSubscriptionInterceptor) { super(theSubscriptionDao, theChannelType, theSubscriptionInterceptor); @@ -60,25 +60,20 @@ public abstract class BaseSubscriptionDeliverySubscriber extends BaseSubscriptio msg.setSubscription(updatedSubscription); } - if (myReloadResourceBeforeDelivery) { - // Reload the payload just in case any interceptors modified - // it before it was saved to the database. This is also - // useful for resources created in a transaction, since they - // can have placeholder IDs in them. - IIdType payloadId = msg.getPayloadId(getContext()); - Class type = getContext().getResourceDefinition(payloadId.getResourceType()).getImplementingClass(); - IFhirResourceDao dao = getSubscriptionInterceptor().getDao(type); - IBaseResource loadedPayload; - try { - loadedPayload = dao.read(payloadId); - } catch (ResourceNotFoundException e) { - // This can happen if a last minute failure happens when saving a resource, - // eg a constraint causes the transaction to roll back on commit - ourLog.warn("Unable to find resource {} - Aborting delivery", payloadId.getValue()); - return; - } - msg.setPayload(getContext(), loadedPayload); + // Load the resource + IIdType payloadId = msg.getPayloadId(getContext()); + Class type = getContext().getResourceDefinition(payloadId.getResourceType()).getImplementingClass(); + IFhirResourceDao dao = getSubscriptionInterceptor().getDao(type); + IBaseResource loadedPayload; + try { + loadedPayload = dao.read(payloadId); + } catch (ResourceNotFoundException e) { + // This can happen if a last minute failure happens when saving a resource, + // eg a constraint causes the transaction to roll back on commit + ourLog.warn("Unable to find resource {} - Aborting delivery", payloadId.getValue()); + return; } + msg.setPayload(getContext(), loadedPayload); handleMessage(msg); } catch (Exception e) { @@ -90,8 +85,4 @@ public abstract class BaseSubscriptionDeliverySubscriber extends BaseSubscriptio public abstract void handleMessage(ResourceDeliveryMessage theMessage) throws Exception; - public void setReloadResourceBeforeDelivery(boolean theReloadResourceBeforeDelivery) { - myReloadResourceBeforeDelivery = theReloadResourceBeforeDelivery; - } - } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/ResourceDeliveryMessage.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/ResourceDeliveryMessage.java index bec9191f5f0..5034c26ed9a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/ResourceDeliveryMessage.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/ResourceDeliveryMessage.java @@ -24,6 +24,7 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import com.fasterxml.jackson.annotation.*; import com.google.gson.Gson; +import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; @@ -41,8 +42,6 @@ public class ResourceDeliveryMessage { private String mySubscriptionString; @JsonIgnore private transient IBaseResource myPayload; - @JsonProperty("payload") - private String myPayoadString; @JsonProperty("payloadId") private String myPayloadId; @JsonProperty("operationType") @@ -57,9 +56,7 @@ public class ResourceDeliveryMessage { } public IBaseResource getPayload(FhirContext theCtx) { - if (myPayload == null && myPayoadString != null) { - myPayload = theCtx.newJsonParser().parseResource(myPayoadString); - } + Validate.notNull(myPayload); return myPayload; } @@ -87,7 +84,6 @@ public class ResourceDeliveryMessage { public void setPayload(FhirContext theCtx, IBaseResource thePayload) { myPayload = thePayload; - myPayoadString = theCtx.newJsonParser().encodeResourceToString(thePayload); } public void setPayloadId(IIdType thePayloadId) { diff --git a/pom.xml b/pom.xml index 9de78fa9f31..5792e8842b5 100644 --- a/pom.xml +++ b/pom.xml @@ -1431,7 +1431,7 @@ org.codehaus.mojo versions-maven-plugin - 2.5 + 2.6-SNAPSHOT false diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 076c8ee11e5..a97c12ab28f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -244,6 +244,11 @@ a resource could be associated with the wrong entry in the response. Thanks to GitHub user @jbalbien for the pull request! + + JPA subscription delivery queues no longer store the resource body in the + queue (only the ID), which should reduce the memory/disk footprint of the queue + when it grows long. + From 0556dfa7af3fe3becdc76c02171bb00e86c71ee8 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Fri, 3 Aug 2018 11:56:06 -0400 Subject: [PATCH 3/3] Work on subscriptions --- .../BaseSubscriptionDeliverySubscriber.java | 9 ++++---- .../BaseSubscriptionInterceptor.java | 11 +--------- .../BaseSubscriptionSubscriber.java | 14 ++++++------- .../subscription/CanonicalSubscription.java | 21 ------------------- .../SubscriptionActivatingSubscriber.java | 11 +++++++--- 5 files changed, 19 insertions(+), 47 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionDeliverySubscriber.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionDeliverySubscriber.java index cec5fb5134f..ac85562506a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionDeliverySubscriber.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionDeliverySubscriber.java @@ -27,7 +27,6 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Subscription; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.lang.NonNullApi; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; @@ -51,15 +50,15 @@ public abstract class BaseSubscriptionDeliverySubscriber extends BaseSubscriptio ResourceDeliveryMessage msg = (ResourceDeliveryMessage) theMessage.getPayload(); subscriptionId = msg.getSubscription().getIdElement(getContext()).getValue(); - if (!subscriptionTypeApplies(getContext(), msg.getSubscription().getBackingSubscription(getContext()))) { - return; - } - CanonicalSubscription updatedSubscription = (CanonicalSubscription) getSubscriptionInterceptor().getIdToSubscription().get(msg.getSubscription().getIdElement(getContext()).getIdPart()); if (updatedSubscription != null) { msg.setSubscription(updatedSubscription); } + if (!subscriptionTypeApplies(msg.getSubscription())) { + return; + } + // Load the resource IIdType payloadId = msg.getPayloadId(getContext()); Class type = getContext().getResourceDefinition(payloadId.getResourceType()).getImplementingClass(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionInterceptor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionInterceptor.java index d5b76d15448..58a01a2b4ac 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionInterceptor.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionInterceptor.java @@ -70,10 +70,6 @@ public abstract class BaseSubscriptionInterceptor exten static final String SUBSCRIPTION_STATUS = "Subscription.status"; static final String SUBSCRIPTION_TYPE = "Subscription.channel.type"; - static final String SUBSCRIPTION_CRITERIA = "Subscription.criteria"; - static final String SUBSCRIPTION_ENDPOINT = "Subscription.channel.endpoint"; - static final String SUBSCRIPTION_PAYLOAD = "Subscription.channel.payload"; - static final String SUBSCRIPTION_HEADER = "Subscription.channel.header"; private static final Integer MAX_SUBSCRIPTION_RESULTS = 1000; private SubscribableChannel myProcessingChannel; private SubscribableChannel myDeliveryChannel; @@ -128,7 +124,6 @@ public abstract class BaseSubscriptionInterceptor exten CanonicalSubscription retVal = new CanonicalSubscription(); try { retVal.setStatus(org.hl7.fhir.r4.model.Subscription.SubscriptionStatus.fromCode(subscription.getStatus())); - retVal.setBackingSubscription(myCtx, theSubscription); retVal.setChannelType(org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType.fromCode(subscription.getChannel().getType())); retVal.setCriteriaString(subscription.getCriteria()); retVal.setEndpointUrl(subscription.getChannel().getEndpoint()); @@ -147,7 +142,6 @@ public abstract class BaseSubscriptionInterceptor exten CanonicalSubscription retVal = new CanonicalSubscription(); try { retVal.setStatus(org.hl7.fhir.r4.model.Subscription.SubscriptionStatus.fromCode(subscription.getStatus().toCode())); - retVal.setBackingSubscription(myCtx, theSubscription); retVal.setChannelType(org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType.fromCode(subscription.getChannel().getType().toCode())); retVal.setCriteriaString(subscription.getCriteria()); retVal.setEndpointUrl(subscription.getChannel().getEndpoint()); @@ -193,7 +187,6 @@ public abstract class BaseSubscriptionInterceptor exten CanonicalSubscription retVal = new CanonicalSubscription(); retVal.setStatus(subscription.getStatus()); - retVal.setBackingSubscription(myCtx, theSubscription); retVal.setChannelType(subscription.getChannel().getType()); retVal.setCriteriaString(subscription.getCriteria()); retVal.setEndpointUrl(subscription.getChannel().getEndpoint()); @@ -204,7 +197,6 @@ public abstract class BaseSubscriptionInterceptor exten if (retVal.getChannelType() == Subscription.SubscriptionChannelType.EMAIL) { String from; String subjectTemplate; - String bodyTemplate; try { from = subscription.getChannel().getExtensionString(JpaConstants.EXT_SUBSCRIPTION_EMAIL_FROM); subjectTemplate = subscription.getChannel().getExtensionString(JpaConstants.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE); @@ -260,8 +252,7 @@ public abstract class BaseSubscriptionInterceptor exten myResourceTypeToDao = theResourceTypeToDao; } - IFhirResourceDao dao = (IFhirResourceDao) myResourceTypeToDao.get(theType); - return dao; + return (IFhirResourceDao) myResourceTypeToDao.get(theType); } public SubscribableChannel getDeliveryChannel() { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionSubscriber.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionSubscriber.java index a5c9f5c2b34..bc2e91c4ff1 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionSubscriber.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionSubscriber.java @@ -22,8 +22,6 @@ package ca.uhn.fhir.jpa.subscription; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.dao.IFhirResourceDao; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.r4.model.Subscription; import org.springframework.messaging.MessageHandler; @@ -62,19 +60,19 @@ public abstract class BaseSubscriptionSubscriber implements MessageHandler { /** * Does this subscription type (e.g. rest hook, websocket, etc) apply to this interceptor? */ - protected boolean subscriptionTypeApplies(FhirContext theCtx, IBaseResource theSubscription) { + protected boolean subscriptionTypeApplies(CanonicalSubscription theSubscription) { Subscription.SubscriptionChannelType channelType = getChannelType(); - return subscriptionTypeApplies(theCtx, theSubscription, channelType); + String subscriptionType = theSubscription.getChannelType().toCode(); + return subscriptionTypeApplies(subscriptionType, channelType); } /** * Does this subscription type (e.g. rest hook, websocket, etc) apply to this interceptor? */ - static boolean subscriptionTypeApplies(FhirContext theCtx, IBaseResource theSubscription, Subscription.SubscriptionChannelType theChannelType) { - IPrimitiveType subscriptionType = theCtx.newTerser().getSingleValueOrNull(theSubscription, BaseSubscriptionInterceptor.SUBSCRIPTION_TYPE, IPrimitiveType.class); + static boolean subscriptionTypeApplies(String theSubscriptionChannelTypeCode, Subscription.SubscriptionChannelType theChannelType) { boolean subscriptionTypeApplies = false; - if (subscriptionType != null) { - if (theChannelType.toCode().equals(subscriptionType.getValueAsString())) { + if (theSubscriptionChannelTypeCode != null) { + if (theChannelType.toCode().equals(theSubscriptionChannelTypeCode)) { subscriptionTypeApplies = true; } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/CanonicalSubscription.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/CanonicalSubscription.java index aa75ce9dfb6..dd21add9ed4 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/CanonicalSubscription.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/CanonicalSubscription.java @@ -22,12 +22,10 @@ package ca.uhn.fhir.jpa.subscription; import ca.uhn.fhir.context.FhirContext; import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.r4.model.EventDefinition; @@ -59,10 +57,6 @@ public class CanonicalSubscription implements Serializable { private Subscription.SubscriptionChannelType myChannelType; @JsonProperty("status") private Subscription.SubscriptionStatus myStatus; - @JsonIgnore - private transient IBaseResource myBackingSubscription; - @JsonProperty("backingSubscription") - private String myBackingSubscriptionString; @JsonProperty("triggerDefinition") private CanonicalEventDefinition myTrigger; @JsonProperty("emailDetails") @@ -91,13 +85,6 @@ public class CanonicalSubscription implements Serializable { .isEquals(); } - public IBaseResource getBackingSubscription(FhirContext theCtx) { - if (myBackingSubscription == null && myBackingSubscriptionString != null) { - myBackingSubscription = theCtx.newJsonParser().parseResource(myBackingSubscriptionString); - } - return myBackingSubscription; - } - public Subscription.SubscriptionChannelType getChannelType() { return myChannelType; } @@ -190,14 +177,6 @@ public class CanonicalSubscription implements Serializable { .toHashCode(); } - public void setBackingSubscription(FhirContext theCtx, IBaseResource theBackingSubscription) { - myBackingSubscription = theBackingSubscription; - myBackingSubscriptionString = null; - if (myBackingSubscription != null) { - myBackingSubscriptionString = theCtx.newJsonParser().encodeResourceToString(myBackingSubscription); - } - } - public void setHeaders(List> theHeader) { myHeaders = new ArrayList<>(); for (IPrimitiveType next : theHeader) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionActivatingSubscriber.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionActivatingSubscriber.java index e276b8ccbcc..89681e0c0da 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionActivatingSubscriber.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionActivatingSubscriber.java @@ -35,7 +35,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.messaging.MessagingException; -import org.springframework.scheduling.TaskScheduler; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; @@ -43,7 +42,6 @@ import org.springframework.transaction.support.TransactionSynchronizationAdapter import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.transaction.support.TransactionTemplate; -import java.util.Date; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -73,7 +71,14 @@ public class SubscriptionActivatingSubscriber { } public void activateAndRegisterSubscriptionIfRequired(final IBaseResource theSubscription) { - boolean subscriptionTypeApplies = BaseSubscriptionSubscriber.subscriptionTypeApplies(myCtx, theSubscription, myChannelType); + + // Grab the value for "Subscription.channel.type" so we can see if this + // subscriber applies.. + String subscriptionChannelType = myCtx + .newTerser() + .getSingleValueOrNull(theSubscription, BaseSubscriptionInterceptor.SUBSCRIPTION_TYPE, IPrimitiveType.class) + .getValueAsString(); + boolean subscriptionTypeApplies = BaseSubscriptionSubscriber.subscriptionTypeApplies(subscriptionChannelType, myChannelType); if (subscriptionTypeApplies == false) { return; }