Skip to content

Commit e781a09

Browse files
authored
Merge pull request #334 from nl-portal/feature/change-dmn-to-support-static-variables
change in the dmn flow to support static variable which can be used i…
2 parents a98014d + b590df5 commit e781a09

File tree

5 files changed

+77
-29
lines changed

5 files changed

+77
-29
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ dokkaVersion=1.9.20
1414

1515
org.gradle.jvmargs=-Xmx6g -XX:MaxMetaspaceSize=2048m
1616
org.gradle.workers.max=10
17-
version=1.4.32-SNAPSHOT
17+
version=1.4.33-SNAPSHOT

product/src/main/kotlin/nl/nlportal/product/domain/BeslisTabelVariable.kt

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ data class BeslisTabelVariable(
1919
val name: String,
2020
val classType: DmnVariableType,
2121
val regex: String?,
22+
val value: String?,
2223
)
2324

2425
data class BeslisTabelConfiguration(

product/src/main/kotlin/nl/nlportal/product/service/DmnService.kt

+61-28
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,25 @@ class DmnService(
9595
)
9696

9797
sources?.forEach {
98-
if (beslisTabelConfiguration.variabelen.containsKey(it.key)) {
99-
variablesMapping.putAll(
100-
mapBeslisTabelVariablesWithSource(
101-
beslisTabelConfiguration.variabelen[it.key]!!,
102-
it.value,
103-
),
104-
)
105-
} else {
106-
logger.warn(BESLISTABLE_NOT_FOUND_BY_KEY, it.key)
107-
}
98+
beslisTabelConfiguration.variabelen[it.key]?.let { variable ->
99+
{
100+
variablesMapping.putAll(
101+
mapBeslisTabelVariablesWithSource(
102+
variable,
103+
it.value,
104+
),
105+
)
106+
}
107+
} ?: logger.warn(BESLISTABLE_NOT_FOUND_BY_KEY, it.key)
108+
}
109+
110+
// handle the configured static variables
111+
beslisTabelConfiguration.variabelen[BESLISTABLE_KEY_STATIC]?.let {
112+
variablesMapping.putAll(
113+
mapBeslisTabelStaticVariables(
114+
it,
115+
),
116+
)
108117
}
109118

110119
if (variablesMapping.isEmpty()) {
@@ -148,35 +157,40 @@ class DmnService(
148157

149158
// loop through the sources and get the Object as Json and map with the variables
150159
sources?.forEach {
151-
val source = productService.getSourceAsJson(it.key, it.value)
152-
153-
if (source == null) {
154-
logger.warn("Could not find objects for key {} with uuid {}", it.key, it.value)
155-
} else {
156-
if (beslisTabelVariables.containsKey(it.key)) {
157-
variablesMapping.putAll(
158-
mapBeslisTabelVariablesWithSource(
159-
beslisTabelVariables[it.key]!!,
160-
source,
161-
),
162-
)
163-
} else {
164-
logger.warn(BESLISTABLE_NOT_FOUND_BY_KEY, it.key)
165-
}
166-
}
160+
productService.getSourceAsJson(it.key, it.value)?.let { source ->
161+
beslisTabelVariables[it.key]?.let { variable ->
162+
{
163+
variablesMapping.putAll(
164+
mapBeslisTabelVariablesWithSource(
165+
variable,
166+
source,
167+
),
168+
)
169+
}
170+
} ?: logger.warn(BESLISTABLE_NOT_FOUND_BY_KEY, it.key)
171+
} ?: logger.warn("Could not find objects for key {} with uuid {}", it.key, it.value)
167172
}
168173

169174
// check if the beslisTabelVariables contains a producttype configuration,
170175
// if yes map the variables with the json of the productType
171-
if (beslisTabelVariables.containsKey("producttype")) {
176+
beslisTabelVariables[BESLISTABLE_KEY_PRODUCT_TYPE]?.let {
172177
variablesMapping.putAll(
173178
mapBeslisTabelVariablesWithSource(
174-
beslisTabelVariables["producttype"]!!,
179+
it,
175180
Mapper.get().writeValueAsString(productType),
176181
),
177182
)
178183
}
179184

185+
// handle the configured static variables
186+
beslisTabelVariables[BESLISTABLE_KEY_STATIC]?.let {
187+
variablesMapping.putAll(
188+
mapBeslisTabelStaticVariables(
189+
it,
190+
),
191+
)
192+
}
193+
180194
if (variablesMapping.isEmpty()) {
181195
throw ResponseStatusException(HttpStatus.BAD_REQUEST, SOURCE_MAPPING_FAILED + productType?.naam)
182196
}
@@ -211,6 +225,23 @@ class DmnService(
211225
)
212226
}
213227

228+
private fun mapBeslisTabelStaticVariables(beslisTabelVariables: List<BeslisTabelVariable>): Map<String, DmnVariable> {
229+
val variablesMapping = mutableMapOf<String, DmnVariable>()
230+
beslisTabelVariables.forEach {
231+
if (it.value != null) {
232+
variablesMapping.put(
233+
it.name,
234+
DmnVariable(
235+
it.value,
236+
it.classType,
237+
),
238+
)
239+
}
240+
}
241+
242+
return variablesMapping
243+
}
244+
214245
private fun mapBeslisTabelVariablesWithSource(
215246
beslisTabelVariables: List<BeslisTabelVariable>,
216247
source: String,
@@ -259,5 +290,7 @@ class DmnService(
259290
val logger = KotlinLogging.logger {}
260291
const val SOURCE_MAPPING_FAILED: String = "Source mapping failed for DMN, check beslistabelmapping of productType: "
261292
const val BESLISTABLE_NOT_FOUND_BY_KEY: String = "Could not find beslisTabel variables for key {}"
293+
const val BESLISTABLE_KEY_STATIC: String = "static"
294+
const val BESLISTABLE_KEY_PRODUCT_TYPE: String = "producttype"
262295
}
263296
}

product/src/test/resources/product/data/get-product-type.json

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
"regex":"$.data.beschikbareDagdelen",
5858
"classType":"Integer"
5959
}
60+
],
61+
"static": [
62+
{
63+
"name":"formulieren",
64+
"classType":"String",
65+
"value":"https://openformulieren-zgw.test.denhaag.nl"
66+
}
6067
]
6168
}
6269
}

product/src/test/resources/product/data/get-product-types.json

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
"classType":"String",
5656
"regex":"$.parameters.contractnummer"
5757
}
58+
],
59+
"static": [
60+
{
61+
"name":"formulieren",
62+
"classType":"String",
63+
"value":"https://openformulieren-zgw.test.denhaag.nl"
64+
}
5865
]
5966
}
6067
}

0 commit comments

Comments
 (0)