Skip to content

Commit 4596ab8

Browse files
committed
Added mapping for list values
1 parent 4f8d554 commit 4596ab8

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

xml-parser-api/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/bpmn/api/info/PropertyType.kt

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ enum class PropertyType(
3737
val externalProperty: ExternalProperty? = null,
3838
val onUpdatedByUseHardcodedValue: Any? = null,
3939
val updatedByWithinSameElement: PropertyType? = null,
40-
val inCascadeOrder: Int = Int.MAX_VALUE
40+
val inCascadeOrder: Int = Int.MAX_VALUE,
41+
val mapValuesTo: Map<Any, Any>? = null
4142
) {
4243
ID("id", "ID", STRING, "id.id", true, null, 1000, explicitIndexCascades = listOf("BPMN_INCOMING", "BPMN_OUTGOING")), // ID should fire last
4344
NAME("name", "Name", STRING),
@@ -180,7 +181,7 @@ enum class PropertyType(
180181
MAPPING_PAYLOAD_FROM_EVENT_VARIABLE_NAME("extensionElementsMappingPayloadFromEvent.@source", "Variable name", STRING, group = listOf(FunctionalGroupType.MAPPING_PAYLOAD_FROM), isUsedOnlyBy = setOf(BpmnSendEventTask::class), indexInGroupArrayName = "source", listenerOrder = 100, indexCascades = CascadeGroup.PARENTS_CASCADE, removeEnclosingNodeIfNullOrEmpty = true, hideIfNullOrEmpty = true, positionInGroup = 1),
181182
MAPPING_PAYLOAD_FROM_EVENT_PROPERTY_NAME("extensionElementsMappingPayloadFromEvent.@target", "Event property name", STRING, group = listOf(FunctionalGroupType.MAPPING_PAYLOAD_FROM), isUsedOnlyBy = setOf(BpmnSendEventTask::class), indexInGroupArrayName = "source"),
182183
MAPPING_PAYLOAD_FROM_EVENT_TYPE("extensionElementsMappingPayloadFromEvent.@type", "Type", LIST_SELECT, setForSelect = setOf("","string", "integer", "double", "boolean"), isUsedOnlyBy = setOf(BpmnSendEventTask::class), group = listOf(FunctionalGroupType.MAPPING_PAYLOAD_FROM), indexInGroupArrayName = "source"),
183-
MULTI_INSTANCE_LOOP_IS_SEQUENTIAL("multiInstanceLoopCharacteristics.sequential", "Multi-instance loop type", LIST_SELECT, setForSelect = setOf("","sequential", "parallel"), group = listOf(FunctionalGroupType.MULTI_INSTANCE_LOOP), listenerOrder = 100, removeEnclosingNodeIfNullOrEmpty = true, hideIfNullOrEmpty = false, indexInGroupArrayName = "isSequential", indexCascades = CascadeGroup.FLAT, positionInGroup = 1),
184+
MULTI_INSTANCE_LOOP_IS_SEQUENTIAL("multiInstanceLoopCharacteristics.sequential", "Multi-instance loop type", LIST_SELECT, setForSelect = setOf("","sequential", "parallel"), group = listOf(FunctionalGroupType.MULTI_INSTANCE_LOOP), listenerOrder = 100, removeEnclosingNodeIfNullOrEmpty = true, hideIfNullOrEmpty = false, indexInGroupArrayName = "isSequential", indexCascades = CascadeGroup.FLAT, positionInGroup = 1, mapValuesTo = mapOf("true" to "sequential", "false" to "parallel")),
184185
MULTI_INSTANCE_LOOP_COLLECTION("multiInstanceLoopCharacteristics.collection", "Multi instance loop-collection", STRING, group = listOf(FunctionalGroupType.MULTI_INSTANCE_LOOP)),
185186
MULTI_INSTANCE_LOOP_ELEMENT_VARIABLE("multiInstanceLoopCharacteristics.elementVariable", "Multi instance loop-elementVariable", STRING, group = listOf(FunctionalGroupType.MULTI_INSTANCE_LOOP)),
186187
MULTI_INSTANCE_LOOP_CARDINALITY_TYPE("multiInstanceLoopCharacteristics.loopCardinality.type", "Multi instance loop-Cardinality type", STRING, group = listOf(FunctionalGroupType.MULTI_INSTANCE_LOOP)),
@@ -192,6 +193,32 @@ enum class PropertyType(
192193
EXECUTION_LISTENER_FIELD_NAME("executionListener.@fields.@name", "Name", STRING, group = listOf(FunctionalGroupType.EXECUTION_LISTENER, FunctionalGroupType.EXECUTION_LISTENER_FILED), indexInGroupArrayName = "clazz.name", indexCascades = CascadeGroup.PARENTS_CASCADE, removeEnclosingNodeIfNullOrEmpty = true, listenerOrder = 95),
193194
EXECUTION_LISTENER_FIELD_STRING("executionListener.@fields.@string", "String", STRING, group = listOf(FunctionalGroupType.EXECUTION_LISTENER, FunctionalGroupType.EXECUTION_LISTENER_FILED), indexInGroupArrayName = "clazz.name", listenerOrder = 90);
194195

196+
private val invertedMapValuesTo: Map<Any, Any>?
197+
198+
init {
199+
if (null == this.mapValuesTo) {
200+
this.invertedMapValuesTo = null
201+
} else {
202+
this.invertedMapValuesTo = this.mapValuesTo.map { (k, v) -> v to k }.toMap()
203+
}
204+
}
205+
206+
fun mapFromXmlValue(value: Any?): Any? {
207+
if (null == this.mapValuesTo) {
208+
return value
209+
}
210+
211+
return this.mapValuesTo[value]
212+
}
213+
214+
fun mapToXmlValue(value: Any?): Any? {
215+
if (null == this.invertedMapValuesTo) {
216+
return value
217+
}
218+
219+
return this.invertedMapValuesTo[value]
220+
}
221+
195222
fun isNestedProperty(): Boolean {
196223
return (group?.size ?: 0) > 1
197224
}

xml-parser-core/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/bpmn/parser/core/BaseBpmnObjectFactory.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ abstract class BaseBpmnObjectFactory : BpmnObjectFactory {
233233
if (null != indexInArray) {
234234
val minPathIdLen = type.indexInGroupArrayName!!.split(".").size
235235
val computedIndex = indexInArray + (0 until minPathIdLen - indexInArray.size).map { "" }.toList()
236-
Property(it, computedIndex)
237-
} else Property(it)
236+
Property(type.mapFromXmlValue(it), computedIndex)
237+
} else Property(type.mapFromXmlValue(it))
238238
}
239239

240240
if (null == node || node.isNull) {

xml-parser-core/src/main/kotlin/com/valb3r/bpmn/intellij/plugin/bpmn/parser/core/BaseBpmnParser.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ abstract class BaseBpmnParser: BpmnParser {
513513
node,
514514
path,
515515
details,
516-
asString(type.valueType, value)
516+
asString(type, value)
517517
)
518518
}
519519
}
@@ -574,7 +574,7 @@ abstract class BaseBpmnParser: BpmnParser {
574574
currentNode,
575575
segments[segments.size - 1],
576576
details,
577-
asString(type.valueType, value)
577+
asString(type, value)
578578
)
579579
}
580580

@@ -681,14 +681,14 @@ abstract class BaseBpmnParser: BpmnParser {
681681
return value.startsWith(" ") || value.endsWith(" ") || value.contains("\n")
682682
}
683683

684-
private fun asString(type: PropertyValueType, value: Any?): String? {
684+
private fun asString(type: PropertyType, value: Any?): String? {
685685
if (null == value || "" == value) {
686686
return null
687687
}
688688

689-
return when (type) {
690-
STRING, CLASS, EXPRESSION, ATTACHED_SEQUENCE_SELECT, LIST_SELECT -> value as String
691-
BOOLEAN -> (value as Boolean).toString()
689+
return when (type.valueType) {
690+
STRING, CLASS, EXPRESSION, ATTACHED_SEQUENCE_SELECT, LIST_SELECT -> type.mapToXmlValue(value)?.toString()
691+
BOOLEAN -> (type.mapToXmlValue(value) as Boolean).toString()
692692
}
693693
}
694694

0 commit comments

Comments
 (0)