Improve error message when $meta-add and $meta-delete are called with no meta element in the

input parameters. Also improve OperationOutcome rendering in narrative generator.
This commit is contained in:
jamesagnew 2015-09-24 08:36:25 -04:00
parent 835abdfbea
commit 70eff0dc7f
5 changed files with 62 additions and 3 deletions

View File

@ -11,7 +11,7 @@
<tr th:each="issue : ${resource.issue}"> <tr th:each="issue : ${resource.issue}">
<td th:text="${issue.severityElement.value}" style="font-weight: bold;"></td> <td th:text="${issue.severityElement.value}" style="font-weight: bold;"></td>
<td th:text="${issue.location}"></td> <td th:text="${issue.location}"></td>
<td><pre th:text="${issue.details}"/></td> <td><pre th:text="${issue.diagnostics}"/></td>
</tr> </tr>
</table> </table>
</div> </div>

View File

@ -39,6 +39,7 @@ import ca.uhn.fhir.rest.annotation.Validate;
import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.ValidationModeEnum; import ca.uhn.fhir.rest.api.ValidationModeEnum;
import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResourceProvider<T> { public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResourceProvider<T> {
@ -112,6 +113,9 @@ public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResour
}) })
//@formatter:on //@formatter:on
public Parameters metaAdd(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta) { public Parameters metaAdd(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta) {
if (theMeta == null) {
throw new InvalidRequestException("Input contains no parameter with name 'meta'");
}
Parameters parameters = new Parameters(); Parameters parameters = new Parameters();
MetaDt metaAddOperation = getDao().metaAddOperation(theId, theMeta); MetaDt metaAddOperation = getDao().metaAddOperation(theId, theMeta);
parameters.addParameter().setName("return").setValue(metaAddOperation); parameters.addParameter().setName("return").setValue(metaAddOperation);
@ -124,6 +128,9 @@ public class JpaResourceProviderDstu2<T extends IResource> extends BaseJpaResour
}) })
//@formatter:on //@formatter:on
public Parameters metaDelete(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta) { public Parameters metaDelete(@IdParam IdDt theId, @OperationParam(name = "meta") MetaDt theMeta) {
if (theMeta == null) {
throw new InvalidRequestException("Input contains no parameter with name 'meta'");
}
Parameters parameters = new Parameters(); Parameters parameters = new Parameters();
parameters.addParameter().setName("return").setValue(getDao().metaDeleteOperation(theId, theMeta)); parameters.addParameter().setName("return").setValue(getDao().metaDeleteOperation(theId, theMeta));
return parameters; return parameters;

View File

@ -747,6 +747,50 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
} }
} }
@Test
public void testMetaOperationWithNoMetaParameter() throws Exception {
Patient p = new Patient();
p.addName().addFamily("testMetaAddInvalid");
IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless();
//@formatter:off
String input = "<Parameters>\n" +
" <meta>\n" +
" <tag>\n" +
" <system value=\"http://example.org/codes/tags\"/>\n" +
" <code value=\"record-lost\"/>\n" +
" <display value=\"Patient File Lost\"/>\n" +
" </tag>\n" +
" </meta>\n" +
"</Parameters>";
//@formatter:on
HttpPost post = new HttpPost(ourServerBase + "/Patient/" + id.getIdPart() + "/$meta-add");
post.setEntity(new StringEntity(input, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
CloseableHttpResponse response = ourHttpClient.execute(post);
try {
String output = IOUtils.toString(response.getEntity().getContent());
ourLog.info(output);
assertEquals(400, response.getStatusLine().getStatusCode());
assertThat(output, containsString("Input contains no parameter with name 'meta'"));
} finally {
response.close();
}
post = new HttpPost(ourServerBase + "/Patient/" + id.getIdPart() + "/$meta-delete");
post.setEntity(new StringEntity(input, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
response = ourHttpClient.execute(post);
try {
String output = IOUtils.toString(response.getEntity().getContent());
ourLog.info(output);
assertEquals(400, response.getStatusLine().getStatusCode());
assertThat(output, containsString("Input contains no parameter with name 'meta'"));
} finally {
response.close();
}
}
@Test @Test
public void testMetaOperations() throws Exception { public void testMetaOperations() throws Exception {
String methodName = "testMetaOperations"; String methodName = "testMetaOperations";

View File

@ -41,6 +41,14 @@
In JSON parsing, finding an object where an array was expected led to an unhelpful In JSON parsing, finding an object where an array was expected led to an unhelpful
error message. Thanks to Avinash Shanbhag for reporting! error message. Thanks to Avinash Shanbhag for reporting!
</action> </action>
<action type="add">
JPA server gave an unhelpful error message if $meta-add or $meta-delete were called
with no meta elements in the input Parameters
</action>
<action type="fix">
Narrative generator did not include OperationOutcome.issue.diagnostics in the
generated narrative.
</action>
</release> </release>
<release version="1.2" date="2015-09-18"> <release version="1.2" date="2015-09-18">
<action type="add"> <action type="add">