From 1e2d8b123ebae5a4feca6df350ae3bf76d586483 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Sat, 31 Aug 2024 20:09:56 -0400 Subject: [PATCH] improve match error (#6260) * improve error message * improve error message * fix tests --- .../main/resources/ca/uhn/fhir/i18n/hapi-messages.properties | 2 +- .../main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java | 3 +++ .../java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java | 2 +- .../ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java | 2 +- .../java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java | 2 +- .../uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java | 2 +- .../test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java | 2 +- .../java/ca/uhn/fhir/jpa/provider/r4/PatchProviderR4Test.java | 2 +- .../ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java | 2 +- .../main/java/ca/uhn/fhir/jpa/dao/BaseStorageResourceDao.java | 1 + 10 files changed, 12 insertions(+), 8 deletions(-) diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties index fbd3091918a..662ce8daf21 100644 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties @@ -91,7 +91,7 @@ ca.uhn.fhir.jpa.dao.BaseHapiFhirDao.incomingNoopInTransaction=Transaction contai ca.uhn.fhir.jpa.dao.BaseHapiFhirDao.invalidMatchUrlInvalidResourceType=Invalid match URL "{0}" - Unknown resource type: "{1}" ca.uhn.fhir.jpa.dao.BaseStorageDao.invalidMatchUrlNoMatches=Invalid match URL "{0}" - No resources match this search ca.uhn.fhir.jpa.dao.BaseStorageDao.inlineMatchNotSupported=Inline match URLs are not supported on this server. Cannot process reference: "{0}" -ca.uhn.fhir.jpa.dao.BaseStorageDao.transactionOperationWithMultipleMatchFailure=Failed to {0} resource with match URL "{1}" because this search matched {2} resources +ca.uhn.fhir.jpa.dao.BaseStorageDao.transactionOperationWithMultipleMatchFailure=Failed to {0} {1} with match URL "{2}" because this search matched {3} resources ca.uhn.fhir.jpa.dao.BaseStorageDao.deleteByUrlThresholdExceeded=Failed to DELETE resources with match URL "{0}" because the resolved number of resources: {1} exceeds the threshold of {2} ca.uhn.fhir.jpa.dao.BaseStorageDao.transactionOperationWithIdNotMatchFailure=Failed to {0} resource with match URL "{1}" because the matching resource does not match the provided ID ca.uhn.fhir.jpa.dao.BaseTransactionProcessor.multiplePartitionAccesses=Can not process transaction with {0} entries: Entries require access to multiple/conflicting partitions diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java index f6a04aa33c5..fbd583d0090 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java @@ -420,6 +420,7 @@ public abstract class BaseHapiFhirResourceDao extends B BaseStorageDao.class, "transactionOperationWithMultipleMatchFailure", "CREATE", + myResourceName, theMatchUrl, match.size()); throw new PreconditionFailedException(Msg.code(958) + msg); @@ -861,6 +862,7 @@ public abstract class BaseHapiFhirResourceDao extends B BaseStorageDao.class, "transactionOperationWithMultipleMatchFailure", "DELETE", + myResourceName, theUrl, resourceIds.size())); } @@ -2335,6 +2337,7 @@ public abstract class BaseHapiFhirResourceDao extends B BaseStorageDao.class, "transactionOperationWithMultipleMatchFailure", "UPDATE", + myResourceName, theMatchUrl, match.size()); throw new PreconditionFailedException(Msg.code(988) + msg); diff --git a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java index e0d0af476a6..68210181c19 100644 --- a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java +++ b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java @@ -761,7 +761,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { mySystemDao.transaction(mySrd, request); fail(""); } catch (PreconditionFailedException e) { - assertThat(e.getMessage()).contains("resource with match URL \"Patient?"); + assertThat(e.getMessage()).contains("Patient with match URL \"Patient?"); } } diff --git a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java index 2283bab81e0..678da5fbfda 100644 --- a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java @@ -641,7 +641,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { //@formatter:on fail(""); } catch (PreconditionFailedException e) { - assertEquals("HTTP 412 Precondition Failed: " + Msg.code(962) + "Failed to DELETE resource with match URL \"Patient?identifier=testDeleteConditionalMultiple\" because this search matched 2 resources", e.getMessage()); + assertEquals("HTTP 412 Precondition Failed: " + Msg.code(962) + "Failed to DELETE Patient with match URL \"Patient?identifier=testDeleteConditionalMultiple\" because this search matched 2 resources", e.getMessage()); } // Not deleted yet.. diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java index 71f54e74401..501e8049b60 100644 --- a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java @@ -1357,7 +1357,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { mySystemDao.transaction(mySrd, request); fail(""); } catch (PreconditionFailedException e) { - assertThat(e.getMessage()).contains("resource with match URL \"Patient?"); + assertThat(e.getMessage()).contains("Patient with match URL \"Patient?"); } } diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java index 72754cb7465..a4bc55eef46 100644 --- a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java @@ -1083,7 +1083,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { //@formatter:on fail(""); } catch (PreconditionFailedException e) { - assertEquals("HTTP 412 Precondition Failed: " + Msg.code(962) + "Failed to DELETE resource with match URL \"Patient?identifier=testDeleteConditionalMultiple&_format=json\" because this search matched 2 resources", e.getMessage()); + assertEquals("HTTP 412 Precondition Failed: " + Msg.code(962) + "Failed to DELETE Patient with match URL \"Patient?identifier=testDeleteConditionalMultiple&_format=json\" because this search matched 2 resources", e.getMessage()); } // Not deleted yet.. diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java index 83c2be3a669..688a74936b8 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java @@ -2548,7 +2548,7 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest { mySystemDao.transaction(mySrd, request); fail(); } catch (PreconditionFailedException e) { - assertThat(e.getMessage()).contains("resource with match URL \"Patient?"); + assertThat(e.getMessage()).contains("Patient with match URL \"Patient?"); } } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatchProviderR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatchProviderR4Test.java index bf0fb811a25..ac515b0d580 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatchProviderR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatchProviderR4Test.java @@ -529,7 +529,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertEquals(412, response.getStatusLine().getStatusCode()); String responseString = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); assertThat(responseString).contains(" extends Ba BaseStorageDao.class, "transactionOperationWithMultipleMatchFailure", "PATCH", + getResourceName(), theConditionalUrl, match.size()); throw new PreconditionFailedException(Msg.code(972) + msg);