-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NU-1579] decision table component - labels change (#5824)
- Loading branch information
1 parent
ac006b7
commit b7cc9ac
Showing
9 changed files
with
129 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...la/pl/touk/nussknacker/defaultmodel/migrations/DecisionTableParameterNamesMigration.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package pl.touk.nussknacker.defaultmodel.migrations | ||
|
||
import pl.touk.nussknacker.engine.api.MetaData | ||
import pl.touk.nussknacker.engine.api.parameter.ParameterName | ||
import pl.touk.nussknacker.engine.graph.evaluatedparam.Parameter | ||
import pl.touk.nussknacker.engine.graph.node | ||
import pl.touk.nussknacker.engine.graph.node.Enricher | ||
import pl.touk.nussknacker.engine.graph.service.ServiceRef | ||
import pl.touk.nussknacker.engine.migration.NodeMigration | ||
|
||
object DecisionTableParameterNamesMigration extends NodeMigration { | ||
|
||
override val description: String = "Change Decision Table component parameter names" | ||
|
||
override def migrateNode(metaData: MetaData): PartialFunction[node.NodeData, node.NodeData] = { | ||
case enricher @ Enricher(_, service @ ServiceRef(_, params), _, _) => | ||
enricher.copy(service = service.copy(parameters = renameParams(params))) | ||
} | ||
|
||
private def renameParams(params: List[Parameter]) = { | ||
params.map { param => | ||
param.name.value match { | ||
case "Basic Decision Table" => param.copy(name = ParameterName("Decision Table")) | ||
case "Expression" => param.copy(name = ParameterName("Filtering expression")) | ||
case _ => param | ||
} | ||
} | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...l/touk/nussknacker/defaultModel/migrations/DecisionTableParameterNamesMigrationSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package pl.touk.nussknacker.defaultModel.migrations | ||
|
||
import org.scalatest.freespec.AnyFreeSpecLike | ||
import org.scalatest.matchers.should.Matchers | ||
import pl.touk.nussknacker.defaultmodel.migrations.DecisionTableParameterNamesMigration | ||
import pl.touk.nussknacker.engine.api.{MetaData, StreamMetaData} | ||
import pl.touk.nussknacker.engine.api.parameter.ParameterName | ||
import pl.touk.nussknacker.engine.graph.node.Enricher | ||
import pl.touk.nussknacker.engine.graph.service.ServiceRef | ||
import pl.touk.nussknacker.engine.graph.evaluatedparam.Parameter | ||
import pl.touk.nussknacker.engine.graph.expression.Expression | ||
import pl.touk.nussknacker.engine.spel.Implicits.asSpelExpression | ||
|
||
class DecisionTableParameterNamesMigrationSpec extends AnyFreeSpecLike with Matchers { | ||
|
||
"DecisionTableParameterNamesMigration should be applied" in { | ||
val metaData = MetaData("test", StreamMetaData(Some(1))) | ||
val beforeMigration = Enricher( | ||
id = "decision-table", | ||
service = ServiceRef( | ||
id = "decision-table-service", | ||
parameters = List( | ||
Parameter(ParameterName("Basic Decision Table"), exampleDecisionTableJson), | ||
Parameter(ParameterName("Expression"), "#ROW['age'] > #input.minAge && #ROW['DoB'] != null"), | ||
) | ||
), | ||
output = "Output", | ||
) | ||
val expectedAfterMigration = Enricher( | ||
id = "decision-table", | ||
service = ServiceRef( | ||
id = "decision-table-service", | ||
parameters = List( | ||
Parameter(ParameterName("Decision Table"), exampleDecisionTableJson), | ||
Parameter(ParameterName("Filtering expression"), "#ROW['age'] > #input.minAge && #ROW['DoB'] != null"), | ||
) | ||
), | ||
output = "Output", | ||
) | ||
|
||
val migrated = DecisionTableParameterNamesMigration.migrateNode(metaData)(beforeMigration) | ||
|
||
migrated shouldBe expectedAfterMigration | ||
} | ||
|
||
private lazy val exampleDecisionTableJson = Expression.tabularDataDefinition { | ||
s"""{ | ||
| "columns": [ | ||
| { "name": "name", "type": "java.lang.String" }, | ||
| { "name": "age", "type": "java.lang.Integer" }, | ||
| { "name": "DoB", "type": "java.time.LocalDate" } | ||
| ], | ||
| "rows": [ | ||
| [ "John", "39", null ], | ||
| [ "Lisa", "21", "2003-01-13" ], | ||
| [ "Mark", "54", "1970-12-30" ] | ||
| ] | ||
|}""".stripMargin | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters