Return an OperationOutcome in the response for a delete in JPA
This commit is contained in:
parent
a665aed85d
commit
d5fbcf8e82
|
@ -226,8 +226,16 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
|
|
||||||
validateDeleteConflictsEmptyOrThrowException(deleteConflicts);
|
validateDeleteConflictsEmptyOrThrowException(deleteConflicts);
|
||||||
|
|
||||||
|
IBaseOperationOutcome oo = OperationOutcomeUtil.newInstance(getContext());
|
||||||
|
String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "successfulDeletes", 1, w.getMillis());
|
||||||
|
String severity = "information";
|
||||||
|
String code = "informational";
|
||||||
|
OperationOutcomeUtil.addIssue(getContext(), oo, severity, message, null, code);
|
||||||
|
|
||||||
ourLog.info("Processed delete on {} in {}ms", theId.getValue(), w.getMillisAndRestart());
|
ourLog.info("Processed delete on {} in {}ms", theId.getValue(), w.getMillisAndRestart());
|
||||||
return toMethodOutcome(savedEntity, null);
|
DaoMethodOutcome retVal = toMethodOutcome(savedEntity, null);
|
||||||
|
retVal.setOperationOutcome(oo);
|
||||||
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -287,7 +295,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
OperationOutcomeUtil.addIssue(getContext(), oo, severity, message, null, code);
|
OperationOutcomeUtil.addIssue(getContext(), oo, severity, message, null, code);
|
||||||
} else {
|
} else {
|
||||||
oo = OperationOutcomeUtil.newInstance(getContext());
|
oo = OperationOutcomeUtil.newInstance(getContext());
|
||||||
String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "successfulDeletes", theUrl, deletedResources.size(), w.getMillis());
|
String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "successfulDeletes", deletedResources.size(), w.getMillis());
|
||||||
String severity = "information";
|
String severity = "information";
|
||||||
String code = "informational";
|
String code = "informational";
|
||||||
OperationOutcomeUtil.addIssue(getContext(), oo, severity, message, null, code);
|
OperationOutcomeUtil.addIssue(getContext(), oo, severity, message, null, code);
|
||||||
|
|
|
@ -161,7 +161,6 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
myDaoConfig.setAllowMultipleDelete(true);
|
myDaoConfig.setAllowMultipleDelete(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void checkParamMissing(String paramName) throws IOException, ClientProtocolException {
|
private void checkParamMissing(String paramName) throws IOException, ClientProtocolException {
|
||||||
HttpGet get = new HttpGet(ourServerBase + "/Observation?" + paramName + ":missing=false");
|
HttpGet get = new HttpGet(ourServerBase + "/Observation?" + paramName + ":missing=false");
|
||||||
CloseableHttpResponse resp = ourHttpClient.execute(get);
|
CloseableHttpResponse resp = ourHttpClient.execute(get);
|
||||||
|
@ -726,7 +725,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
* Test for #345
|
* Test for #345
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteNormal() throws IOException {
|
public void testDeleteNormal() {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
p.addName().setFamily("FAM");
|
p.addName().setFamily("FAM");
|
||||||
IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless();
|
IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless();
|
||||||
|
@ -743,6 +742,17 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteReturnsOperationOutcome() {
|
||||||
|
Patient p = new Patient();
|
||||||
|
p.addName().setFamily("FAM");
|
||||||
|
IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
|
IBaseOperationOutcome resp = ourClient.delete().resourceById(id).execute();
|
||||||
|
OperationOutcome oo = (OperationOutcome) resp;
|
||||||
|
assertThat(oo.getIssueFirstRep().getDiagnostics(), startsWith("Successfully deleted 1 resource(s) in "));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteResourceConditional1() throws IOException {
|
public void testDeleteResourceConditional1() throws IOException {
|
||||||
String methodName = "testDeleteResourceConditional1";
|
String methodName = "testDeleteResourceConditional1";
|
||||||
|
@ -768,6 +778,10 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
response = ourHttpClient.execute(delete);
|
response = ourHttpClient.execute(delete);
|
||||||
try {
|
try {
|
||||||
assertEquals(200, response.getStatusLine().getStatusCode());
|
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||||
|
String resp = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
|
||||||
|
ourLog.info(resp);
|
||||||
|
OperationOutcome oo = myFhirCtx.newXmlParser().parseResource(OperationOutcome.class, resp);
|
||||||
|
assertThat(oo.getIssueFirstRep().getDiagnostics(), startsWith("Successfully deleted 1 resource(s) in "));
|
||||||
} finally {
|
} finally {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
@ -777,6 +791,24 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
try {
|
try {
|
||||||
ourLog.info(response.toString());
|
ourLog.info(response.toString());
|
||||||
assertEquals(Constants.STATUS_HTTP_410_GONE, response.getStatusLine().getStatusCode());
|
assertEquals(Constants.STATUS_HTTP_410_GONE, response.getStatusLine().getStatusCode());
|
||||||
|
String resp = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
|
||||||
|
ourLog.info(resp);
|
||||||
|
OperationOutcome oo = myFhirCtx.newXmlParser().parseResource(OperationOutcome.class, resp);
|
||||||
|
assertThat(oo.getIssueFirstRep().getDiagnostics(), startsWith("Resource was deleted at"));
|
||||||
|
} finally {
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete should now have no matches
|
||||||
|
|
||||||
|
delete = new HttpDelete(ourServerBase + "/Patient?name=" + methodName);
|
||||||
|
response = ourHttpClient.execute(delete);
|
||||||
|
try {
|
||||||
|
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||||
|
String resp = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
|
||||||
|
ourLog.info(resp);
|
||||||
|
OperationOutcome oo = myFhirCtx.newXmlParser().parseResource(OperationOutcome.class, resp);
|
||||||
|
assertThat(oo.getIssueFirstRep().getDiagnostics(), startsWith("Unable to find resource matching URL \"Patient?name=testDeleteResourceConditional1\". Deletion failed."));
|
||||||
} finally {
|
} finally {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
@ -1781,7 +1813,10 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
ourLog.info("Response: {}", respString);
|
ourLog.info("Response: {}", respString);
|
||||||
assertEquals(400, response.getStatusLine().getStatusCode());
|
assertEquals(400, response.getStatusLine().getStatusCode());
|
||||||
OperationOutcome oo = myFhirCtx.newXmlParser().parseResource(OperationOutcome.class, respString);
|
OperationOutcome oo = myFhirCtx.newXmlParser().parseResource(OperationOutcome.class, respString);
|
||||||
assertEquals("Can not update resource, resource body must contain an ID element which matches the request URL for update (PUT) operation - Resource body ID of \"AAA\" does not match URL ID of \"" + id.getIdPart() + "\"", oo.getIssue().get(0).getDiagnostics());
|
assertEquals(
|
||||||
|
"Can not update resource, resource body must contain an ID element which matches the request URL for update (PUT) operation - Resource body ID of \"AAA\" does not match URL ID of \""
|
||||||
|
+ id.getIdPart() + "\"",
|
||||||
|
oo.getIssue().get(0).getDiagnostics());
|
||||||
} finally {
|
} finally {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
@ -1814,7 +1849,6 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
p.getManagingOrganization().setReference("http://example.com/Organization/123");
|
p.getManagingOrganization().setReference("http://example.com/Organization/123");
|
||||||
ourClient.create().resource(p).execute();
|
ourClient.create().resource(p).execute();
|
||||||
|
|
||||||
|
|
||||||
Bundle b = ourClient.search().forResource("Patient").include(Patient.INCLUDE_ORGANIZATION).returnBundle(Bundle.class).execute();
|
Bundle b = ourClient.search().forResource("Patient").include(Patient.INCLUDE_ORGANIZATION).returnBundle(Bundle.class).execute();
|
||||||
assertEquals(1, b.getEntry().size());
|
assertEquals(1, b.getEntry().size());
|
||||||
}
|
}
|
||||||
|
@ -1834,7 +1868,6 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMetadataSuperParamsAreIncluded() throws IOException {
|
public void testMetadataSuperParamsAreIncluded() throws IOException {
|
||||||
StructureDefinition p = new StructureDefinition();
|
StructureDefinition p = new StructureDefinition();
|
||||||
|
@ -1843,11 +1876,11 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless();
|
IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
Bundle resp = ourClient
|
Bundle resp = ourClient
|
||||||
.search()
|
.search()
|
||||||
.forResource(StructureDefinition.class)
|
.forResource(StructureDefinition.class)
|
||||||
.where(StructureDefinition.URL.matches().value("http://example.com/foo"))
|
.where(StructureDefinition.URL.matches().value("http://example.com/foo"))
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
assertEquals(1, resp.getTotal());
|
assertEquals(1, resp.getTotal());
|
||||||
}
|
}
|
||||||
|
@ -2102,8 +2135,9 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
String respString = ourClient.transaction().withBundle(input).prettyPrint().execute();
|
String respString = ourClient.transaction().withBundle(input).prettyPrint().execute();
|
||||||
ourLog.info(respString);
|
ourLog.info(respString);
|
||||||
|
|
||||||
ourHttpClient.execute(new HttpGet("http://localhost:" + ourPort + "/QuestionnaireResponse?patient=QR3295&questionnaire=profile&_sort:desc=authored&_count=5&_include=QuestionnaireResponse:questionnaire&_include=QuestionnaireResponse:subject"));
|
ourHttpClient.execute(new HttpGet("http://localhost:" + ourPort
|
||||||
// Bundle bundle =
|
+ "/QuestionnaireResponse?patient=QR3295&questionnaire=profile&_sort:desc=authored&_count=5&_include=QuestionnaireResponse:questionnaire&_include=QuestionnaireResponse:subject"));
|
||||||
|
// Bundle bundle =
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2284,11 +2318,11 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
Bundle found = ourClient
|
Bundle found = ourClient
|
||||||
.search()
|
.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(BaseResource.RES_ID.exactly().systemAndValues(null, id1.getIdPart(), id2.getIdPart()))
|
.where(BaseResource.RES_ID.exactly().systemAndValues(null, id1.getIdPart(), id2.getIdPart()))
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
assertThat(toUnqualifiedVersionlessIds(found), empty());
|
assertThat(toUnqualifiedVersionlessIds(found), empty());
|
||||||
|
|
||||||
|
@ -2321,12 +2355,12 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1));
|
assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1));
|
||||||
|
|
||||||
found = ourClient
|
found = ourClient
|
||||||
.search()
|
.search()
|
||||||
.forResource(Patient.class)
|
.forResource(Patient.class)
|
||||||
.where(BaseResource.RES_ID.exactly().codes(Arrays.asList(id1.getIdPart(), id2.getIdPart(), "FOOOOO")))
|
.where(BaseResource.RES_ID.exactly().codes(Arrays.asList(id1.getIdPart(), id2.getIdPart(), "FOOOOO")))
|
||||||
.and(BaseResource.RES_ID.exactly().code(id1.getIdPart()))
|
.and(BaseResource.RES_ID.exactly().code(id1.getIdPart()))
|
||||||
.returnBundle(Bundle.class)
|
.returnBundle(Bundle.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1));
|
assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1));
|
||||||
|
|
||||||
|
@ -3445,7 +3479,9 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
ourLog.info(responseString);
|
ourLog.info(responseString);
|
||||||
assertEquals(400, response.getStatusLine().getStatusCode());
|
assertEquals(400, response.getStatusLine().getStatusCode());
|
||||||
OperationOutcome oo = myFhirCtx.newXmlParser().parseResource(OperationOutcome.class, responseString);
|
OperationOutcome oo = myFhirCtx.newXmlParser().parseResource(OperationOutcome.class, responseString);
|
||||||
assertEquals("Can not update resource, resource body must contain an ID element which matches the request URL for update (PUT) operation - Resource body ID of \"333\" does not match URL ID of \"A2\"", oo.getIssue().get(0).getDiagnostics());
|
assertEquals(
|
||||||
|
"Can not update resource, resource body must contain an ID element which matches the request URL for update (PUT) operation - Resource body ID of \"333\" does not match URL ID of \"A2\"",
|
||||||
|
oo.getIssue().get(0).getDiagnostics());
|
||||||
} finally {
|
} finally {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,10 @@
|
||||||
Client revincludes did not include the :recurse modifier. Thanks to
|
Client revincludes did not include the :recurse modifier. Thanks to
|
||||||
Jenny Meinsma for pointing this out on Zulip!
|
Jenny Meinsma for pointing this out on Zulip!
|
||||||
</action>
|
</action>
|
||||||
|
<action type="add">
|
||||||
|
JPA server did not return an OperationOutcome in the response for
|
||||||
|
a normal delete operation.
|
||||||
|
</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="2.2" date="2016-12-20">
|
<release version="2.2" date="2016-12-20">
|
||||||
<action type="add">
|
<action type="add">
|
||||||
|
|
Loading…
Reference in New Issue