From a308f60e16dbff70a7b41f2342cab47bcab4d2c2 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Sat, 13 May 2023 22:35:18 -0400 Subject: [PATCH] relax (#4880) Co-authored-by: Ken Stevens --- .../provider/HashMapResourceProvider.java | 10 +++++-- .../provider/HashMapResourceProviderTest.java | 27 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 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 42499500488..5efe1e59b85 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 @@ -257,7 +257,11 @@ public class HashMapResourceProvider implements IResour } @Read(version = true) - public synchronized T read(@IdParam IIdType theId, RequestDetails theRequestDetails) { + public T read(@IdParam IIdType theId, RequestDetails theRequestDetails) { + return read(theId, theRequestDetails, false); + } + + public synchronized T read(IIdType theId, RequestDetails theRequestDetails, boolean theDeletedOk) { TreeMap versions = myIdToVersionToResourceMap.get(theId.getIdPart()); if (versions == null || versions.isEmpty()) { throw new ResourceNotFoundException(Msg.code(2247) + theId); @@ -276,7 +280,9 @@ public class HashMapResourceProvider implements IResour } if (retVal == null || retVal.isDeleted()) { - throw new ResourceGoneException(Msg.code(2244) + theId); + if (!theDeletedOk) { + throw new ResourceGoneException(Msg.code(2244) + theId); + } } myReadCount.incrementAndGet(); 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 3bfbf90c7a7..8bd87cfbef3 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 @@ -3,15 +3,13 @@ package ca.uhn.fhir.rest.server.provider; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.interceptor.api.IAnonymousInterceptor; import ca.uhn.fhir.interceptor.api.Pointcut; +import ca.uhn.fhir.rest.api.server.SystemRequestDetails; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor; import ca.uhn.fhir.test.utilities.server.HashMapResourceProviderExtension; import ca.uhn.fhir.test.utilities.server.RestfulServerExtension; import ca.uhn.fhir.util.TestUtil; -import ca.uhn.fhir.validation.FhirValidator; -import ca.uhn.fhir.validation.ResultSeverityEnum; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Bundle; @@ -350,6 +348,29 @@ public class HashMapResourceProviderTest { } } + @Test + void testReadDeletedOk() { + Patient patient = new Patient(); + patient.setActive(true); + SystemRequestDetails srd = new SystemRequestDetails(); + + IIdType patientId = myPatientResourceProvider.create(patient, srd).getId().toVersionless(); + Patient readPatient = myPatientResourceProvider.read(patientId, srd, true); + assertFalse(readPatient.isDeleted()); + } + + @Test + void testReadDeletedDeletedOk() { + Patient patient = new Patient(); + patient.setActive(true); + SystemRequestDetails srd = new SystemRequestDetails(); + + IIdType patientId = myPatientResourceProvider.create(patient, srd).getId().toVersionless(); + myPatientResourceProvider.delete(patientId, srd); + Patient readPatient = myPatientResourceProvider.read(patientId, srd, true); + assertTrue(readPatient.isDeleted()); + } + @AfterAll public static void afterClassClearContext() throws Exception { TestUtil.randomizeLocaleAndTimezone();