Move subscription models to legacy, except the ones that are subscription specific

This commit is contained in:
Tadgh 2020-09-09 15:58:41 -04:00
parent df20a04b53
commit 2229233749
36 changed files with 595 additions and 88 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 {

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<ActiveSubscription> subscriptions = mySubscriptionRegistry.getAll();

View File

@ -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;

View File

@ -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<String, String> myAttributes;
/**
* Returns an attribute stored in this message.
* <p>
* 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.
* </p>
* <p>
* 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.
* </p>
*/
public Optional<String> 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.
* <p>
* 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.
* </p>
* <p>
* 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.
* </p>
*
* @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);
}
}
}

View File

@ -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<LegacyResourceModifiedMessage> {
@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();
}
}

View File

@ -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<ResourceReferenceInfo> 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();
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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(() -> {

View File

@ -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;

View File

@ -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;

View File

@ -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 {

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -73,6 +73,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
</dependency>
</dependencies>

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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<T> implements Message<T>, 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;
}
}

View File

@ -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;

View File

@ -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<ResourceModifiedSubscriptionMessage> {
@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();
}
}