Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return group elements, and return extension properties with documentation for elements #2

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -25,5 +25,6 @@ enum class BpmnElementType {
BUSINESS_RULE_TASK,
SCRIPT_TASK,
SEND_TASK,
INCLUSIVE_GATEWAY
INCLUSIVE_GATEWAY,
GROUP
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.zeebe.zeeqs.data.service

data class BpmnElementExtensionProperties (
val name: String? = null,
val value: String? = null,
)
Original file line number Diff line number Diff line change
@@ -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<BpmnElementExtensionProperties>?,
val documentation: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -72,7 +72,7 @@ class ProcessInstanceService(
}

else {
return processInstancesRepository.countByStateIn(stateIn);
return processInstancesRepository.countByProcessDefinitionKeyAndStateIn(processDefinitionKey, stateIn);
}
}

Expand Down
54 changes: 39 additions & 15 deletions data/src/main/kotlin/io/zeebe/zeeqs/data/service/ProcessService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,28 @@ class ProcessService(val processRepository: ProcessRepository) {
@Cacheable(cacheNames = ["bpmnElementInfo"])
fun getBpmnElementInfo(processDefinitionKey: Long): Map<String, BpmnElementInfo>? {
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? {
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -156,6 +167,19 @@ class ProcessService(val processRepository: ProcessRepository) {
)
}

private fun getExtensionProperties(element: BaseElement): Collection<BpmnElementExtensionProperties>? {
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)
Expand Down
11 changes: 6 additions & 5 deletions data/src/test/kotlin/io/zeebe/zeeqs/ProcessServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,7 +90,8 @@ class ProcessServiceTest(
key = "camunda-forms:bpmn:form_A",
resource = """{"x":1}"""
)
)
),
listOf(BpmnElementExtensionProperties()), ""
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -41,6 +42,21 @@ class BpmnElementResolver(
?: BpmnElementMetadata()
}


@SchemaMapping(typeName = "BpmnElement", field = "extensionProperties")
fun extensionProperties(element: BpmnElement): Collection<BpmnElementExtensionProperties>? {
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)
Expand Down
14 changes: 14 additions & 0 deletions graphql-api/src/main/resources/graphql/Element.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,6 +52,7 @@ enum BpmnElementType {
SCRIPT_TASK
SEND_TASK
INCLUSIVE_GATEWAY
GROUP
}

# Additional metadata that are defined statically on the BPMN element.
Expand Down Expand Up @@ -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
}