Skip to content

Commit

Permalink
Extrend MandatoryParameterValidator to treat string expression with o…
Browse files Browse the repository at this point in the history
…nly quotes as empty value
  • Loading branch information
philemone committed Sep 30, 2024
1 parent d5a9006 commit bba1e43
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ case object MandatoryParameterValidator extends ParameterValidator {
override def isValid(paramName: ParameterName, expression: Expression, value: Option[Any], label: Option[String])(
implicit nodeId: NodeId
): Validated[PartSubGraphCompilationError, Unit] =
if (!expression.expression.isBlank) valid(()) else invalid(error(paramName, nodeId.id))
if (!expression.expression.isBlank && !isEmptyStringOrQuotesOnly(value, expression.expression)) valid(())
else invalid(error(paramName, nodeId.id))

private def error(paramName: ParameterName, nodeId: String): EmptyMandatoryParameter = EmptyMandatoryParameter(
message = "This field is mandatory and can not be empty",
Expand All @@ -52,6 +53,14 @@ case object MandatoryParameterValidator extends ParameterValidator {
nodeId = nodeId
)

private def isEmptyStringOrQuotesOnly(value: Option[Any], expression: String): Boolean = {
val exprValue = expression.trim
value match {
case Some(_: String) => exprValue.isBlank || exprValue.equals("''") || exprValue.equals("""""""")
case _ => false
}
}

}

case object NotNullParameterValidator extends ParameterValidator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class ParameterValidatorSpec extends AnyFunSuite with TableDrivenPropertyChecks
(" ", Some(null), false),
("\t", Some(null), false),
(" \n ", Some(null), false),
("''", Some(""), false),
("""""""", Some(""), false),
("null", Some(null), true),
("#input.foo['bar']", None, true),
("true", Some(true), true),
("''", Some(""), true),
("'foo'", Some("foo"), true),
("1", Some(1), true),
("1 + 1", Some(2), true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ const valueStartsWithQuotationMark = (value) => startsWith(value, '"') || starts
const quotationMark = (value) => (valueStartsWithQuotationMark(value) ? valueQuotationMark(value) : defaultQuotationMark);

export const stringSpelFormatter: Formatter = {
encode: (value) => {
if (value === "") return value;
else return quotationMark(value) + value + quotationMark(value);
},
encode: (value) => quotationMark(value) + value + quotationMark(value),
decode: (value) => value.substring(1, value.length - 1),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class ManagementResourcesSpec
"end",
"kafka-string",
TopicParamName.value -> "'end.topic'".spel,
SinkValueParamName.value -> "''".spel
SinkValueParamName.value -> "'sth'".spel
)
val testDataContent =
"""{"sourceId":"startProcess","record":"ala"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class BaseFlowTest
.streaming(processId)
.source("source", "csv-source")
.enricher("enricher", "out", "complexReturnObjectService")
.emptySink("end", "sendSms", "Value" -> "''".spel)
.emptySink("end", "sendSms", "Value" -> "'welcome'".spel)

saveProcess(process)

Expand Down

0 comments on commit bba1e43

Please sign in to comment.