Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/1.0.1.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
hhund committed Sep 12, 2023
2 parents 3e24adc + 28adc11 commit 6312e7d
Show file tree
Hide file tree
Showing 11 changed files with 431 additions and 238 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

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

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

<dsf.version>1.1.0</dsf.version>
<dsf.version>1.2.0</dsf.version>
<dsf.location>../dsf</dsf.location>
</properties>

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/dsf/bpe/PingProcessPluginDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

public class PingProcessPluginDefinition implements ProcessPluginDefinition
{
public static final String VERSION = "1.0.0.0";
public static final LocalDate RELEASE_DATE = LocalDate.of(2023, 8, 22);
public static final String VERSION = "1.0.1.0";
public static final LocalDate RELEASE_DATE = LocalDate.of(2023, 9, 12);

@Override
public String getName()
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/dev/dsf/bpe/listener/SetCorrelationKeyListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.dsf.bpe.listener;

import java.util.Objects;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.ExecutionListener;
import org.springframework.beans.factory.InitializingBean;

import dev.dsf.bpe.v1.ProcessPluginApi;
import dev.dsf.bpe.v1.constants.BpmnExecutionVariables;
import dev.dsf.bpe.v1.variables.Target;
import dev.dsf.bpe.v1.variables.Variables;

public class SetCorrelationKeyListener implements ExecutionListener, InitializingBean
{
private final ProcessPluginApi api;

public SetCorrelationKeyListener(ProcessPluginApi api)
{
this.api = api;
}

@Override
public void afterPropertiesSet() throws Exception
{
Objects.requireNonNull(api, "api");
}

@Override
public void notify(DelegateExecution execution) throws Exception
{
Variables variables = api.getVariables(execution);
Target target = variables.getTarget();

execution.setVariableLocal(BpmnExecutionVariables.CORRELATION_KEY, target.getCorrelationKey());
}
}
73 changes: 20 additions & 53 deletions src/main/java/dev/dsf/bpe/message/SendPing.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.dsf.bpe.message;

import java.util.Objects;
import java.util.stream.Stream;

import org.camunda.bpm.engine.delegate.DelegateExecution;
Expand All @@ -11,35 +10,18 @@
import org.hl7.fhir.r4.model.Task.ParameterComponent;

import dev.dsf.bpe.ConstantsPing;
import dev.dsf.bpe.mail.ErrorMailService;
import dev.dsf.bpe.util.PingStatusGenerator;
import dev.dsf.bpe.v1.ProcessPluginApi;
import dev.dsf.bpe.v1.activity.AbstractTaskMessageSend;
import dev.dsf.bpe.v1.variables.Target;
import dev.dsf.bpe.v1.variables.Variables;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.StatusType;

public class SendPing extends AbstractTaskMessageSend
{
private final PingStatusGenerator statusGenerator;
private final ErrorMailService errorMailService;

public SendPing(ProcessPluginApi api, PingStatusGenerator statusGenerator, ErrorMailService errorMailService)
public SendPing(ProcessPluginApi api)
{
super(api);

this.statusGenerator = statusGenerator;
this.errorMailService = errorMailService;
}

@Override
public void afterPropertiesSet() throws Exception
{
super.afterPropertiesSet();

Objects.requireNonNull(statusGenerator, "statusGenerator");
Objects.requireNonNull(errorMailService, "errorMailService");
}

@Override
Expand All @@ -51,36 +33,17 @@ protected Stream<ParameterComponent> getAdditionalInputParameters(DelegateExecut
}

@Override
protected void handleSendTaskError(DelegateExecution execution, Variables variables, Exception exception,
String errorMessage)
protected void handleIntermediateThrowEventError(DelegateExecution execution, Variables variables,
Exception exception, String errorMessage)
{
Target target = variables.getTarget();
Task mainTask = variables.getStartTask();

if (mainTask != null)
{
String statusCode = ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_REACHABLE;
if (exception instanceof WebApplicationException webApplicationException)
{
if (webApplicationException.getResponse() != null && webApplicationException.getResponse()
.getStatus() == Response.Status.FORBIDDEN.getStatusCode())
{
statusCode = ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_ALLOWED;
}
}

String specialErrorMessage = createErrorMessage(exception);

mainTask.addOutput(statusGenerator.createPingStatusOutput(target, statusCode, specialErrorMessage));
variables.updateTask(mainTask);

if (ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_REACHABLE.equals(statusCode))
errorMailService.endpointNotReachableForPing(mainTask.getIdElement(), target, specialErrorMessage);
else if (ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_ALLOWED.equals(statusCode))
errorMailService.endpointReachablePingForbidden(mainTask.getIdElement(), target, specialErrorMessage);
}

super.handleSendTaskError(execution, variables, exception, errorMessage);
String statusCode = exception instanceof WebApplicationException w && w.getResponse() != null
&& w.getResponse().getStatus() == Response.Status.FORBIDDEN.getStatusCode()
? ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_ALLOWED
: ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_REACHABLE;
execution.setVariableLocal("statusCode", statusCode);

String specialErrorMessage = createErrorMessage(exception);
execution.setVariableLocal("errorMessage", specialErrorMessage);
}

@Override
Expand All @@ -91,10 +54,14 @@ protected void addErrorMessage(Task task, String errorMessage)

private String createErrorMessage(Exception exception)
{
return exception.getClass().getSimpleName()
+ ((exception.getMessage() != null && !exception.getMessage().isBlank())
? (": " + exception.getMessage())
: "");
if (exception instanceof WebApplicationException w
&& (exception.getMessage() == null || exception.getMessage().isBlank()))
{
StatusType statusInfo = w.getResponse().getStatusInfo();
return statusInfo.getStatusCode() + " " + statusInfo.getReasonPhrase();
}
else
return exception.getMessage();
}

private Identifier getLocalEndpointIdentifier()
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/dev/dsf/bpe/message/SendPong.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import dev.dsf.bpe.v1.variables.Variables;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.StatusType;

public class SendPong extends AbstractTaskMessageSend
{
Expand Down Expand Up @@ -58,16 +59,10 @@ protected void handleEndEventError(DelegateExecution execution, Variables variab

if (mainTask != null)
{
String statusCode = ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_REACHABLE;
if (exception instanceof WebApplicationException)
{
WebApplicationException webApplicationException = (WebApplicationException) exception;
if (webApplicationException.getResponse() != null && webApplicationException.getResponse()
.getStatus() == Response.Status.FORBIDDEN.getStatusCode())
{
statusCode = ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_ALLOWED;
}
}
String statusCode = exception instanceof WebApplicationException w && w.getResponse() != null
&& w.getResponse().getStatus() == Response.Status.FORBIDDEN.getStatusCode()
? ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_ALLOWED
: ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_REACHABLE;

String specialErrorMessage = createErrorMessage(exception);

Expand All @@ -85,9 +80,13 @@ else if (ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_NOT_ALLOWED.equals(statu

private String createErrorMessage(Exception exception)
{
return exception.getClass().getSimpleName()
+ ((exception.getMessage() != null && !exception.getMessage().isBlank())
? (": " + exception.getMessage())
: "");
if (exception instanceof WebApplicationException w
&& (exception.getMessage() == null || exception.getMessage().isBlank()))
{
StatusType statusInfo = w.getResponse().getStatusInfo();
return statusInfo.getStatusCode() + " " + statusInfo.getReasonPhrase();
}
else
return exception.getMessage();
}
}
39 changes: 4 additions & 35 deletions src/main/java/dev/dsf/bpe/service/LogNoResponse.java
Original file line number Diff line number Diff line change
@@ -1,65 +1,34 @@
package dev.dsf.bpe.service;

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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import dev.dsf.bpe.ConstantsPing;
import dev.dsf.bpe.mail.ErrorMailService;
import dev.dsf.bpe.util.PingStatusGenerator;
import dev.dsf.bpe.v1.ProcessPluginApi;
import dev.dsf.bpe.v1.activity.AbstractServiceDelegate;
import dev.dsf.bpe.v1.variables.Target;
import dev.dsf.bpe.v1.variables.Targets;
import dev.dsf.bpe.v1.variables.Variables;

public class LogNoResponse extends AbstractServiceDelegate
{
private static final Logger logger = LoggerFactory.getLogger(LogNoResponse.class);

private final PingStatusGenerator responseGenerator;
private final ErrorMailService errorMailService;

public LogNoResponse(ProcessPluginApi api, PingStatusGenerator responseGenerator, ErrorMailService errorMailService)
public LogNoResponse(ProcessPluginApi api)
{
super(api);

this.responseGenerator = responseGenerator;
this.errorMailService = errorMailService;
}

@Override
public void afterPropertiesSet() throws Exception
{
super.afterPropertiesSet();

Objects.requireNonNull(responseGenerator, "responseGenerator");
Objects.requireNonNull(errorMailService, "errorLogger");
}


@Override
protected void doExecute(DelegateExecution execution, Variables variables) throws BpmnError, Exception
{
Task mainTask = variables.getStartTask();

Targets targets = variables.getTargets();
targets.getEntries().forEach(t -> logAndAddResponseToTask(mainTask, t));
Target target = variables.getTarget();

variables.updateTask(mainTask);
}

private void logAndAddResponseToTask(Task task, Target target)
{
logger.warn("PONG from organization {} (endpoint {}) missing", target.getOrganizationIdentifierValue(),
target.getEndpointIdentifierValue());

task.addOutput(responseGenerator.createPingStatusOutput(target,
ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_PONG_MISSING));
errorMailService.pongMessageNotReceived(task.getIdElement(), target);
variables.setString("statusCode_" + target.getCorrelationKey(),
ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_PONG_MISSING);
}
}
30 changes: 4 additions & 26 deletions src/main/java/dev/dsf/bpe/service/LogPong.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,26 @@
package dev.dsf.bpe.service;

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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import dev.dsf.bpe.ConstantsPing;
import dev.dsf.bpe.util.PingStatusGenerator;
import dev.dsf.bpe.v1.ProcessPluginApi;
import dev.dsf.bpe.v1.activity.AbstractServiceDelegate;
import dev.dsf.bpe.v1.variables.Target;
import dev.dsf.bpe.v1.variables.Targets;
import dev.dsf.bpe.v1.variables.Variables;

public class LogPong extends AbstractServiceDelegate
{
private static final Logger logger = LoggerFactory.getLogger(LogPong.class);

private final PingStatusGenerator responseGenerator;

public LogPong(ProcessPluginApi api, PingStatusGenerator responseGenerator)
public LogPong(ProcessPluginApi api)
{
super(api);

this.responseGenerator = responseGenerator;
}

@Override
public void afterPropertiesSet() throws Exception
{
super.afterPropertiesSet();

Objects.requireNonNull(responseGenerator, "responseGenerator");
}


@Override
protected void doExecute(DelegateExecution execution, Variables variables) throws BpmnError, Exception
{
Expand All @@ -46,13 +29,8 @@ protected void doExecute(DelegateExecution execution, Variables variables) throw
logger.info("PONG from {} (endpoint: {})", target.getOrganizationIdentifierValue(),
target.getEndpointIdentifierValue());

Task mainTask = variables.getStartTask();
mainTask.addOutput(responseGenerator.createPingStatusOutput(target,
ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_PONG_RECEIVED));
variables.updateTask(mainTask);

Targets targets = variables.getTargets();
targets = targets.removeByEndpointIdentifierValue(target.getEndpointIdentifierValue());
variables.setTargets(targets);
execution.removeVariable("statusCode");
variables.setString("statusCode_" + target.getCorrelationKey(),
ConstantsPing.CODESYSTEM_DSF_PING_STATUS_VALUE_PONG_RECEIVED);
}
}
35 changes: 35 additions & 0 deletions src/main/java/dev/dsf/bpe/service/LogSendError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package dev.dsf.bpe.service;

import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import dev.dsf.bpe.v1.ProcessPluginApi;
import dev.dsf.bpe.v1.activity.AbstractServiceDelegate;
import dev.dsf.bpe.v1.variables.Target;
import dev.dsf.bpe.v1.variables.Variables;

public class LogSendError extends AbstractServiceDelegate
{
private static final Logger logger = LoggerFactory.getLogger(LogSendError.class);

public LogSendError(ProcessPluginApi api)
{
super(api);
}

@Override
protected void doExecute(DelegateExecution execution, Variables variables) throws BpmnError, Exception
{
Target target = variables.getTarget();
String statusCode = (String) execution.getVariableLocal("statusCode");
String errorMessage = (String) execution.getVariableLocal("errorMessage");

logger.warn("Unable to send PING to {} (endpoint: {}): {}", target.getOrganizationIdentifierValue(),
target.getEndpointIdentifierValue(), errorMessage);

variables.setString("statusCode_" + target.getCorrelationKey(), statusCode);
variables.setString("errorMessage_" + target.getCorrelationKey(), errorMessage);
}
}
Loading

0 comments on commit 6312e7d

Please sign in to comment.