Skip to content

Commit 60a948c

Browse files
committed
Merge remote-tracking branch 'origin/develop' into
issues/44_Upgrade_to_DSF_0.9.0
2 parents 415b230 + 5ef8a11 commit 60a948c

20 files changed

+522
-291
lines changed

dsf-bpe-process-ping/pom.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
<artifactId>spring-web</artifactId>
2727
<scope>provided</scope>
2828
</dependency>
29+
<dependency>
30+
<groupId>org.highmed.dsf</groupId>
31+
<artifactId>dsf-tools-documentation-generator</artifactId>
32+
<scope>provided</scope>
33+
</dependency>
2934

3035
<dependency>
3136
<groupId>de.hs-heilbronn.mi</groupId>
@@ -45,6 +50,40 @@
4550
</dependency>
4651
</dependencies>
4752

53+
<build>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.codehaus.mojo</groupId>
57+
<artifactId>exec-maven-plugin</artifactId>
58+
<executions>
59+
<execution>
60+
<goals>
61+
<goal>exec</goal>
62+
</goals>
63+
<phase>prepare-package</phase>
64+
</execution>
65+
</executions>
66+
<configuration>
67+
<executable>java</executable>
68+
<arguments>
69+
<argument>-classpath</argument>
70+
<classpath/>
71+
<argument>
72+
org.highmed.dsf.tools.generator.DocumentationGenerator
73+
</argument>
74+
<argument>
75+
de.netzwerk_universitaetsmedizin.codex.processes.data_transfer.spring.config
76+
</argument>
77+
</arguments>
78+
<includeProjectDependencies>true</includeProjectDependencies>
79+
<addResourcesToClasspath>true</addResourcesToClasspath>
80+
<classpathScope>compile</classpathScope>
81+
<workingDirectory>${project.basedir}</workingDirectory>
82+
</configuration>
83+
</plugin>
84+
</plugins>
85+
</build>
86+
4887
<profiles>
4988
<profile>
5089
<id>copy-to-highmed-dsf-process</id>

dsf-bpe-process-ping/src/main/java/org/highmed/dsf/bpe/logging/ErrorLogger.java

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
package org.highmed.dsf.bpe.mail;
2+
3+
import static org.highmed.dsf.bpe.ConstantsBase.NAMINGSYSTEM_HIGHMED_ENDPOINT_IDENTIFIER;
4+
5+
import java.util.Collections;
6+
import java.util.Map;
7+
import java.util.Objects;
8+
9+
import org.highmed.dsf.bpe.service.MailService;
10+
import org.highmed.dsf.fhir.client.FhirWebserviceClientProvider;
11+
import org.highmed.dsf.fhir.variables.Target;
12+
import org.hl7.fhir.r4.model.Bundle;
13+
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
14+
import org.hl7.fhir.r4.model.Endpoint;
15+
import org.hl7.fhir.r4.model.IdType;
16+
import org.hl7.fhir.r4.model.Identifier;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
import org.springframework.beans.factory.InitializingBean;
20+
21+
public class ErrorMailService implements InitializingBean
22+
{
23+
private static final Logger pingProcessErrorLogger = LoggerFactory.getLogger("ping-process-error-logger");
24+
private static final Logger pongProcessErrorLogger = LoggerFactory.getLogger("pong-process-error-logger");
25+
26+
private static final String SUBJECT_PING_PROCESS_FAILED = "Ping Process Failed";
27+
private static final String SUBJECT_PONG_PROCESS_FAILED = "Pong Process Failed";
28+
29+
private final String localOrganizationIdentifierValue;
30+
31+
private final MailService mailService;
32+
private final FhirWebserviceClientProvider clientProvider;
33+
34+
private final boolean sendPingProcessFailedMail;
35+
private final boolean sendPongProcessFailedMail;
36+
37+
public ErrorMailService(MailService mailService, FhirWebserviceClientProvider clientProvider,
38+
String localOrganizationIdentifierValue, boolean sendPingProcessFailedMail,
39+
boolean sendPongProcessFailedMail)
40+
{
41+
this.mailService = mailService;
42+
this.clientProvider = clientProvider;
43+
this.localOrganizationIdentifierValue = localOrganizationIdentifierValue;
44+
45+
this.sendPingProcessFailedMail = sendPingProcessFailedMail;
46+
this.sendPongProcessFailedMail = sendPongProcessFailedMail;
47+
}
48+
49+
@Override
50+
public void afterPropertiesSet() throws Exception
51+
{
52+
Objects.requireNonNull(mailService, "mailService");
53+
Objects.requireNonNull(clientProvider, "clientProvider");
54+
Objects.requireNonNull(localOrganizationIdentifierValue, "localOrganizationIdentifierValue");
55+
}
56+
57+
private String localEndpointIdentifierValue()
58+
{
59+
Bundle result = clientProvider.getLocalWebserviceClient().searchWithStrictHandling(Endpoint.class,
60+
Map.of("address", Collections.singletonList(clientProvider.getLocalBaseUrl())));
61+
62+
if (result.getTotal() != 1)
63+
return "?";
64+
65+
return result.getEntry().stream().filter(BundleEntryComponent::hasResource)
66+
.map(BundleEntryComponent::getResource).filter(r -> r instanceof Endpoint).map(r -> (Endpoint) r)
67+
.findFirst().stream().flatMap(e -> e.getIdentifier().stream())
68+
.filter(i -> NAMINGSYSTEM_HIGHMED_ENDPOINT_IDENTIFIER.equals(i.getSystem())).findFirst()
69+
.map(Identifier::getValue).orElse("?");
70+
}
71+
72+
private String createMessage(Target target, String message, String messageDetails, IdType taskId)
73+
{
74+
StringBuilder b = new StringBuilder();
75+
76+
b.append(localOrganizationIdentifierValue);
77+
b.append('/');
78+
b.append(localEndpointIdentifierValue());
79+
80+
b.append(" -> ");
81+
82+
b.append(target.getOrganizationIdentifierValue());
83+
b.append('/');
84+
b.append(target.getEndpointIdentifierValue());
85+
86+
b.append(": ");
87+
b.append(message);
88+
89+
if (messageDetails != null)
90+
{
91+
b.append("\n\t");
92+
b.append(messageDetails);
93+
}
94+
95+
b.append("\n\nProcess started by: ");
96+
b.append(taskId.toVersionless().withServerBase(clientProvider.getLocalBaseUrl(), "Task").getValue());
97+
98+
return b.toString();
99+
}
100+
101+
public void pongMessageNotReceived(IdType taskId, Target target)
102+
{
103+
pingProcessErrorLogger.debug("No pong from organization '{}', Endpoint '{}' received",
104+
target.getOrganizationIdentifierValue(), target.getEndpointIdentifierValue());
105+
106+
if (sendPingProcessFailedMail)
107+
{
108+
mailService.send(SUBJECT_PING_PROCESS_FAILED,
109+
createMessage(target, "No pong message received", null, taskId));
110+
}
111+
}
112+
113+
public void endpointNotReachableForPing(IdType taskId, Target target, String errorMessage)
114+
{
115+
pingProcessErrorLogger.debug("Endpoint '{}' at organization '{}' not reachable with ping: {}",
116+
target.getOrganizationIdentifierValue(), target.getEndpointIdentifierValue(), errorMessage);
117+
118+
if (sendPingProcessFailedMail)
119+
{
120+
mailService.send(SUBJECT_PING_PROCESS_FAILED,
121+
createMessage(target, "Not reachable with ping", errorMessage, taskId));
122+
}
123+
}
124+
125+
public void endpointReachablePingForbidden(IdType taskId, Target target, String errorMessage)
126+
{
127+
pingProcessErrorLogger.debug("Endpoint '{}' at organization '{}' reachable, ping forbidden: {}",
128+
target.getOrganizationIdentifierValue(), target.getEndpointIdentifierValue(), errorMessage);
129+
130+
if (sendPongProcessFailedMail)
131+
{
132+
mailService.send(SUBJECT_PING_PROCESS_FAILED,
133+
createMessage(target, "Ping forbidden", errorMessage, taskId));
134+
}
135+
}
136+
137+
public void endpointNotReachableForPong(IdType taskId, Target target, String errorMessage)
138+
{
139+
pongProcessErrorLogger.debug("Endpoint '{}' at organization '{}' not reachable with pong: {}",
140+
target.getOrganizationIdentifierValue(), target.getEndpointIdentifierValue(), errorMessage);
141+
142+
if (sendPongProcessFailedMail)
143+
{
144+
mailService.send(SUBJECT_PONG_PROCESS_FAILED,
145+
createMessage(target, "Not reachable with pong", errorMessage, taskId));
146+
}
147+
}
148+
149+
public void endpointReachablePongForbidden(IdType taskId, Target target, String errorMessage)
150+
{
151+
pongProcessErrorLogger.debug("Endpoint '{}' at organization '{}' reachable, pong forbidden: {}",
152+
target.getOrganizationIdentifierValue(), target.getEndpointIdentifierValue(), errorMessage);
153+
154+
if (sendPongProcessFailedMail)
155+
{
156+
mailService.send(SUBJECT_PONG_PROCESS_FAILED,
157+
createMessage(target, "Pong forbidden", errorMessage, taskId));
158+
}
159+
}
160+
}

dsf-bpe-process-ping/src/main/java/org/highmed/dsf/bpe/message/SendPing.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
package org.highmed.dsf.bpe.message;
22

3+
import static org.highmed.dsf.bpe.ConstantsBase.NAMINGSYSTEM_HIGHMED_ENDPOINT_IDENTIFIER;
34
import static org.highmed.dsf.bpe.ConstantsPing.CODESYSTEM_HIGHMED_PING;
45
import static org.highmed.dsf.bpe.ConstantsPing.CODESYSTEM_HIGHMED_PING_STATUS_VALUE_NOT_ALLOWED;
56
import static org.highmed.dsf.bpe.ConstantsPing.CODESYSTEM_HIGHMED_PING_STATUS_VALUE_NOT_REACHABLE;
67
import static org.highmed.dsf.bpe.ConstantsPing.CODESYSTEM_HIGHMED_PING_VALUE_ENDPOINT_IDENTIFIER;
78

9+
import java.util.Collections;
10+
import java.util.Map;
811
import java.util.Objects;
912
import java.util.stream.Stream;
1013

1114
import javax.ws.rs.WebApplicationException;
1215
import javax.ws.rs.core.Response;
1316

1417
import org.camunda.bpm.engine.delegate.DelegateExecution;
15-
import org.highmed.dsf.bpe.logging.ErrorLogger;
18+
import org.highmed.dsf.bpe.mail.ErrorMailService;
1619
import org.highmed.dsf.bpe.util.PingStatusGenerator;
1720
import org.highmed.dsf.fhir.authorization.read.ReadAccessHelper;
1821
import org.highmed.dsf.fhir.client.FhirWebserviceClientProvider;
19-
import org.highmed.dsf.fhir.organization.EndpointProvider;
2022
import org.highmed.dsf.fhir.organization.OrganizationProvider;
2123
import org.highmed.dsf.fhir.task.AbstractTaskMessageSend;
2224
import org.highmed.dsf.fhir.task.TaskHelper;
2325
import org.highmed.dsf.fhir.variables.Target;
26+
import org.hl7.fhir.r4.model.Bundle;
27+
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
28+
import org.hl7.fhir.r4.model.Endpoint;
29+
import org.hl7.fhir.r4.model.Identifier;
2430
import org.hl7.fhir.r4.model.Reference;
2531
import org.hl7.fhir.r4.model.ResourceType;
2632
import org.hl7.fhir.r4.model.Task;
@@ -30,17 +36,15 @@
3036

3137
public class SendPing extends AbstractTaskMessageSend
3238
{
33-
private final EndpointProvider endpointProvider;
3439
private final PingStatusGenerator statusGenerator;
35-
private final ErrorLogger errorLogger;
40+
private final ErrorMailService errorLogger;
3641

3742
public SendPing(FhirWebserviceClientProvider clientProvider, TaskHelper taskHelper,
3843
ReadAccessHelper readAccessHelper, OrganizationProvider organizationProvider, FhirContext fhirContext,
39-
EndpointProvider endpointProvider, PingStatusGenerator statusGenerator, ErrorLogger errorLogger)
44+
PingStatusGenerator statusGenerator, ErrorMailService errorLogger)
4045
{
4146
super(clientProvider, taskHelper, readAccessHelper, organizationProvider, fhirContext);
4247

43-
this.endpointProvider = endpointProvider;
4448
this.statusGenerator = statusGenerator;
4549
this.errorLogger = errorLogger;
4650
}
@@ -50,18 +54,16 @@ public void afterPropertiesSet() throws Exception
5054
{
5155
super.afterPropertiesSet();
5256

53-
Objects.requireNonNull(endpointProvider, "endpointProvider");
5457
Objects.requireNonNull(statusGenerator, "statusGenerator");
5558
Objects.requireNonNull(errorLogger, "errorLogger");
5659
}
5760

5861
@Override
5962
protected Stream<ParameterComponent> getAdditionalInputParameters(DelegateExecution execution)
6063
{
61-
return Stream.of(
62-
getTaskHelper().createInput(CODESYSTEM_HIGHMED_PING, CODESYSTEM_HIGHMED_PING_VALUE_ENDPOINT_IDENTIFIER,
63-
new Reference().setIdentifier(endpointProvider.getLocalEndpointIdentifier())
64-
.setType(ResourceType.Endpoint.name())));
64+
return Stream.of(getTaskHelper().createInput(CODESYSTEM_HIGHMED_PING,
65+
CODESYSTEM_HIGHMED_PING_VALUE_ENDPOINT_IDENTIFIER,
66+
new Reference().setIdentifier(getLocalEndpointIdentifier()).setType(ResourceType.Endpoint.name())));
6567
}
6668

6769
@Override
@@ -88,11 +90,13 @@ protected void handleSendTaskError(DelegateExecution execution, Exception except
8890
task.addOutput(statusGenerator.createPingStatusOutput(target, statusCode, specialErrorMessage));
8991
updateLeadingTaskInExecutionVariables(execution, task);
9092

91-
errorLogger.logPingStatus(target, statusCode, specialErrorMessage);
93+
if (CODESYSTEM_HIGHMED_PING_STATUS_VALUE_NOT_REACHABLE.equals(statusCode))
94+
errorLogger.endpointNotReachableForPing(task.getIdElement(), target, specialErrorMessage);
95+
else if (CODESYSTEM_HIGHMED_PING_STATUS_VALUE_NOT_ALLOWED.equals(statusCode))
96+
errorLogger.endpointReachablePingForbidden(task.getIdElement(), target, specialErrorMessage);
9297
}
9398

9499
super.handleSendTaskError(execution, exception, errorMessage);
95-
96100
}
97101

98102
@Override
@@ -108,4 +112,17 @@ private String createErrorMessage(Exception exception)
108112
? (": " + exception.getMessage())
109113
: "");
110114
}
115+
116+
private Identifier getLocalEndpointIdentifier()
117+
{
118+
Bundle bundle = getFhirWebserviceClientProvider().getLocalWebserviceClient().search(Endpoint.class,
119+
Map.of("address", Collections.singletonList(getFhirWebserviceClientProvider().getLocalBaseUrl())));
120+
return bundle.getEntry().stream().filter(BundleEntryComponent::hasResource)
121+
.filter(e -> e.getResource() instanceof Endpoint).map(e -> (Endpoint) e.getResource()).findFirst()
122+
.filter(e -> e.hasIdentifier())
123+
.flatMap(e -> e.getIdentifier().stream()
124+
.filter(i -> NAMINGSYSTEM_HIGHMED_ENDPOINT_IDENTIFIER.equals(i.getSystem())).findFirst())
125+
.orElseThrow(() -> new IllegalStateException("No Identifier for Endpoint or Endpoint with address "
126+
+ getFhirWebserviceClientProvider().getLocalBaseUrl() + " found"));
127+
}
111128
}

dsf-bpe-process-ping/src/main/java/org/highmed/dsf/bpe/message/SendPong.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import javax.ws.rs.core.Response;
1111

1212
import org.camunda.bpm.engine.delegate.DelegateExecution;
13-
import org.highmed.dsf.bpe.logging.ErrorLogger;
13+
import org.highmed.dsf.bpe.mail.ErrorMailService;
1414
import org.highmed.dsf.bpe.util.PingStatusGenerator;
1515
import org.highmed.dsf.fhir.authorization.read.ReadAccessHelper;
1616
import org.highmed.dsf.fhir.client.FhirWebserviceClientProvider;
@@ -25,11 +25,11 @@
2525
public class SendPong extends AbstractTaskMessageSend
2626
{
2727
private final PingStatusGenerator statusGenerator;
28-
private final ErrorLogger errorLogger;
28+
private final ErrorMailService errorLogger;
2929

3030
public SendPong(FhirWebserviceClientProvider clientProvider, TaskHelper taskHelper,
3131
ReadAccessHelper readAccessHelper, OrganizationProvider organizationProvider, FhirContext fhirContext,
32-
PingStatusGenerator statusGenerator, ErrorLogger errorLogger)
32+
PingStatusGenerator statusGenerator, ErrorMailService errorLogger)
3333
{
3434
super(clientProvider, taskHelper, readAccessHelper, organizationProvider, fhirContext);
3535

@@ -81,7 +81,10 @@ protected void handleEndEventError(DelegateExecution execution, Exception except
8181
task.addOutput(statusGenerator.createPongStatusOutput(target, statusCode, specialErrorMessage));
8282
updateLeadingTaskInExecutionVariables(execution, task);
8383

84-
errorLogger.logPongStatus(target, statusCode, specialErrorMessage);
84+
if (CODESYSTEM_HIGHMED_PING_STATUS_VALUE_NOT_REACHABLE.equals(statusCode))
85+
errorLogger.endpointNotReachableForPong(task.getIdElement(), target, specialErrorMessage);
86+
else if (CODESYSTEM_HIGHMED_PING_STATUS_VALUE_NOT_ALLOWED.equals(statusCode))
87+
errorLogger.endpointReachablePongForbidden(task.getIdElement(), target, specialErrorMessage);
8588
}
8689

8790
super.handleEndEventError(execution, exception, errorMessage);

0 commit comments

Comments
 (0)