From 078dcd9c0d88c6c2be318758caa7dfdbe17c7710 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Thu, 26 Jan 2023 12:22:30 -0500 Subject: [PATCH] One more fix for #4467 --- .../server/provider/HashMapResourceProvider.java | 11 +++++------ .../server/provider/HashMapResourceProviderTest.java | 12 +++++++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/HashMapResourceProvider.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/HashMapResourceProvider.java index ce3b17905a4..045147d5aa0 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/HashMapResourceProvider.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/HashMapResourceProvider.java @@ -264,17 +264,16 @@ public class HashMapResourceProvider implements IResour if (!versions.containsKey(versionId)) { throw new ResourceNotFoundException(Msg.code(1982) + theId); } else { - T resource = versions.get(versionId); - if (resource == null || ResourceMetadataKeyEnum.DELETED_AT.get(resource) != null) { - throw new ResourceGoneException(Msg.code(1983) + theId); - } - retVal = resource; + retVal = versions.get(versionId); } - } else { retVal = versions.lastEntry().getValue(); } + if (retVal == null || ResourceMetadataKeyEnum.DELETED_AT.get(retVal) != null) { + throw new ResourceGoneException(Msg.code(1983) + theId); + } + myReadCount.incrementAndGet(); retVal = fireInterceptorsAndFilterAsNeeded(retVal, theRequestDetails); diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/provider/HashMapResourceProviderTest.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/provider/HashMapResourceProviderTest.java index 526ef9dab6b..3bfbf90c7a7 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/provider/HashMapResourceProviderTest.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/provider/HashMapResourceProviderTest.java @@ -115,8 +115,10 @@ public class HashMapResourceProviderTest { assertEquals(1, myPatientResourceProvider.getCountDelete()); - // Read + // VRead original version ourRestServer.getFhirClient().read().resource("Patient").withId(id.withVersion("1")).execute(); + + // Vread gone version try { ourRestServer.getFhirClient().read().resource("Patient").withId(id.withVersion("2")).execute(); fail(); @@ -124,6 +126,14 @@ public class HashMapResourceProviderTest { // good } + // Read (non vread) gone version + try { + ourRestServer.getFhirClient().read().resource("Patient").withId(id.toUnqualifiedVersionless()).execute(); + fail(); + } catch (ResourceGoneException e) { + // good + } + // History should include deleted entry Bundle history = ourRestServer.getFhirClient().history().onType(Patient.class).returnBundle(Bundle.class).execute(); ourLog.info("History:\n{}", ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(history));