@@ -95,16 +95,25 @@ class DmnService(
95
95
)
96
96
97
97
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
+ )
108
117
}
109
118
110
119
if (variablesMapping.isEmpty()) {
@@ -148,35 +157,40 @@ class DmnService(
148
157
149
158
// loop through the sources and get the Object as Json and map with the variables
150
159
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)
167
172
}
168
173
169
174
// check if the beslisTabelVariables contains a producttype configuration,
170
175
// if yes map the variables with the json of the productType
171
- if ( beslisTabelVariables.containsKey( " producttype " )) {
176
+ beslisTabelVariables[ BESLISTABLE_KEY_PRODUCT_TYPE ]?. let {
172
177
variablesMapping.putAll(
173
178
mapBeslisTabelVariablesWithSource(
174
- beslisTabelVariables[ " producttype " ] !! ,
179
+ it ,
175
180
Mapper .get().writeValueAsString(productType),
176
181
),
177
182
)
178
183
}
179
184
185
+ // handle the configured static variables
186
+ beslisTabelVariables[BESLISTABLE_KEY_STATIC ]?.let {
187
+ variablesMapping.putAll(
188
+ mapBeslisTabelStaticVariables(
189
+ it,
190
+ ),
191
+ )
192
+ }
193
+
180
194
if (variablesMapping.isEmpty()) {
181
195
throw ResponseStatusException (HttpStatus .BAD_REQUEST , SOURCE_MAPPING_FAILED + productType?.naam)
182
196
}
@@ -211,6 +225,23 @@ class DmnService(
211
225
)
212
226
}
213
227
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
+
214
245
private fun mapBeslisTabelVariablesWithSource (
215
246
beslisTabelVariables : List <BeslisTabelVariable >,
216
247
source : String ,
@@ -259,5 +290,7 @@ class DmnService(
259
290
val logger = KotlinLogging .logger {}
260
291
const val SOURCE_MAPPING_FAILED : String = " Source mapping failed for DMN, check beslistabelmapping of productType: "
261
292
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"
262
295
}
263
296
}
0 commit comments