1
1
package pl .touk .nussknacker .engine .compile .nodecompilation
2
2
3
- import cats .data .{NonEmptyList , ValidatedNel , Writer }
3
+ import cats .data .{NonEmptyList , Validated , ValidatedNel , Writer }
4
4
import cats .data .Validated .{invalid , valid , Invalid , Valid }
5
5
import cats .implicits ._
6
6
import pl .touk .nussknacker .engine .{api , compiledgraph , RuntimeMode , ScenarioCompilationDependencies }
@@ -21,7 +21,10 @@ import pl.touk.nussknacker.engine.compile.{
21
21
FragmentSourceWithTestWithParametersSupportFactory ,
22
22
NodeValidationExceptionHandler
23
23
}
24
- import pl .touk .nussknacker .engine .compile .nodecompilation .NodeCompiler .NodeCompilationResult
24
+ import pl .touk .nussknacker .engine .compile .nodecompilation .NodeCompiler .{
25
+ EnricherCompilationResult ,
26
+ NodeCompilationResult
27
+ }
25
28
import pl .touk .nussknacker .engine .compiledgraph .{CompiledParameter , TypedParameter }
26
29
import pl .touk .nussknacker .engine .definition .component .ComponentDefinitionWithImplementation
27
30
import pl .touk .nussknacker .engine .definition .component .dynamic .{
@@ -60,6 +63,11 @@ object NodeCompiler {
60
63
61
64
}
62
65
66
+ final case class EnricherCompilationResult (
67
+ serviceRef : compiledgraph.service.ServiceRef ,
68
+ mockOutputExpression : Option [CompiledExpression ]
69
+ )
70
+
63
71
}
64
72
65
73
class NodeCompiler (
@@ -374,8 +382,29 @@ class NodeCompiler(
374
382
def compileEnricher (n : Enricher , ctx : ValidationContext , outputVar : OutputVar )(
375
383
implicit nodeId : NodeId ,
376
384
scenarioCompilationDependencies : ScenarioCompilationDependencies
377
- ): NodeCompilationResult [compiledgraph.service.ServiceRef ] = {
378
- compileService(n.service, ctx, Some (outputVar))
385
+ ): NodeCompilationResult [EnricherCompilationResult ] = {
386
+ val serviceCompilationResult = compileService(n.service, ctx, Some (outputVar))
387
+
388
+ val expressionCompilationResult = n.mockExpression match {
389
+ case Some (expression) =>
390
+ compileEnricherMockExpression(expression, serviceCompilationResult.expressionType.getOrElse(Unknown ), ctx)
391
+ .map(Some (_))
392
+ case None => Validated .validNel(None )
393
+ }
394
+ serviceCompilationResult.copy(
395
+ compiledObject = serviceCompilationResult.compiledObject.product(expressionCompilationResult).map {
396
+ case (service, mockedExpression) =>
397
+ EnricherCompilationResult (service, mockedExpression)
398
+ }
399
+ )
400
+ }
401
+
402
+ private def compileEnricherMockExpression (expression : Expression , expectedType : TypingResult , ctx : ValidationContext )(
403
+ implicit nodeId : NodeId
404
+ ): ValidatedNel [ProcessCompilationError , CompiledExpression ] = {
405
+ expressionCompiler
406
+ .compile(expression, None , ctx, expectedType)
407
+ .map(_.expression)
379
408
}
380
409
381
410
private def compileService (n : ServiceRef , validationContext : ValidationContext , outputVar : Option [OutputVar ])(
0 commit comments