Make sure we load subscriptions from DB at some point

This commit is contained in:
James Agnew 2018-02-15 17:13:27 -05:00
parent c8e61cd9a3
commit 8ea527fa76
1 changed files with 12 additions and 0 deletions

View File

@ -21,6 +21,8 @@ package ca.uhn.fhir.jpa.subscription;
*/ */
import ca.uhn.fhir.jpa.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Subscription; import org.hl7.fhir.r4.model.Subscription;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -51,6 +53,16 @@ public abstract class BaseSubscriptionDeliverySubscriber extends BaseSubscriptio
msg.setSubscription(updatedSubscription); msg.setSubscription(updatedSubscription);
} }
// 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 = Class.forName(payloadId.getResourceType());
IFhirResourceDao dao = getSubscriptionDao().getDao(type);
IBaseResource loadedPayload = dao.read(payloadId);
msg.setPayload(getContext(), loadedPayload);
handleMessage(msg); handleMessage(msg);
} catch (Exception e) { } catch (Exception e) {
ourLog.error("Failure handling subscription payload", e); ourLog.error("Failure handling subscription payload", e);