Skip to content

Commit 9329a54

Browse files
committed
adds mail service with configurable mails on ping/pong process failure
Three different mails are send for the ping process, if enabled: * If not pong message is received * If endpoint is not reachable for ping message * If Task with ping message could not be created (FORBIDDEN) Two different mails are send for the pong process, if enabled: * If endpoint is not reachable for pong message * If Task with pong message could not be created (FORBIDDEN) Fixes endpoint target of pingAutostart process for Task with "startPing" message, if organization has more than one endpoint.
1 parent 2ff73c9 commit 9329a54

File tree

9 files changed

+246
-46
lines changed

9 files changed

+246
-46
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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import javax.ws.rs.core.Response;
1616

1717
import org.camunda.bpm.engine.delegate.DelegateExecution;
18-
import org.highmed.dsf.bpe.logging.ErrorLogger;
18+
import org.highmed.dsf.bpe.mail.ErrorMailService;
1919
import org.highmed.dsf.bpe.util.PingStatusGenerator;
2020
import org.highmed.dsf.fhir.authorization.read.ReadAccessHelper;
2121
import org.highmed.dsf.fhir.client.FhirWebserviceClientProvider;
@@ -37,11 +37,11 @@
3737
public class SendPing extends AbstractTaskMessageSend
3838
{
3939
private final PingStatusGenerator statusGenerator;
40-
private final ErrorLogger errorLogger;
40+
private final ErrorMailService errorLogger;
4141

4242
public SendPing(FhirWebserviceClientProvider clientProvider, TaskHelper taskHelper,
4343
ReadAccessHelper readAccessHelper, OrganizationProvider organizationProvider, FhirContext fhirContext,
44-
PingStatusGenerator statusGenerator, ErrorLogger errorLogger)
44+
PingStatusGenerator statusGenerator, ErrorMailService errorLogger)
4545
{
4646
super(clientProvider, taskHelper, readAccessHelper, organizationProvider, fhirContext);
4747

@@ -90,11 +90,13 @@ protected void handleSendTaskError(DelegateExecution execution, Exception except
9090
task.addOutput(statusGenerator.createPingStatusOutput(target, statusCode, specialErrorMessage));
9191
updateLeadingTaskInExecutionVariables(execution, task);
9292

93-
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);
9497
}
9598

9699
super.handleSendTaskError(execution, exception, errorMessage);
97-
98100
}
99101

100102
@Override

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);

dsf-bpe-process-ping/src/main/java/org/highmed/dsf/bpe/service/LogNoResponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import org.camunda.bpm.engine.delegate.DelegateExecution;
1010
import org.highmed.dsf.bpe.delegate.AbstractServiceDelegate;
11-
import org.highmed.dsf.bpe.logging.ErrorLogger;
11+
import org.highmed.dsf.bpe.mail.ErrorMailService;
1212
import org.highmed.dsf.bpe.util.PingStatusGenerator;
1313
import org.highmed.dsf.fhir.authorization.read.ReadAccessHelper;
1414
import org.highmed.dsf.fhir.client.FhirWebserviceClientProvider;
@@ -25,10 +25,10 @@ public class LogNoResponse extends AbstractServiceDelegate
2525
private static final Logger logger = LoggerFactory.getLogger(LogNoResponse.class);
2626

2727
private final PingStatusGenerator responseGenerator;
28-
private final ErrorLogger errorLogger;
28+
private final ErrorMailService errorLogger;
2929

3030
public LogNoResponse(FhirWebserviceClientProvider clientProvider, TaskHelper taskHelper,
31-
ReadAccessHelper readAccessHelper, PingStatusGenerator responseGenerator, ErrorLogger errorLogger)
31+
ReadAccessHelper readAccessHelper, PingStatusGenerator responseGenerator, ErrorMailService errorLogger)
3232
{
3333
super(clientProvider, taskHelper, readAccessHelper);
3434

@@ -63,6 +63,6 @@ private void logAndAddResponseToTask(Task task, Target target)
6363

6464
task.addOutput(
6565
responseGenerator.createPingStatusOutput(target, CODESYSTEM_HIGHMED_PING_STATUS_VALUE_PONG_MISSING));
66-
errorLogger.logPingStatus(target, CODESYSTEM_HIGHMED_PING_STATUS_VALUE_PONG_MISSING);
66+
errorLogger.pongMessageNotReceived(task.getIdElement(), target);
6767
}
6868
}

dsf-bpe-process-ping/src/main/java/org/highmed/dsf/bpe/service/SetTargetAndConfigureTimer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected void doExecute(DelegateExecution execution) throws BpmnError, Exceptio
5858
execution.setVariable(BPMN_EXECUTION_VARIABLE_TARGET,
5959
TargetValues.create(Target.createUniDirectionalTarget(organizationProvider.getLocalIdentifierValue(),
6060
endpointProvider.getLocalEndpointIdentifier().getValue(),
61-
endpointProvider.getLocalEndpointAddress())));
61+
getFhirWebserviceClientProvider().getLocalBaseUrl())));
6262
}
6363

6464
private String getTimerInterval(DelegateExecution execution)

0 commit comments

Comments
 (0)