Skip to content

Commit 38c7c30

Browse files
committed
new resourceNotAllowedWithError impl working for DELETE entries
DELETE entries do not have a resource, resulting in a NullPointerException in the previous implementation.
1 parent 801d58c commit 38c7c30

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/java/dev/dsf/bpe/service/CheckAllowList.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.hl7.fhir.r4.model.Organization;
1212
import org.hl7.fhir.r4.model.OrganizationAffiliation;
1313
import org.hl7.fhir.r4.model.Resource;
14+
import org.hl7.fhir.r4.model.ResourceType;
1415
import org.hl7.fhir.r4.model.StringType;
1516
import org.hl7.fhir.r4.model.Task;
1617
import org.slf4j.Logger;
@@ -76,10 +77,17 @@ private Predicate<BundleEntryComponent> entryNotAllowedWithError(Task task, Stri
7677
private boolean resourceNotAllowedWithError(BundleEntryComponent entry, Task task, String bundleUrl)
7778
{
7879
Resource resource = entry.getResource();
79-
boolean resourceAllowed = (resource instanceof Organization || resource instanceof OrganizationAffiliation
80-
|| resource instanceof Endpoint);
81-
82-
if (!resourceAllowed)
80+
boolean resourceAllowed = (HTTPVerb.DELETE.equals(entry.getRequest().getMethod())
81+
&& (entry.getRequest().getUrl().startsWith(ResourceType.Organization.name())
82+
|| entry.getRequest().getUrl().startsWith(ResourceType.OrganizationAffiliation.name())
83+
|| entry.getRequest().getUrl().startsWith(ResourceType.Endpoint.name())))
84+
|| (resource instanceof Organization || resource instanceof OrganizationAffiliation
85+
|| resource instanceof Endpoint);
86+
87+
if (HTTPVerb.DELETE.equals(entry.getRequest().getMethod()) && !resourceAllowed)
88+
addError(task, "Resource delete of '" + entry.getRequest().getUrl() + "' not allowed in Bundle with id '"
89+
+ bundleUrl + "'");
90+
else if (!HTTPVerb.DELETE.equals(entry.getRequest().getMethod()) && !resourceAllowed)
8391
addError(task, "Resource of type '" + resource.getResourceType().name()
8492
+ "' not allowed in Bundle with id '" + bundleUrl + "'");
8593

0 commit comments

Comments
 (0)