From 876f22c9edbba4ca72d7e6ef5ec4fd8f6ff3ddcd Mon Sep 17 00:00:00 2001 From: Tim Silhan Date: Wed, 6 Sep 2023 15:25:00 +0200 Subject: [PATCH] fix #862: Made start form key retrieval more robust --- .../definition/ProcessDefinitionService.kt | 10 +++- .../itest/tx/ProcessDefinitionServiceITest.kt | 46 +++++++++++++++++++ .../resources/itest/message_start_event.bpmn | 44 ++++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 integration/camunda-bpm/taskpool-collector/src/test/resources/itest/message_start_event.bpmn diff --git a/integration/camunda-bpm/taskpool-collector/src/main/kotlin/io/holunda/polyflow/taskpool/collector/process/definition/ProcessDefinitionService.kt b/integration/camunda-bpm/taskpool-collector/src/main/kotlin/io/holunda/polyflow/taskpool/collector/process/definition/ProcessDefinitionService.kt index aa0c7c404..61846b701 100644 --- a/integration/camunda-bpm/taskpool-collector/src/main/kotlin/io/holunda/polyflow/taskpool/collector/process/definition/ProcessDefinitionService.kt +++ b/integration/camunda-bpm/taskpool-collector/src/main/kotlin/io/holunda/polyflow/taskpool/collector/process/definition/ProcessDefinitionService.kt @@ -50,7 +50,15 @@ class ProcessDefinitionService( this.processDefinitions.clear() } this.processDefinitions.addAll(newDefinitions) - return newDefinitions.map { it.asCommand(applicationName = collectorProperties.applicationName, formKey = formService.getStartFormKey(it.id)) } + return newDefinitions.map { it.asCommand(applicationName = collectorProperties.applicationName, formKey = getStartFormKey(it, formService)) } + } + + private fun getStartFormKey(processDefinitionEntity: ProcessDefinitionEntity, formService: FormService): String? { + return if (processDefinitionEntity.hasStartFormKey) { + formService.getStartFormKey(processDefinitionEntity.id) + } else { + null + } } /** diff --git a/integration/camunda-bpm/taskpool-collector/src/test/kotlin/io/holunda/polyflow/taskpool/itest/tx/ProcessDefinitionServiceITest.kt b/integration/camunda-bpm/taskpool-collector/src/test/kotlin/io/holunda/polyflow/taskpool/itest/tx/ProcessDefinitionServiceITest.kt index 125771b68..f5914dfe8 100644 --- a/integration/camunda-bpm/taskpool-collector/src/test/kotlin/io/holunda/polyflow/taskpool/itest/tx/ProcessDefinitionServiceITest.kt +++ b/integration/camunda-bpm/taskpool-collector/src/test/kotlin/io/holunda/polyflow/taskpool/itest/tx/ProcessDefinitionServiceITest.kt @@ -86,6 +86,52 @@ class ProcessDefinitionServiceITest { assertThat(definitions[0].candidateStarterGroups).containsExactlyElementsOf(listOf("muppetshow")) } + @Test + fun `should not deliver process starter if no start form is available`() { + + val processId = "my-id" + val startEventId = "start" + val modelInstance = Bpmn + .createExecutableProcess(processId) + .startEvent(startEventId) + .endEvent("end") + .done().apply { + getModelElementById(processId).setAttributeValue("name", "My Process") + getModelElementById(processId).setAttributeValueNs(NS_CAMUNDA, "candidateStarterGroups", "muppetshow") + } + + repositoryService + .createDeployment() + .addModelInstance("process-without-start-form.bpmn", modelInstance) + .deploy() + + + val definitions = processDefinitionService.getProcessDefinitions(processEngine.processEngineConfiguration as ProcessEngineConfigurationImpl) + + assertThat(definitions).isNotEmpty + assertThat(definitions[0].processName).isEqualTo("My Process") + assertThat(definitions[0].processDefinitionKey).isEqualTo("my-id") + assertThat(definitions[0].processDefinitionVersion).isEqualTo(1) + assertThat(definitions[0].formKey).isNull() + assertThat(definitions[0].candidateStarterGroups).containsExactlyElementsOf(listOf("muppetshow")) + } + + @Test + fun `should not deliver process starter if only two message start events are available`() { + repositoryService + .createDeployment() + .addClasspathResource("itest/message_start_event.bpmn") + .deploy() + + val definitions = processDefinitionService.getProcessDefinitions(processEngine.processEngineConfiguration as ProcessEngineConfigurationImpl) + + assertThat(definitions).isNotEmpty + assertThat(definitions[0].processName).isEqualTo("My Process") + assertThat(definitions[0].processDefinitionKey).isEqualTo("my-id") + assertThat(definitions[0].processDefinitionVersion).isEqualTo(1) + assertThat(definitions[0].formKey).isNull() + } + /** * Internal test application. */ diff --git a/integration/camunda-bpm/taskpool-collector/src/test/resources/itest/message_start_event.bpmn b/integration/camunda-bpm/taskpool-collector/src/test/resources/itest/message_start_event.bpmn new file mode 100644 index 000000000..67f5ead53 --- /dev/null +++ b/integration/camunda-bpm/taskpool-collector/src/test/resources/itest/message_start_event.bpmn @@ -0,0 +1,44 @@ + + + + + Flow_0rqm55e + Flow_1k4xpiz + + + + + Flow_0rqm55e + + + + Flow_1k4xpiz + + + + + + + + + + + + + + + + + + + + + + + + + + + + +