From 39104fc093d836f028b2bf15bf1c9d0056416f51 Mon Sep 17 00:00:00 2001 From: Hussain Mubaireek Date: Sun, 31 Mar 2024 11:14:55 +0300 Subject: [PATCH 1/2] fix: bug fix for not filtering by instance key --- .../io/zeebe/zeeqs/data/service/ProcessInstanceService.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/src/main/kotlin/io/zeebe/zeeqs/data/service/ProcessInstanceService.kt b/data/src/main/kotlin/io/zeebe/zeeqs/data/service/ProcessInstanceService.kt index 24c871a..dc860be 100644 --- a/data/src/main/kotlin/io/zeebe/zeeqs/data/service/ProcessInstanceService.kt +++ b/data/src/main/kotlin/io/zeebe/zeeqs/data/service/ProcessInstanceService.kt @@ -61,7 +61,7 @@ class ProcessInstanceService( return filteredProcessInstances; } else { - return processInstancesRepository.findByStateIn(stateIn, PageRequest.of(page, perPage)).toList(); + return processInstancesRepository.findByProcessDefinitionKeyAndStateIn(processDefinitionKey, stateIn, PageRequest.of(page, perPage)).toList(); } } @@ -72,7 +72,7 @@ class ProcessInstanceService( } else { - return processInstancesRepository.countByStateIn(stateIn); + return processInstancesRepository.countByProcessDefinitionKeyAndStateIn(processDefinitionKey, stateIn); } } From 1814d0081cd28b39c16011fbeb40ee4d3a6b6ba4 Mon Sep 17 00:00:00 2001 From: Hussain Mubaireek Date: Tue, 30 Apr 2024 11:56:45 +0300 Subject: [PATCH 2/2] feat: return group elements, and return extension properties with documentation for elements --- .../zeeqs/data/entity/BpmnElementType.kt | 3 +- .../service/BpmnElementExtensionProperties.kt | 6 +++ .../zeeqs/data/service/BpmnElementInfo.kt | 6 ++- .../zeeqs/data/service/ProcessService.kt | 54 +++++++++++++------ .../io/zeebe/zeeqs/ProcessServiceTest.kt | 11 ++-- .../resolvers/type/BpmnElementResolver.kt | 16 ++++++ .../main/resources/graphql/Element.graphqls | 14 +++++ 7 files changed, 88 insertions(+), 22 deletions(-) create mode 100644 data/src/main/kotlin/io/zeebe/zeeqs/data/service/BpmnElementExtensionProperties.kt diff --git a/data/src/main/kotlin/io/zeebe/zeeqs/data/entity/BpmnElementType.kt b/data/src/main/kotlin/io/zeebe/zeeqs/data/entity/BpmnElementType.kt index 570be2e..08ba658 100644 --- a/data/src/main/kotlin/io/zeebe/zeeqs/data/entity/BpmnElementType.kt +++ b/data/src/main/kotlin/io/zeebe/zeeqs/data/entity/BpmnElementType.kt @@ -25,5 +25,6 @@ enum class BpmnElementType { BUSINESS_RULE_TASK, SCRIPT_TASK, SEND_TASK, - INCLUSIVE_GATEWAY + INCLUSIVE_GATEWAY, + GROUP } diff --git a/data/src/main/kotlin/io/zeebe/zeeqs/data/service/BpmnElementExtensionProperties.kt b/data/src/main/kotlin/io/zeebe/zeeqs/data/service/BpmnElementExtensionProperties.kt new file mode 100644 index 0000000..5bc1f02 --- /dev/null +++ b/data/src/main/kotlin/io/zeebe/zeeqs/data/service/BpmnElementExtensionProperties.kt @@ -0,0 +1,6 @@ +package io.zeebe.zeeqs.data.service + +data class BpmnElementExtensionProperties ( + val name: String? = null, + val value: String? = null, +) \ No newline at end of file diff --git a/data/src/main/kotlin/io/zeebe/zeeqs/data/service/BpmnElementInfo.kt b/data/src/main/kotlin/io/zeebe/zeeqs/data/service/BpmnElementInfo.kt index f3d786e..74520c5 100644 --- a/data/src/main/kotlin/io/zeebe/zeeqs/data/service/BpmnElementInfo.kt +++ b/data/src/main/kotlin/io/zeebe/zeeqs/data/service/BpmnElementInfo.kt @@ -1,10 +1,14 @@ package io.zeebe.zeeqs.data.service +import io.camunda.zeebe.model.bpmn.instance.Documentation +import io.camunda.zeebe.model.bpmn.instance.zeebe.ZeebeProperty import io.zeebe.zeeqs.data.entity.BpmnElementType data class BpmnElementInfo( val elementId: String, val elementName: String?, val elementType: BpmnElementType, - val metadata: BpmnElementMetadata + val metadata: BpmnElementMetadata, + val extensionProperties: Collection?, + val documentation: String? ) \ No newline at end of file diff --git a/data/src/main/kotlin/io/zeebe/zeeqs/data/service/ProcessService.kt b/data/src/main/kotlin/io/zeebe/zeeqs/data/service/ProcessService.kt index 794a692..fa698a1 100644 --- a/data/src/main/kotlin/io/zeebe/zeeqs/data/service/ProcessService.kt +++ b/data/src/main/kotlin/io/zeebe/zeeqs/data/service/ProcessService.kt @@ -20,18 +20,28 @@ class ProcessService(val processRepository: ProcessRepository) { @Cacheable(cacheNames = ["bpmnElementInfo"]) fun getBpmnElementInfo(processDefinitionKey: Long): Map? { return getBpmnModel(processDefinitionKey) - ?.let { it.getModelElementsByType(FlowElement::class.java) } - ?.map { flowElement -> - Pair( - flowElement.id, BpmnElementInfo( - elementId = flowElement.id, - elementName = flowElement.name, - elementType = getBpmnElementType(flowElement), - metadata = getMetadata(flowElement) - ) - ) - } - ?.toMap() + ?.let { model -> + (model.getModelElementsByType(FlowElement::class.java)?.associate { flowElement -> + flowElement.id to BpmnElementInfo( + elementId = flowElement.id, + elementName = flowElement.name, + elementType = getBpmnElementType(flowElement), + metadata = getMetadata(flowElement), + extensionProperties = getExtensionProperties(flowElement), + documentation = getDocumentation(flowElement) + ) + }.orEmpty() + + model.getModelElementsByType(Group::class.java)?.associate { groupElement -> + groupElement.id to BpmnElementInfo( + elementId = groupElement.id, + elementName = groupElement.category?.value ?: "", + elementType = getBpmnElementType(groupElement), + metadata = getMetadata(groupElement), + extensionProperties = getExtensionProperties(groupElement), + documentation = getDocumentation(groupElement) + ) + }.orEmpty()) + } } private fun getBpmnModel(processDefinitionKey: Long): BpmnModelInstance? { @@ -41,7 +51,7 @@ class ProcessService(val processRepository: ProcessRepository) { ?.let { Bpmn.readModelFromStream(it) } } - private fun getBpmnElementType(element: FlowElement): BpmnElementType { + private fun getBpmnElementType(element: BaseElement): BpmnElementType { return when (element.elementType.typeName) { BpmnModelConstants.BPMN_ELEMENT_PROCESS -> BpmnElementType.PROCESS BpmnModelConstants.BPMN_ELEMENT_SUB_PROCESS -> getBpmnSubprocessType(element) @@ -63,11 +73,12 @@ class ProcessService(val processRepository: ProcessRepository) { BpmnModelConstants.BPMN_ELEMENT_BUSINESS_RULE_TASK -> BpmnElementType.BUSINESS_RULE_TASK BpmnModelConstants.BPMN_ELEMENT_SCRIPT_TASK -> BpmnElementType.SCRIPT_TASK BpmnModelConstants.BPMN_ELEMENT_INCLUSIVE_GATEWAY -> BpmnElementType.INCLUSIVE_GATEWAY + BpmnModelConstants.BPMN_ELEMENT_GROUP -> BpmnElementType.GROUP else -> BpmnElementType.UNKNOWN } } - private fun getBpmnSubprocessType(element: FlowElement) = + private fun getBpmnSubprocessType(element: BaseElement) = if (element is SubProcess) { if (element.triggeredByEvent()) { BpmnElementType.EVENT_SUB_PROCESS @@ -78,7 +89,7 @@ class ProcessService(val processRepository: ProcessRepository) { BpmnElementType.UNKNOWN } - private fun getMetadata(element: FlowElement): BpmnElementMetadata { + private fun getMetadata(element: BaseElement): BpmnElementMetadata { return BpmnElementMetadata( jobType = element .getSingleExtensionElement(ZeebeTaskDefinition::class.java) @@ -156,6 +167,19 @@ class ProcessService(val processRepository: ProcessRepository) { ) } + private fun getExtensionProperties(element: BaseElement): Collection? { + return element.extensionElements?.elementsQuery + ?.filterByType(ZeebeProperties::class.java) + ?.singleResult() + ?.properties + ?.map { BpmnElementExtensionProperties(name = it.name, value = it.value) } + } + + + private fun getDocumentation(element: BaseElement): String { + return element.documentations.joinToString(separator = "") { it.textContent } + } + @Cacheable(cacheNames = ["userTaskForm"]) fun getForm(processDefinitionKey: Long, formKey: String): String? { return getBpmnModel(processDefinitionKey) diff --git a/data/src/test/kotlin/io/zeebe/zeeqs/ProcessServiceTest.kt b/data/src/test/kotlin/io/zeebe/zeeqs/ProcessServiceTest.kt index 337243b..8b5445c 100644 --- a/data/src/test/kotlin/io/zeebe/zeeqs/ProcessServiceTest.kt +++ b/data/src/test/kotlin/io/zeebe/zeeqs/ProcessServiceTest.kt @@ -52,12 +52,12 @@ class ProcessServiceTest( // then assertThat(info) .isNotNull() - .contains(entry("s", BpmnElementInfo("s", "start", BpmnElementType.START_EVENT, BpmnElementMetadata()))) - .contains(entry("t", BpmnElementInfo("t", "task", BpmnElementType.SERVICE_TASK, BpmnElementMetadata(jobType = "test")))) + .contains(entry("s", BpmnElementInfo("s", "start", BpmnElementType.START_EVENT, BpmnElementMetadata(), listOf(BpmnElementExtensionProperties()), ""))) + .contains(entry("t", BpmnElementInfo("t", "task", BpmnElementType.SERVICE_TASK, BpmnElementMetadata(jobType = "test"), listOf(BpmnElementExtensionProperties()), ""))) .contains(entry("u", BpmnElementInfo("u", "userTask", BpmnElementType.USER_TASK, BpmnElementMetadata( - userTaskAssignmentDefinition = UserTaskAssignmentDefinition(assignee = "user1", candidateGroups = "group1")))) + userTaskAssignmentDefinition = UserTaskAssignmentDefinition(assignee = "user1", candidateGroups = "group1")), listOf(BpmnElementExtensionProperties()), "")) ) - .contains(entry("e", BpmnElementInfo("e", null, BpmnElementType.END_EVENT, BpmnElementMetadata()))) + .contains(entry("e", BpmnElementInfo("e", null, BpmnElementType.END_EVENT, BpmnElementMetadata(), listOf(BpmnElementExtensionProperties()), ""))) } @Test @@ -90,7 +90,8 @@ class ProcessServiceTest( key = "camunda-forms:bpmn:form_A", resource = """{"x":1}""" ) - ) + ), + listOf(BpmnElementExtensionProperties()), "" ) ) } diff --git a/graphql-api/src/main/kotlin/io/zeebe/zeeqs/graphql/resolvers/type/BpmnElementResolver.kt b/graphql-api/src/main/kotlin/io/zeebe/zeeqs/graphql/resolvers/type/BpmnElementResolver.kt index b867d74..1704a71 100644 --- a/graphql-api/src/main/kotlin/io/zeebe/zeeqs/graphql/resolvers/type/BpmnElementResolver.kt +++ b/graphql-api/src/main/kotlin/io/zeebe/zeeqs/graphql/resolvers/type/BpmnElementResolver.kt @@ -5,6 +5,7 @@ import io.zeebe.zeeqs.data.entity.ElementInstanceState import io.zeebe.zeeqs.data.entity.Process import io.zeebe.zeeqs.data.repository.ElementInstanceRepository import io.zeebe.zeeqs.data.repository.ProcessRepository +import io.zeebe.zeeqs.data.service.BpmnElementExtensionProperties import io.zeebe.zeeqs.data.service.BpmnElementInfo import io.zeebe.zeeqs.data.service.BpmnElementMetadata import io.zeebe.zeeqs.data.service.ProcessService @@ -41,6 +42,21 @@ class BpmnElementResolver( ?: BpmnElementMetadata() } + + @SchemaMapping(typeName = "BpmnElement", field = "extensionProperties") + fun extensionProperties(element: BpmnElement): Collection? { + return findElementInfo(element) + ?.extensionProperties + } + + + @SchemaMapping(typeName = "BpmnElement", field = "documentation") + fun documentation(element: BpmnElement): String? { + return findElementInfo(element) + ?.documentation + + } + @SchemaMapping(typeName = "BpmnElement", field = "process") fun process(element: BpmnElement): Process? { return processRepository.findByIdOrNull(element.processDefinitionKey) diff --git a/graphql-api/src/main/resources/graphql/Element.graphqls b/graphql-api/src/main/resources/graphql/Element.graphqls index 4e84b9e..3209d16 100644 --- a/graphql-api/src/main/resources/graphql/Element.graphqls +++ b/graphql-api/src/main/resources/graphql/Element.graphqls @@ -10,6 +10,12 @@ type BpmnElement { # the metadata of the BPMN element metadata: BpmnElementMetadata! + # extension properties of the BPMN element + extensionProperties: [BpmnElementExtensionProperties] + + # documentation of the BPMN element + documentation: String + # the process that contains the BPMN element process: Process # the instances of the BPMN element @@ -46,6 +52,7 @@ enum BpmnElementType { SCRIPT_TASK SEND_TASK INCLUSIVE_GATEWAY + GROUP } # Additional metadata that are defined statically on the BPMN element. @@ -84,4 +91,11 @@ type UserTaskAssignmentDefinition { assignee: String # the candidate groups candidateGroups: String +} + +type BpmnElementExtensionProperties { + # the name of property + name: String + # the value of property + value: String } \ No newline at end of file