Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

71 from poc - dynamic import loading #225

Merged
merged 6 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions api-check-ignore.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
<!-- num method params -->
<differenceType>7004</differenceType>
<method>*$anonfun*</method>
<from>*</from>
<to>*</to>
</difference>
<difference>
<className>org/camunda/dmn/**</className>
<!-- method param type -->
<differenceType>7005</differenceType>
<method>*$anonfun*</method>
<!--don't care what the type has changed to-->
<from>*</from>
<to>*</to>
</difference>
<difference>
Expand All @@ -43,4 +40,39 @@
<differenceType>7002</differenceType>
<method>*</method>
</difference>
<!-- changes from 1.8.1 to 1.9 -->
<difference>
<className>org/camunda/dmn/DmnEngine</className>
<differenceType>7004</differenceType>
<method>DmnEngine(*</method>
</difference>
<difference>
<className>org/camunda/dmn/parser/DmnParser</className>
<differenceType>7004</differenceType>
<method>DmnParser(*</method>
</difference>
<difference>
<className>org/camunda/dmn/parser/ParsedDmn</className>
<differenceType>7004</differenceType>
<method>*</method>
</difference>
<difference>
<className>org/camunda/dmn/parser/ParsedBusinessKnowledgeModel</className>
<differenceType>2000</differenceType>
</difference>
<difference>
<className>org/camunda/dmn/parser/ParsedBusinessKnowledgeModel</className>
<differenceType>4001</differenceType>
<to>**</to>
</difference>
<difference>
<className>org/camunda/dmn/parser/ParsedDecision</className>
<differenceType>2000</differenceType>
</difference>
<difference>
<className>org/camunda/dmn/parser/ParsedDecision</className>
<differenceType>4001</differenceType>
<to>**</to>
</difference>
<!-- END changes from 1.8.1 to 1.9 -->
</differences>
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.camunda.bpm.extension.dmn.scala</groupId>
<artifactId>dmn-engine</artifactId>
<name>DMN Scala Engine</name>
<version>1.8.2-SNAPSHOT</version>
<version>1.9.0-SNAPSHOT</version>

<parent>
<groupId>org.camunda</groupId>
Expand All @@ -15,7 +15,7 @@
</parent>

<properties>
<feel.version>1.16.0</feel.version>
<feel.version>1.16.1</feel.version>
<camunda-model-api.version>7.19.0</camunda-model-api.version>
<version.java>11</version.java>
<scala.version>2.13.11</scala.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BusinessKnowledgeEvaluator(
def eval(bkm: ParsedBusinessKnowledgeModel,
context: EvalContext): Either[Failure, Val] = {

evalRequiredKnowledge(bkm.requiredBkms, context)
evalRequiredKnowledge(bkm.requiredBkms.map(_.resolve()), context)
.flatMap(functions => {

val evalContext =
Expand All @@ -47,7 +47,7 @@ class BusinessKnowledgeEvaluator(
bkm: ParsedBusinessKnowledgeModel,
context: EvalContext): Either[Failure, (String, ValFunction)] = {

evalRequiredKnowledge(bkm.requiredBkms, context).map(functions => {
evalRequiredKnowledge(bkm.requiredBkms.map(_.resolve()), context).map(functions => {

val evalContext = context.copy(variables = context.variables ++ functions,
currentElement = bkm)
Expand Down
71 changes: 34 additions & 37 deletions src/main/scala/org/camunda/dmn/evaluation/DecisionEvaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ package org.camunda.dmn.evaluation
import org.camunda.dmn.DmnEngine._
import org.camunda.dmn.FunctionalHelper._
import org.camunda.feel.syntaxtree.{Val, ValContext, ValFunction}
import org.camunda.dmn.parser.{ParsedBusinessKnowledgeModel, ParsedDecision, ParsedDecisionLogic}
import org.camunda.dmn.parser.{
ParsedBusinessKnowledgeModel,
ParsedBusinessKnowledgeModelReference,
ParsedDecision,
ParsedDecisionReference,
ParsedDecisionLogic,
ParsedDecisionLogicContainerReference}
import org.camunda.feel.context.Context.StaticContext

class DecisionEvaluator(
Expand All @@ -42,38 +48,10 @@ class DecisionEvaluator(
evalRequiredKnowledge(decision.requiredBkms, context)
.flatMap(functions => {

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(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 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
++ embeddedDecisions ++ importedDecisions
++ embeddedFunctions ++ importedFunctions,
currentElement = decision)
++ decisionResults ++ functions,
currentElement = decision)

eval(decision.logic, decisionEvaluationContext)
.flatMap(
Expand All @@ -87,17 +65,36 @@ class DecisionEvaluator(
}

private def evalRequiredDecisions(
requiredDecisions: Iterable[ParsedDecision],
context: EvalContext): Either[Failure, List[(String, Val)]] = {
requiredDecisions: Iterable[ParsedDecisionReference],
context: EvalContext): Either[Failure, List[(String, Val)]] = {
mapEither(requiredDecisions,
(d: ParsedDecision) => evalDecision(d, context))
(decisionRef: ParsedDecisionReference) => evalDecision(decisionRef.resolve(), context)
.map(maybeWrapResult(decisionRef, _)))
}

private def evalRequiredKnowledge(
requiredBkms: Iterable[ParsedBusinessKnowledgeModel],
context: EvalContext): Either[Failure, List[(String, ValFunction)]] = {
requiredBkms: Iterable[ParsedBusinessKnowledgeModelReference],
context: EvalContext): Either[Failure, List[(String, Val)]] = {
mapEither(requiredBkms,
(bkm: ParsedBusinessKnowledgeModel) => evalBkm(bkm, context))
(bkmRef: ParsedBusinessKnowledgeModelReference) => evalBkm(bkmRef.resolve(), context)
.map(maybeWrapResult(bkmRef, _)))
}

private def maybeWrapResult(
reference: ParsedDecisionLogicContainerReference[_], result: (String, Val)) =
reference.importedModelName match {
case Some(importName) =>
val ctx = result._2 match {
case func: ValFunction => StaticContext(
variables = Map.empty,
functions = Map(result._1 -> List(func))
)
case _ => StaticContext(
variables = Map(result._1 -> result._2),
functions = Map.empty
)
}
importName -> ValContext(ctx)
case _ => result
}
}
Loading