Skip to content

Commit 006f0f7

Browse files
committed
added Mapped Diagnostic Context log infos for process plugin executions
1 parent 7c9fe0c commit 006f0f7

33 files changed

+633
-187
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package dev.dsf.bpe.v1.logging;
2+
3+
import java.util.Objects;
4+
import java.util.function.Function;
5+
6+
import org.camunda.bpm.engine.delegate.DelegateExecution;
7+
import org.hl7.fhir.r4.model.Coding;
8+
import org.hl7.fhir.r4.model.ResourceType;
9+
import org.hl7.fhir.r4.model.StringType;
10+
import org.hl7.fhir.r4.model.Task;
11+
import org.hl7.fhir.r4.model.Task.ParameterComponent;
12+
13+
import dev.dsf.bpe.api.Constants;
14+
import dev.dsf.bpe.api.logging.AbstractPluginMdc;
15+
import dev.dsf.bpe.v1.constants.CodeSystems.BpmnMessage;
16+
import dev.dsf.bpe.v1.variables.Variables;
17+
18+
public class PluginMdcImpl extends AbstractPluginMdc
19+
{
20+
private final String serverBaseUrl;
21+
private final Function<DelegateExecution, Variables> variablesFactory;
22+
23+
/**
24+
* @param apiVersion
25+
* @param name
26+
* not <code>null</code>
27+
* @param version
28+
* not <code>null</code>
29+
* @param jar
30+
* not <code>null</code>
31+
* @param serverBaseUrl
32+
* not <code>null</code>
33+
* @param variablesFactory
34+
* not <code>null</code>
35+
*/
36+
public PluginMdcImpl(int apiVersion, String name, String version, String jar, String serverBaseUrl,
37+
Function<DelegateExecution, Variables> variablesFactory)
38+
{
39+
super(apiVersion, name, version, jar);
40+
41+
this.serverBaseUrl = Objects.requireNonNull(serverBaseUrl, "serverBaseUrl");
42+
this.variablesFactory = Objects.requireNonNull(variablesFactory, "variablesFactory");
43+
}
44+
45+
@Override
46+
protected ProcessValues getProcessValues(DelegateExecution delegateExecution)
47+
{
48+
Variables variables = variablesFactory.apply(delegateExecution);
49+
50+
Task startTask = variables.getStartTask();
51+
if (startTask == null)
52+
startTask = variables.getResource(Constants.TASK_VARIABLE);
53+
54+
Task latestTask = variables.getLatestTask();
55+
if (startTask == latestTask)
56+
latestTask = null;
57+
58+
return new ProcessValues(startTask == null ? null : startTask.getInstantiatesCanonical(),
59+
getLocalVersionlessAbsoluteUrl(startTask), getRequesterIdentifierValue(startTask),
60+
getFirstInputParameter(latestTask, BpmnMessage.correlationKey()),
61+
getLocalVersionlessAbsoluteUrl(latestTask), getRequesterIdentifierValue(latestTask));
62+
}
63+
64+
private String getLocalVersionlessAbsoluteUrl(Task task)
65+
{
66+
return task == null ? null
67+
: task.getIdElement().toVersionless().withServerBase(serverBaseUrl, ResourceType.Task.name())
68+
.getValue();
69+
}
70+
71+
private String getRequesterIdentifierValue(Task task)
72+
{
73+
if (task == null)
74+
return null;
75+
76+
return task.getRequester().getIdentifier().getValue();
77+
}
78+
79+
private String getFirstInputParameter(Task task, Coding code)
80+
{
81+
if (task == null || code == null)
82+
return null;
83+
84+
return task.getInput().stream().filter(ParameterComponent::hasType)
85+
.filter(c -> c.getType().getCoding().stream()
86+
.anyMatch(co -> co != null && Objects.equals(code.getSystem(), co.getSystem())
87+
&& Objects.equals(code.getCode(), co.getCode())))
88+
.filter(ParameterComponent::hasValue).map(ParameterComponent::getValue)
89+
.filter(v -> v instanceof StringType).map(v -> (StringType) v).map(StringType::getValue).findFirst()
90+
.orElse(null);
91+
}
92+
}

dsf-bpe/dsf-bpe-process-api-v1-impl/src/main/java/dev/dsf/bpe/v1/plugin/ProcessPluginApiBuilderImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public class ProcessPluginApiBuilderImpl implements ProcessPluginApiBuilder
1111
{
1212
@Override
1313
public ProcessPluginFactory build(ClassLoader apiClassLoader, ApplicationContext apiApplicationContext,
14-
ConfigurableEnvironment environment)
14+
ConfigurableEnvironment environment, String serverBaseUrl)
1515
{
16-
return new ProcessPluginFactoryImpl(apiClassLoader, apiApplicationContext, environment);
16+
return new ProcessPluginFactoryImpl(apiClassLoader, apiApplicationContext, environment, serverBaseUrl);
1717
}
1818

1919
@Override

dsf-bpe/dsf-bpe-process-api-v1-impl/src/main/java/dev/dsf/bpe/v1/plugin/ProcessPluginFactoryImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ public class ProcessPluginFactoryImpl extends AbstractProcessPluginFactory imple
1919
public static final int API_VERSION = 1;
2020

2121
public ProcessPluginFactoryImpl(ClassLoader apiClassLoader, ApplicationContext apiApplicationContext,
22-
ConfigurableEnvironment environment)
22+
ConfigurableEnvironment environment, String serverBaseUrl)
2323
{
24-
super(API_VERSION, apiClassLoader, apiApplicationContext, environment, ProcessPluginDefinition.class);
24+
super(API_VERSION, apiClassLoader, apiApplicationContext, environment, serverBaseUrl,
25+
ProcessPluginDefinition.class);
2526
}
2627

2728
@Override
2829
protected ProcessPlugin createProcessPlugin(Object processPluginDefinition, boolean draft, Path jarFile,
2930
URLClassLoader pluginClassLoader)
3031
{
3132
return new ProcessPluginImpl((ProcessPluginDefinition) processPluginDefinition, API_VERSION, draft, jarFile,
32-
pluginClassLoader, environment, apiApplicationContext);
33+
pluginClassLoader, environment, apiApplicationContext, serverBaseUrl);
3334
}
3435

3536
@Override

dsf-bpe/dsf-bpe-process-api-v1-impl/src/main/java/dev/dsf/bpe/v1/plugin/ProcessPluginImpl.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import ca.uhn.fhir.context.FhirContext;
4545
import ca.uhn.fhir.parser.IParser;
46+
import dev.dsf.bpe.api.logging.PluginMdc;
4647
import dev.dsf.bpe.api.plugin.AbstractProcessPlugin;
4748
import dev.dsf.bpe.api.plugin.FhirResourceModifier;
4849
import dev.dsf.bpe.api.plugin.ProcessPlugin;
@@ -55,7 +56,9 @@
5556
import dev.dsf.bpe.v1.constants.CodeSystems.BpmnMessage;
5657
import dev.dsf.bpe.v1.constants.NamingSystems.OrganizationIdentifier;
5758
import dev.dsf.bpe.v1.constants.NamingSystems.TaskIdentifier;
59+
import dev.dsf.bpe.v1.logging.PluginMdcImpl;
5860
import dev.dsf.bpe.v1.variables.FhirResourceValues;
61+
import dev.dsf.bpe.v1.variables.VariablesImpl;
5962

6063
public class ProcessPluginImpl extends AbstractProcessPlugin<TaskListener> implements ProcessPlugin
6164
{
@@ -64,9 +67,11 @@ public class ProcessPluginImpl extends AbstractProcessPlugin<TaskListener> imple
6467
private final ProcessPluginDefinition processPluginDefinition;
6568
private final ProcessPluginApi processPluginApi;
6669

70+
private final PluginMdcImpl pluginMdc;
71+
6772
public ProcessPluginImpl(ProcessPluginDefinition processPluginDefinition, int processPluginApiVersion,
6873
boolean draft, Path jarFile, ClassLoader classLoader, ConfigurableEnvironment environment,
69-
ApplicationContext apiApplicationContext)
74+
ApplicationContext apiApplicationContext, String serverBaseUrl)
7075
{
7176
super(ProcessPluginDefinition.class, processPluginApiVersion, draft, jarFile, classLoader, environment,
7277
apiApplicationContext, ApiServicesSpringConfiguration.class, JavaDelegate.class, JavaDelegate.class,
@@ -75,6 +80,15 @@ public ProcessPluginImpl(ProcessPluginDefinition processPluginDefinition, int pr
7580

7681
this.processPluginDefinition = processPluginDefinition;
7782
processPluginApi = apiApplicationContext.getBean(ProcessPluginApi.class);
83+
84+
pluginMdc = new PluginMdcImpl(processPluginApiVersion, processPluginDefinition.getName(),
85+
processPluginDefinition.getVersion(), jarFile.toString(), serverBaseUrl, VariablesImpl::new);
86+
}
87+
88+
@Override
89+
public PluginMdc getPluginMdc()
90+
{
91+
return pluginMdc;
7892
}
7993

8094
@Override

dsf-bpe/dsf-bpe-process-api-v1-impl/src/test/java/dev/dsf/bpe/v1/plugin/ProcessPluginImplTest.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public ProcessPluginImplTest()
171171
@Test
172172
public void testInitializeAndValidateResourcesAllNull() throws Exception
173173
{
174-
var definition = createPluginDefinition(null, null, null, null, null);
174+
var definition = createPluginDefinition(null, null, null);
175175
ProcessPluginImpl plugin = createPlugin(definition, false);
176176

177177
assertFalse(plugin.initializeAndValidateResources(null));
@@ -205,7 +205,7 @@ public void testInitializeAndValidateResourcesAllNull() throws Exception
205205
@Test
206206
public void testInitializeAndValidateResourcesEmptySpringConfigBpmnAndFhirResources() throws Exception
207207
{
208-
var definition = createPluginDefinition("1.0.0.0", LocalDate.now(), List.of(), List.of(), Map.of());
208+
var definition = createPluginDefinition(List.of(), List.of(), Map.of());
209209
ProcessPluginImpl plugin = createPlugin(definition, false);
210210

211211
assertFalse(plugin.initializeAndValidateResources(null));
@@ -239,8 +239,7 @@ public void testInitializeAndValidateResourcesEmptySpringConfigBpmnAndFhirResour
239239
@Test
240240
public void testInitializeAndValidateResourcesNotExistingModelAndFhirResources() throws Exception
241241
{
242-
var definition = createPluginDefinition("1.0.0.0", LocalDate.now(), List.of(TestConfig.class),
243-
List.of("test-plugin/does_not_exist.bpmn"),
242+
var definition = createPluginDefinition(List.of(TestConfig.class), List.of("test-plugin/does_not_exist.bpmn"),
244243
Map.of("testorg_test", List.of("test-plugin/does_not_exist.xml")));
245244
ProcessPluginImpl plugin = createPlugin(definition, false);
246245

@@ -275,8 +274,8 @@ public void testInitializeAndValidateResourcesNotExistingModelAndFhirResources()
275274
@Test
276275
public void testInitializeAndValidateResourcesNotExistingFhirResources() throws Exception
277276
{
278-
var definition = createPluginDefinition("1.0.0.0", LocalDate.now(), List.of(TestConfig.class),
279-
List.of("test-plugin/test.bpmn"), Map.of("testorg_test", List.of("test-plugin/does_not_exist.xml")));
277+
var definition = createPluginDefinition(List.of(TestConfig.class), List.of("test-plugin/test.bpmn"),
278+
Map.of("testorg_test", List.of("test-plugin/does_not_exist.xml")));
280279
ProcessPluginImpl plugin = createPlugin(definition, false);
281280

282281
assertFalse(plugin.initializeAndValidateResources(null));
@@ -303,8 +302,7 @@ public void testInitializeAndValidateResourcesNotExistingFhirResources() throws
303302
@Test
304303
public void testInitializeAndValidateResources() throws Exception
305304
{
306-
var definition = createPluginDefinition("1.0.0.0", LocalDate.now(), List.of(TestConfig.class),
307-
List.of("test-plugin/test.bpmn"),
305+
var definition = createPluginDefinition(List.of(TestConfig.class), List.of("test-plugin/test.bpmn"),
308306
Map.of("testorg_test", List.of("test-plugin/ActivityDefinition_test.xml")));
309307
ProcessPluginImpl plugin = createPlugin(definition, false);
310308

@@ -336,16 +334,17 @@ public void testInitializeAndValidateResources() throws Exception
336334
assertEquals(ProcessPluginFactoryImpl.API_VERSION, Integer.parseInt(property.getCamundaValue()));
337335
}
338336

339-
private ProcessPluginDefinition createPluginDefinition(String version, LocalDate releaseDate,
340-
List<Class<?>> springConfigurations, List<String> processModels, Map<String, List<String>> fhirResources)
337+
private ProcessPluginDefinition createPluginDefinition(List<Class<?>> springConfigurations,
338+
List<String> processModels, Map<String, List<String>> fhirResources)
341339
{
342-
return new TestProcessPluginDefinition(fhirResources, processModels, version, springConfigurations,
343-
releaseDate);
340+
return new TestProcessPluginDefinition(fhirResources, processModels, "1.0.0.0", springConfigurations,
341+
LocalDate.now());
344342
}
345343

346344
private ProcessPluginImpl createPlugin(ProcessPluginDefinition processPluginDefinition, boolean draft)
347345
{
348346
return new ProcessPluginImpl(processPluginDefinition, ProcessPluginFactoryImpl.API_VERSION, draft,
349-
Paths.get("test.jar"), getClass().getClassLoader(), environment, apiApplicationContext);
347+
Paths.get("test.jar"), getClass().getClassLoader(), environment, apiApplicationContext,
348+
"https://localhost/fhir");
350349
}
351350
}

dsf-bpe/dsf-bpe-process-api-v2-impl/src/main/java/dev/dsf/bpe/v2/activity/AbstractMessageDelegate.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package dev.dsf.bpe.v2.activity;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
3+
import java.util.function.Function;
4+
5+
import org.camunda.bpm.engine.delegate.DelegateExecution;
46

57
import dev.dsf.bpe.v2.ProcessPluginApi;
68
import dev.dsf.bpe.v2.activity.values.SendTaskValues;
9+
import dev.dsf.bpe.v2.variables.Variables;
710

811
public class AbstractMessageDelegate<D> extends AbstractProcessPluginDelegate<D>
912
{
1013
protected final SendTaskValues sendTaskValues;
1114

12-
public AbstractMessageDelegate(ProcessPluginApi api, ObjectMapper objectMapper, D delegate,
13-
SendTaskValues sendTaskValues)
15+
public AbstractMessageDelegate(ProcessPluginApi api, Function<DelegateExecution, Variables> variablesFactory,
16+
D delegate, SendTaskValues sendTaskValues)
1417
{
15-
super(api, objectMapper, delegate);
18+
super(api, variablesFactory, delegate);
1619

1720
this.sendTaskValues = sendTaskValues;
1821
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
package dev.dsf.bpe.v2.activity;
22

33
import java.util.Objects;
4+
import java.util.function.Function;
45

56
import org.camunda.bpm.engine.delegate.DelegateExecution;
67

7-
import com.fasterxml.jackson.databind.ObjectMapper;
8-
98
import dev.dsf.bpe.v2.ProcessPluginApi;
109
import dev.dsf.bpe.v2.variables.Variables;
11-
import dev.dsf.bpe.v2.variables.VariablesImpl;
1210

1311
public abstract class AbstractProcessPluginDelegate<D>
1412
{
1513
protected final ProcessPluginApi api;
16-
protected final ObjectMapper objectMapper;
1714
protected final D delegate;
1815

19-
public AbstractProcessPluginDelegate(ProcessPluginApi api, ObjectMapper objectMapper, D delegate)
16+
private final Function<DelegateExecution, Variables> variablesFactory;
17+
18+
public AbstractProcessPluginDelegate(ProcessPluginApi api, Function<DelegateExecution, Variables> variablesFactory,
19+
D delegate)
2020
{
2121
this.api = Objects.requireNonNull(api, "api");
22-
this.objectMapper = Objects.requireNonNull(objectMapper, "objectMapper");
22+
this.variablesFactory = Objects.requireNonNull(variablesFactory, "variablesFactory");
2323
this.delegate = Objects.requireNonNull(delegate, "delegate");
2424
}
2525

2626
protected Variables createVariables(DelegateExecution execution)
2727
{
28-
return new VariablesImpl(execution, objectMapper);
28+
return variablesFactory.apply(execution);
2929
}
3030
}

dsf-bpe/dsf-bpe-process-api-v2-impl/src/main/java/dev/dsf/bpe/v2/activity/ExecutionListenerDelegate.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package dev.dsf.bpe.v2.activity;
22

3-
import org.camunda.bpm.engine.delegate.DelegateExecution;
3+
import java.util.function.Function;
44

5-
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import org.camunda.bpm.engine.delegate.DelegateExecution;
66

77
import dev.dsf.bpe.v2.ProcessPluginApi;
88
import dev.dsf.bpe.v2.error.ExecutionListenerErrorHandler;
@@ -11,9 +11,10 @@
1111
public class ExecutionListenerDelegate extends AbstractProcessPluginDelegate<ExecutionListener>
1212
implements org.camunda.bpm.engine.delegate.ExecutionListener
1313
{
14-
public ExecutionListenerDelegate(ProcessPluginApi api, ObjectMapper objectMapper, ExecutionListener delegate)
14+
public ExecutionListenerDelegate(ProcessPluginApi api, Function<DelegateExecution, Variables> variablesFactory,
15+
ExecutionListener delegate)
1516
{
16-
super(api, objectMapper, delegate);
17+
super(api, variablesFactory, delegate);
1718
}
1819

1920
@Override

dsf-bpe/dsf-bpe-process-api-v2-impl/src/main/java/dev/dsf/bpe/v2/activity/MessageEndEventDelegate.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package dev.dsf.bpe.v2.activity;
22

3+
import java.util.function.Function;
4+
35
import org.camunda.bpm.engine.delegate.DelegateExecution;
46
import org.camunda.bpm.engine.delegate.JavaDelegate;
57

6-
import com.fasterxml.jackson.databind.ObjectMapper;
7-
88
import dev.dsf.bpe.v2.ProcessPluginApi;
99
import dev.dsf.bpe.v2.activity.values.SendTaskValues;
1010
import dev.dsf.bpe.v2.error.MessageEndEventErrorHandler;
1111
import dev.dsf.bpe.v2.variables.Variables;
1212

1313
public class MessageEndEventDelegate extends AbstractMessageDelegate<MessageEndEvent> implements JavaDelegate
1414
{
15-
public MessageEndEventDelegate(ProcessPluginApi api, ObjectMapper objectMapper, MessageEndEvent delegate,
16-
SendTaskValues sendTask)
15+
public MessageEndEventDelegate(ProcessPluginApi api, Function<DelegateExecution, Variables> variablesFactory,
16+
MessageEndEvent delegate, SendTaskValues sendTask)
1717
{
18-
super(api, objectMapper, delegate, sendTask);
18+
super(api, variablesFactory, delegate, sendTask);
1919
}
2020

2121
@Override

dsf-bpe/dsf-bpe-process-api-v2-impl/src/main/java/dev/dsf/bpe/v2/activity/MessageIntermediateThrowEventDelegate.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package dev.dsf.bpe.v2.activity;
22

3+
import java.util.function.Function;
4+
35
import org.camunda.bpm.engine.delegate.DelegateExecution;
46
import org.camunda.bpm.engine.delegate.JavaDelegate;
57

6-
import com.fasterxml.jackson.databind.ObjectMapper;
7-
88
import dev.dsf.bpe.v2.ProcessPluginApi;
99
import dev.dsf.bpe.v2.activity.values.SendTaskValues;
1010
import dev.dsf.bpe.v2.error.MessageIntermediateThrowEventErrorHandler;
@@ -13,10 +13,11 @@
1313
public class MessageIntermediateThrowEventDelegate extends AbstractMessageDelegate<MessageIntermediateThrowEvent>
1414
implements JavaDelegate
1515
{
16-
public MessageIntermediateThrowEventDelegate(ProcessPluginApi api, ObjectMapper objectMapper,
17-
MessageIntermediateThrowEvent delegate, SendTaskValues sendTask)
16+
public MessageIntermediateThrowEventDelegate(ProcessPluginApi api,
17+
Function<DelegateExecution, Variables> variablesFactory, MessageIntermediateThrowEvent delegate,
18+
SendTaskValues sendTask)
1819
{
19-
super(api, objectMapper, delegate, sendTask);
20+
super(api, variablesFactory, delegate, sendTask);
2021
}
2122

2223
@Override

0 commit comments

Comments
 (0)