add RESOURCE_PID to resource UserData before STORAGE_PRECOMMIT_RESOURCE_UPDATED hooks are called
This commit is contained in:
parent
fe7d38d0b5
commit
634718c503
|
@ -1216,6 +1216,9 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
|
|||
// Update version/lastUpdated so that interceptors see the correct version
|
||||
updateResourceMetadata(savedEntity, theResource);
|
||||
|
||||
// Populate the PID in the resource so it is available to hooks
|
||||
addPidToResource(savedEntity, theResource);
|
||||
|
||||
// Notify interceptors
|
||||
if (!savedEntity.isUnchangedInCurrentOperation()) {
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
|
||||
|
@ -1234,6 +1237,12 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
|
|||
return savedEntity;
|
||||
}
|
||||
|
||||
protected void addPidToResource(ResourceTable theEntity, IBaseResource theResource) {
|
||||
if (theResource instanceof IAnyResource) {
|
||||
IDao.RESOURCE_PID.put((IAnyResource) theResource, theEntity.getId());
|
||||
}
|
||||
}
|
||||
|
||||
protected void doCallHooks(RequestDetails theRequestDetails, Pointcut thePointcut, HookParams theParams) {
|
||||
JpaInterceptorBroadcaster.doCallHooks(myInterceptorBroadcaster, theRequestDetails, thePointcut, theParams);
|
||||
}
|
||||
|
|
|
@ -462,9 +462,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
updateResourceMetadata(entity, theResource);
|
||||
|
||||
// Populate the PID in the resource so it is available to hooks
|
||||
if (theResource instanceof IAnyResource) {
|
||||
IDao.RESOURCE_PID.put((IAnyResource)theResource, entity.getId());
|
||||
}
|
||||
addPidToResource(entity, theResource);
|
||||
|
||||
// Notify JPA interceptors
|
||||
if (!updatedEntity.isUnchangedInCurrentOperation()) {
|
||||
|
|
|
@ -78,6 +78,31 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test {
|
|||
assertTrue(pid.get() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSTORAGE_PRECOMMIT_RESOURCE_UPDATED_hasPid() {
|
||||
AtomicLong oldPid = new AtomicLong();
|
||||
AtomicLong newPid = new AtomicLong();
|
||||
myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.STORAGE_PRECOMMIT_RESOURCE_UPDATED, (thePointcut, t) -> {
|
||||
|
||||
IAnyResource oldResource = (IAnyResource) t.get(IBaseResource.class, 0);
|
||||
Long oldResourcePid = (Long) oldResource.getUserData("RESOURCE_PID");
|
||||
assertNotNull("Expecting RESOURCE_PID to be set on resource user data.", oldResourcePid);
|
||||
oldPid.set(oldResourcePid);
|
||||
|
||||
IAnyResource newResource = (IAnyResource) t.get(IBaseResource.class, 1);
|
||||
Long newResourcePid = (Long) newResource.getUserData("RESOURCE_PID");
|
||||
assertNotNull("Expecting RESOURCE_PID to be set on resource user data.", newResourcePid);
|
||||
newPid.set(newResourcePid);
|
||||
});
|
||||
Patient patient = new Patient();
|
||||
IIdType id = ourClient.create().resource(patient).execute().getId();
|
||||
patient.setId(id);
|
||||
patient.getNameFirstRep().setFamily("SOMECHANGE");
|
||||
ourClient.update().resource(patient).execute();
|
||||
assertTrue(oldPid.get() > 0);
|
||||
assertTrue(newPid.get() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOP_PRESTORAGE_RESOURCE_UPDATED_ModifyResource() {
|
||||
Patient p = new Patient();
|
||||
|
|
Loading…
Reference in New Issue