Skip to content

Commit

Permalink
renames and remove unused def
Browse files Browse the repository at this point in the history
  • Loading branch information
mslabek committed Nov 18, 2024
1 parent b62efde commit a7c4ee6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ object LazyParameter {
sealed trait TemplateExpressionPart

object TemplateExpressionPart {
case class NonTemplatedPart(value: String) extends TemplateExpressionPart
case class Literal(value: String) extends TemplateExpressionPart

trait TemplatedPart extends TemplateExpressionPart {
trait Placeholder extends TemplateExpressionPart {
val evaluate: Evaluate[String]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import pl.touk.nussknacker.engine.definition.component.parameter.defaults.Editor
import pl.touk.nussknacker.engine.expression.ExpressionEvaluator
import pl.touk.nussknacker.engine.graph.expression.Expression.Language
import pl.touk.nussknacker.engine.spel.SpelExpression
import pl.touk.nussknacker.engine.spel.SpelTemplateSubexpression.{NonTemplatedValue, TemplatedExpression}
import pl.touk.nussknacker.engine.spel.SpelTemplateExpressionPart.{Literal, Placeholder}

class EvaluableLazyParameter[T <: AnyRef](
compiledParameter: BaseCompiledParameter,
Expand Down Expand Up @@ -40,14 +40,14 @@ class SpelTemplateEvaluableLazyParameter[T <: AnyRef](
expression.templateSubexpressions match {
case Some(subexpressions) =>
val templateParts = subexpressions.map {
case TemplatedExpression(expression) => {
new TemplateExpressionPart.TemplatedPart {
case Placeholder(expression) => {
new TemplateExpressionPart.Placeholder {
override val evaluate: Evaluate[String] = context => {
expressionEvaluator.evaluate[String](expression, "expressionId", nodeId.id, context)(jobData).value
}
}
}
case NonTemplatedValue(value) => TemplateExpressionPart.NonTemplatedPart(value)
case Literal(value) => TemplateExpressionPart.Literal(value)
}
TemplateExpression(templateParts)
case None =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import pl.touk.nussknacker.engine.graph.expression.Expression.Language
import pl.touk.nussknacker.engine.graph.expression.{Expression => GraphExpression}
import pl.touk.nussknacker.engine.spel.SpelExpressionParseError.ExpressionCompilationError
import pl.touk.nussknacker.engine.spel.SpelExpressionParser.{Flavour, Standard}
import pl.touk.nussknacker.engine.spel.SpelTemplateSubexpression.{NonTemplatedValue, TemplatedExpression}
import pl.touk.nussknacker.engine.spel.SpelTemplateExpressionPart.{Literal, Placeholder}
import pl.touk.nussknacker.engine.spel.internal.EvaluationContextPreparer

import scala.util.control.NonFatal
Expand Down Expand Up @@ -81,15 +81,11 @@ class SpelExpressionEvaluationException(val expression: String, val ctxId: Strin
cause = cause
)

sealed trait SpelTemplateSubexpression

object SpelTemplateSubexpression {
final case class NonTemplatedValue(val value: String) extends SpelTemplateSubexpression

final case class TemplatedExpression(expression: SpelExpression) extends SpelTemplateSubexpression {
def evaluate: (Context, Map[String, Any]) => String = expression.evaluate[String]
}
sealed trait SpelTemplateExpressionPart

object SpelTemplateExpressionPart {
final case class Literal(value: String) extends SpelTemplateExpressionPart
final case class Placeholder(expression: SpelExpression) extends SpelTemplateExpressionPart
}

class SpelExpression(
Expand All @@ -104,29 +100,29 @@ class SpelExpression(

override val language: Language = flavour.languageId

def templateSubexpressions: Option[List[SpelTemplateSubexpression]] = {
def createTemplatedExpression(expression: org.springframework.expression.spel.standard.SpelExpression) = {
def templateSubexpressions: Option[List[SpelTemplateExpressionPart]] = {
def createEvaluablePlaceholder(expression: org.springframework.expression.spel.standard.SpelExpression) = {
val parsedTemplateExpr = ParsedSpelExpression(expression.getExpressionString, parsed.parser, expression)
val compiledExpr = new SpelExpression(
parsedTemplateExpr,
typing.Typed[String],
Standard,
evaluationContextPreparer
)
TemplatedExpression(compiledExpr)
Placeholder(compiledExpr)
}
flavour.languageId match {
case Language.SpelTemplate =>
Some(parsed.parsed match {
case compositeExpr: CompositeStringExpression =>
compositeExpr.getExpressions.toList.map {
case lit: LiteralExpression => NonTemplatedValue(lit.getExpressionString)
case lit: LiteralExpression => Literal(lit.getExpressionString)
case spelExpr: org.springframework.expression.spel.standard.SpelExpression =>
createTemplatedExpression(spelExpr)
createEvaluablePlaceholder(spelExpr)
}
case spelExpr: org.springframework.expression.spel.standard.SpelExpression =>
List(createTemplatedExpression(spelExpr))
case litExpr: LiteralExpression => List(NonTemplatedValue(litExpr.getExpressionString))
case singleEvaluableSpelExpr: org.springframework.expression.spel.standard.SpelExpression =>
List(createEvaluablePlaceholder(singleEvaluableSpelExpr))
case singleLiteralExpr: LiteralExpression => List(Literal(singleLiteralExpr.getExpressionString))
case other =>
throw new IllegalArgumentException(s"Unsupported expression type: [${other.getClass.getName}]")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package pl.touk.nussknacker.engine.testcomponents

import pl.touk.nussknacker.engine.api.LazyParameter.TemplateLazyParameter
import pl.touk.nussknacker.engine.api.LazyParameter.TemplateLazyParameter.TemplateExpressionPart.{
NonTemplatedPart,
TemplatedPart
}
import pl.touk.nussknacker.engine.api.LazyParameter.TemplateLazyParameter.TemplateExpressionPart._
import pl.touk.nussknacker.engine.api.{Context, EagerService, NodeId, Params, ServiceInvoker}
import pl.touk.nussknacker.engine.api.context.{OutputVar, ValidationContext}
import pl.touk.nussknacker.engine.api.context.transformation.{
Expand Down Expand Up @@ -67,8 +64,8 @@ object SpelTemplateAstOperationService extends EagerService with SingleInputDyna
.extractValueUnsafe(params)
.asInstanceOf[TemplateLazyParameter[String]]
val result = lazyParam.templateExpression.parts.map {
case NonTemplatedPart(value) => s"[$value]-literal"
case template: TemplatedPart => s"[${template.evaluate(context)}]-templated"
case Literal(value) => s"[$value]-literal"
case template: Placeholder => s"[${template.evaluate(context)}]-templated"
}.mkString
Future.successful(result)
}
Expand Down

0 comments on commit a7c4ee6

Please sign in to comment.