Skip to content

Commit 30758ca

Browse files
author
Łukasz Bigorajski
committed
[NU-1862] Simplify parameters editors API
more API simplification fixes review fixes removed simpleParameter review fixes fix openapi test review fixes part 2 test fixes rebase FE adjustments rebase and test fixes
1 parent 307b203 commit 30758ca

File tree

131 files changed

+1147
-1068
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+1147
-1068
lines changed

common-api/src/main/scala/pl/touk/nussknacker/engine/api/CirceUtil.scala

+19-9
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,34 @@ object CirceUtil {
1818
io.circe.parser.parse(json).flatMap(Decoder[T].decodeJson)
1919

2020
def decodeJson[T: Decoder](json: Array[Byte]): Either[circe.Error, T] =
21-
decodeJson(new String(json, StandardCharsets.UTF_8))
21+
decodeJson(toString(json))
2222

23-
def decodeJsonUnsafe[T: Decoder](json: String): T = unsafe(decodeJson(json))
23+
def decodeJsonUnsafe[T: Decoder](json: String): T = unsafe(decodeJson(json), json)
2424

25-
def decodeJsonUnsafe[T: Decoder](json: String, message: String): T = unsafe(decodeJson(json), message)
25+
def decodeJsonUnsafe[T: Decoder](json: String, message: String): T = unsafe(decodeJson(json), json, message)
2626

27-
def decodeJsonUnsafe[T: Decoder](json: Array[Byte]): T = unsafe(decodeJson(json))
27+
def decodeJsonUnsafe[T: Decoder](json: Array[Byte]): T = {
28+
val jsonString = toString(json)
29+
unsafe(decodeJson(jsonString), jsonString)
30+
}
31+
32+
def decodeJsonUnsafe[T: Decoder](json: Array[Byte], message: String): T = {
33+
val jsonString = toString(json)
34+
unsafe(decodeJson(jsonString), jsonString, message)
35+
}
2836

29-
def decodeJsonUnsafe[T: Decoder](json: Array[Byte], message: String): T = unsafe(decodeJson(json), message)
37+
def decodeJsonUnsafe[T: Decoder](json: Json): T = unsafe(Decoder[T].decodeJson(json), json.asString.getOrElse(""))
3038

31-
def decodeJsonUnsafe[T: Decoder](json: Json): T = unsafe(Decoder[T].decodeJson(json))
39+
def decodeJsonUnsafe[T: Decoder](json: Json, message: String): T =
40+
unsafe(Decoder[T].decodeJson(json), json.asString.getOrElse(""), message)
3241

33-
def decodeJsonUnsafe[T: Decoder](json: Json, message: String): T = unsafe(Decoder[T].decodeJson(json), message)
42+
private def toString(json: Array[Byte]): String =
43+
new String(json, StandardCharsets.UTF_8)
3444

35-
private def unsafe[T](result: Either[circe.Error, T], message: String = "") = result match {
45+
private def unsafe[T](result: Either[circe.Error, T], json: => String, message: String = "") = result match {
3646
case Left(error) =>
3747
throw DecodingError(
38-
s"Failed to decode${if (message.isBlank) "" else s" - $message"}, error: ${error.getMessage}",
48+
s"Failed to decode${if (message.isBlank) "" else s" - $message"}, error: ${error.getMessage}, json: $json",
3949
error
4050
)
4151
case Right(data) => data

common-api/src/main/scala/pl/touk/nussknacker/engine/util/Implicits.scala

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ object Implicits {
8383
accumulator(list, f, Nil)
8484
}
8585

86+
def orElseIfEmpty(default: => List[T]): List[T] = list match {
87+
case Nil => default
88+
case _ => list
89+
}
90+
8691
}
8792

8893
}

components-api/src/main/java/pl/touk/nussknacker/engine/api/editor/DualEditor.java

-15
This file was deleted.

components-api/src/main/java/pl/touk/nussknacker/engine/api/editor/DualEditorMode.java

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
package pl.touk.nussknacker.engine.api.editor;
22

33
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Repeatable;
45
import java.lang.annotation.Retention;
56
import java.lang.annotation.RetentionPolicy;
67
import java.lang.annotation.Target;
78
import java.time.temporal.ChronoUnit;
89

910
@Target(ElementType.PARAMETER)
1011
@Retention(RetentionPolicy.RUNTIME)
11-
public @interface SimpleEditor {
12+
@Repeatable(Editors.class)
13+
public @interface Editor {
1214

13-
SimpleEditorType type();
15+
EditorType type();
1416

1517
/**
16-
* This field should be used only with {@link SimpleEditorType#FIXED_VALUES_EDITOR}
18+
* This field should be used only with {@link EditorType#FIXED_VALUES_EDITOR}
1719
*/
1820
LabeledExpression[] possibleValues() default {};
1921

2022
/**
21-
* This field should be used only with {@link SimpleEditorType#DURATION_EDITOR} or {@link SimpleEditorType#PERIOD_EDITOR}
23+
* This field should be used only with {@link EditorType#DURATION_EDITOR} or {@link EditorType#PERIOD_EDITOR}
2224
*/
2325
ChronoUnit[] timeRangeComponents() default {};
2426

2527
/**
26-
* This field should be used only with {@link SimpleEditorType#DICT_EDITOR}
28+
* This field should be used only with {@link EditorType#DICT_EDITOR}
2729
*/
2830
String dictId() default "";
2931
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package pl.touk.nussknacker.engine.api.editor;
22

3-
public enum SimpleEditorType {
3+
public enum EditorType {
44
BOOL_EDITOR,
55
CRON_EDITOR,
66
DATE_EDITOR,
77
DATE_TIME_EDITOR,
88
DURATION_EDITOR,
99
FIXED_VALUES_EDITOR,
1010
PERIOD_EDITOR,
11-
STRING_EDITOR,
1211
TIME_EDITOR,
1312
TEXTAREA_EDITOR,
1413
JSON_EDITOR,
1514
SQL_EDITOR,
1615
SPEL_TEMPLATE_EDITOR,
1716
DICT_EDITOR,
18-
TYPED_TABULAR_DATA_EDITOR
17+
TYPED_TABULAR_DATA_EDITOR,
18+
SPEL_EDITOR,
1919
}

components-api/src/main/java/pl/touk/nussknacker/engine/api/editor/RawEditor.java renamed to components-api/src/main/java/pl/touk/nussknacker/engine/api/editor/Editors.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77

88
@Target(ElementType.PARAMETER)
99
@Retention(RetentionPolicy.RUNTIME)
10-
public @interface RawEditor {
10+
public @interface Editors {
11+
Editor[] value();
1112
}

components-api/src/main/scala/pl/touk/nussknacker/engine/api/component/ComponentConfig.scala

+20-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ package pl.touk.nussknacker.engine.api.component
33
import cats.implicits.catsSyntaxSemigroup
44
import cats.kernel.Semigroup
55
import io.circe.generic.JsonCodec
6-
import pl.touk.nussknacker.engine.api.definition.{ParameterEditor, ParameterValidator, SimpleParameterEditor}
6+
import pl.touk.nussknacker.engine.api.definition.{
7+
ParameterEditor,
8+
ParameterValidator,
9+
StaticParameterEditor,
10+
StaticStringParameterEditor
11+
}
712
import pl.touk.nussknacker.engine.api.parameter.ParameterName
813

914
case class ComponentConfig(
@@ -61,19 +66,31 @@ object ComponentConfig {
6166

6267
case class ParameterConfig(
6368
defaultValue: Option[String],
64-
editor: Option[ParameterEditor],
69+
editors: Option[List[ParameterEditor]],
6570
validators: Option[List[ParameterValidator]],
6671
label: Option[String],
6772
hintText: Option[String]
6873
)
6974

75+
case class StaticParameterConfig(
76+
defaultValue: Option[String],
77+
editor: StaticParameterEditor = StaticStringParameterEditor,
78+
validators: Option[List[ParameterValidator]],
79+
label: Option[String],
80+
hintText: Option[String]
81+
)
82+
83+
object StaticParameterConfig {
84+
val empty: StaticParameterConfig = StaticParameterConfig(None, StaticStringParameterEditor, None, None, None)
85+
}
86+
7087
object ParameterConfig {
7188
val empty: ParameterConfig = ParameterConfig(None, None, None, None, None)
7289
}
7390

7491
@JsonCodec case class ScenarioPropertyConfig(
7592
defaultValue: Option[String],
76-
editor: Option[SimpleParameterEditor],
93+
editor: Option[StaticParameterEditor],
7794
validators: Option[List[ParameterValidator]],
7895
label: Option[String],
7996
hintText: Option[String]

components-api/src/main/scala/pl/touk/nussknacker/engine/api/context/ProcessCompilationError.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ object ProcessCompilationError {
332332
final case class IncompatibleParameterDefinitionModification(
333333
paramName: ParameterName,
334334
language: Language,
335-
parameterEditor: Option[ParameterEditor],
335+
parameterEditors: List[ParameterEditor],
336336
nodeId: String
337337
) extends PartSubGraphCompilationError
338338
with InASingleNode

components-api/src/main/scala/pl/touk/nussknacker/engine/api/definition/NodeDependency.scala

+16-13
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ object Parameter {
7070
Parameter(
7171
name,
7272
typ,
73-
editor = None,
73+
editors = Nil,
7474
validators = validators,
7575
defaultValue = None,
7676
additionalVariables = Map.empty,
@@ -92,7 +92,7 @@ object Parameter {
9292
Parameter(
9393
name,
9494
typ,
95-
editor = None,
95+
editors = Nil,
9696
validators = List.empty,
9797
defaultValue = None,
9898
additionalVariables = Map.empty,
@@ -123,7 +123,7 @@ object NotBlankParameter {
123123
case class Parameter(
124124
name: ParameterName,
125125
typ: TypingResult,
126-
editor: Option[ParameterEditor],
126+
editors: List[ParameterEditor],
127127
validators: List[ParameterValidator],
128128
defaultValue: Option[Expression],
129129
additionalVariables: Map[String, AdditionalVariable],
@@ -139,7 +139,7 @@ case class Parameter(
139139
def copy(
140140
name: ParameterName,
141141
typ: TypingResult,
142-
editor: Option[ParameterEditor],
142+
editors: List[ParameterEditor],
143143
validators: List[ParameterValidator],
144144
defaultValue: Option[Expression],
145145
additionalVariables: Map[String, AdditionalVariable],
@@ -152,7 +152,7 @@ case class Parameter(
152152
copy(
153153
name,
154154
typ,
155-
editor,
155+
editors,
156156
validators,
157157
defaultValue,
158158
additionalVariables,
@@ -169,7 +169,7 @@ case class Parameter(
169169
def copy(
170170
name: ParameterName = this.name,
171171
typ: TypingResult = this.typ,
172-
editor: Option[ParameterEditor] = this.editor,
172+
editors: List[ParameterEditor] = this.editors,
173173
validators: List[ParameterValidator] = this.validators,
174174
defaultValue: Option[Expression] = this.defaultValue,
175175
additionalVariables: Map[String, AdditionalVariable] = this.additionalVariables,
@@ -184,7 +184,7 @@ case class Parameter(
184184
new Parameter(
185185
name,
186186
typ,
187-
editor,
187+
editors,
188188
validators,
189189
defaultValue,
190190
additionalVariables,
@@ -201,7 +201,7 @@ case class Parameter(
201201
def apply(
202202
name: ParameterName,
203203
typ: TypingResult,
204-
editor: Option[ParameterEditor],
204+
editors: List[ParameterEditor],
205205
validators: List[ParameterValidator],
206206
defaultValue: Option[Expression],
207207
additionalVariables: Map[String, AdditionalVariable],
@@ -216,7 +216,7 @@ case class Parameter(
216216
new Parameter(
217217
name,
218218
typ,
219-
editor,
219+
editors,
220220
validators,
221221
defaultValue,
222222
additionalVariables,
@@ -233,7 +233,7 @@ case class Parameter(
233233
def apply(
234234
name: ParameterName,
235235
typ: TypingResult,
236-
editor: Option[ParameterEditor],
236+
editors: List[ParameterEditor],
237237
validators: List[ParameterValidator],
238238
defaultValue: Option[Expression],
239239
additionalVariables: Map[String, AdditionalVariable],
@@ -246,7 +246,7 @@ case class Parameter(
246246
new Parameter(
247247
name,
248248
typ,
249-
editor,
249+
editors,
250250
validators,
251251
defaultValue,
252252
additionalVariables,
@@ -275,8 +275,11 @@ case class Parameter(
275275

276276
val isOptional: Boolean = !validators.contains(MandatoryParameterValidator)
277277

278-
// TODO: all three methods below could be removed when we split this class into api class and domain model class
279-
def finalEditor: ParameterEditor = editor.getOrElse(RawParameterEditor)
278+
// // TODO: all three methods below could be removed when we split this class into api class and domain model class
279+
def editorsWithDefault: List[ParameterEditor] = editors match {
280+
case Nil => List(SpelParameterEditor)
281+
case nel => nel
282+
}
280283

281284
def finalDefaultValue: Expression = defaultValue.getOrElse(Expression.spel(""))
282285

0 commit comments

Comments
 (0)