Skip to content

Commit ae74594

Browse files
committed
feat: add command to start process at specific element
1 parent 695259b commit ae74594

File tree

3 files changed

+83
-10
lines changed

3 files changed

+83
-10
lines changed

api-impl/src/main/kotlin/dev/bpmcrafters/processengineapi/impl/task/TaskSubscriptionHandle.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data class TaskSubscriptionHandle(
3131
*/
3232
val taskDescriptionKey: String?,
3333
/**
34-
* Action handler to execute, if the task is delivered.
34+
* Action handler to execute if the task is delivered.
3535
*/
3636
val action: TaskHandler,
3737
/**
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package dev.bpmcrafters.processengineapi.process
2+
3+
import dev.bpmcrafters.processengineapi.PayloadSupplier
4+
5+
/**
6+
* Command to start a new process instance at a specific activity.
7+
* @since 1.5.0
8+
*/
9+
data class StartProcessByDefinitionAtElementCmd(
10+
/**
11+
* Process definition key.
12+
*/
13+
val definitionKey: String,
14+
/**
15+
* ID of the element to start the process at.
16+
*/
17+
val elementId: String,
18+
/**
19+
* Payload supplier to pass to the new process instance.
20+
*/
21+
val payloadSupplier: PayloadSupplier,
22+
/**
23+
* Restrictions applied for this start command.
24+
*/
25+
val restrictions: Map<String, String> = emptyMap()
26+
) : StartProcessCommand, PayloadSupplier by payloadSupplier {
27+
/**
28+
* Constructs a start command with a definition key, element ID, payload, and restrictions.
29+
* @param definitionKey process definition key.
30+
* @param elementId element ID (activity ID) to start the process at.
31+
* @param payload payload to use.
32+
* @param restrictions restrictions for the start command.
33+
*/
34+
constructor(definitionKey: String, elementId: String, payload: Map<String, Any>, restrictions: Map<String, String>) : this(
35+
definitionKey = definitionKey,
36+
elementId = elementId,
37+
payloadSupplier = PayloadSupplier { payload },
38+
restrictions = restrictions
39+
)
40+
/**
41+
* Constructs a start command with a definition key, element ID, and payload.
42+
* @param definitionKey process definition key.
43+
* @param elementId element ID (activity ID) to start the process at.
44+
* @param payload payload to use.
45+
*/
46+
constructor(definitionKey: String, elementId: String, payload: Map<String, Any>) : this(
47+
definitionKey = definitionKey,
48+
elementId = elementId,
49+
payloadSupplier = PayloadSupplier { payload } ,
50+
restrictions = mapOf()
51+
)
52+
53+
/**
54+
* Constructs a start command with definition key, element ID, and no payload.
55+
* @param definitionKey process definition key.
56+
* @param elementId element ID (activity ID) to start the process at.
57+
*/
58+
constructor(definitionKey: String, elementId: String) : this(
59+
definitionKey = definitionKey,
60+
elementId = elementId,
61+
payload = mapOf(),
62+
)
63+
}

docs/process-api.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
title: Process API
33
---
44

5-
The Process API provides functionality, required to control the lifecycle of the processes. It allows to start new process instances.
6-
It is intended to be used in outbound adapters of the port/adapter architecture, in order to control the process engine
7-
from your application.
5+
The Process API provides functionality required to control the lifecycle of the processes.
6+
It allows to start new process instances.
7+
It is intended to be used in outbound adapters of the port/adapter architecture
8+
to control the process engine from your application.
89

9-
There are two ways to start processes:
10+
There are three ways to start processes:
1011
* by providing a process definition key
1112
* by providing a start message
13+
* by providing a process definition key and a specific activity to start at
1214

13-
In both cases, you might provide a process payload passed to the started process instance.
15+
In all cases, you might provide a process payload passed to the started process instance.
1416

1517
Here is an example of usage:
1618

1719
```java
18-
1920
@Component
2021
@RequiredArgsConstructor
2122
public class ProcessStarter {
@@ -33,7 +34,6 @@ public class ProcessStarter {
3334
).get();
3435
}
3536

36-
3737
@SneakyThrows
3838
public void startByMessage(Order order) {
3939
startProcessApi.startProcess(
@@ -44,10 +44,20 @@ public class ProcessStarter {
4444
)
4545
).get();
4646
}
47-
48-
}
4947

48+
@SneakyThrows
49+
public void startByDefinitionAtActivity(Order order) {
50+
startProcessApi.startProcess(
51+
new StartProcessByDefinitionAtActivityCmd(
52+
"MyExampleProcessKey",
53+
"Activity_ProcessOrder",
54+
() -> Map.of("order", order),
55+
Map.of()
56+
)
57+
).get();
58+
}
5059

60+
}
5161
```
5262

5363
For supported engines (currently only C7 Embedded and C7 Remote) it is possible to set a business key by providing it

0 commit comments

Comments
 (0)