Fixing response message when deleting non-existing or deleted resource. (#3898)
* Fixing response message when deleting non-existing or deleted resource. * Changed names of properties. * The full ID shown in message, not just IdPart
This commit is contained in:
parent
f4a0397b18
commit
64e1f4d381
|
@ -103,6 +103,8 @@ ca.uhn.fhir.jpa.dao.BaseStorageDao.unableToDeleteNotFound=Unable to find resourc
|
|||
ca.uhn.fhir.jpa.dao.BaseStorageDao.successfulCreate=Successfully created resource "{0}" in {1}ms
|
||||
ca.uhn.fhir.jpa.dao.BaseStorageDao.successfulUpdate=Successfully updated resource "{0}" in {1}ms
|
||||
ca.uhn.fhir.jpa.dao.BaseStorageDao.successfulDeletes=Successfully deleted {0} resource(s) in {1}ms
|
||||
ca.uhn.fhir.jpa.dao.BaseStorageDao.deleteResourceNotExisting=Not deleted, resource {0} does not exist.
|
||||
ca.uhn.fhir.jpa.dao.BaseStorageDao.deleteResourceAlreadyDeleted=Not deleted, resource {0} was already deleted.
|
||||
ca.uhn.fhir.jpa.dao.BaseStorageDao.invalidSearchParameter=Unknown search parameter "{0}" for resource type "{1}". Valid search parameters for this search are: {2}
|
||||
ca.uhn.fhir.jpa.dao.BaseStorageDao.invalidSortParameter=Unknown _sort parameter value "{0}" for resource type "{1}" (Note: sort parameters values must use a valid Search Parameter). Valid values for this search are: {2}
|
||||
ca.uhn.fhir.jpa.dao.BaseStorageDao.updateWithNoId=Can not update resource of type {0} as it has no ID
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 3897
|
||||
title: "Providing a meaningful response message when deleting non-existing or already deleted resources."
|
|
@ -513,7 +513,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
*
|
||||
* @param theId - the id of the object being deleted. Eg: Patient/123
|
||||
*/
|
||||
private DaoMethodOutcome createMethodOutcomeForDelete(String theId) {
|
||||
private DaoMethodOutcome createMethodOutcomeForDelete(String theId, String theKey) {
|
||||
DaoMethodOutcome outcome = new DaoMethodOutcome();
|
||||
|
||||
IIdType id = getContext().getVersion().newIdType();
|
||||
|
@ -521,7 +521,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
outcome.setId(id);
|
||||
|
||||
IBaseOperationOutcome oo = OperationOutcomeUtil.newInstance(getContext());
|
||||
String message = getContext().getLocalizer().getMessage(BaseStorageDao.class, "successfulDeletes", 1, 0);
|
||||
String message = getContext().getLocalizer().getMessage(BaseStorageDao.class, theKey, id);
|
||||
String severity = "information";
|
||||
String code = "informational";
|
||||
OperationOutcomeUtil.addIssue(getContext(), oo, severity, message, null, code);
|
||||
|
@ -546,7 +546,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
// if not found, return an outcome anyways.
|
||||
// Because no object actually existed, we'll
|
||||
// just set the id and nothing else
|
||||
DaoMethodOutcome outcome = createMethodOutcomeForDelete(theId.getValue());
|
||||
DaoMethodOutcome outcome = createMethodOutcomeForDelete(theId.getValue(), "deleteResourceNotExisting");
|
||||
return outcome;
|
||||
}
|
||||
|
||||
|
@ -556,7 +556,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
|
||||
// Don't delete again if it's already deleted
|
||||
if (isDeleted(entity)) {
|
||||
DaoMethodOutcome outcome = createMethodOutcomeForDelete(entity.getIdDt().getValue());
|
||||
DaoMethodOutcome outcome = createMethodOutcomeForDelete(entity.getIdDt().getValue(), "deleteResourceAlreadyDeleted");
|
||||
|
||||
// used to exist, so we'll set the persistent id
|
||||
outcome.setPersistentId(new ResourcePersistentId(entity.getResourceId()));
|
||||
|
|
|
@ -1737,6 +1737,32 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
assertThat(oo.getIssueFirstRep().getDiagnostics(), startsWith("Successfully deleted 1 resource(s) in "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteNonExistingResourceReturnsOperationOutcome() {
|
||||
String resourceType = "Patient";
|
||||
String logicalID = "12345";
|
||||
|
||||
MethodOutcome resp = myClient.delete().resourceById(resourceType, logicalID).execute();
|
||||
|
||||
OperationOutcome oo = (OperationOutcome) resp.getOperationOutcome();
|
||||
assertThat(oo.getIssueFirstRep().getDiagnostics(), startsWith("Not deleted, resource " + resourceType + "/" + logicalID + " does not exist."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteAlreadyDeletedReturnsOperationOutcome() {
|
||||
Patient p = new Patient();
|
||||
IIdType id = myClient.create().resource(p).execute().getId();
|
||||
|
||||
MethodOutcome resp = myClient.delete().resourceById(id).execute();
|
||||
OperationOutcome oo = (OperationOutcome) resp.getOperationOutcome();
|
||||
assertThat(oo.getIssueFirstRep().getDiagnostics(), startsWith("Successfully deleted 1 resource(s) in "));
|
||||
|
||||
resp = myClient.delete().resourceById(id).execute();
|
||||
oo = (OperationOutcome) resp.getOperationOutcome();
|
||||
assertThat(oo.getIssueFirstRep().getDiagnostics(), startsWith("Not deleted, resource "));
|
||||
assertThat(oo.getIssueFirstRep().getDiagnostics(), endsWith("was already deleted."));
|
||||
}
|
||||
|
||||
/**
|
||||
* See issue #52
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue