mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-16 18:05:19 +00:00
Clean up exception handling
This commit is contained in:
parent
fc4d2ae7e2
commit
09d97106d3
@ -217,10 +217,9 @@ public abstract class BaseFhirDao implements IDao {
|
|||||||
Long valueOf;
|
Long valueOf;
|
||||||
try {
|
try {
|
||||||
valueOf = translateForcedIdToPid(nextValue.getReference());
|
valueOf = translateForcedIdToPid(nextValue.getReference());
|
||||||
} catch (Exception e) {
|
} catch (ResourceNotFoundException e) {
|
||||||
String resName = getContext().getResourceDefinition(type).getName();
|
String resName = getContext().getResourceDefinition(type).getName();
|
||||||
throw new InvalidRequestException("Resource " + resName + "/" + id + " not found, specified in path: " + nextPathsUnsplit
|
throw new InvalidRequestException("Resource " + resName + "/" + id + " not found, specified in path: " + nextPathsUnsplit);
|
||||||
+ " (this is an invalid ID, must be numeric on this server)");
|
|
||||||
}
|
}
|
||||||
ResourceTable target = myEntityManager.find(ResourceTable.class, valueOf);
|
ResourceTable target = myEntityManager.find(ResourceTable.class, valueOf);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
|
@ -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
|
@Test
|
||||||
public void testTransactionFromBundle() throws Exception {
|
public void testTransactionFromBundle() throws Exception {
|
||||||
|
|
||||||
|
17
pom.xml
17
pom.xml
@ -713,6 +713,23 @@
|
|||||||
|
|
||||||
<reporting>
|
<reporting>
|
||||||
<plugins>
|
<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>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-changes-plugin</artifactId>
|
<artifactId>maven-changes-plugin</artifactId>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user