Skip to content

Commit

Permalink
Integer dictionary support in fragment inputs (#7341)
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkp96 committed Dec 18, 2024
1 parent ae7bee7 commit 7b050ef
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function isPermittedTypeVariant(item: FragmentInputParameter): item is Pe
resolveRefClazzName(item.typ.refClazzName) === "String",
resolveRefClazzName(item.typ.refClazzName) === "Boolean",
resolveRefClazzName(item.typ.refClazzName) === "Long",
resolveRefClazzName(item.typ.refClazzName) === "Integer",
].includes(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,20 @@ object PrettyValidationErrors {
)
case UnsupportedFixedValuesType(paramName, typ, _) =>
node(
message = s"Fixed values list can only be be provided for type String or Boolean, found: $typ",
message = s"Fixed values list can only be be provided for type String, Integer, Long or Boolean, found: $typ",
description = "Please check component definition",
paramName = Some(qualifiedParamFieldName(paramName = paramName, subFieldName = Some(TypFieldName)))
)
case UnsupportedDictParameterEditorType(paramName, typ, _) =>
node(
s"Dictionary parameter editor can only be used for parameters of type String, Long or Boolean, found: $typ",
"Please check component definition",
message =
s"Dictionary parameter editor can only be used for parameters of type String, Integer, Long or Boolean, found: $typ",
description = "Please check component definition",
paramName = Some(qualifiedParamFieldName(paramName = paramName, subFieldName = Some(TypFieldName)))
)
case EmptyFixedListForRequiredField(paramName, _) =>
node(
s"Non-empty fixed list of values have to be declared for required parameter",
message = s"Non-empty fixed list of values have to be declared for required parameter",
description = "Please add a value to the list of possible values",
paramName = Some(qualifiedParamFieldName(paramName = paramName, subFieldName = Some(InputModeFieldName)))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ class DictApiHttpServiceSpec
.post(s"$nuDesignerHttpAddress/api/processDefinitionData/${Streaming.stringify}/dicts")
.Then()
.statusCode(200)
.equalsJsonBody("[]")

.equalsJsonBody(
s"""[
| {
| "id" : "integer_dict",
| "label" : "integer_dict"
| }
|]""".stripMargin
)
}

"return proper list for expected type String" in {
Expand Down Expand Up @@ -83,6 +89,10 @@ class DictApiHttpServiceSpec
.statusCode(200)
.equalsJsonBody(
s"""[
| {
| "id": "integer_dict",
| "label": "integer_dict"
| },
| {
| "id" : "long_dict",
| "label" : "long_dict"
Expand All @@ -91,7 +101,7 @@ class DictApiHttpServiceSpec
)
}

"return proper list for expected type BigDecimal" in {
"return proper list for expected type BigInteger" in {
given()
.when()
.basicAuthAllPermUser()
Expand All @@ -107,6 +117,11 @@ class DictApiHttpServiceSpec
.statusCode(200)
.equalsJsonBody(
s"""[
|
| {
| "id": "integer_dict",
| "label": "integer_dict"
| },
| {
| "id" : "long_dict",
| "label" : "long_dict"
Expand Down
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Improved scenario state management to include information about current and deployed versions and allow more customization
* [#7184](https://github.com/TouK/nussknacker/pull/7184) Improve Nu Designer API notifications endpoint, to include events related to currently displayed scenario
* [#7323](https://github.com/TouK/nussknacker/pull/7323) Improve Periodic DeploymentManager db queries
* [#7341](https://github.com/TouK/nussknacker/pull/7341) Added possibility to choose presets and define lists for Integer typed parameter inputs in fragments.

### 1.18.2 (Not released)
* [#7324](https://github.com/TouK/nussknacker/pull/7324) Fix: Passing Flink Job Global Params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class DevProcessConfigCreator extends ProcessConfigCreator {
BusinessConfigDictionary.id -> BusinessConfigDictionary.definition,
BooleanDictionary.id -> BooleanDictionary.definition, // not available through global variables, but still available through DictParameterEditor
LongDictionary.id -> LongDictionary.definition, // not available through global variables, but still available through DictParameterEditor
IntegerDictionary.id -> IntegerDictionary.definition // not available through global variables, but still available through DictParameterEditor
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package pl.touk.nussknacker.engine.management.sample.dict

import pl.touk.nussknacker.engine.api.dict.embedded.EmbeddedDictDefinition
import pl.touk.nussknacker.engine.api.dict.{DictDefinition, DictInstance, ReturningKeyWithoutTransformation}
import pl.touk.nussknacker.engine.api.typed.typing
import pl.touk.nussknacker.engine.api.typed.typing.Typed

object IntegerDictionary {
val id: String = "integer_dict"

val definition: DictDefinition = new EmbeddedDictDefinition with ReturningKeyWithoutTransformation {
override def valueType(dictId: String): typing.SingleTypingResult = Typed.typedClass[java.lang.Integer]

override def labelByKey: Map[String, String] = Map(
"-2147483648" -> "large (negative) number",
"42" -> "small number",
"2147483647" -> "big number"
)

}

val instance: DictInstance = DictInstance(id, definition)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ import scala.util.Try
object FragmentParameterValidator {

val permittedTypesForEditors: List[FragmentClazzRef] = List(
FragmentClazzRef[java.lang.Boolean],
FragmentClazzRef[String],
FragmentClazzRef[java.lang.Boolean],
FragmentClazzRef[java.lang.Integer],
FragmentClazzRef[java.lang.Long],
FragmentClazzRef("String"),
FragmentClazzRef("Boolean"),
FragmentClazzRef("Long")
FragmentClazzRef("Integer"),
FragmentClazzRef("Long"),
)

}
Expand Down

0 comments on commit 7b050ef

Please sign in to comment.