Skip to content

Commit

Permalink
Merge remote-tracking branch
Browse files Browse the repository at this point in the history
'origin/issues/1_Upgrade_to_New_Process_Plugin_API' into develop
  • Loading branch information
hhund committed May 20, 2023
2 parents 0ba5ecf + 9386810 commit 63b4187
Show file tree
Hide file tree
Showing 31 changed files with 751 additions and 847 deletions.
20 changes: 11 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>dev.dsf</groupId>
<artifactId>dsf-process-ping-pong</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

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

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

Expand All @@ -39,10 +38,16 @@
<dependencies>
<dependency>
<groupId>dev.dsf</groupId>
<artifactId>dsf-bpe-process-base</artifactId>
<artifactId>dsf-bpe-process-api-v1</artifactId>
<version>${dsf.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.0.8</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -54,7 +59,7 @@
<!-- testing -->
<dependency>
<groupId>dev.dsf</groupId>
<artifactId>dsf-bpe-process-base</artifactId>
<artifactId>dsf-bpe-process-api-v1</artifactId>
<version>${dsf.version}</version>
<scope>test</scope>
<type>test-jar</type>
Expand Down Expand Up @@ -163,7 +168,7 @@
<executions>
<execution>
<goals>
<goal>documentation-generation</goal>
<goal>generate</goal>
</goals>
</execution>
</executions>
Expand Down Expand Up @@ -192,9 +197,6 @@
<id>github</id>
<name>GitHub DSF Apache Maven Packages</name>
<url>https://maven.pkg.github.com/datasharingframework/dsf</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
Expand Down
29 changes: 6 additions & 23 deletions src/main/java/dev/dsf/bpe/ConstantsPing.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,25 @@ public interface ConstantsPing
String PROCESS_NAME_FULL_PING = "dsfdev_" + PROCESS_NAME_PING;
String PROCESS_NAME_FULL_PONG = "dsfdev_" + PROCESS_NAME_PONG;

String PROCESS_DSF_URI_BASE = "http://dsf.dev/bpe/Process/";

String PROFILE_DSF_TASK_START_PING_AUTOSTART = "http://dsf.dev/fhir/StructureDefinition/task-start-ping-autostart";
String PROFILE_DSF_TASK_START_PING_AUTOSTART_AND_LATEST_VERSION = PROFILE_DSF_TASK_START_PING_AUTOSTART + "|"
+ PingProcessPluginDefinition.VERSION;
String PROFILE_DSF_TASK_START_PING_AUTOSTART_PROCESS_URI = ConstantsBase.PROCESS_DSF_URI_BASE
+ PROCESS_NAME_PING_AUTOSTART + "/";
String PROFILE_DSF_TASK_START_PING_AUTOSTART_PROCESS_URI_AND_LATEST_VERSION = PROFILE_DSF_TASK_START_PING_AUTOSTART_PROCESS_URI
+ PingProcessPluginDefinition.VERSION;
String PROFILE_DSF_TASK_START_PING_AUTOSTART_PROCESS_URI = PROCESS_DSF_URI_BASE + PROCESS_NAME_PING_AUTOSTART;
String PROFILE_DSF_TASK_START_PING_AUTOSTART_MESSAGE_NAME = "startPingAutostart";

String PROFILE_DSF_TASK_STOP_PING_AUTOSTART = "http://dsf.dev/fhir/StructureDefinition/task-stop-ping-autostart";
String PROFILE_DSF_TASK_STOP_PING_AUTOSTART_AND_LATEST_VERSION = PROFILE_DSF_TASK_STOP_PING_AUTOSTART + "|"
+ PingProcessPluginDefinition.VERSION;
String PROFILE_DSF_TASK_STOP_PING_AUTOSTART_PROCESS_URI = ConstantsBase.PROCESS_DSF_URI_BASE
+ PROCESS_NAME_PING_AUTOSTART + "/";
String PROFILE_DSF_TASK_STOP_PING_AUTOSTART_PROCESS_URI_AND_LATEST_VERSION = PROFILE_DSF_TASK_STOP_PING_AUTOSTART_PROCESS_URI
+ PingProcessPluginDefinition.VERSION;
String PROFILE_DSF_TASK_STOP_PING_AUTOSTART_PROCESS_URI = PROCESS_DSF_URI_BASE + PROCESS_NAME_PING_AUTOSTART;
String PROFILE_DSF_TASK_STOP_PING_AUTOSTART_MESSAGE_NAME = "stopPingAutostart";

String PROFILE_DSF_TASK_START_PING = "http://dsf.dev/fhir/StructureDefinition/task-start-ping";
String PROFILE_DSF_TASK_START_PING_AND_LATEST_VERSION = PROFILE_DSF_TASK_START_PING + "|"
+ PingProcessPluginDefinition.VERSION;
String PROFILE_DSF_TASK_START_PING_MESSAGE_NAME = "startPing";

String PROFILE_DSF_TASK_PING = "http://dsf.dev/fhir/StructureDefinition/task-ping";
String PROFILE_DSF_TASK_PING_AND_LATEST_VERSION = PROFILE_DSF_TASK_PING + "|" + PingProcessPluginDefinition.VERSION;
String PROFILE_DSF_TASK_PING_PROCESS_URI = ConstantsBase.PROCESS_DSF_URI_BASE + PROCESS_NAME_PING + "/";
String PROFILE_DSF_TASK_PING_PROCESS_URI_AND_LATEST_VERSION = PROFILE_DSF_TASK_PING_PROCESS_URI
+ PingProcessPluginDefinition.VERSION;
String PROFILE_DSF_TASK_PING_PROCESS_URI = PROCESS_DSF_URI_BASE + PROCESS_NAME_PING;
String PROFILE_DSF_TASK_PING_MESSAGE_NAME = "ping";

String PROFILE_DSF_TASK_PONG_TASK = "http://dsf.dev/fhir/StructureDefinition/task-pong";
String PROFILE_DSF_TASK_PONG_TASK_AND_LATEST_VERSION = PROFILE_DSF_TASK_PONG_TASK + "|"
+ PingProcessPluginDefinition.VERSION;
String PROFILE_DSF_TASK_PONG_PROCESS_URI = ConstantsBase.PROCESS_DSF_URI_BASE + PROCESS_NAME_PONG + "/";
String PROFILE_DSF_TASK_PONG_PROCESS_URI_AND_LATEST_VERSION = PROFILE_DSF_TASK_PONG_PROCESS_URI
+ PingProcessPluginDefinition.VERSION;
String PROFILE_DSF_TASK_PONG_PROCESS_URI = PROCESS_DSF_URI_BASE + PROCESS_NAME_PONG;
String PROFILE_DSF_TASK_PONG_MESSAGE_NAME = "pong";

String CODESYSTEM_DSF_PING = "http://dsf.dev/fhir/CodeSystem/ping";
Expand Down
74 changes: 30 additions & 44 deletions src/main/java/dev/dsf/bpe/PingProcessPluginDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,19 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import org.springframework.core.env.PropertyResolver;

import ca.uhn.fhir.context.FhirContext;
import dev.dsf.bpe.spring.config.PingConfig;
import dev.dsf.fhir.resources.AbstractResource;
import dev.dsf.fhir.resources.ActivityDefinitionResource;
import dev.dsf.fhir.resources.CodeSystemResource;
import dev.dsf.fhir.resources.ResourceProvider;
import dev.dsf.fhir.resources.StructureDefinitionResource;
import dev.dsf.fhir.resources.ValueSetResource;
import dev.dsf.bpe.v1.ProcessPluginDefinition;

public class PingProcessPluginDefinition implements ProcessPluginDefinition
{
public static final String VERSION = "0.7.0";
public static final LocalDate RELEASE_DATE = LocalDate.of(2022, 10, 18);
public static final String VERSION = "1.0.0.0";
public static final LocalDate RELEASE_DATE = LocalDate.of(2023, 5, 20);

@Override
public String getName()
{
return "dsf-bpe-process-ping";
return "dsf-process-ping-pong";
}

@Override
Expand All @@ -41,51 +32,46 @@ public LocalDate getReleaseDate()
}

@Override
public Stream<String> getBpmnFiles()
public List<String> getProcessModels()
{
return Stream.of("bpe/ping-autostart.bpmn", "bpe/ping.bpmn", "bpe/pong.bpmn");
return List.of("bpe/ping-autostart.bpmn", "bpe/ping.bpmn", "bpe/pong.bpmn");
}

@Override
public Stream<Class<?>> getSpringConfigClasses()
public List<Class<?>> getSpringConfigurations()
{
return Stream.of(PingConfig.class);
return List.of(PingConfig.class);
}

@Override
public ResourceProvider getResourceProvider(FhirContext fhirContext, ClassLoader classLoader,
PropertyResolver resolver)
public Map<String, List<String>> getFhirResourcesByProcessId()
{
var aPing = ActivityDefinitionResource.file("fhir/ActivityDefinition/dsf-ping.xml");
var aPingAutostart = ActivityDefinitionResource.file("fhir/ActivityDefinition/dsf-ping-autostart.xml");
var aPong = ActivityDefinitionResource.file("fhir/ActivityDefinition/dsf-pong.xml");
var aPing = "fhir/ActivityDefinition/dsf-ping.xml";
var aPingAutostart = "fhir/ActivityDefinition/dsf-ping-autostart.xml";
var aPong = "fhir/ActivityDefinition/dsf-pong.xml";

var cPing = "fhir/CodeSystem/dsf-ping.xml";
var cPingStatus = "fhir/CodeSystem/dsf-ping-status.xml";

var cPing = CodeSystemResource.file("fhir/CodeSystem/dsf-ping.xml");
var cPingStatus = CodeSystemResource.file("fhir/CodeSystem/dsf-ping-status.xml");
var sPingStatus = "fhir/StructureDefinition/dsf-extension-ping-status.xml";
var sPing = "fhir/StructureDefinition/dsf-task-ping.xml";
var sPong = "fhir/StructureDefinition/dsf-task-pong.xml";
var sStartPing = "fhir/StructureDefinition/dsf-task-start-ping.xml";
var sStartPingAutostart = "fhir/StructureDefinition/dsf-task-start-ping-autostart.xml";
var sStopPingAutostart = "fhir/StructureDefinition/dsf-task-stop-ping-autostart.xml";

var sPingStatus = StructureDefinitionResource.file("fhir/StructureDefinition/dsf-extension-ping-status.xml");
var sPing = StructureDefinitionResource.file("fhir/StructureDefinition/dsf-task-ping.xml");
var sPong = StructureDefinitionResource.file("fhir/StructureDefinition/dsf-task-pong.xml");
var sStartPing = StructureDefinitionResource.file("fhir/StructureDefinition/dsf-task-start-ping.xml");
var sStartPingAutostart = StructureDefinitionResource
.file("fhir/StructureDefinition/dsf-task-start-ping-autostart.xml");
var sStopPingAutostart = StructureDefinitionResource
.file("fhir/StructureDefinition/dsf-task-stop-ping-autostart.xml");
var tStartPing = "fhir/Task/dsf-task-start-ping.xml";

var vPing = ValueSetResource.file("fhir/ValueSet/dsf-ping.xml");
var vPingStatus = ValueSetResource.file("fhir/ValueSet/dsf-ping-status.xml");
var vPongStatus = ValueSetResource.file("fhir/ValueSet/dsf-pong-status.xml");
var vPing = "fhir/ValueSet/dsf-ping.xml";
var vPingStatus = "fhir/ValueSet/dsf-ping-status.xml";
var vPongStatus = "fhir/ValueSet/dsf-pong-status.xml";

Map<String, List<AbstractResource>> resourcesByProcessKeyAndVersion = Map.of(
ConstantsPing.PROCESS_NAME_FULL_PING + "/" + VERSION,
Arrays.asList(aPing, cPing, cPingStatus, sPingStatus, sStartPing, sPong, vPing, vPingStatus),
ConstantsPing.PROCESS_NAME_FULL_PING_AUTOSTART + "/" + VERSION,
return Map.of(ConstantsPing.PROCESS_NAME_FULL_PING,
Arrays.asList(aPing, cPing, cPingStatus, sPingStatus, sStartPing, sPong, tStartPing, vPing,
vPingStatus),
ConstantsPing.PROCESS_NAME_FULL_PING_AUTOSTART,
Arrays.asList(aPingAutostart, cPing, sStartPingAutostart, sStopPingAutostart, vPing),
ConstantsPing.PROCESS_NAME_FULL_PONG + "/" + VERSION,
ConstantsPing.PROCESS_NAME_FULL_PONG,
Arrays.asList(aPong, cPing, cPingStatus, sPingStatus, sPing, vPing, vPongStatus));

return ResourceProvider.read(VERSION, RELEASE_DATE,
() -> fhirContext.newXmlParser().setStripVersionsFromReferences(false), classLoader, resolver,
resourcesByProcessKeyAndVersion);
}
}
61 changes: 15 additions & 46 deletions src/main/java/dev/dsf/bpe/mail/ErrorMailService.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
package dev.dsf.bpe.mail;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;

import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Endpoint;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;

import dev.dsf.bpe.ConstantsBase;
import dev.dsf.bpe.service.MailService;
import dev.dsf.fhir.client.FhirWebserviceClientProvider;
import dev.dsf.fhir.variables.Target;
import dev.dsf.bpe.v1.ProcessPluginApi;
import dev.dsf.bpe.v1.variables.Target;

public class ErrorMailService implements InitializingBean
{
Expand All @@ -26,21 +18,14 @@ public class ErrorMailService implements InitializingBean
private static final String SUBJECT_PING_PROCESS_FAILED = "Ping Process Failed";
private static final String SUBJECT_PONG_PROCESS_FAILED = "Pong Process Failed";

private final String localOrganizationIdentifierValue;

private final MailService mailService;
private final FhirWebserviceClientProvider clientProvider;
private final ProcessPluginApi api;

private final boolean sendPingProcessFailedMail;
private final boolean sendPongProcessFailedMail;

public ErrorMailService(MailService mailService, FhirWebserviceClientProvider clientProvider,
String localOrganizationIdentifierValue, boolean sendPingProcessFailedMail,
boolean sendPongProcessFailedMail)
public ErrorMailService(ProcessPluginApi api, boolean sendPingProcessFailedMail, boolean sendPongProcessFailedMail)
{
this.mailService = mailService;
this.clientProvider = clientProvider;
this.localOrganizationIdentifierValue = localOrganizationIdentifierValue;
this.api = api;

this.sendPingProcessFailedMail = sendPingProcessFailedMail;
this.sendPongProcessFailedMail = sendPongProcessFailedMail;
Expand All @@ -49,33 +34,16 @@ public ErrorMailService(MailService mailService, FhirWebserviceClientProvider cl
@Override
public void afterPropertiesSet() throws Exception
{
Objects.requireNonNull(mailService, "mailService");
Objects.requireNonNull(clientProvider, "clientProvider");
Objects.requireNonNull(localOrganizationIdentifierValue, "localOrganizationIdentifierValue");
}

private String localEndpointIdentifierValue()
{
Bundle result = clientProvider.getLocalWebserviceClient().searchWithStrictHandling(Endpoint.class,
Map.of("address", Collections.singletonList(clientProvider.getLocalBaseUrl())));

if (result.getTotal() != 1)
return "?";

return result.getEntry().stream().filter(BundleEntryComponent::hasResource)
.map(BundleEntryComponent::getResource).filter(r -> r instanceof Endpoint).map(r -> (Endpoint) r)
.findFirst().stream().flatMap(e -> e.getIdentifier().stream())
.filter(i -> ConstantsBase.NAMINGSYSTEM_DSF_ENDPOINT_IDENTIFIER.equals(i.getSystem())).findFirst()
.map(Identifier::getValue).orElse("?");
Objects.requireNonNull(api, "api");
}

private String createMessage(Target target, String message, String messageDetails, IdType taskId)
{
StringBuilder b = new StringBuilder();

b.append(localOrganizationIdentifierValue);
b.append(api.getOrganizationProvider().getLocalOrganizationIdentifierValue().orElse("?"));
b.append('/');
b.append(localEndpointIdentifierValue());
b.append(api.getEndpointProvider().getLocalEndpointIdentifierValue().orElse("?"));

b.append(" -> ");

Expand All @@ -93,7 +61,8 @@ private String createMessage(Target target, String message, String messageDetail
}

b.append("\n\nProcess started by: ");
b.append(taskId.toVersionless().withServerBase(clientProvider.getLocalBaseUrl(), "Task").getValue());
b.append(taskId.toVersionless().withServerBase(api.getEndpointProvider().getLocalEndpointAddress(), "Task")
.getValue());

return b.toString();
}
Expand All @@ -105,7 +74,7 @@ public void pongMessageNotReceived(IdType taskId, Target target)

if (sendPingProcessFailedMail)
{
mailService.send(SUBJECT_PING_PROCESS_FAILED,
api.getMailService().send(SUBJECT_PING_PROCESS_FAILED,
createMessage(target, "No pong message received", null, taskId));
}
}
Expand All @@ -117,7 +86,7 @@ public void endpointNotReachableForPing(IdType taskId, Target target, String err

if (sendPingProcessFailedMail)
{
mailService.send(SUBJECT_PING_PROCESS_FAILED,
api.getMailService().send(SUBJECT_PING_PROCESS_FAILED,
createMessage(target, "Not reachable with ping", errorMessage, taskId));
}
}
Expand All @@ -129,7 +98,7 @@ public void endpointReachablePingForbidden(IdType taskId, Target target, String

if (sendPongProcessFailedMail)
{
mailService.send(SUBJECT_PING_PROCESS_FAILED,
api.getMailService().send(SUBJECT_PING_PROCESS_FAILED,
createMessage(target, "Ping forbidden", errorMessage, taskId));
}
}
Expand All @@ -141,7 +110,7 @@ public void endpointNotReachableForPong(IdType taskId, Target target, String err

if (sendPongProcessFailedMail)
{
mailService.send(SUBJECT_PONG_PROCESS_FAILED,
api.getMailService().send(SUBJECT_PONG_PROCESS_FAILED,
createMessage(target, "Not reachable with pong", errorMessage, taskId));
}
}
Expand All @@ -153,7 +122,7 @@ public void endpointReachablePongForbidden(IdType taskId, Target target, String

if (sendPongProcessFailedMail)
{
mailService.send(SUBJECT_PONG_PROCESS_FAILED,
api.getMailService().send(SUBJECT_PONG_PROCESS_FAILED,
createMessage(target, "Pong forbidden", errorMessage, taskId));
}
}
Expand Down
Loading

0 comments on commit 63b4187

Please sign in to comment.