Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/1.0.0.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
hhund committed Aug 22, 2023
2 parents 1563b0a + 8ac681f commit 3e1d4f5
Show file tree
Hide file tree
Showing 21 changed files with 438 additions and 120 deletions.
39 changes: 20 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

<groupId>dev.dsf</groupId>
<artifactId>dsf-process-allow-list</artifactId>
<version>1.0.0.0-M1</version>
<version>1.0.0.0</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compileSource>17</compileSource>
<compileTarget>17</compileTarget>

<dsf.version>1.0.0-M1</dsf.version>
<dsf.version>1.1.0</dsf.version>
<dsf.location>../dsf</dsf.location>
</properties>

Expand Down Expand Up @@ -87,7 +87,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -109,21 +109,22 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<!-- 3.1.0 not working, no git commit hash as buildnumber -->
<version>1.4</version>
<executions>
<execution>
Expand All @@ -141,7 +142,7 @@
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.22.0</version>
<version>2.23.0</version>
<configuration>
<configFile>eclipse-formatter-config.xml</configFile>
</configuration>
Expand Down Expand Up @@ -272,7 +273,7 @@
</configuration>
</execution>
<execution>
<id>copy-process-plugin-to-docker-test-setup-3medic-ttp/medic1</id>
<id>copy-process-plugin-to-docker-test-setup-3dic-ttp/dic1</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
Expand All @@ -285,11 +286,11 @@
<version>${project.version}</version>
</artifactItem>
</artifactItems>
<outputDirectory>${dsf.location}/dsf-docker-test-setup-3medic-ttp/medic1/bpe/process</outputDirectory>
<outputDirectory>${dsf.location}/dsf-docker-test-setup-3dic-ttp/dic1/bpe/process</outputDirectory>
</configuration>
</execution>
<execution>
<id>copy-process-plugin-to-docker-test-setup-3medic-ttp/medic2</id>
<id>copy-process-plugin-to-docker-test-setup-3dic-ttp/dic2</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
Expand All @@ -302,11 +303,11 @@
<version>${project.version}</version>
</artifactItem>
</artifactItems>
<outputDirectory>${dsf.location}/dsf-docker-test-setup-3medic-ttp/medic2/bpe/process</outputDirectory>
<outputDirectory>${dsf.location}/dsf-docker-test-setup-3dic-ttp/dic2/bpe/process</outputDirectory>
</configuration>
</execution>
<execution>
<id>copy-process-plugin-to-docker-test-setup-3medic-ttp/medic3</id>
<id>copy-process-plugin-to-docker-test-setup-3dic-ttp/dic3</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
Expand All @@ -319,11 +320,11 @@
<version>${project.version}</version>
</artifactItem>
</artifactItems>
<outputDirectory>${dsf.location}/dsf-docker-test-setup-3medic-ttp/medic3/bpe/process</outputDirectory>
<outputDirectory>${dsf.location}/dsf-docker-test-setup-3dic-ttp/dic3/bpe/process</outputDirectory>
</configuration>
</execution>
<execution>
<id>copy-process-plugin-to-docker-test-setup-3medic-ttp/ttp</id>
<id>copy-process-plugin-to-docker-test-setup-3dic-ttp/ttp</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
Expand All @@ -336,7 +337,7 @@
<version>${project.version}</version>
</artifactItem>
</artifactItems>
<outputDirectory>${dsf.location}/dsf-docker-test-setup-3medic-ttp/ttp/bpe/process</outputDirectory>
<outputDirectory>${dsf.location}/dsf-docker-test-setup-3dic-ttp/ttp/bpe/process</outputDirectory>
</configuration>
</execution>
</executions>
Expand All @@ -354,28 +355,28 @@
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${dsf.location}/dsf-docker-test-setup-3medic-ttp/medic1/bpe/process</directory>
<directory>${dsf.location}/dsf-docker-test-setup-3dic-ttp/dic1/bpe/process</directory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${dsf.location}/dsf-docker-test-setup-3medic-ttp/medic2/bpe/process</directory>
<directory>${dsf.location}/dsf-docker-test-setup-3dic-ttp/dic2/bpe/process</directory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${dsf.location}/dsf-docker-test-setup-3medic-ttp/medic3/bpe/process</directory>
<directory>${dsf.location}/dsf-docker-test-setup-3dic-ttp/dic3/bpe/process</directory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>${dsf.location}/dsf-docker-test-setup-3medic-ttp/ttp/bpe/process</directory>
<directory>${dsf.location}/dsf-docker-test-setup-3dic-ttp/ttp/bpe/process</directory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/dev/dsf/bpe/AllowListProcessPluginDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class AllowListProcessPluginDefinition implements ProcessPluginDefinition
{
public static final String VERSION = "1.0.0.0";
public static final LocalDate RELEASE_DATE = LocalDate.of(2023, 5, 20);
public static final LocalDate RELEASE_DATE = LocalDate.of(2023, 8, 22);

@Override
public String getName()
Expand All @@ -34,7 +34,7 @@ public LocalDate getReleaseDate()
@Override
public List<String> getProcessModels()
{
return List.of("bpe/updateAllowList.bpmn", "bpe/downloadAllowList.bpmn");
return List.of("bpe/update-allow-list.bpmn", "bpe/download-allow-list.bpmn");
}

@Override
Expand All @@ -48,15 +48,19 @@ public Map<String, List<String>> getFhirResourcesByProcessId()
{
var c = "fhir/CodeSystem/dsf-allow-list.xml";

var aDown = "fhir/ActivityDefinition/dsf-downloadAllowList.xml";
var aUp = "fhir/ActivityDefinition/dsf-updateAllowList.xml";
var aDown = "fhir/ActivityDefinition/dsf-download-allow-list.xml";
var aUp = "fhir/ActivityDefinition/dsf-update-allow-list.xml";

var sDown = "fhir/StructureDefinition/dsf-task-download-allow-list.xml";
var sUp = "fhir/StructureDefinition/dsf-task-update-allow-list.xml";

var tDown = "fhir/Task/dsf-task-download-allow-list.xml";
var tUp = "fhir/Task/dsf-task-update-allow-list.xml";

var v = "fhir/ValueSet/dsf-allow-list.xml";

return Map.of(ConstantsAllowList.PROCESS_NAME_FULL_DOWNLOAD_ALLOW_LIST, Arrays.asList(c, aDown, sDown, v),
ConstantsAllowList.PROCESS_NAME_FULL_UPDATE_ALLOW_LIST, Arrays.asList(c, aUp, sUp, v));
return Map.of(ConstantsAllowList.PROCESS_NAME_FULL_DOWNLOAD_ALLOW_LIST,
Arrays.asList(c, aDown, sDown, tDown, v), ConstantsAllowList.PROCESS_NAME_FULL_UPDATE_ALLOW_LIST,
Arrays.asList(c, aUp, sUp, tUp, v));
}
}
5 changes: 4 additions & 1 deletion src/main/java/dev/dsf/bpe/ConstantsAllowList.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ public interface ConstantsAllowList

String PROFILE_DSF_TASK_UPDATE_ALLOW_LIST = "http://dsf.dev/fhir/StructureDefinition/task-update-allow-list";
String PROFILE_DSF_TASK_UPDATE_ALLOW_LIST_PROCESS_URI = PROCESS_DSF_URI_BASE + PROCESS_NAME_UPDATE_ALLOW_LIST;
String PROFILE_DSF_TASK_UPDATE_ALLOW_LIST_MESSAGE_NAME = "updateAllowListMessage";
String PROFILE_DSF_TASK_UPDATE_ALLOW_LIST_MESSAGE_NAME = "updateAllowList";

String BPMN_EXECUTION_VARIABLE_BUNDLE = "bundle";
String BPMN_EXECUTION_VARIABLE_BUNDLE_URL = "bundleUrl";
}
108 changes: 108 additions & 0 deletions src/main/java/dev/dsf/bpe/service/CheckAllowList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package dev.dsf.bpe.service;

import java.util.EnumSet;
import java.util.function.Predicate;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
import org.hl7.fhir.r4.model.Endpoint;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.OrganizationAffiliation;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import dev.dsf.bpe.ConstantsAllowList;
import dev.dsf.bpe.v1.ProcessPluginApi;
import dev.dsf.bpe.v1.activity.AbstractServiceDelegate;
import dev.dsf.bpe.v1.constants.CodeSystems;
import dev.dsf.bpe.v1.variables.Variables;

public class CheckAllowList extends AbstractServiceDelegate
{
private static final Logger logger = LoggerFactory.getLogger(CheckAllowList.class);

public CheckAllowList(ProcessPluginApi api)
{
super(api);
}

@Override
protected void doExecute(DelegateExecution execution, Variables variables)
{
Bundle bundle = variables.getResource(ConstantsAllowList.BPMN_EXECUTION_VARIABLE_BUNDLE);
String bundleUrl = variables.getString(ConstantsAllowList.BPMN_EXECUTION_VARIABLE_BUNDLE_URL);

if (!EnumSet.of(Bundle.BundleType.TRANSACTION, Bundle.BundleType.BATCH).contains(bundle.getType()))
{
logger.error("Bundle type TRANSACTION or BATCH expected, but got '{}' in Bundle with id '{}'",
bundle.getType(), bundleUrl);
throw new RuntimeException("Bundle type TRANSACTION or BATCH expected, but got '" + bundle.getType()
+ "' in Bundle with id '" + bundleUrl + "'");
}

Task task = variables.getStartTask();

if (bundle.getEntry().stream().anyMatch(entryNotAllowedWithError(task, bundleUrl)))
{
variables.updateTask(task);

logger.error("Expected Bundle with id '{}' containing only resource types Organization, "
+ "OrganizationAffiliation or Endpoint and request methods PUT or DELETE, but found different "
+ "types or methods.", bundleUrl);
throw new RuntimeException("Expected Bundle with id '" + bundleUrl + " 'containing only resource "
+ "types Organization, OrganizationAffiliation or Endpoint and "
+ "request methods PUT or DELETE, but found different types or methods.");
}
}

private Predicate<BundleEntryComponent> entryNotAllowedWithError(Task task, String bundleUrl)
{
return entry ->
{
boolean resourceNotAllowed = resourceNotAllowedWithError(entry, task, bundleUrl);
boolean requestNotAllowed = requestNotAllowedWithError(entry, task, bundleUrl);

// Split into two method calls and not inline to ensure that both methods
// are executed so that all given error messages can be written to Task.output
return resourceNotAllowed || requestNotAllowed;
};
}

private boolean resourceNotAllowedWithError(BundleEntryComponent entry, Task task, String bundleUrl)
{
Resource resource = entry.getResource();
boolean resourceAllowed = (resource instanceof Organization || resource instanceof OrganizationAffiliation
|| resource instanceof Endpoint);

if (!resourceAllowed)
addError(task, "Resource of type '" + resource.getResourceType().name()
+ "' not allowed in Bundle with id '" + bundleUrl + "'");

return !resourceAllowed;
}

private boolean requestNotAllowedWithError(BundleEntryComponent entry, Task task, String bundleUrl)
{
boolean requestAllowed = false;

if (entry.hasRequest())
requestAllowed = EnumSet.of(HTTPVerb.PUT, HTTPVerb.DELETE).contains(entry.getRequest().getMethod());

if (!requestAllowed)
addError(task, "Request with Method '" + entry.getRequest().getMethod()
+ "' not allowed in Bundle with id '" + bundleUrl + "'");

return !requestAllowed;
}

private void addError(Task task, String message)
{
logger.warn(message);
task.addOutput(api.getTaskHelper().createOutput(new StringType(message), CodeSystems.BpmnMessage.error()));
}
}
Loading

0 comments on commit 3e1d4f5

Please sign in to comment.