Skip to content

Commit

Permalink
wip: evaluate decision with imported decision
Browse files Browse the repository at this point in the history
  • Loading branch information
saig0 committed Jun 27, 2023
1 parent f84fe71 commit caf6088
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 130 deletions.
24 changes: 20 additions & 4 deletions src/main/scala/org/camunda/dmn/evaluation/DecisionEvaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,37 @@ class DecisionEvaluator(
evalRequiredKnowledge(decision.requiredBkms, context)
.flatMap(functions => {

// todo: replace the hack to wrap the imported BKMs into a context, maybe move to the BKM evaluation logic
val isImported: ((String, Val)) => Boolean = {
case (name, _) => name.contains(".")
}

// todo: replace the hack to wrap the imported BKMs and decisions into a context, maybe move to the BKM evaluation logic
val importedFunctions = functions
.filter { case (name, _) => name.contains(".") }
.filter(isImported)
.map { case (name, function) =>
val Array(prefix: String, functionName: String) = name.split('.')
prefix -> ValContext(StaticContext(
variables = Map.empty,
functions = Map(functionName -> List(function))
))
}
val embeddedFunctions = functions.filterNot(isImported)

val embeddedFunctions = functions.filterNot { case (name, _) => name.contains(".") }
val importedDecisions = decisionResults
.filter(isImported)
.map { case (name, decisionResult) =>
val Array(prefix: String, decisionName: String) = name.split('.')
prefix -> ValContext(StaticContext(
variables = Map(decisionName -> decisionResult),
functions = Map.empty
))
}
val embeddedDecisions = decisionResults.filterNot(isImported)

val decisionEvaluationContext = context.copy(
variables = context.variables ++ decisionResults ++ embeddedFunctions ++ importedFunctions,
variables = context.variables
++ embeddedDecisions ++ importedDecisions
++ embeddedFunctions ++ importedFunctions,
currentElement = decision)

eval(decision.logic, decisionEvaluationContext)
Expand Down
Loading

0 comments on commit caf6088

Please sign in to comment.