Skip to content

Commit

Permalink
do not pass tries but optionals for min-/maxLength
Browse files Browse the repository at this point in the history
  • Loading branch information
zingmane committed Aug 2, 2024
1 parent 6b1c23a commit 5fec4d9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 41 deletions.
21 changes: 0 additions & 21 deletions src/main/scala/com/campudus/tableaux/arguments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,6 @@ object ArgumentChecker {
}
}

def isDefined(options: Seq[Option[_]], trys: Seq[Try[Option[_]]], name: String): ArgumentCheck[Unit] = {
val empty = !options.exists(_.isDefined)
val noneHaveBeenDefined = trys.forall(_.isFailure)

if (empty && noneHaveBeenDefined) {
FailArg(InvalidRequestException(s"None of these options has a (valid) value. ($name)"))
} else {
OkArg(())
}

}

def nullableValuesAreDefined(trys: Seq[Try[Option[_]]], name: String = ""): ArgumentCheck[Unit] = {
val allHaveBeenSupplied = trys.forall(_.isSuccess)
if (allHaveBeenSupplied) {
FailArg(InvalidRequestException(s"None of these options has a (valid) value. ($name)"))
} else {
OkArg(())
}
}

def oneOf[A](x: => A, list: List[A], name: String): ArgumentCheck[A] = {
if (list.contains(x)) {
OkArg(x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,20 +474,16 @@ class StructureController(
attributes,
rules,
hidden,
showMemberColumns
maxLength,
minLength,
showMemberColumns,
decimalDigits
),
Seq(maxLengthTry, minLengthTry),
"name, ordering, kind, identifier, displayInfos, countryCodes, separator, attributes, rules, hidden, maxLength, minLength, showMemberColumns"
"name, ordering, kind, identifier, displayInfos, countryCodes, separator, attributes, " +
"rules, hidden, maxLength, minLength, showMemberColumns, decimalDigits"
)
)
val maxLength = maxLengthTry match {
case Failure(exception) => None
case Success(opt) => opt
}
val minLength = minLengthTry match {
case Failure(exception) => None
case Success(opt) => opt
}

val structureProperties: Seq[Option[Any]] = Seq(columnName, ordering, kind, identifier, countryCodes)
val isAtLeastOneStructureProperty: Boolean = structureProperties.exists(_.isDefined)

Expand All @@ -514,7 +510,8 @@ class StructureController(
hidden,
maxLength,
minLength,
showMemberColumns
showMemberColumns,
decimalDigits
)

for {
Expand Down
19 changes: 11 additions & 8 deletions src/main/scala/com/campudus/tableaux/helper/JsonUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ object JsonUtils extends LazyLogging {
} yield valueList
}

private def getNullableJsonIntegerValue(key: String, json: JsonObject): Try[Option[Int]] = {
private def getNullableJsonIntegerValue(key: String, json: JsonObject): Try[Int] = {
Try({
json.containsKey(key) match {
case false => throw new KeyNotFoundInJsonException(key)
case true => Option(json.getInteger(key)).map(_.toInt)
case true => json.getInteger(key)
}
})
}
Expand All @@ -343,9 +343,10 @@ object JsonUtils extends LazyLogging {
Option[JsonObject],
Option[JsonArray],
Option[Boolean],
Try[Option[Int]],
Try[Option[Int]],
Option[Boolean]
Option[Int],
Option[Int],
Option[Boolean],
Option[Int]
) = {

val name = Try(notNull(json.getString("name"), "name").get).toOption
Expand Down Expand Up @@ -378,8 +379,9 @@ object JsonUtils extends LazyLogging {
}
).map(_.asScala.toSeq.map({ case code: String => code }))

val maxLength = getNullableJsonIntegerValue("maxLength", json)
val minLength = getNullableJsonIntegerValue("minLength", json)
val maxLength = getNullableJsonIntegerValue("maxLength", json).toOption
val minLength = getNullableJsonIntegerValue("minLength", json).toOption
val decimalDigits = getNullableJsonIntegerValue("decimalDigits", json).toOption

(
name,
Expand All @@ -394,7 +396,8 @@ object JsonUtils extends LazyLogging {
hidden,
maxLength,
minLength,
showMemberColumns
showMemberColumns,
decimalDigits
)
}

Expand Down

0 comments on commit 5fec4d9

Please sign in to comment.