Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Camunda License 1.0. You may not use this file
* except in compliance with the Camunda License 1.0.
*/
package org.camunda.conversion.execution_listeners;

import java.util.Map;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ExecutionListenerTestController {

private final RuntimeService runtimeService;

public ExecutionListenerTestController(RuntimeService runtimeService) {
this.runtimeService = runtimeService;
}

/**
* Start the execution-listener-test process with variable "foo".
*
* Usage: curl -X POST "http://localhost:8080/test/execution-listener?foo=bar"
*/
@PostMapping("/test/execution-listener")
public String startProcess(@RequestParam(name = "foo", defaultValue = "bar") String foo) {
ProcessInstance pi = runtimeService.startProcessInstanceByKey(
"execution-listener-test",
Map.of("foo", foo)
);
return "Started process instance: " + pi.getId() + " with foo=" + foo;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Camunda License 1.0. You may not use this file
* except in compliance with the Camunda License 1.0.
*/
package org.camunda.conversion.execution_listeners;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.ExecutionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class MyExecutionListener implements ExecutionListener {

private static final Logger LOG = LoggerFactory.getLogger(MyExecutionListener.class);

@Override
public void notify(DelegateExecution execution) {
String someVar = (String) execution.getVariable("foo");
LOG.info(">>> ExecutionListener triggered! foo = {}", someVar);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Map;

@Configuration
@ExternalTaskSubscription("retrievePaymentAdapter")
@ExternalTaskSubscription("retrievePaymentAdapterBpmnErrorJavaObjectAPI")
public class RetrievePaymentWorkerBPMNErrorJavaObjectAPI implements ExternalTaskHandler {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.springframework.context.annotation.Configuration;

@Configuration
@ExternalTaskSubscription("retrievePaymentAdapter")
@ExternalTaskSubscription("retrievePaymentAdapterBpmnErrorTypedValueAPI")
public class RetrievePaymentWorkerBPMNErrorTypedValueAPI implements ExternalTaskHandler {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Map;

@Configuration
@ExternalTaskSubscription("retrievePaymentAdapter")
@ExternalTaskSubscription("retrievePaymentAdapterFailure")
public class RetrievePaymentWorkerFailure implements ExternalTaskHandler {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Map;

@Configuration
@ExternalTaskSubscription("retrievePaymentAdapter")
@ExternalTaskSubscription("retrievePaymentAdapterIncident")
public class RetrievePaymentWorkerIncident implements ExternalTaskHandler {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Map;

@Configuration
@ExternalTaskSubscription("retrievePaymentAdapter")
@ExternalTaskSubscription("retrievePaymentAdapterProcessVarsJavaObjectAPI")
public class RetrievePaymentWorkerProcessVariablesJavaObjectAPI implements ExternalTaskHandler {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.springframework.context.annotation.Configuration;

@Configuration
@ExternalTaskSubscription("retrievePaymentAdapter")
@ExternalTaskSubscription("retrievePaymentAdapterProcessVarsTypedValueAPI")
public class RetrievePaymentWorkerProcessVariablesTypedValueAPI implements ExternalTaskHandler {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ spring.datasource.url: jdbc:h2:file:./camunda-h2-database

camunda.bpm.admin-user:
id: demo
password: demo
password: demo

camunda.bpm.client:
base-url: http://localhost:8080/engine-rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
id="Definitions_el_test"
targetNamespace="http://bpmn.io/schema/bpmn">

<bpmn:process id="execution-listener-test" name="Execution Listener Test" isExecutable="true" camunda:historyTimeToLive="180">

<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_1</bpmn:outgoing>
</bpmn:startEvent>

<bpmn:sequenceFlow id="Flow_1" sourceRef="StartEvent_1" targetRef="ServiceTask_1" />

<bpmn:serviceTask id="ServiceTask_1" name="Task with Execution Listener" camunda:expression="${true}">
<bpmn:extensionElements>
<camunda:executionListener event="start" delegateExpression="${myExecutionListener}" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_1</bpmn:incoming>
<bpmn:outgoing>Flow_2</bpmn:outgoing>
</bpmn:serviceTask>

<bpmn:sequenceFlow id="Flow_2" sourceRef="ServiceTask_1" targetRef="EndEvent_1" />

<bpmn:endEvent id="EndEvent_1">
<bpmn:incoming>Flow_2</bpmn:incoming>
</bpmn:endEvent>

</bpmn:process>

<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="execution-listener-test">
<bpmndi:BPMNShape id="StartEvent_1_di" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ServiceTask_1_di" bpmnElement="ServiceTask_1">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_1_di" bpmnElement="EndEvent_1">
<dc:Bounds x="432" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1_di" bpmnElement="Flow_1">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_2_di" bpmnElement="Flow_2">
<di:waypoint x="370" y="117" />
<di:waypoint x="432" y="117" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Do we want to delete mvnw* in camunda-8 directory too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Removed files

This file was deleted.

3 changes: 2 additions & 1 deletion code-conversion/patterns/code-examples/camunda-8/pom.xml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃 Maybe move dependencyManagement section before dependencies, the pom is a bit chaotic at the moment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Cleaned up the pom.xml file.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
Expand All @@ -65,6 +65,7 @@
<groupId>io.camunda</groupId>
<artifactId>camunda-process-test-spring</artifactId>
<version>${version.camunda-8}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@Deployment(resources = "classpath*:*.bpmn")
public class ProcessPaymentsApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Camunda License 1.0. You may not use this file
* except in compliance with the Camunda License 1.0.
*/
package io.camunda.conversion.execution_listeners;

import io.camunda.client.CamundaClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class ExecutionListenerTestController {

private final CamundaClient camundaClient;

public ExecutionListenerTestController(CamundaClient camundaClient) {
this.camundaClient = camundaClient;
}

/**
* Start the execution-listener-test process with variable "foo".
*
* Usage: curl -X POST "http://localhost:8080/test/execution-listener?foo=bar"
*/
@PostMapping("/test/execution-listener")
public String startProcess(@RequestParam(name = "foo", defaultValue = "bar") String foo) {
var result = camundaClient.newCreateInstanceCommand()
.bpmnProcessId("execution-listener-test")
.latestVersion()
.variables(Map.of("foo", foo))
.send()
.join();
return "Started process instance: " + result.getProcessInstanceKey() + " with foo=" + foo;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Camunda License 1.0. You may not use this file
* except in compliance with the Camunda License 1.0.
*/
package io.camunda.conversion.execution_listeners;

import io.camunda.client.annotation.JobWorker;
import io.camunda.client.api.response.ActivatedJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class MyExecutionListener {

private static final Logger LOG = LoggerFactory.getLogger(MyExecutionListener.class);

@JobWorker(type = "myExecutionListener", autoComplete = true)
public Map<String, Object> executeJobMigrated(ActivatedJob job) throws Exception {
Map<String, Object> resultMap = new HashMap<>();
String someVar = (String) job.getVariable("foo");
LOG.info(">>> Migrated JobWorker triggered! foo = {}", someVar);
return resultMap;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
xmlns:zeebe="http://camunda.org/schema/zeebe/1.0"
id="Definitions_el_test"
targetNamespace="http://bpmn.io/schema/bpmn"
exporter="Camunda Modeler"
exporterVersion="5.25.0">

<bpmn:process id="execution-listener-test" name="Execution Listener Test" isExecutable="true">

<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_1</bpmn:outgoing>
</bpmn:startEvent>

<bpmn:sequenceFlow id="Flow_1" sourceRef="StartEvent_1" targetRef="ServiceTask_1" />

<bpmn:serviceTask id="ServiceTask_1" name="Migrated Execution Listener">
<bpmn:extensionElements>
<zeebe:taskDefinition type="myExecutionListener" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_1</bpmn:incoming>
<bpmn:outgoing>Flow_2</bpmn:outgoing>
</bpmn:serviceTask>

<bpmn:sequenceFlow id="Flow_2" sourceRef="ServiceTask_1" targetRef="EndEvent_1" />

<bpmn:endEvent id="EndEvent_1">
<bpmn:incoming>Flow_2</bpmn:incoming>
</bpmn:endEvent>

</bpmn:process>

<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="execution-listener-test">
<bpmndi:BPMNShape id="StartEvent_1_di" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ServiceTask_1_di" bpmnElement="ServiceTask_1">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_1_di" bpmnElement="EndEvent_1">
<dc:Bounds x="432" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1_di" bpmnElement="Flow_1">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_2_di" bpmnElement="Flow_2">
<di:waypoint x="370" y="117" />
<di:waypoint x="432" y="117" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Camunda License 1.0. You may not use this file
* except in compliance with the Camunda License 1.0.
*/
package io.camunda.conversion.execution_listeners;

import static io.camunda.process.test.api.assertions.ProcessInstanceSelectors.byProcessId;

import io.camunda.client.CamundaClient;
import io.camunda.process.test.api.CamundaAssert;
import io.camunda.process.test.api.CamundaSpringProcessTest;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
@CamundaSpringProcessTest
class MyExecutionListenerTest {

@Autowired
private CamundaClient camundaClient;

@Test
void shouldExecuteMigratedExecutionListener() {
// given: deploy and start process with variable "foo"
camundaClient.newCreateInstanceCommand()
.bpmnProcessId("execution-listener-test")
.latestVersion()
.variables(Map.of("foo", "bar"))
.send()
.join();

// then: the process completes (the @JobWorker handles the service task)
CamundaAssert.assertThat(byProcessId("execution-listener-test")).isCompleted();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring.application.name=Process payments

# Connection properties are managed by @CamundaSpringProcessTest / Testcontainers