diff --git a/one-time-examples/jakarta_sample_with_test/README.md b/one-time-examples/jakarta_sample_with_test/README.md new file mode 100644 index 0000000000..79479ad86f --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/README.md @@ -0,0 +1,64 @@ + +# Sample JEE Project which use only java jakarta depedencies + +Generated with wildfly archetype +```shell +mvn archetype:generate \ + -DarchetypeGroupId=org.wildfly.archetype \ + -DarchetypeArtifactId=wildfly-getting-started-archetype + +``` + +The `sample` project is a simple Jakarta EE application with a HTTP endpoint that is running in +[WildFly](https://wildfly.org). + +The `src/main` folder contains a simple 'Hello world' style Jakarta EE application using JAX-RS. + +## Building the application + +To run the application, you use Maven: + +```shell +mvn clean package +``` + + +Maven will compile the application, provision a WildFly server +The WildFly server is created in `target/server` with the application deployed in it. + +## Running the application + +To run the application, run the commands: + +```shell +cd target/server +./bin/standalone.sh +``` + +Once WildFly is running, the application can be accessed at `http://localhost:8080/` + +You will reached the camunda cockpit under `http://localhost:8080/camunda` + +Following Endpoints are available + +```shell +curl http://localhost:8080/hello/users +``` +Return a list of users with their ids + +```shell +curl http://localhost:8080/hello/{NamingOfFoo} +``` + +`NamingOfFoo` will create a user entry in the database, if it is already created, it will return the message `user is already created` + +```shell +curl -X POST http://localhost:8080/engine-rest/process-definition/key/Process_Sample/start -H "Content-Type: application/json" '{"variables": {"user": {"value": "nom"}}}' +``` +will create a new process instance in our sample application + +## Resources + +* [WildFly](https://wildfly.org) +* [WildFly Documentation](https://docs.wildfly.org) +* [Camunda Documentation](https://docs.camunda.org/manual/latest/installation/full/jboss/manual/) \ No newline at end of file diff --git a/one-time-examples/jakarta_sample_with_test/pom.xml b/one-time-examples/jakarta_sample_with_test/pom.xml new file mode 100644 index 0000000000..f9e7deebcb --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/pom.xml @@ -0,0 +1,384 @@ + + + + 4.0.0 + com.camunda.consulting + sample + 0.0.1-SNAPSHOT + + war + sample + Insert description for your project here. + + + + + UTF-8 + + + 5.0.0.Final + 33.0.0.Final + + + 5.10.1 + + + 3.13.0 + 3.0.0 + 3.3.1 + 3.4.0 + 7.22.0-alpha4 + + 11 + 7.22.0-alpha4 + + 4.13.2 + 1.10.19 + + + + + + central + Main Apache Maven Repository + https://repo.maven.apache.org/maven2/ + default + + true + never + + + false + never + + + + + never + + + never + + jboss-public-repository-group + JBoss Public Repository Group + https://repository.jboss.org/nexus/content/groups/public/ + default + + + + + central + Main Apache Maven Repository + https://repo.maven.apache.org/maven2/ + + true + never + + + false + never + + + + + + + + jboss-public-repository-group + JBoss Public Repository Group + https://repository.jboss.org/nexus/content/groups/public/ + + + + + + + + org.wildfly.bom + wildfly-ee-with-tools + ${version.wildfly.bom} + pom + import + + + + org.camunda.bpm + camunda-bom + ${camunda.version} + import + pom + + + + + + + + org.camunda.bpm + camunda-engine + provided + + + org.camunda.bpm + camunda-external-task-client + ${camunda.external-task-client.version} + + + + org.camunda.bpm.javaee + camunda-ejb-client-jakarta + + + + org.camunda.bpm + camunda-engine-cdi-jakarta + + + + org.slf4j + slf4j-simple + 1.7.36 + + + jakarta.xml.bind + jakarta.xml.bind-api + 4.0.2 + + + + + com.h2database + h2 + 2.3.232 + + + + + + org.hibernate.orm + hibernate-core + 6.6.0.Final + provided + + + + + + jakarta.enterprise + jakarta.enterprise.cdi-api + provided + + + jakarta.ejb + jakarta.ejb-api + 4.0.1 + provided + + + + jakarta.ws.rs + jakarta.ws.rs-api + provided + + + + + + org.camunda.bpm + camunda-engine-spring + ${camunda.version} + test + + + + jakarta.platform + jakarta.jakartaee-api + 10.0.0 + provided + + + + + junit + junit + ${junit.version} + test + + + + + org.mockito + mockito-core + 5.3.1 + test + + + org.jboss.resteasy + resteasy-client + test + + + + + org.camunda.bpm.extension + camunda-bpm-assert + 1.2 + test + + + + + jakarta.el + jakarta.el-api + 5.0.1 + test + + + + org.glassfish + jakarta.el + 5.0.0-M1 + test + + + org.assertj + assertj-core + 3.26.3 + test + + + + org.hamcrest + hamcrest + 3.0 + test + + + + + + org.jboss.arquillian.container + arquillian-weld-embedded + 3.0.2.Final + test + + + org.jboss.weld.se + weld-se-core + 5.1.3.Final + test + + + + org.jboss.weld.servlet + weld-servlet-shaded + 5.1.3.Final + test + + + + org.jboss.weld + weld-junit4 + 4.0.3.Final + test + + + + + + ROOT + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${version.compiler.plugin} + + + + + + org.apache.maven.plugins + maven-war-plugin + ${version.war.plugin} + + + false + + + + + + org.wildfly.plugins + wildfly-maven-plugin + ${version.wildfly.maven.plugin} + + + + org.wildfly:wildfly-galleon-pack:${version.wildfly.bom} + + + + + cloud-server + + + + + + package + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + ${version.failsafe.plugin} + + + **/*IT + + + + + + integration-test + verify + + + + + + + \ No newline at end of file diff --git a/one-time-examples/jakarta_sample_with_test/sample_standalone.xml b/one-time-examples/jakarta_sample_with_test/sample_standalone.xml new file mode 100644 index 0000000000..34518b0df0 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/sample_standalone.xml @@ -0,0 +1,575 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + java:jboss/datasources/ProcessEngine + full + + + default + + + true + + + true + + + true + + + + + org.camunda.connect.plugin.impl.ConnectProcessEnginePlugin + + + + + + 3 + 5 + 10 + + + + + 300000 + + + 5000 + + + 3 + + + + + + + + + + + jdbc:h2:./camunda-h2-dbs/process-engine;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + h2 + + + + + org.h2.jdbcx.JdbcDataSource + + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${jboss.bind.address:127.0.0.1} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/one-time-examples/jakarta_sample_with_test/src/main/java/com/camunda/consulting/SampleApplication.java b/one-time-examples/jakarta_sample_with_test/src/main/java/com/camunda/consulting/SampleApplication.java new file mode 100644 index 0000000000..30b479eb37 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/main/java/com/camunda/consulting/SampleApplication.java @@ -0,0 +1,9 @@ +package com.camunda.consulting; + +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; + +@ApplicationPath("/") +public class SampleApplication extends Application { + +} diff --git a/one-time-examples/jakarta_sample_with_test/src/main/java/com/camunda/consulting/endpoint/SampleEndpoint.java b/one-time-examples/jakarta_sample_with_test/src/main/java/com/camunda/consulting/endpoint/SampleEndpoint.java new file mode 100644 index 0000000000..e472ff45d1 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/main/java/com/camunda/consulting/endpoint/SampleEndpoint.java @@ -0,0 +1,56 @@ +package com.camunda.consulting.endpoint; + +import com.camunda.consulting.model.SampleUserEntity; +import com.camunda.consulting.service.SampleUserService; +import jakarta.ejb.Stateless; +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import org.camunda.bpm.engine.RuntimeService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Path("/") +@Stateless +public class SampleEndpoint { + private static final Logger log = LoggerFactory.getLogger(SampleEndpoint.class); + @Inject + private SampleUserService userService; + + @Inject + RuntimeService runtimeService; + + @GET + @Path("/hello/{name}") + @Produces(MediaType.TEXT_PLAIN) + public Response sayHello(final @PathParam("name") String name) { + Map variables = new HashMap(); + variables.put("user", name); + log.info("Create process with username {}", name); + var process = runtimeService.startProcessInstanceByKey("Process_Sample", variables); + log.info("process use id {}", process.getId()); + return Response.ok("Hello " + name).build(); + } + + @GET + @Path("/ping") + public Response ping() { + return Response.ok("ping").build(); + } + + @GET + @Path("/hello/users") + @Produces(MediaType.APPLICATION_JSON) + public Response getAllUsers() { + List response = userService.getAllUsers(); + return Response.ok(response).build(); + } +} diff --git a/one-time-examples/jakarta_sample_with_test/src/main/java/com/camunda/consulting/model/SampleUserEntity.java b/one-time-examples/jakarta_sample_with_test/src/main/java/com/camunda/consulting/model/SampleUserEntity.java new file mode 100644 index 0000000000..573bb5b0b8 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/main/java/com/camunda/consulting/model/SampleUserEntity.java @@ -0,0 +1,44 @@ +package com.camunda.consulting.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +import java.io.Serializable; + +@Entity(name = "SAMPLE_USER") +public class SampleUserEntity implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "SampleUserEntity{" + + "id=" + id + + ", name='" + name + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/one-time-examples/jakarta_sample_with_test/src/main/java/com/camunda/consulting/service/SampleUserService.java b/one-time-examples/jakarta_sample_with_test/src/main/java/com/camunda/consulting/service/SampleUserService.java new file mode 100644 index 0000000000..7bc90d2394 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/main/java/com/camunda/consulting/service/SampleUserService.java @@ -0,0 +1,39 @@ +package com.camunda.consulting.service; + +import com.camunda.consulting.model.SampleUserEntity; +import jakarta.ejb.Stateless; +import jakarta.inject.Named; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +@Stateless +@Named(value = "sampleUserService") +public class SampleUserService { + private static final Logger log = LoggerFactory.getLogger(SampleUserService.class); + + public List getAllUsers() { + return Arrays.asList("Name1", "Name2"); + } + + public void findUserByName(DelegateExecution delegateExecution, String executionStep) { + // Get all process variables + log.info("Executing findUserByName called by service task by Step: " + executionStep); + Map variables = delegateExecution.getVariables(); + String name = variables.get("user").toString(); + if (name == null) { + var userEntity = new SampleUserEntity(); + log.error("user does not exists create new one"); + userEntity.setName("John Doe"); + delegateExecution.setVariable("userId", userEntity.getId()); + } else { + log.info("Executing without any problems for user {}", name); + + delegateExecution.setVariable("userId", 1); + } + } +} diff --git a/one-time-examples/jakarta_sample_with_test/src/main/resources/META-INF/beans.xml b/one-time-examples/jakarta_sample_with_test/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000000..43c46c7c68 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/main/resources/META-INF/beans.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/one-time-examples/jakarta_sample_with_test/src/main/resources/META-INF/persistence.xml b/one-time-examples/jakarta_sample_with_test/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000000..ec8dc05218 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,24 @@ + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.camunda.consulting.model.SampleUserEntity + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/one-time-examples/jakarta_sample_with_test/src/main/resources/META-INF/processes.xml b/one-time-examples/jakarta_sample_with_test/src/main/resources/META-INF/processes.xml new file mode 100644 index 0000000000..417f437378 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/main/resources/META-INF/processes.xml @@ -0,0 +1,14 @@ + + + + + default + + false + true + + + + diff --git a/one-time-examples/jakarta_sample_with_test/src/main/resources/bpmn/sample.bpmn b/one-time-examples/jakarta_sample_with_test/src/main/resources/bpmn/sample.bpmn new file mode 100644 index 0000000000..568cca0a4e --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/main/resources/bpmn/sample.bpmn @@ -0,0 +1,46 @@ + + + + + Flow_013w6iu + + + + + Flow_013w6iu + Flow_0x0je6q + + + Flow_0x0je6q + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/one-time-examples/jakarta_sample_with_test/src/main/resources/bpmn/sample_task.bpmn b/one-time-examples/jakarta_sample_with_test/src/main/resources/bpmn/sample_task.bpmn new file mode 100644 index 0000000000..3b918ead0e --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/main/resources/bpmn/sample_task.bpmn @@ -0,0 +1,62 @@ + + + + + Flow_013w6iu + + + + + Flow_013w6iu + Flow_0x0je6q + + + Flow_1hqlcou + + + + + + Flow_0x0je6q + Flow_1hqlcou + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/one-time-examples/jakarta_sample_with_test/src/main/webapp/WEB-INF/beans.xml b/one-time-examples/jakarta_sample_with_test/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000000..31098cbdd3 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/one-time-examples/jakarta_sample_with_test/src/test/java/com/camunda/consulting/service/SampleUserServiceTest.java b/one-time-examples/jakarta_sample_with_test/src/test/java/com/camunda/consulting/service/SampleUserServiceTest.java new file mode 100644 index 0000000000..39ae219d61 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/test/java/com/camunda/consulting/service/SampleUserServiceTest.java @@ -0,0 +1,74 @@ +package com.camunda.consulting.service; + +import org.camunda.bpm.engine.RepositoryService; +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.TaskService; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.camunda.bpm.engine.task.Task; +import org.camunda.bpm.engine.test.Deployment; +import org.camunda.bpm.engine.test.ProcessEngineRule; +import org.camunda.bpm.engine.test.assertions.ProcessEngineAssertions; +import org.camunda.bpm.engine.test.assertions.ProcessEngineTests; +import org.camunda.bpm.engine.test.mock.Mocks; +import org.camunda.bpm.engine.variable.VariableMap; +import org.camunda.bpm.engine.variable.Variables; +import org.jboss.weld.environment.se.Weld; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class SampleUserServiceTest { + + + @Rule + public ProcessEngineRule processEngineRule = new ProcessEngineRule(); + + private Weld weld; + protected RuntimeService runtimeService = null; + protected TaskService taskService = null; + protected RepositoryService repositoryService = null; + + @Before + public void setUp() { + weld = new Weld(); + weld.initialize(); + ProcessEngineAssertions.init(processEngineRule.getProcessEngine()); + runtimeService = ProcessEngineTests.runtimeService(); + taskService = processEngineRule.getTaskService(); + repositoryService = processEngineRule.getRepositoryService(); + ProcessEngineAssertions.init(processEngineRule.getProcessEngine()); + repositoryService.createDeployment().addClasspathResource("bpmn/sample.bpmn").deploy(); + } + + @After + public void tearDown() { + if (weld != null) { + weld.shutdown(); + } + } + + @Test + public void extensionUsageExample() { + // Given we create a new process instance + VariableMap map = Variables.putValue("user", "john"); + ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process_Sample", map); + assertNotNull(processInstance.getProcessInstanceId()); + } + + @Test + @Deployment(resources = "bpmn/sample_task.bpmn") + public void extensionUsageSampleTask() { + // Given we create a new process instance + VariableMap map = Variables.putValue("user", "john"); + ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process_Sample_Task", map); + assertNotNull(processInstance.getProcessInstanceId()); + + TaskService taskService = processEngineRule.getTaskService(); + Task task = taskService.createTaskQuery().singleResult(); + assertEquals(task.getName(), "Do Something with UserId"); + } +} \ No newline at end of file diff --git a/one-time-examples/jakarta_sample_with_test/src/test/resources/META-INF/beans.xml b/one-time-examples/jakarta_sample_with_test/src/test/resources/META-INF/beans.xml new file mode 100644 index 0000000000..1fc63e4484 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/test/resources/META-INF/beans.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/one-time-examples/jakarta_sample_with_test/src/test/resources/META-INF/persistance.xml b/one-time-examples/jakarta_sample_with_test/src/test/resources/META-INF/persistance.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/one-time-examples/jakarta_sample_with_test/src/test/resources/META-INF/processes.xml b/one-time-examples/jakarta_sample_with_test/src/test/resources/META-INF/processes.xml new file mode 100644 index 0000000000..a5d3dbb8b9 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/test/resources/META-INF/processes.xml @@ -0,0 +1,14 @@ + + + + + default + + true + true + + + + diff --git a/one-time-examples/jakarta_sample_with_test/src/test/resources/camunda.cfg.xml b/one-time-examples/jakarta_sample_with_test/src/test/resources/camunda.cfg.xml new file mode 100644 index 0000000000..dd53d2f494 --- /dev/null +++ b/one-time-examples/jakarta_sample_with_test/src/test/resources/camunda.cfg.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file