Skip to content

Commit

Permalink
[NU-1836] Implement generic conversion extension methods: is, to and …
Browse files Browse the repository at this point in the history
…toOrNull

# Conflicts:
#	engine/flink/management/dev-model/src/test/resources/extractedTypes/devCreator.json
#	engine/flink/tests/src/test/resources/extractedTypes/defaultModel.json
#	scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/extension/ExtensionMethodsSpec.scala
  • Loading branch information
Łukasz Bigorajski committed Oct 24, 2024
1 parent bad9782 commit 284c362
Show file tree
Hide file tree
Showing 20 changed files with 2,408 additions and 1,067 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object typing {
fields.map { case (fieldName, fieldType) =>
fieldName -> fieldType.withoutValue
},
runtimeObjType,
runtimeObjType.withoutValue,
additionalInfo
)

Expand Down Expand Up @@ -206,7 +206,7 @@ object typing {
case class TypedClass private[typing] (klass: Class[_], params: List[TypingResult]) extends SingleTypingResult {
override val valueOpt: None.type = None

override def withoutValue: TypedClass = this
override def withoutValue: TypedClass = TypedClass(klass, params.map(_.withoutValue))

override def display: String = {
val className = if (klass.isArray) "List" else ReflectUtils.simpleNameWithoutSuffix(runtimeObjType.klass)
Expand Down Expand Up @@ -353,8 +353,9 @@ object typing {
supertypeOfElementTypes(javaList.asScala.toList).withoutValue,
javaList
)
case set: java.util.Set[_] =>
genericTypeClass(classOf[java.util.Set[_]], List(supertypeOfElementTypes(set.asScala.toList)))
case typeFromInstance: TypedFromInstance => typeFromInstance.typingResult
// TODO: handle more types, for example Set
case other =>
Typed(other.getClass) match {
case typedClass: TypedClass =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,17 +780,11 @@ class ExpressionSuggesterSpec
}

test("should suggest parameters for casts methods") {
spelSuggestionsFor("#unknown.canCastTo('')", column = 20) should contain theSameElementsAs List(
suggestion("String", Typed[String]),
suggestion("Duration", Typed[Duration]),
suggestion("LocalDateTime", Typed[LocalDateTime]),
suggestion("Map", Typed[java.util.Map[_, _]]),
suggestion("A", Typed[A]),
suggestion("AA", Typed[AA]),
suggestion("B", Typed[B]),
suggestion("C", Typed[C]),
suggestion("Util", Typed[Util]),
suggestion("WithList", Typed[WithList]),
spelSuggestionsFor("#unknown.to('')", column = 13) should contain theSameElementsAs List(

Check failure on line 783 in designer/server/src/test/scala/pl/touk/nussknacker/ui/api/ExpressionSuggesterSpec.scala

View workflow job for this annotation

GitHub Actions / REPORT-BackendTests-2.13

pl.touk.nussknacker.ui.api.ExpressionSuggesterSpec ► should suggest parameters for casts methods

Failed test found in: designer/server/target/test-reports/TEST-pl.touk.nussknacker.ui.api.ExpressionSuggesterSpec.xml Error: org.scalatest.exceptions.TestFailedException: List(ExpressionSuggestion("BigDecimal", TypedClass(class java.math.BigDecimal, List()), false, None, List()), ExpressionSuggestion("Boolean", TypedClass(class java.lang.Boolean, List()), false, None, List()), ExpressionSuggestion("Double", TypedClass(class java.lang.Double, List()), false, None, List()), ExpressionSuggestion("List", TypedClass(interface java.util.List, List(Unknown)), false, None, List()), ExpressionSuggestion("Long", TypedClass(class java.lang.Long, List()), false, None, List()), ExpressionSuggestion("Map", TypedClass(interface java.util.Map, List(Unknown, Unknown)), false, None, List()), ExpressionSuggestion("String", TypedClass(class java.lang.String, List()), false, None, List())) did not contain the same elements as List(ExpressionSuggestion("BigDecimal", TypedClass(class java.math.BigDecimal, List()), false, None, List()), ExpressionSuggestion("Boolean", TypedClass(class java.lang.Boolean, List()), false, None, List()), ExpressionSuggestion("Double", TypedClass(class java.lang.Double, List()), false, None, List()), ExpressionSuggestion("Long", TypedClass(class java.lang.Long, List()), false, None, List()))
Raw output
org.scalatest.exceptions.TestFailedException: List(ExpressionSuggestion("BigDecimal", TypedClass(class java.math.BigDecimal, List()), false, None, List()), ExpressionSuggestion("Boolean", TypedClass(class java.lang.Boolean, List()), false, None, List()), ExpressionSuggestion("Double", TypedClass(class java.lang.Double, List()), false, None, List()), ExpressionSuggestion("List", TypedClass(interface java.util.List, List(Unknown)), false, None, List()), ExpressionSuggestion("Long", TypedClass(class java.lang.Long, List()), false, None, List()), ExpressionSuggestion("Map", TypedClass(interface java.util.Map, List(Unknown, Unknown)), false, None, List()), ExpressionSuggestion("String", TypedClass(class java.lang.String, List()), false, None, List())) did not contain the same elements as List(ExpressionSuggestion("BigDecimal", TypedClass(class java.math.BigDecimal, List()), false, None, List()), ExpressionSuggestion("Boolean", TypedClass(class java.lang.Boolean, List()), false, None, List()), ExpressionSuggestion("Double", TypedClass(class java.lang.Double, List()), false, None, List()), ExpressionSuggestion("Long", TypedClass(class java.lang.Long, List()), false, None, List()))
	at org.scalatest.matchers.MatchersHelper$.indicateFailure(MatchersHelper.scala:392)
	at org.scalatest.matchers.dsl.ResultOfContainWord.theSameElementsAs(ResultOfContainWord.scala:205)
	at pl.touk.nussknacker.ui.api.ExpressionSuggesterSpec.$anonfun$new$72(ExpressionSuggesterSpec.scala:783)
	at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
	at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
	at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
	at org.scalatest.Transformer.apply(Transformer.scala:22)
	at org.scalatest.Transformer.apply(Transformer.scala:20)
	at org.scalatest.funsuite.AnyFunSuiteLike$$anon$1.apply(AnyFunSuiteLike.scala:226)
	at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
	at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
	at org.scalatest.funsuite.AnyFunSuite.withFixture(AnyFunSuite.scala:1564)
	at org.scalatest.funsuite.AnyFunSuiteLike.invokeWithFixture$1(AnyFunSuiteLike.scala:224)
	at org.scalatest.funsuite.AnyFunSuiteLike.$anonfun$runTest$1(AnyFunSuiteLike.scala:236)
	at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
	at org.scalatest.funsuite.AnyFunSuiteLike.runTest(AnyFunSuiteLike.scala:236)
	at org.scalatest.funsuite.AnyFunSuiteLike.runTest$(AnyFunSuiteLike.scala:218)
	at org.scalatest.funsuite.AnyFunSuite.runTest(AnyFunSuite.scala:1564)
	at org.scalatest.funsuite.AnyFunSuiteLike.$anonfun$runTests$1(AnyFunSuiteLike.scala:269)
	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:413)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:396)
	at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:475)
	at org.scalatest.funsuite.AnyFunSuiteLike.runTests(AnyFunSuiteLike.scala:269)
	at org.scalatest.funsuite.AnyFunSuiteLike.runTests$(AnyFunSuiteLike.scala:268)
	at org.scalatest.funsuite.AnyFunSuite.runTests(AnyFunSuite.scala:1564)
	at org.scalatest.Suite.run(Suite.scala:1114)
	at org.scalatest.Suite.run$(Suite.scala:1096)
	at org.scalatest.funsuite.AnyFunSuite.org$scalatest$funsuite$AnyFunSuiteLike$$super$run(AnyFunSuite.scala:1564)
	at org.scalatest.funsuite.AnyFunSuiteLike.$anonfun$run$1(AnyFunSuiteLike.scala:273)
	at org.scalatest.SuperEngine.runImpl(Engine.scala:535)
	at org.scalatest.funsuite.AnyFunSuiteLike.run(AnyFunSuiteLike.scala:273)
	at org.scalatest.funsuite.AnyFunSuiteLike.run$(AnyFunSuiteLike.scala:272)
	at org.scalatest.funsuite.AnyFunSuite.run(AnyFunSuite.scala:1564)
	at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:321)
	at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:517)
	at sbt.TestRunner.runTest$1(TestFramework.scala:153)
	at sbt.TestRunner.run(TestFramework.scala:168)
	at sbt.TestFramework$$anon$3$$anonfun$$lessinit$greater$1.$anonfun$apply$1(TestFramework.scala:336)
	at sbt.TestFramework$.sbt$TestFramework$$withContextLoader(TestFramework.scala:296)
	at sbt.TestFramework$$anon$3$$anonfun$$lessinit$greater$1.apply(TestFramework.scala:336)
	at sbt.TestFramework$$anon$3$$anonfun$$lessinit$greater$1.apply(TestFramework.scala:336)
	at sbt.TestFunction.apply(TestFramework.scala:348)
	at sbt.Tests$.processRunnable$1(Tests.scala:475)
	at sbt.Tests$.$anonfun$makeSerial$1(Tests.scala:481)
	at sbt.std.Transform$$anon$3.$anonfun$apply$2(Transform.scala:47)
	at sbt.std.Transform$$anon$4.work(Transform.scala:69)
	at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
	at sbt.Execute.work(Execute.scala:292)
	at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
	at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
suggestion("BigDecimal", Typed[java.math.BigDecimal]),
suggestion("Boolean", Typed[java.lang.Boolean]),
suggestion("Double", Typed[java.lang.Double]),
suggestion("Long", Typed[java.lang.Long]),
)
}

Expand Down
17 changes: 9 additions & 8 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
* [#6750](https://github.com/TouK/nussknacker/pull/6750) Add varargs to `#COLLECTION.concat` and `#COLLECTION.merge`.
* [#6778](https://github.com/TouK/nussknacker/pull/6778) SpeL: check for methods if a property for a given name does not exist.
* [#6769](https://github.com/TouK/nussknacker/pull/6769) Added possibility to choose presets and define lists for Long typed parameter inputs in fragments.
* [#6807](https://github.com/TouK/nussknacker/pull/6807) Add conversion functions to primitives to: `#CONV`:
* toNumberOrNull
* toString
* [#6807](https://github.com/TouK/nussknacker/pull/6807) Add `toNumberOrNull` conversion function, to `#CONV`.
* [#6995](https://github.com/TouK/nussknacker/pull/6995) Add `toJson` and `toJsonString` conversions (in the `#CONV` helper)
* [#6995](https://github.com/TouK/nussknacker/pull/6995) Add `#BASE64` helper to decode/encode Base64 values
* [#6826](https://github.com/TouK/nussknacker/pull/6826) Security fix: added validation of expression used inside
Expand All @@ -59,16 +57,19 @@
* [#6925](https://github.com/TouK/nussknacker/pull/6925) Fix situation when preset labels were presented as `null` when node didn't pass the validation.
* [#6935](https://github.com/TouK/nussknacker/pull/6935) Spel: Scenario labels added to meta variable - `#meta.scenarioLabels`
* [#6952](https://github.com/TouK/nussknacker/pull/6952) Improvement: TypeInformation support for scala.Option
* [#6840](https://github.com/TouK/nussknacker/pull/6840) Introduce canCastTo, castTo and castToOrNull extension methods in SpeL.
* [#6840](https://github.com/TouK/nussknacker/pull/6840) Introduce is, to and toOrNull conversion extension methods in
SpeL.
* [#6974](https://github.com/TouK/nussknacker/pull/6974) Add SpeL suggestions for cast methods parameter.
* [#6958](https://github.com/TouK/nussknacker/pull/6958) Add message size limit in the "Kafka" exceptionHandler
* [#6988](https://github.com/TouK/nussknacker/pull/6988) Remove unused API classes: `MultiMap`, `TimestampedEvictableStateFunction`
* [#7000](https://github.com/TouK/nussknacker/pull/7000) Show all possible options for dictionary editor on open.
* [#7061](https://github.com/TouK/nussknacker/pull/7061) SpeL: add conversion to primitives extension methods:
* isBoolean/toBoolean/toBooleanOrNull
* isLong/toLong/toLongOrNull
* isDouble/toDouble/toDoubleOrNull
* isBigDecimal/toBigDecimal/toBigDecimalOrNull
* isBoolean/toBoolean/toBooleanOrNull
* isLong/toLong/toLongOrNull
* isDouble/toDouble/toDoubleOrNull
* isBigDecimal/toBigDecimal/toBigDecimalOrNull
* isList/toList/toListOrNull - a collection or unknown collection can be converted to a list.
* isMap/toMap/toMapOrNull - the list of key-value pairs or unknown map can be converted to a map.

## 1.17

Expand Down
Loading

0 comments on commit 284c362

Please sign in to comment.