-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
377 additions
and
71 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,42 +1,58 @@ | ||
# camunda-admin-process-registry | ||
|
||
Template repository for usage in organizations: toolisticon, holunda-io, holixon... | ||
Run administration tasks directly from the camunda 7 cockpit using generated mini-processes. | ||
|
||
[![incubating](https://img.shields.io/badge/lifecycle-INCUBATING-orange.svg)](https://github.com/holisticon#open-source-lifecycle) | ||
[![Build Status](https://github.com/holunda-io/camunda-admin-process-registry/workflows/Development%20branches/badge.svg)](https://github.com/holunda-io/camunda-admin-process-registry/actions) | ||
[![sponsored](https://img.shields.io/badge/sponsoredBy-Holisticon-RED.svg)](https://holisticon.de/) | ||
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.holunda/camunda-admin-process-registry/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.holunda/camunda-admin-process-registry) | ||
![Compatible with: Camunda Platform 7](https://img.shields.io/badge/Compatible%20with-Camunda%20Platform%207-26d07c) | ||
|
||
This repository is a **template repository** designed to be a template for the next project. | ||
This lib/spring-boot-auto-config allows you to easily and fast generate and deploy single-service-task processes that can e started from the camunda-webapp/tasklist. | ||
|
||
## How to use | ||
Doing so enables you to implement administration/house-keeping jobs as a process, use camundas form/ui and run tasks controlled with the full power of the engine cockpit, including error handling and analysis. | ||
|
||
* create a new repo on github (can be in any organization). Choose this project as template repository. Copy all branches, so the `master`exists in your repo (for the github actions) | ||
* on the command line: clone your new repo locally | ||
* in the `setup.sh` script: set your organization, repository and base package | ||
* run the `setup.sh` script, all placeholders are filled with your information | ||
* delete the setup-script | ||
* Update the `README.md` | ||
* in the `developers` section of the `pom.xml`: mention yourself ... it is your project. | ||
## How does it work | ||
|
||
## Things to change after usage of template | ||
Once you included the lib in your camunda spring boot application, create an [AdminProcess](src/main/kotlin/io/holunda/camunda/platform/adminprocess/AdminProcess.kt) bean like this: | ||
|
||
To change the following values, modify the placeholders in `setup.sh` and run it. | ||
This is a one-time operation, you can safely delete the `setup.sh` file afterwards. | ||
```kotlin | ||
|
||
Of course, you can also edit manually .... and do not forget to change this `README.md` with YOUR project specific information :-). | ||
@Bean | ||
fun helloWorldAdminProcess(): AdminProcess { | ||
val foo = StringField("foo", "Foo - enter your name") | ||
val date = DateField("date", "Date - select some magic") | ||
|
||
### Maven pom.xml | ||
return adminProcess( | ||
activityId = "helloWorld", | ||
label = "Hello World 2", | ||
formFields = listOf(foo, date) | ||
) { | ||
val variables = CamundaBpmData.reader(it) | ||
|
||
* Maven coordinates: `groupId`, `artifactId` and `version` | ||
* Main description: `name`, `url`, `description` | ||
* SCM: `connection`, `url`, `developerConnection` | ||
logger.info { """ Hi, I am the process running with: | ||
* foo: ${variables.get(foo)} | ||
* date: ${variables.get(date)} | ||
""".trimIndent() | ||
} | ||
} | ||
} | ||
|
||
``` | ||
|
||
### Issue Template | ||
And you are done! | ||
|
||
* correct the URL to repo | ||
--- | ||
|
||
### Issue Labels | ||
The generated model looks like this: | ||
|
||
* Check the release-notes.yml for details, but create the following labels: Type: dependencies, Type: bug, Type: documentation, Type: question, Type: enhancement | ||
![generated model](.docs/admin-process-3.png) | ||
|
||
You can run the process in the webapp: | ||
|
||
![start process](.docs/admin-process-1.png) | ||
|
||
And fill out the form: | ||
|
||
![fill out form](.docs/admin-process-2.png) | ||
|
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 was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
src/main/kotlin/io/holunda/camunda/platform/adminprocess/AdminProcess.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,50 @@ | ||
package io.holunda.camunda.platform.adminprocess | ||
|
||
import org.camunda.bpm.engine.delegate.JavaDelegate | ||
import org.camunda.bpm.model.bpmn.Bpmn | ||
import org.camunda.bpm.model.bpmn.BpmnModelInstance | ||
import org.camunda.bpm.model.bpmn.builder.StartEventBuilder | ||
|
||
|
||
abstract class AdminProcess( | ||
val activityId: String, | ||
private val label: String = activityId, | ||
private val formFields: List<FormField<*>>, | ||
private val historyTimeToLive: Int = 0, | ||
private val versionTag: String = "1" | ||
) : JavaDelegate { | ||
|
||
val processDefinitionKey = "admin_$activityId" | ||
val processName = "[admin] $label" | ||
|
||
val modelInstance: BpmnModelInstance by lazy { | ||
Bpmn.createExecutableProcess(processDefinitionKey) | ||
.name(processName) | ||
.camundaHistoryTimeToLive(historyTimeToLive) | ||
.camundaVersionTag(versionTag) | ||
.camundaStartableInTasklist(true) | ||
.startEvent() | ||
.camundaFormFields(formFields) | ||
.serviceTask(activityId) | ||
.camundaAsyncBefore() | ||
.name(label) | ||
.camundaDelegateExpression("#{${AdminProcessRegistry.NAME}}") | ||
.endEvent() | ||
.done() | ||
} | ||
|
||
override fun toString(): String { | ||
return "${this::class.simpleName ?: AdminProcess::class.simpleName}(activityName='$activityId', label='$label', processDefinitionKey='$processDefinitionKey', processName='$processName')" | ||
} | ||
} | ||
|
||
|
||
fun StartEventBuilder.camundaFormFields(formFields: List<FormField<*>>): StartEventBuilder = formFields.fold(this) { builder, formField -> | ||
builder.camundaFormField() | ||
.camundaLabel(formField.label) | ||
.camundaType(formField.type) | ||
.camundaId(formField.id) | ||
.camundaDefaultValue(formField.defaultValue?.toString()) | ||
.camundaFormFieldDone() | ||
} | ||
|
53 changes: 53 additions & 0 deletions
53
src/main/kotlin/io/holunda/camunda/platform/adminprocess/AdminProcessRegistry.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,53 @@ | ||
package io.holunda.camunda.platform.adminprocess | ||
|
||
import mu.KLogging | ||
import org.camunda.bpm.engine.RepositoryService | ||
import org.camunda.bpm.engine.delegate.DelegateExecution | ||
import org.camunda.bpm.engine.delegate.JavaDelegate | ||
import org.camunda.bpm.engine.repository.Deployment | ||
import org.camunda.bpm.spring.boot.starter.event.PostDeployEvent | ||
import org.springframework.context.event.EventListener | ||
|
||
|
||
class AdminProcessRegistry( | ||
private val processes: Map<ActivityId, AdminProcess> | ||
) : JavaDelegate { | ||
companion object : KLogging() { | ||
|
||
const val NAME = "adminProcessRegistry" | ||
|
||
/** | ||
* Implementation of [AdminProcess] that does not get deployed and is only used as a fallback, when | ||
* the engine tries to run an activity that is not registered. | ||
*/ | ||
val WARN = CamundaAdminProcessRegistryLib.adminProcess("WARN") { | ||
logger.warn { "no adminProcess registered with processDefinitionKey=${it.currentActivityId}" } | ||
} | ||
|
||
} | ||
|
||
@EventListener | ||
fun deploy(evt: PostDeployEvent) { | ||
if (processes.isNotEmpty()) { | ||
logger.info { "deploying admin processes: ${processes.values}" } | ||
createDeployment(evt.processEngine.repositoryService) | ||
} else | ||
logger.info { "no admin processes registered - skip deployment." } | ||
} | ||
|
||
fun createDeployment(repositoryService: RepositoryService, tenantId: String? = NAME): Deployment = | ||
processes.values.fold(repositoryService.createDeployment()) { builder, process -> | ||
builder.addModelInstance( | ||
"${process.processDefinitionKey}.bpmn", | ||
process.modelInstance | ||
) | ||
}.tenantId(tenantId) | ||
.enableDuplicateFiltering(true) | ||
.deploy() | ||
|
||
/** | ||
* Delegates the execution to a registered admin process. | ||
*/ | ||
override fun execute(execution: DelegateExecution): Unit = processes.getOrDefault(execution.currentActivityId, WARN).execute(execution) | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/io/holunda/camunda/platform/adminprocess/CamundaAdminProcessRegistryLib.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,38 @@ | ||
package io.holunda.camunda.platform.adminprocess | ||
|
||
import mu.KLogging | ||
import org.camunda.bpm.engine.delegate.DelegateExecution | ||
import org.camunda.bpm.engine.delegate.JavaDelegate | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import javax.annotation.PostConstruct | ||
|
||
object CamundaAdminProcessRegistryLib { | ||
fun adminProcess( | ||
activityId: String, | ||
label: String = activityId, | ||
formFields: List<FormField<*>> = emptyList(), | ||
historyTimeToLive: Int = 0, | ||
versionTag: String = "1", | ||
delegate: JavaDelegate | ||
): AdminProcess = object : AdminProcess(activityId, label, formFields, historyTimeToLive, versionTag) { | ||
override fun execute(execution: DelegateExecution) { | ||
delegate.execute(execution) | ||
} | ||
} | ||
} | ||
|
||
@Configuration | ||
class CamundaAdminProcessAutoConfiguration { | ||
companion object : KLogging() | ||
|
||
/** | ||
* Collects all beans of type [AdminProcess] in context and registers them in a map. | ||
*/ | ||
@Bean(AdminProcessRegistry.NAME) | ||
fun adminProcessRegistry( | ||
processes: List<AdminProcess>? | ||
) = AdminProcessRegistry((processes?: emptyList()).associateBy { it.activityId }) | ||
|
||
} |
Oops, something went wrong.