Skip to content

Commit 997002a

Browse files
committed
repl: Use the new FEEL API
1 parent 2b64ab9 commit 997002a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

feel-repl.sc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// import the FEEL engine library
2-
import $ivy.`org.camunda.feel:feel-engine:1.18.0`, org.camunda.feel._
2+
import $ivy.`org.camunda.feel:feel-engine:1.18.0`, org.camunda.feel._, org.camunda.feel.api._
33

44
// import a logging library
55
import $ivy.`org.apache.logging.log4j:log4j-slf4j-impl:2.14.0`,
@@ -9,26 +9,25 @@ org.apache.logging.log4j.Level
99
Configurator.setRootLevel(Level.WARN)
1010

1111
// initialize the FEEL engine
12-
val feelEngine = new FeelEngine()
12+
val feelEngine = FeelEngineBuilder.create().build()
1313

1414
val feelEngineVersion = classOf[FeelEngine].getPackage.getImplementationVersion
1515

1616
// define a shortcut function for evaluation
1717
def feel(expression: String, context: Map[String, Any] = Map.empty): Unit = {
18-
val evalResult = feelEngine.evalExpression(expression, context)
18+
val evalResult = feelEngine.evaluateExpression(expression, context)
1919
printResult(evalResult)
2020
}
2121

22-
def feel(expression: String, jsonContext: String): Any = {
22+
def feel(expression: String, jsonContext: String): Unit = {
2323
parseJsonObject(jsonContext)
2424
.map(context => feel(expression, context))
2525
}
2626

2727
def unaryTests(expression: String,
2828
inputValue: Any,
2929
context: Map[String, Any] = Map.empty): Unit = {
30-
val contextWithInputValue = context + (FeelEngine.UnaryTests.defaultInputVariable -> inputValue)
31-
val evalResult = feelEngine.evalUnaryTests(expression, contextWithInputValue)
30+
val evalResult = feelEngine.evaluateUnaryTests(expression, inputValue, context)
3231
printResult(evalResult)
3332
}
3433

@@ -41,16 +40,17 @@ def unaryTests(expression: String,
4140
}
4241
}
4342

44-
private def printResult(evalResult: Either[FeelEngine.Failure, Any]): Unit = {
45-
evalResult match {
46-
case Right(result) => println(fansi.Color.LightGreen(s"> $result"))
47-
case Left(failure) => println(fansi.Color.LightRed(s"> $failure"))
43+
private def printResult(evalResult: EvaluationResult): Unit = {
44+
if (evalResult.isSuccess) {
45+
println(fansi.Color.LightGreen(s"> ${evalResult.result}"))
46+
} else {
47+
println(fansi.Color.LightRed(s"> ${evalResult.failure}"))
4848
}
4949
}
5050

5151
private def parseJsonObject(json: String): Option[Map[String, Any]] = {
5252
parseJson(json) match {
53-
case objectValue: Map[String, Any] => Some(objectValue)
53+
case objectValue: Map[_,_] => Some(objectValue.asInstanceOf[Map[String, Any]])
5454
case otherValue =>
5555
println(
5656
fansi.Color.LightRed(

0 commit comments

Comments
 (0)