-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from bpm-crafters/feature/separate_correlation…
…_api Separate SignalAPI from CorrelationAPI
- Loading branch information
Showing
16 changed files
with
251 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
api/src/main/kotlin/dev/bpmcrafters/processengineapi/correlation/SignalApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.bpmcrafters.processengineapi.correlation | ||
|
||
import dev.bpmcrafters.processengineapi.Empty | ||
import dev.bpmcrafters.processengineapi.MetaInfoAware | ||
import dev.bpmcrafters.processengineapi.RestrictionAware | ||
import java.util.concurrent.Future | ||
|
||
/** | ||
* API to send signals to running process instances. | ||
* @since 0.0.1 | ||
*/ | ||
interface SignalApi : MetaInfoAware, RestrictionAware { | ||
|
||
/** | ||
* Delivers a signal event to process engine. | ||
* @param cmd command to deliver. | ||
* @return future to indicate completion. | ||
*/ | ||
fun sendSignal(cmd: SendSignalCmd): Future<Empty> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
.../src/main/kotlin/dev/bpmcrafters/processengineapi/adapter/c7/correlation/SignalApiImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package dev.bpmcrafters.processengineapi.adapter.c7.correlation | ||
|
||
import dev.bpmcrafters.processengineapi.CommonRestrictions | ||
import dev.bpmcrafters.processengineapi.Empty | ||
import dev.bpmcrafters.processengineapi.MetaInfo | ||
import dev.bpmcrafters.processengineapi.MetaInfoAware | ||
import dev.bpmcrafters.processengineapi.correlation.* | ||
import org.camunda.bpm.engine.RuntimeService | ||
import org.camunda.bpm.engine.runtime.MessageCorrelationBuilder | ||
import org.camunda.bpm.engine.runtime.SignalEventReceivedBuilder | ||
import java.util.concurrent.CompletableFuture | ||
import java.util.concurrent.Future | ||
|
||
class SignalApiImpl( | ||
private val runtimeService: RuntimeService | ||
) : SignalApi { | ||
|
||
override fun sendSignal(cmd: SendSignalCmd): Future<Empty> { | ||
return CompletableFuture.supplyAsync { | ||
val correlation = cmd.correlation | ||
runtimeService | ||
.createSignalEvent(cmd.signalName) | ||
.buildCorrelation(correlation) | ||
.setVariables(cmd.payloadSupplier.get()) | ||
.send() | ||
Empty | ||
} | ||
} | ||
|
||
override fun getSupportedRestrictions(): Set<String> = setOf( | ||
CommonRestrictions.PROCESS_INSTANCE_ID, | ||
CommonRestrictions.TENANT_ID, | ||
) | ||
|
||
private fun SignalEventReceivedBuilder.buildCorrelation(correlation: CorrelationSupplier) = this.apply { | ||
val restrictions = correlation.get().restrictions | ||
ensureSupported(restrictions) | ||
restrictions | ||
.forEach { (key, value) -> | ||
when (key) { | ||
CommonRestrictions.TENANT_ID -> this.tenantId(value) | ||
CommonRestrictions.EXECUTION_ID -> this.executionId(value) | ||
} | ||
} | ||
} | ||
|
||
override fun meta(instance: MetaInfoAware): MetaInfo { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
.../src/main/kotlin/dev/bpmcrafters/processengineapi/adapter/c8/correlation/SignalApiImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package dev.bpmcrafters.processengineapi.adapter.c8.correlation | ||
|
||
import dev.bpmcrafters.processengineapi.CommonRestrictions | ||
import dev.bpmcrafters.processengineapi.Empty | ||
import dev.bpmcrafters.processengineapi.MetaInfo | ||
import dev.bpmcrafters.processengineapi.MetaInfoAware | ||
import dev.bpmcrafters.processengineapi.correlation.CorrelateMessageCmd | ||
import dev.bpmcrafters.processengineapi.correlation.CorrelationApi | ||
import dev.bpmcrafters.processengineapi.correlation.SendSignalCmd | ||
import dev.bpmcrafters.processengineapi.correlation.SignalApi | ||
import io.camunda.zeebe.client.ZeebeClient | ||
import io.camunda.zeebe.client.api.command.BroadcastSignalCommandStep1 | ||
import io.camunda.zeebe.client.api.command.PublishMessageCommandStep1.PublishMessageCommandStep2 | ||
import io.camunda.zeebe.client.api.command.PublishMessageCommandStep1.PublishMessageCommandStep3 | ||
import java.util.concurrent.CompletableFuture | ||
import java.util.concurrent.Future | ||
|
||
class SignalApiImpl( | ||
private val zeebeClient: ZeebeClient | ||
) : SignalApi { | ||
|
||
override fun sendSignal(cmd: SendSignalCmd): Future<Empty> { | ||
return CompletableFuture.supplyAsync { | ||
val restrictions = cmd.correlation.get().restrictions | ||
zeebeClient | ||
.newBroadcastSignalCommand() | ||
.signalName(cmd.signalName) | ||
.buildCorrelation(restrictions) | ||
.variables(cmd.payloadSupplier.get()) | ||
.send() | ||
.get() // FIXME Chain | ||
Empty | ||
} | ||
} | ||
|
||
override fun getSupportedRestrictions(): Set<String> = setOf( | ||
CommonRestrictions.TENANT_ID, | ||
) | ||
|
||
fun BroadcastSignalCommandStep1.BroadcastSignalCommandStep2.buildCorrelation(restrictions: Map<String, String>) = this.apply { | ||
if (restrictions.containsKey(CommonRestrictions.TENANT_ID)) { | ||
this.tenantId(restrictions[CommonRestrictions.TENANT_ID]) | ||
} | ||
} | ||
|
||
override fun meta(instance: MetaInfoAware): MetaInfo { | ||
TODO("Not yet implemented") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
### Start process | ||
< {% | ||
client.global.clearAll() | ||
%} | ||
POST http://localhost:8080/simple-service-tasks/start-process?value=string&intValue=1 | ||
|
||
> {% | ||
client.test("Request executed successfully", function () { | ||
client.assert(response.status === 201, "Response status is not 201"); | ||
}); | ||
|
||
client.global.set("instanceId", response.headers.valueOf("Location")); | ||
%} | ||
|
||
### Get user tasks | ||
|
||
GET http://localhost:8080/simple-service-tasks/tasks | ||
Accept: application/json | ||
|
||
> {% | ||
client.test("Request executed successfully", function () { | ||
client.assert(response.status === 200, "Response status is not 201"); | ||
}); | ||
client.test("Content-Type is application/json", () => { | ||
const contentType = response.headers.valueOf("content-type"); | ||
client.assert(contentType == "application/json", | ||
`Expected Content-Type is application/json, but actual is ${contentType}`) | ||
}) | ||
|
||
const tasks = response.body; | ||
const taskId = jsonPath(tasks, "$[0].taskId"); | ||
console.log("Created user task: ", taskId); | ||
client.global.set("taskId", taskId); | ||
%} | ||
|
||
### Complete user task | ||
POST http://localhost:8080/simple-service-tasks/tasks/{{ taskId }}/error?value=value-of-user-task-error | ||
|
||
> {% | ||
client.test("Request executed successfully", function () { | ||
client.assert(response.status === 204, "Response status is not 204"); | ||
}); | ||
%} | ||
|
||
### Correlate signal | ||
POST http://localhost:8080/simple-service-tasks/signal?value=value-delivered-by-signal | ||
|
||
> {% | ||
client.test("Request executed successfully", function () { | ||
client.assert(response.status === 204, "Response status is not 204"); | ||
}); | ||
%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.