Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 34 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<compileSource>17</compileSource>
<compileTarget>17</compileTarget>

<dsf.version>1.8.0</dsf.version>
<dsf.version>1.9.0</dsf.version>
<spring.version>6.2.12</spring.version>
<dsf.location>../dsf</dsf.location>
</properties>

Expand Down Expand Up @@ -45,21 +46,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.0.10</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.7</version>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.19.0</version>
<version>2.20.0</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down Expand Up @@ -103,7 +97,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.14.1</version>
<configuration>
<source>${compileSource}</source>
<target>${compileTarget}</target>
Expand All @@ -112,12 +106,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<version>3.5.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
Expand All @@ -134,7 +128,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.1</version>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -158,18 +152,18 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.0</version>
<version>3.9.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.3.1</version>
<version>3.5.0</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>
<version>3.2.1</version>
<executions>
<execution>
<phase>validate</phase>
Expand All @@ -186,15 +180,15 @@
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.23.0</version>
<version>2.29.0</version>
<configuration>
<configFile>eclipse-formatter-config.xml</configFile>
</configuration>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>1.9.0</version>
<version>1.12.0</version>
<configuration>
<compliance>17</compliance>
<groups>java.,javax.,org.,com.</groups>
Expand All @@ -218,6 +212,27 @@
</workingPackages>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.6.2</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.6.3</version>
</requireMavenVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/dsf/bpe/CodeSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public BigDecimal calculateSpeed(long bytes, Duration duration)
@Override
public String toUcum()
{
return "Kbit/s";
return "kbit/s";
}
},
Mbps
Expand Down Expand Up @@ -281,7 +281,7 @@ public BigDecimal calculateSpeed(long bytes, Duration duration)
@Override
public String toUcum()
{
return "KBy/s";
return "kBy/s";
}
},
MBps
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/dsf/bpe/ConstantsPing.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ private ConstantsPing()

public static final String TIMER_INTERVAL_DEFAULT_VALUE = "PT24H";

public static final String PONG_TIMEOUT_DURATION_DEFAULT_VALUE = "PT30S";

public static final String BPMN_ERROR_CODE_UNEXPECTED_ERROR = "unexpected-error";

public static final String POTENTIAL_FIX_URL_BASE = "https://dsf.dev/s";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package dev.dsf.bpe.listener;

import static dev.dsf.bpe.PingProcessPluginDefinition.RESOURCE_VERSION;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.DecimalType;
import org.hl7.fhir.r4.model.MetadataResource;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.r4.model.Task;
import org.springframework.beans.factory.InitializingBean;

import dev.dsf.bpe.ConstantsPing;
import dev.dsf.bpe.PingProcessPluginDefinition;
import dev.dsf.bpe.v1.ProcessPluginApi;
import dev.dsf.bpe.v1.ProcessPluginDeploymentStateListener;
import dev.dsf.fhir.client.FhirWebserviceClient;

public class PingPongProcessPluginDeploymentStateListener
implements ProcessPluginDeploymentStateListener, InitializingBean
Expand Down Expand Up @@ -52,6 +59,62 @@ public void onProcessesDeployed(List<String> activeProcesses)

updateOlderResourcesIfCurrentIsNewestResource(ConstantsPing.STRUCTURE_DEFINITION_URL_EXTENSION_PING_STATUS,
StructureDefinition.class, adaptExtensionStructureDefinitions());

updateDraftTaskResources();
}

private void updateDraftTaskResources()
{
FhirWebserviceClient client = api.getFhirWebserviceClientProvider().getLocalWebserviceClient();

String pingProcessPrefix = "http://dsf.dev/bpe/Process/ping/" + RESOURCE_VERSION;
List<String> draftTaskResourceIdentifiers = List.of(pingProcessPrefix + "/task-start-ping",
pingProcessPrefix + "task-start-ping-autostart");

for (String identifier : draftTaskResourceIdentifiers)
{
Optional<Task> optionalTask = searchTask(identifier).getEntry().stream()
.map(Bundle.BundleEntryComponent::getResource).map(Task.class::cast).findFirst();

if (optionalTask.isPresent())
{
Task toUpdate = optionalTask.get();
adaptDraftTask(toUpdate);
client.update(toUpdate);
}
}
}

private void adaptDraftTask(Task task)
{
Coding downloadResourceSizeBytesCoding = new Coding();
downloadResourceSizeBytesCoding.setSystem(dev.dsf.bpe.CodeSystem.DsfPing.URL)
.setCode(dev.dsf.bpe.CodeSystem.DsfPing.Code.DOWNLOAD_RESOURCE_SIZE_BYTES.getValue())
.setVersion(RESOURCE_VERSION);

Optional<Task.ParameterComponent> optInput = api.getTaskHelper().getFirstInputParameter(task,
downloadResourceSizeBytesCoding, DecimalType.class);
if (optInput.isEmpty())
{
Task.ParameterComponent downloadResourceSizeBytes = new Task.ParameterComponent();
downloadResourceSizeBytes.getType().addCoding(downloadResourceSizeBytesCoding);
downloadResourceSizeBytes.setValue(new DecimalType(ConstantsPing.DOWNLOAD_RESOURCE_SIZE_BYTES_DEFAULT));
task.addInput(downloadResourceSizeBytes);
}

Coding pongTimeoutDurationCoding = new Coding();
pongTimeoutDurationCoding.setSystem(dev.dsf.bpe.CodeSystem.DsfPing.URL)
.setCode(dev.dsf.bpe.CodeSystem.DsfPing.Code.PONG_TIMEOUT_DURATION_ISO_8601.getValue())
.setVersion(RESOURCE_VERSION);

optInput = api.getTaskHelper().getFirstInputParameter(task, pongTimeoutDurationCoding, StringType.class);
if (optInput.isEmpty())
{
Task.ParameterComponent pongTimeoutDuration = new Task.ParameterComponent();
pongTimeoutDuration.getType().addCoding(pongTimeoutDurationCoding);
pongTimeoutDuration.setValue(new StringType(ConstantsPing.PONG_TIMEOUT_DURATION_DEFAULT_VALUE));
task.addInput(pongTimeoutDuration);
}
}

private <T extends MetadataResource> void updateOlderResourcesIfCurrentIsNewestResource(String url, Class<T> type,
Expand All @@ -74,6 +137,12 @@ private Bundle search(Class<? extends Resource> type, String url)
Map.of("url", List.of(url)));
}

private Bundle searchTask(String identifier)
{
return api.getFhirWebserviceClientProvider().getLocalWebserviceClient().search(Task.class,
Map.of("identifier", List.of(identifier), "status", List.of("draft")));
}

private <T extends MetadataResource> List<T> extractAndSortResources(Bundle bundle, Class<T> type, String url)
{
return bundle.getEntry().stream().filter(Bundle.BundleEntryComponent::hasResource)
Expand All @@ -100,8 +169,7 @@ else if (version1.major < version2.major)

private boolean currentIsNewestResource(List<? extends MetadataResource> resources)
{
return !resources.isEmpty() && PingProcessPluginDefinition.RESOURCE_VERSION
.equals(resources.get(resources.size() - 1).getVersion());
return !resources.isEmpty() && RESOURCE_VERSION.equals(resources.get(resources.size() - 1).getVersion());
}

private MinorMajorVersion getMajorMinorVersion(String version)
Expand Down
44 changes: 24 additions & 20 deletions src/main/java/dev/dsf/bpe/service/ping/CheckPingTaskStatus.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dev.dsf.bpe.service.ping;

import java.util.Objects;

import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.hl7.fhir.r4.model.Task;
Expand Down Expand Up @@ -38,28 +36,34 @@ protected void doExecuteWithErrorHandling(DelegateExecution delegateExecution, V
Target target = variables.getTarget();
String correlationKey = target.getCorrelationKey();

String taskId = (String) delegateExecution.getVariableLocal(ExecutionVariables.pingTaskId.name());
// Do not use getVariableLocal() here. CheckPingTaskStatus gets executed in a child execution of the one that
// stored the variable. GetVariableLocal() will only look in the child execution's variables and find nothing.
// GetVariable() or the DSF API's getString() does look for values in the parent execution's variables.
String taskId = variables.getString(ExecutionVariables.pingTaskId.name());

Objects.requireNonNull(taskId);
FhirWebserviceClient fhirWebserviceClient = api.getFhirWebserviceClientProvider()
.getWebserviceClient(target.getEndpointUrl());
try
{
Task pingTask = fhirWebserviceClient.withRetry(3, 1000).read(Task.class, taskId);
ProcessError error = switch (pingTask.getStatus())
if (taskId != null)
{
case COMPLETED -> new ProcessError(ConstantsPing.PROCESS_NAME_PING,
CodeSystem.DsfPingError.Concept.RESPONSE_MESSAGE_TIMEOUT_STATUS_COMPLETED, null);
case FAILED -> new ProcessError(ConstantsPing.PROCESS_NAME_PING,
CodeSystem.DsfPingError.Concept.RESPONSE_MESSAGE_TIMEOUT_STATUS_FAILED, null);
case INPROGRESS -> new ProcessError(ConstantsPing.PROCESS_NAME_PING,
CodeSystem.DsfPingError.Concept.RESPONSE_MESSAGE_TIMEOUT_STATUS_IN_PROGRESS, null);
case REQUESTED -> new ProcessError(ConstantsPing.PROCESS_NAME_PING,
CodeSystem.DsfPingError.Concept.RESPONSE_MESSAGE_TIMEOUT_STATUS_REQUESTED, null);
default -> new ProcessError(ConstantsPing.PROCESS_NAME_PING,
CodeSystem.DsfPingError.Concept.RESPONSE_MESSAGE_TIMEOUT_STATUS_UNEXPECTED, null);
};
ErrorListUtils.add(error, delegateExecution, correlationKey);
FhirWebserviceClient fhirWebserviceClient = api.getFhirWebserviceClientProvider()
.getWebserviceClient(target.getEndpointUrl());

Task pingTask = fhirWebserviceClient.withRetry(3, 1000).read(Task.class, taskId);
ProcessError error = switch (pingTask.getStatus())
{
case COMPLETED -> new ProcessError(ConstantsPing.PROCESS_NAME_PING,
CodeSystem.DsfPingError.Concept.RESPONSE_MESSAGE_TIMEOUT_STATUS_COMPLETED, null);
case FAILED -> new ProcessError(ConstantsPing.PROCESS_NAME_PING,
CodeSystem.DsfPingError.Concept.RESPONSE_MESSAGE_TIMEOUT_STATUS_FAILED, null);
case INPROGRESS -> new ProcessError(ConstantsPing.PROCESS_NAME_PING,
CodeSystem.DsfPingError.Concept.RESPONSE_MESSAGE_TIMEOUT_STATUS_IN_PROGRESS, null);
case REQUESTED -> new ProcessError(ConstantsPing.PROCESS_NAME_PING,
CodeSystem.DsfPingError.Concept.RESPONSE_MESSAGE_TIMEOUT_STATUS_REQUESTED, null);
default -> new ProcessError(ConstantsPing.PROCESS_NAME_PING,
CodeSystem.DsfPingError.Concept.RESPONSE_MESSAGE_TIMEOUT_STATUS_UNEXPECTED, null);
};
ErrorListUtils.add(error, delegateExecution, correlationKey);
}
}
catch (WebApplicationException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ private static ProcessErrorWithStatusCode convertWebApplicationException(WebAppl
CodeSystem.DsfPingError.Concept.SEND_MESSAGE_HTTP_401,
ConstantsPing.POTENTIAL_FIX_URL_ERROR_HTTP),
CodeSystem.DsfPingStatus.Code.NOT_ALLOWED);
case 403 ->
{
case 403 -> {
if (messageWithReference)
{
yield new ProcessErrorWithStatusCode(
Expand Down Expand Up @@ -332,8 +331,7 @@ yield new ProcessErrorWithStatusCode(
CodeSystem.DsfPingError.Concept.RECEIVE_MESSAGE_HTTP_401,
ConstantsPing.POTENTIAL_FIX_URL_ERROR_HTTP),
CodeSystem.DsfPingStatus.Code.NOT_ALLOWED);
case 403 ->
{
case 403 -> {
if (messageWithReference)
{
yield new ProcessErrorWithStatusCode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
</type>
<valueString value="PT24H"/>
</input>
<input>
<!--Resource will get updated in DeploymentStateListener because FHIR validation does not use the version of the CodeSystem
to differentiate between CodeSystems that differ from one plugin version to the next-->
<!--<input>
<type>
<coding>
<system value="http://dsf.dev/fhir/CodeSystem/ping"/>
Expand All @@ -74,5 +76,5 @@
</coding>
</type>
<valueString value="PT30S"/>
</input>
</input>-->
</Task>
6 changes: 4 additions & 2 deletions src/main/resources/fhir/Task/dsf-task-start-ping.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
</type>
<valueString value="Endpoint?status=active&amp;identifier=http://dsf.dev/sid/endpoint-identifier|"/>
</input>
<input>
<!--Resource will get updated in DeploymentStateListener because FHIR validation does not use the version of the CodeSystem
to differentiate between CodeSystems that differ from one plugin version to the next-->
<!--<input>
<type>
<coding>
<system value="http://dsf.dev/fhir/CodeSystem/ping"/>
Expand All @@ -64,5 +66,5 @@
</coding>
</type>
<valueString value="PT30S"/>
</input>
</input>-->
</Task>
Loading