Skip to content

Commit a71bfbc

Browse files
committed
enables autowiring via constructor in ActivityPrototypeBeanCreator
* BPMN Activity classes, created via an ActivityPrototypeBeanCreator, can now express dependencies to other spring beans via constructor arguments without the need for @autowire annotations. * Adds Test to verify autowiring.
1 parent bfe0edd commit a71bfbc

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

dsf-bpe/dsf-bpe-process-api-v2/src/main/java/dev/dsf/bpe/v2/spring/ActivityPrototypeBeanCreator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/**
1919
* Helper class to register {@link Activity}s as prototype beans. Must be configured as a <code>static</code>
20-
* {@link Bean} inside a {@link Configuration} class.
20+
* {@link Bean} inside a {@link Configuration} class. Autowiring via constructor arguments is enabled.
2121
* <p>
2222
* Usage:
2323
* <p>
@@ -73,6 +73,7 @@ private BeanDefinition createBeanDefinition(Class<? extends Activity> activity)
7373
GenericBeanDefinition definition = new GenericBeanDefinition();
7474
definition.setBeanClass(activity);
7575
definition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
76+
definition.setAutowireMode(GenericBeanDefinition.AUTOWIRE_CONSTRUCTOR);
7677
return definition;
7778
}
7879
}

dsf-bpe/dsf-bpe-server/src/test/java/dev/dsf/bpe/integration/PluginV2IntegrationTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,10 @@ public void startSensitiveDataLoggerTest() throws Exception
251251
{
252252
executePluginTest(createTestTask("DataLoggerTest"));
253253
}
254+
255+
@Test
256+
public void startAutowireTest() throws Exception
257+
{
258+
executePluginTest(createTestTask("AutowireTest"));
259+
}
254260
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package dev.dsf.bpe.test.autowire;
2+
3+
public class DemoService
4+
{
5+
// Intentionally empty
6+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package dev.dsf.bpe.test.service;
2+
3+
import static dev.dsf.bpe.test.PluginTestExecutor.expectNotNull;
4+
5+
import dev.dsf.bpe.test.AbstractTest;
6+
import dev.dsf.bpe.test.PluginTest;
7+
import dev.dsf.bpe.test.TestProcessPluginDefinition;
8+
import dev.dsf.bpe.test.autowire.DemoService;
9+
import dev.dsf.bpe.v2.ProcessPluginApi;
10+
import dev.dsf.bpe.v2.activity.ServiceTask;
11+
import dev.dsf.bpe.v2.error.ErrorBoundaryEvent;
12+
import dev.dsf.bpe.v2.variables.Variables;
13+
14+
public class AutowireTest extends AbstractTest implements ServiceTask
15+
{
16+
private final DemoService demoService;
17+
private final TestProcessPluginDefinition pluginDefinition;
18+
19+
public AutowireTest(DemoService demoService, TestProcessPluginDefinition pluginDefinition)
20+
{
21+
this.demoService = demoService;
22+
this.pluginDefinition = pluginDefinition;
23+
}
24+
25+
@Override
26+
public void execute(ProcessPluginApi api, Variables variables) throws ErrorBoundaryEvent, Exception
27+
{
28+
executeTests(api, variables);
29+
}
30+
31+
@PluginTest
32+
public void demoServiceNotNull() throws Exception
33+
{
34+
expectNotNull(demoService);
35+
}
36+
37+
@PluginTest
38+
public void testProcessPluginDefinitionNotNull() throws Exception
39+
{
40+
expectNotNull(pluginDefinition);
41+
}
42+
}

dsf-bpe/dsf-bpe-test-plugin-v2/src/main/java/dev/dsf/bpe/test/spring/config/Config.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
import org.springframework.context.annotation.Configuration;
1010
import org.springframework.context.annotation.Scope;
1111

12+
import dev.dsf.bpe.test.autowire.DemoService;
1213
import dev.dsf.bpe.test.deployment.ProcessPluginDeploymentListenerTestImpl;
1314
import dev.dsf.bpe.test.fhir.FhirResourceModifierImpl;
1415
import dev.dsf.bpe.test.listener.StartFieldInjectionTestListener;
1516
import dev.dsf.bpe.test.listener.StartSendTaskTestListener;
1617
import dev.dsf.bpe.test.message.ContinueSendTestSend;
1718
import dev.dsf.bpe.test.message.SendTaskTest;
1819
import dev.dsf.bpe.test.service.ApiTest;
20+
import dev.dsf.bpe.test.service.AutowireTest;
1921
import dev.dsf.bpe.test.service.ContinueSendTest;
2022
import dev.dsf.bpe.test.service.ContinueSendTestEvaluate;
2123
import dev.dsf.bpe.test.service.CryptoServiceTest;
@@ -72,7 +74,7 @@ public static ActivityPrototypeBeanCreator activityPrototypeBeanCreator()
7274
ExceptionTest.class, ContinueSendTest.class, ContinueSendTestSend.class, ContinueSendTestEvaluate.class,
7375
JsonVariableTestSet.class, JsonVariableTestGet.class, CryptoServiceTest.class,
7476
MimeTypeServiceTest.class, FhirBinaryVariableTestSet.class, FhirBinaryVariableTestGet.class,
75-
DsfClientTest.class, TargetProviderTest.class, DataLoggerTest.class);
77+
DsfClientTest.class, TargetProviderTest.class, DataLoggerTest.class, AutowireTest.class);
7678
}
7779

7880
@Bean
@@ -93,4 +95,10 @@ public ProcessPluginDeploymentListener processPluginDeploymentListener()
9395
{
9496
return new ProcessPluginDeploymentListenerTestImpl();
9597
}
98+
99+
@Bean
100+
public DemoService demoService()
101+
{
102+
return new DemoService();
103+
}
96104
}

dsf-bpe/dsf-bpe-test-plugin-v2/src/main/resources/bpe/test.bpmn

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<bpmn:outgoing>Flow_1gipugc</bpmn:outgoing>
4141
<bpmn:outgoing>Flow_1wjdaz2</bpmn:outgoing>
4242
<bpmn:outgoing>Flow_0jlkf4u</bpmn:outgoing>
43+
<bpmn:outgoing>Flow_1x18y7y</bpmn:outgoing>
4344
</bpmn:exclusiveGateway>
4445
<bpmn:sequenceFlow id="Flow_1bqddk1" sourceRef="TestActivitySelector" targetRef="Gateway_0eszi2t" />
4546
<bpmn:sequenceFlow id="Flow_14rzc0j" sourceRef="Gateway_0eszi2t" targetRef="ProxyTest">
@@ -68,6 +69,7 @@
6869
<bpmn:incoming>Flow_04z1f6i</bpmn:incoming>
6970
<bpmn:incoming>Flow_0w963xd</bpmn:incoming>
7071
<bpmn:incoming>Flow_17to6o7</bpmn:incoming>
72+
<bpmn:incoming>Flow_0scl0xx</bpmn:incoming>
7173
<bpmn:outgoing>Flow_0a1kwg9</bpmn:outgoing>
7274
</bpmn:exclusiveGateway>
7375
<bpmn:sequenceFlow id="Flow_08zzudo" sourceRef="ProxyTest" targetRef="Gateway_056f6tw" />
@@ -310,6 +312,14 @@
310312
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${testActivity == 'DataLoggerTest'}</bpmn:conditionExpression>
311313
</bpmn:sequenceFlow>
312314
<bpmn:sequenceFlow id="Flow_17to6o7" sourceRef="DataLoggerTest" targetRef="Gateway_056f6tw" />
315+
<bpmn:serviceTask id="AutowireTest" name="AutowireTest" camunda:class="dev.dsf.bpe.test.service.AutowireTest">
316+
<bpmn:incoming>Flow_1x18y7y</bpmn:incoming>
317+
<bpmn:outgoing>Flow_0scl0xx</bpmn:outgoing>
318+
</bpmn:serviceTask>
319+
<bpmn:sequenceFlow id="Flow_1x18y7y" sourceRef="Gateway_0eszi2t" targetRef="AutowireTest">
320+
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${testActivity == 'AutowireTest'}</bpmn:conditionExpression>
321+
</bpmn:sequenceFlow>
322+
<bpmn:sequenceFlow id="Flow_0scl0xx" sourceRef="AutowireTest" targetRef="Gateway_056f6tw" />
313323
</bpmn:process>
314324
<bpmn:message id="Message_1nn2wdw" name="start" />
315325
<bpmn:message id="Message_2iq6v5e" name="proxyTest" />
@@ -441,6 +451,10 @@
441451
<dc:Bounds x="480" y="2050" width="100" height="80" />
442452
<bpmndi:BPMNLabel />
443453
</bpmndi:BPMNShape>
454+
<bpmndi:BPMNShape id="BPMNShape_0a3e66p" bpmnElement="AutowireTest">
455+
<dc:Bounds x="480" y="2160" width="100" height="80" />
456+
<bpmndi:BPMNLabel />
457+
</bpmndi:BPMNShape>
444458
<bpmndi:BPMNShape id="Event_1w9i7ga_di" bpmnElement="Event_1dnlmzp">
445459
<dc:Bounds x="562" y="912" width="36" height="36" />
446460
</bpmndi:BPMNShape>
@@ -682,6 +696,16 @@
682696
<di:waypoint x="1180" y="2090" />
683697
<di:waypoint x="1180" y="145" />
684698
</bpmndi:BPMNEdge>
699+
<bpmndi:BPMNEdge id="Flow_1x18y7y_di" bpmnElement="Flow_1x18y7y">
700+
<di:waypoint x="410" y="145" />
701+
<di:waypoint x="410" y="2200" />
702+
<di:waypoint x="480" y="2200" />
703+
</bpmndi:BPMNEdge>
704+
<bpmndi:BPMNEdge id="Flow_0scl0xx_di" bpmnElement="Flow_0scl0xx">
705+
<di:waypoint x="580" y="2200" />
706+
<di:waypoint x="1180" y="2200" />
707+
<di:waypoint x="1180" y="145" />
708+
</bpmndi:BPMNEdge>
685709
</bpmndi:BPMNPlane>
686710
</bpmndi:BPMNDiagram>
687711
</bpmn:definitions>

0 commit comments

Comments
 (0)