Skip to content

Commit 0e5fa26

Browse files
committed
Draft Task resources are now backwards compatible to 1.x plugin versions and get updated to the desired state for 2.0 in the DeploymentStateListener.
This fixes inconsistent deployment behavior where sometimes the plugin was unable to be deployed because the wrong versions of CodeSystems were used to validate the Task resources
1 parent 9ae859a commit 0e5fa26

File tree

4 files changed

+82
-4
lines changed

4 files changed

+82
-4
lines changed

src/main/java/dev/dsf/bpe/ConstantsPing.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ private ConstantsPing()
6161

6262
public static final String TIMER_INTERVAL_DEFAULT_VALUE = "PT24H";
6363

64+
public static final String PONG_TIMEOUT_DURATION_DEFAULT_VALUE = "PT30S";
65+
6466
public static final String BPMN_ERROR_CODE_UNEXPECTED_ERROR = "unexpected-error";
6567

6668
public static final String POTENTIAL_FIX_URL_BASE = "https://dsf.dev/s";

src/main/java/dev/dsf/bpe/listener/PingPongProcessPluginDeploymentStateListener.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@
33
import java.util.List;
44
import java.util.Map;
55
import java.util.Objects;
6+
import java.util.Optional;
67
import java.util.Set;
78
import java.util.function.BiConsumer;
89
import java.util.stream.Collectors;
910

1011
import org.hl7.fhir.r4.model.Bundle;
1112
import org.hl7.fhir.r4.model.CodeSystem;
13+
import org.hl7.fhir.r4.model.Coding;
14+
import org.hl7.fhir.r4.model.DecimalType;
1215
import org.hl7.fhir.r4.model.MetadataResource;
1316
import org.hl7.fhir.r4.model.Resource;
17+
import org.hl7.fhir.r4.model.StringType;
1418
import org.hl7.fhir.r4.model.StructureDefinition;
19+
import org.hl7.fhir.r4.model.Task;
1520
import org.springframework.beans.factory.InitializingBean;
1621

1722
import dev.dsf.bpe.ConstantsPing;
1823
import dev.dsf.bpe.PingProcessPluginDefinition;
1924
import dev.dsf.bpe.v1.ProcessPluginApi;
2025
import dev.dsf.bpe.v1.ProcessPluginDeploymentStateListener;
26+
import dev.dsf.fhir.client.FhirWebserviceClient;
2127

2228
public class PingPongProcessPluginDeploymentStateListener
2329
implements ProcessPluginDeploymentStateListener, InitializingBean
@@ -52,6 +58,61 @@ public void onProcessesDeployed(List<String> activeProcesses)
5258

5359
updateOlderResourcesIfCurrentIsNewestResource(ConstantsPing.STRUCTURE_DEFINITION_URL_EXTENSION_PING_STATUS,
5460
StructureDefinition.class, adaptExtensionStructureDefinitions());
61+
62+
updateDraftTaskResources();
63+
}
64+
65+
private void updateDraftTaskResources()
66+
{
67+
FhirWebserviceClient client = api.getFhirWebserviceClientProvider().getLocalWebserviceClient();
68+
69+
List<String> draftTaskResourceProfiles = List.of("http://dsf.dev/fhir/StructureDefinition/task-start-ping",
70+
"http://dsf.dev/fhir/StructureDefinition/task-start-ping-autostart");
71+
72+
for (String profile : draftTaskResourceProfiles)
73+
{
74+
Optional<Task> optionalTask = searchTask(profile, PingProcessPluginDefinition.RESOURCE_VERSION).getEntry()
75+
.stream().map(Bundle.BundleEntryComponent::getResource).map(Task.class::cast).findFirst();
76+
77+
if (optionalTask.isPresent())
78+
{
79+
Task toUpdate = optionalTask.get();
80+
adaptDraftTask(toUpdate);
81+
client.update(toUpdate);
82+
}
83+
}
84+
}
85+
86+
private void adaptDraftTask(Task task)
87+
{
88+
Coding downloadResourceSizeBytesCoding = new Coding();
89+
downloadResourceSizeBytesCoding.setSystem(dev.dsf.bpe.CodeSystem.DsfPing.URL)
90+
.setCode(dev.dsf.bpe.CodeSystem.DsfPing.Code.DOWNLOAD_RESOURCE_SIZE_BYTES.getValue())
91+
.setVersion(PingProcessPluginDefinition.RESOURCE_VERSION);
92+
93+
Optional<Task.ParameterComponent> optInput = api.getTaskHelper().getFirstInputParameter(task,
94+
downloadResourceSizeBytesCoding, DecimalType.class);
95+
if (optInput.isEmpty())
96+
{
97+
Task.ParameterComponent downloadResourceSizeBytes = new Task.ParameterComponent();
98+
downloadResourceSizeBytes.getType().addCoding(downloadResourceSizeBytesCoding);
99+
downloadResourceSizeBytes.setValue(new DecimalType(ConstantsPing.DOWNLOAD_RESOURCE_SIZE_BYTES_DEFAULT));
100+
task.addInput(downloadResourceSizeBytes);
101+
}
102+
103+
Coding pongTimeoutDurationCoding = new Coding();
104+
pongTimeoutDurationCoding.setSystem(dev.dsf.bpe.CodeSystem.DsfPing.URL)
105+
.setCode(dev.dsf.bpe.CodeSystem.DsfPing.Code.PONG_TIMEOUT_DURATION_ISO_8601.getValue())
106+
.setVersion(PingProcessPluginDefinition.RESOURCE_VERSION);
107+
108+
optInput = api.getTaskHelper().getFirstInputParameter(task, pongTimeoutDurationCoding, StringType.class);
109+
if (optInput.isEmpty())
110+
{
111+
Task.ParameterComponent pongTimeoutDuration = new Task.ParameterComponent();
112+
pongTimeoutDuration.getType().addCoding(pongTimeoutDurationCoding);
113+
pongTimeoutDuration.setValue(new StringType(ConstantsPing.PONG_TIMEOUT_DURATION_DEFAULT_VALUE));
114+
task.addInput(pongTimeoutDuration);
115+
}
55116
}
56117

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

138+
private Bundle searchTask(String profile, String version)
139+
{
140+
return api.getFhirWebserviceClientProvider().getLocalWebserviceClient().search(Task.class,
141+
Map.of("_profile", List.of(profile + "|" + version), "status", List.of("draft")));
142+
}
143+
77144
private <T extends MetadataResource> List<T> extractAndSortResources(Bundle bundle, Class<T> type, String url)
78145
{
79146
return bundle.getEntry().stream().filter(Bundle.BundleEntryComponent::hasResource)
@@ -104,6 +171,11 @@ private boolean currentIsNewestResource(List<? extends MetadataResource> resourc
104171
.equals(resources.get(resources.size() - 1).getVersion());
105172
}
106173

174+
private <T> Optional<T> getNewestResource(List<T> resources)
175+
{
176+
return resources.isEmpty() ? Optional.empty() : Optional.of(resources.get(resources.size() - 1));
177+
}
178+
107179
private MinorMajorVersion getMajorMinorVersion(String version)
108180
{
109181
if (version.matches("\\d\\.\\d"))

src/main/resources/fhir/Task/dsf-task-start-ping-autostart.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
</type>
5656
<valueString value="PT24H"/>
5757
</input>
58-
<input>
58+
<!--Resource will get updated in DeploymentStateListener because FHIR validation does not use the version of the CodeSystem
59+
to differentiate between CodeSystems that differ from one plugin version to the next-->
60+
<!--<input>
5961
<type>
6062
<coding>
6163
<system value="http://dsf.dev/fhir/CodeSystem/ping"/>
@@ -74,5 +76,5 @@
7476
</coding>
7577
</type>
7678
<valueString value="PT30S"/>
77-
</input>
79+
</input>-->
7880
</Task>

src/main/resources/fhir/Task/dsf-task-start-ping.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
</type>
4646
<valueString value="Endpoint?status=active&amp;identifier=http://dsf.dev/sid/endpoint-identifier|"/>
4747
</input>
48-
<input>
48+
<!--Resource will get updated in DeploymentStateListener because FHIR validation does not use the version of the CodeSystem
49+
to differentiate between CodeSystems that differ from one plugin version to the next-->
50+
<!--<input>
4951
<type>
5052
<coding>
5153
<system value="http://dsf.dev/fhir/CodeSystem/ping"/>
@@ -64,5 +66,5 @@
6466
</coding>
6567
</type>
6668
<valueString value="PT30S"/>
67-
</input>
69+
</input>-->
6870
</Task>

0 commit comments

Comments
 (0)