Add config

This commit is contained in:
jamesagnew 2018-02-18 11:11:35 -05:00
parent 2f4ac42edb
commit a60e5cab2a
1 changed files with 19 additions and 12 deletions

View File

@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.subscription;
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -31,6 +31,7 @@ import org.springframework.messaging.MessagingException;
public abstract class BaseSubscriptionDeliverySubscriber extends BaseSubscriptionSubscriber { public abstract class BaseSubscriptionDeliverySubscriber extends BaseSubscriptionSubscriber {
private static final Logger ourLog = LoggerFactory.getLogger(BaseSubscriptionDeliverySubscriber.class); private static final Logger ourLog = LoggerFactory.getLogger(BaseSubscriptionDeliverySubscriber.class);
private boolean myReloadResourceBeforeDelivery = true;
public BaseSubscriptionDeliverySubscriber(IFhirResourceDao<?> theSubscriptionDao, Subscription.SubscriptionChannelType theChannelType, BaseSubscriptionInterceptor theSubscriptionInterceptor) { public BaseSubscriptionDeliverySubscriber(IFhirResourceDao<?> theSubscriptionDao, Subscription.SubscriptionChannelType theChannelType, BaseSubscriptionInterceptor theSubscriptionInterceptor) {
super(theSubscriptionDao, theChannelType, theSubscriptionInterceptor); super(theSubscriptionDao, theChannelType, theSubscriptionInterceptor);
@ -48,20 +49,22 @@ public abstract class BaseSubscriptionDeliverySubscriber extends BaseSubscriptio
return; return;
} }
CanonicalSubscription updatedSubscription = (CanonicalSubscription)getSubscriptionInterceptor().getIdToSubscription().get(msg.getSubscription().getIdElement(getContext()).getIdPart()); CanonicalSubscription updatedSubscription = (CanonicalSubscription) getSubscriptionInterceptor().getIdToSubscription().get(msg.getSubscription().getIdElement(getContext()).getIdPart());
if (updatedSubscription != null) { if (updatedSubscription != null) {
msg.setSubscription(updatedSubscription); msg.setSubscription(updatedSubscription);
} }
// Reload the payload just in case any interceptors modified if (myReloadResourceBeforeDelivery) {
// it before it was saved to the database. This is also // Reload the payload just in case any interceptors modified
// useful for resources created in a transaction, since they // it before it was saved to the database. This is also
// can have placeholder IDs in them. // useful for resources created in a transaction, since they
IIdType payloadId = msg.getPayloadId(getContext()); // can have placeholder IDs in them.
Class type = getContext().getResourceDefinition(payloadId.getResourceType()).getImplementingClass(); IIdType payloadId = msg.getPayloadId(getContext());
IFhirResourceDao dao = getSubscriptionDao().getDao(type); Class type = getContext().getResourceDefinition(payloadId.getResourceType()).getImplementingClass();
IBaseResource loadedPayload = dao.read(payloadId); IFhirResourceDao dao = getSubscriptionDao().getDao(type);
msg.setPayload(getContext(), loadedPayload); IBaseResource loadedPayload = dao.read(payloadId);
msg.setPayload(getContext(), loadedPayload);
}
handleMessage(msg); handleMessage(msg);
} catch (Exception e) { } catch (Exception e) {
@ -72,4 +75,8 @@ public abstract class BaseSubscriptionDeliverySubscriber extends BaseSubscriptio
public abstract void handleMessage(ResourceDeliveryMessage theMessage) throws Exception; public abstract void handleMessage(ResourceDeliveryMessage theMessage) throws Exception;
public void setReloadResourceBeforeDelivery(boolean theReloadResourceBeforeDelivery) {
myReloadResourceBeforeDelivery = theReloadResourceBeforeDelivery;
}
} }