Skip to content

Commit

Permalink
FBP-100. Update basic flow (ephemeral updates)
Browse files Browse the repository at this point in the history
  • Loading branch information
valb3r committed Jul 1, 2023
1 parent ce4acc5 commit c9b2d3a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ class CurrentStateProvider(private val project: Project) {
return updateId(processId, event.bpmnElementId, event.newIdValue!!, updatedShapes, updatedEdges, updatedElementByDiagramId, updatedElementByStaticId, updatedElemPropertiesByStaticElementId)
}

if (null != event.property.externalProperty) {
updateExternalProperty(event, updatedElemPropertiesByStaticElementId)
updateProperty(event, updatedElemPropertiesByStaticElementId)
return processId
}

updateProperty(event, updatedElemPropertiesByStaticElementId)
return processId
}
Expand All @@ -215,6 +221,16 @@ class CurrentStateProvider(private val project: Project) {
}
}

private fun updateExternalProperty(event: PropertyUpdateWithId, updatedElemPropertiesByStaticElementId: MutableMap<BpmnElementId, PropertyTable>) {
val externalProperty = event.property.externalProperty!!
val referencingElementTable = updatedElemPropertiesByStaticElementId[event.bpmnElementId]!!
val externalRef = externalProperty.externalValueReference(referencingElementTable)!!
val newExternalValue = externalProperty.castToExternalValue(referencingElementTable, event.newValue)

val updated = updatedElemPropertiesByStaticElementId[externalRef.first] ?: PropertyTable(mutableMapOf())
updated[externalRef.second] = Property(newExternalValue)
}

private fun updateProperty(event: PropertyUpdateWithId, updatedElemPropertiesByStaticElementId: MutableMap<BpmnElementId, PropertyTable>) {
val updated = updatedElemPropertiesByStaticElementId[event.bpmnElementId] ?: PropertyTable(mutableMapOf())
if (null == event.propertyIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@ data class BpmnProcessObject(val process: BpmnProcess, val diagram: List<Diagram
val externalProperties = PropertyType.values().filter {
it.isUsedOnlyBy.contains(element::class) && (it.externalProperty?.isPresent(elementById, propertiesByElemId, propertiesByElemId[element.id]!!) ?: false)
}
println()

val elemProps = propertiesByElemId[element.id]!!
for (prop in externalProperties) {
val externalProp = prop.externalProperty!!
val ref = externalProp.externalValueReference(elemProps) ?: continue
val externalValue = propertiesByElemId[ref.first]?.get(ref.second)
propertiesByElemId[element.id]?.add(prop, Property(externalProp.castFromExternalValue(elemProps, externalValue?.value)))
}
}

private fun fillForTargetRefParent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ enum class FunctionalGroupType(val groupCaption: String, val actionResult: NewEl

interface ExternalProperty {
fun isPresent(allElems: Map<BpmnElementId, WithParentId>, allElemProps: Map<BpmnElementId, PropertyTable>, elemProps: PropertyTable): Boolean
fun externalValueReference(): Pair<BpmnElementId, PropertyType>
fun castFromExternalValue(value: Any): Any
fun castToExternalValue(value: Any): Any
fun externalValueReference(elemProps: PropertyTable): Pair<BpmnElementId, PropertyType>?
fun castFromExternalValue(elemProps: PropertyTable, value: Any?): Any?
fun castToExternalValue(elemProps: PropertyTable, value: Any?): Any?
}

class DefaultFlowExternalProp: ExternalProperty {
Expand All @@ -249,15 +249,20 @@ class DefaultFlowExternalProp: ExternalProperty {
return allElems[BpmnElementId(elemProps[PropertyType.SOURCE_REF]?.value as String? ?: "")]?.element is BpmnExclusiveGateway
}

override fun externalValueReference(): Pair<BpmnElementId, PropertyType> {
TODO("Not yet implemented")
override fun externalValueReference(elemProps: PropertyTable): Pair<BpmnElementId, PropertyType>? {
val gatewayId = elemProps[PropertyType.SOURCE_REF]?.value ?: return null
return BpmnElementId(gatewayId as String) to PropertyType.DEFAULT_FLOW
}

override fun castFromExternalValue(value: Any): Any {
TODO("Not yet implemented")
override fun castFromExternalValue(elemProps: PropertyTable, value: Any?): Any {
return elemProps[PropertyType.ID]?.value == value
}

override fun castToExternalValue(value: Any): Any {
TODO("Not yet implemented")
override fun castToExternalValue(elemProps: PropertyTable, value: Any?): Any? {
if (value == true) {
return elemProps[PropertyType.ID]?.value!!
}

return null
}
}

0 comments on commit c9b2d3a

Please sign in to comment.