1
1
package pl .touk .nussknacker .engine .compile
2
2
3
- import cats .data .Validated .valid
4
- import com .typesafe .scalalogging .LazyLogging
5
- import pl .touk .nussknacker .engine .api .{JobData , NodeId }
3
+ import cats .data .{NonEmptyList , Validated }
4
+ import pl .touk .nussknacker .engine .api .NodeId
6
5
import pl .touk .nussknacker .engine .api .context ._
7
- import pl .touk .nussknacker .engine .api .context .ProcessCompilationError .MissingParameters
8
6
import pl .touk .nussknacker .engine .api .definition .{Parameter , Validator }
9
7
import pl .touk .nussknacker .engine .api .parameter .ParameterName
10
8
import pl .touk .nussknacker .engine .compiledgraph .TypedParameter
11
9
import pl .touk .nussknacker .engine .expression .parse .{TypedExpression , TypedExpressionMap }
12
- import pl .touk .nussknacker .engine .graph .evaluatedparam .{Parameter => NodeParameter }
13
10
import pl .touk .nussknacker .engine .graph .expression .Expression
14
11
15
- object Validations extends LazyLogging {
12
+ object Validations {
16
13
17
14
import cats .data .ValidatedNel
18
15
import cats .implicits ._
19
16
20
- def validateRedundantAndMissingParameters (
21
- parameterDefinitions : List [Parameter ],
22
- parameters : List [NodeParameter ]
23
- )(
24
- implicit nodeId : NodeId ,
25
- jobData : JobData
26
- ): ValidatedNel [PartSubGraphCompilationError , Unit ] = {
27
- val definedParamNamesSet = parameterDefinitions.map(_.name).toSet
28
- val usedParamNamesSet = parameters.map(_.name).toSet
29
-
30
- checkRedundancyAndWarnIfNeeded(definedParamNamesSet, usedParamNamesSet)
31
- validateMissingness(definedParamNamesSet, usedParamNamesSet)
32
- }
33
-
34
17
def validateWithCustomValidators (
35
18
parameters : List [(TypedParameter , Parameter )],
36
19
paramValidatorsMap : Map [ParameterName , ValidatedNel [PartSubGraphCompilationError , List [Validator ]]]
37
20
)(
38
21
implicit nodeId : NodeId
39
- ): ValidatedNel [PartSubGraphCompilationError , List [( TypedParameter , Parameter )] ] =
22
+ ): ValidatedNel [PartSubGraphCompilationError , Unit ] =
40
23
parameters
41
24
.map { case (typedParam, _) =>
42
25
paramValidatorsMap(typedParam.name).andThen(validator => validate(validator, typedParam))
43
26
}
44
27
.sequence
45
- .map(_ => parameters)
46
-
47
- private def checkRedundancyAndWarnIfNeeded (
48
- definedParamNamesSet : Set [ParameterName ],
49
- usedParamNamesSet : Set [ParameterName ]
50
- )(
51
- implicit nodeId : NodeId ,
52
- jobData : JobData
53
- ): Unit = {
54
- val redundantParams = usedParamNamesSet.diff(definedParamNamesSet)
55
- if (redundantParams.nonEmpty) {
56
- logger.warn(
57
- s " Scenario [ ${jobData.metaData.name}] node [ $nodeId] compilation warning. " +
58
- s " Found redundant parameters: ${redundantParams.toList.map(_.value).sorted.mkString(" , " )}. They will be skipped. "
59
- )
60
- }
61
- }
62
-
63
- private def validateMissingness (definedParamNamesSet : Set [ParameterName ], usedParamNamesSet : Set [ParameterName ])(
64
- implicit nodeId : NodeId
65
- ) = {
66
- val notUsedParams = definedParamNamesSet.diff(usedParamNamesSet)
67
- if (notUsedParams.nonEmpty) MissingParameters (notUsedParams).invalidNel[Unit ] else valid(())
68
- }
69
-
70
- def validate [T ](validators : List [Validator ], parameter : (TypedParameter , T ))(
71
- implicit nodeId : NodeId
72
- ): ValidatedNel [PartSubGraphCompilationError , (TypedParameter , T )] = {
73
- validate(validators, parameter._1).map((_, parameter._2))
74
- }
28
+ .map(_ => ())
75
29
76
30
def validate (validators : List [Validator ], parameter : TypedParameter )(
77
31
implicit nodeId : NodeId
78
- ): ValidatedNel [ PartSubGraphCompilationError , TypedParameter ] = {
32
+ ): Validated [ NonEmptyList [ PartSubGraphCompilationError ], Unit ] = {
79
33
val paramWithValueAndExpressionList = parameter.typedValue match {
80
34
case te : TypedExpression => List ((parameter.name, te.typingInfo.typingResult.valueOpt, te.expression))
81
35
case tem : TypedExpressionMap =>
@@ -95,7 +49,7 @@ object Validations extends LazyLogging {
95
49
}
96
50
}
97
51
.sequence
98
- .map(_ => parameter )
52
+ .map(_ => () )
99
53
}
100
54
101
55
}
0 commit comments