Clean up exception handling

This commit is contained in:
James Agnew 2015-06-05 11:57:13 -04:00
parent fc4d2ae7e2
commit 09d97106d3
3 changed files with 57 additions and 3 deletions

View File

@ -217,10 +217,9 @@ public abstract class BaseFhirDao implements IDao {
Long valueOf;
try {
valueOf = translateForcedIdToPid(nextValue.getReference());
} catch (Exception e) {
} catch (ResourceNotFoundException e) {
String resName = getContext().getResourceDefinition(type).getName();
throw new InvalidRequestException("Resource " + resName + "/" + id + " not found, specified in path: " + nextPathsUnsplit
+ " (this is an invalid ID, must be numeric on this server)");
throw new InvalidRequestException("Resource " + resName + "/" + id + " not found, specified in path: " + nextPathsUnsplit);
}
ResourceTable target = myEntityManager.find(ResourceTable.class, valueOf);
if (target == null) {

View File

@ -100,6 +100,44 @@ public class FhirSystemDaoDstu2Test {
}
@Test
public void testTransactionCreateWithInvalidReferenceNumeric() {
String methodName = "testTransactionCreateWithInvalidReferenceNumeric";
Bundle request = new Bundle();
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("Hello");
p.getManagingOrganization().setReference("Organization/9999999999999999");
request.addEntry().setResource(p).getTransaction().setMethod(HTTPVerbEnum.POST);
try {
ourSystemDao.transaction(request);
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Resource Organization/9999999999999999 not found, specified in path: Patient.managingOrganization"));
}
}
@Test
public void testTransactionCreateWithInvalidReferenceTextual() {
String methodName = "testTransactionCreateWithInvalidReferenceTextual";
Bundle request = new Bundle();
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("Hello");
p.getManagingOrganization().setReference("Organization/" + methodName);
request.addEntry().setResource(p).getTransaction().setMethod(HTTPVerbEnum.POST);
try {
ourSystemDao.transaction(request);
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Resource Organization/" + methodName + " not found, specified in path: Patient.managingOrganization"));
}
}
@Test
public void testTransactionFromBundle() throws Exception {

17
pom.xml
View File

@ -713,6 +713,23 @@
<reporting>
<plugins>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<reportSets>
<reportSet>
<reports><report>checkstyle-aggregate</report></reports>
</reportSet>
</reportSets>
<configuration>
<configLocation>config/sun_checks.xml</configLocation>
<includes>
hapi-fhir-base/src/main/java/**/*.java
</includes>
</configuration>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>