Skip to content

Commit

Permalink
add decimalDigits to create and update routes
Browse files Browse the repository at this point in the history
  • Loading branch information
zingmane committed Aug 2, 2024
1 parent 0360794 commit 16c8503
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 19 deletions.
21 changes: 20 additions & 1 deletion src/main/resources/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3887,6 +3887,24 @@
"type": "boolean",
"description": "Flag if the member columns should be displayed in the frontend table view (They are always displayed in entity view).",
"example": true
},
"minLength": {
"type": "integer",
"description": "Minimum length of the value, only for text columns",
"format": "int32",
"example": 1
},
"maxLength": {
"type": "integer",
"description": "Maximum length of the value, only for text columns",
"format": "int32",
"example": 255
},
"decimalDigits": {
"type": "integer",
"description": "Number of decimal digits, only for numeric columns. Values between 0 and 10 are allowed. If not set, the default value is 3.",
"format": "int32",
"example": 2
}
},
"description": "A column object, which is used to create a new column.",
Expand Down Expand Up @@ -3925,7 +3943,8 @@
2
],
"formatPattern": "city {{1}} has {{2}} inhabitants",
"showMemberColumns": true
"showMemberColumns": true,
"decimalDigits": 6
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sealed trait CreateColumn {
val hidden: Boolean
val maxLength: Option[Int] = None
val minLength: Option[Int] = None
val decimalDigits: Option[Int] = None
}

case class CreateSimpleColumn(
Expand All @@ -30,7 +31,8 @@ case class CreateSimpleColumn(
override val attributes: Option[JsonObject],
override val hidden: Boolean = false,
override val maxLength: Option[Int] = None,
override val minLength: Option[Int] = None
override val minLength: Option[Int] = None,
override val decimalDigits: Option[Int] = None
) extends CreateColumn

case class CreateBackLinkColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ class CachedColumnModel(
hidden: Option[Boolean],
maxLength: Option[Int],
minLength: Option[Int],
showMemberColumns: Option[Boolean]
showMemberColumns: Option[Boolean],
decimalDigits: Option[Int]
)(implicit user: TableauxUser): Future[ColumnType[_]] = {
for {
_ <- removeCache(table.id, Some(columnId))
Expand All @@ -205,7 +206,8 @@ class CachedColumnModel(
hidden,
maxLength,
minLength,
showMemberColumns
showMemberColumns,
decimalDigits
)
} yield r
}
Expand Down Expand Up @@ -573,9 +575,10 @@ class ColumnModel(val connection: DatabaseConnection)(
| hidden,
| max_length,
| min_length,
| show_member_columns
| show_member_columns,
| decimal_digits
| )
| VALUES (?, nextval('system_columns_column_id_table_$tableId'), ?, ?, $ordering, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
| VALUES (?, nextval('system_columns_column_id_table_$tableId'), ?, ?, $ordering, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
| RETURNING column_id, ordering
|""".stripMargin
}
Expand Down Expand Up @@ -637,7 +640,8 @@ class ColumnModel(val connection: DatabaseConnection)(
createColumn.hidden,
maxLength,
minLength,
showMemberColumns
showMemberColumns,
createColumn.decimalDigits.orNull
)
)
case Some(ord) =>
Expand All @@ -659,7 +663,8 @@ class ColumnModel(val connection: DatabaseConnection)(
createColumn.hidden,
maxLength,
minLength,
showMemberColumns
showMemberColumns,
createColumn.decimalDigits.orNull
)
)
}
Expand Down Expand Up @@ -879,7 +884,9 @@ class ColumnModel(val connection: DatabaseConnection)(
| hidden,
| max_length,
| min_length,
| show_member_columns""".stripMargin
| show_member_columns,
| decimal_digits
|""".stripMargin

private def retrieveOne(table: Table, columnId: ColumnId, depth: Int)(
implicit user: TableauxUser
Expand Down Expand Up @@ -1172,6 +1179,7 @@ class ColumnModel(val connection: DatabaseConnection)(
val maxLength = Option(row.get[Int](13))
val minLength = Option(row.get[Int](14))
val showMemberColumns = row.get[Boolean](15)
val decimalDigits = Option(row.get[Int](16))

for {
displayInfoSeq <- retrieveDisplayInfo(table, columnId)
Expand All @@ -1188,7 +1196,8 @@ class ColumnModel(val connection: DatabaseConnection)(
attributes,
hidden,
maxLength,
minLength
minLength,
decimalDigits
)

column <- mapColumn(depth, kind, languageType, columnInformation, formatPattern, rules, showMemberColumns)
Expand Down Expand Up @@ -1486,7 +1495,8 @@ class ColumnModel(val connection: DatabaseConnection)(
hidden: Option[Boolean],
maxLength: Option[Int],
minLength: Option[Int],
showMemberColumns: Option[Boolean]
showMemberColumns: Option[Boolean],
decimalDigits: Option[Int]
)(implicit user: TableauxUser): Future[ColumnType[_]] = {
val tableId = table.id

Expand All @@ -1507,7 +1517,7 @@ class ColumnModel(val connection: DatabaseConnection)(
t <- connection.begin()

// change column settings
(t, resultName) <- maybeUpdateColumn(t, "user_column_name", columnName)
(t, resultColumnName) <- maybeUpdateColumn(t, "user_column_name", columnName)
(t, resultOrdering) <- maybeUpdateColumn(t, "ordering", ordering)
(t, resultKind) <- maybeUpdateColumn(t, "column_type", kind, (k: TableauxDbType) => k.name)
(t, resultIdentifier) <- maybeUpdateColumn(t, "identifier", identifier)
Expand All @@ -1518,6 +1528,7 @@ class ColumnModel(val connection: DatabaseConnection)(
maybeUpdateColumn(t, "country_codes", countryCodes, (c: Seq[String]) => Json.arr(c: _*))
(t, resultHidden) <- maybeUpdateColumn(t, "hidden", hidden)
(t, resultShowMemberColumns) <- maybeUpdateColumn(t, "show_member_columns", showMemberColumns)
(t, resultDecimalDigits) <- maybeUpdateColumn(t, "decimal_digits", decimalDigits)

// cannot use optionToValidFuture here, we need to be able to set these settings to null
(t, resultMaxLength) <- maxLength match {
Expand Down Expand Up @@ -1546,7 +1557,7 @@ class ColumnModel(val connection: DatabaseConnection)(

_ <- Future(
checkUpdateResults(
resultName,
resultColumnName,
resultOrdering,
resultKind,
resultIdentifier,
Expand All @@ -1556,7 +1567,8 @@ class ColumnModel(val connection: DatabaseConnection)(
resultRules,
resultMaxLength,
resultMinLength,
resultShowMemberColumns
resultShowMemberColumns,
resultDecimalDigits
)
)
.recoverWith(t.rollbackAndFail())
Expand Down
8 changes: 5 additions & 3 deletions src/main/scala/com/campudus/tableaux/helper/JsonUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ object JsonUtils extends LazyLogging {
case Failure(s) => throw WrongJsonTypeException("Field attributes is not a valid json object.")
}

val maxLength = Option(json.getInteger("maxLength")).map(_.toInt)
val minLength = Option(json.getInteger("minLength")).map(_.toInt)
val maxLength = Try(json.getInteger("maxLength").intValue()).toOption
val minLength = Try(json.getInteger("minLength").intValue()).toOption
val decimalDigits = Try(json.getInteger("decimalDigits").intValue()).toOption

// languageType or deprecated multilanguage
// if languageType == 'country' countryCodes must be specified
Expand Down Expand Up @@ -230,7 +231,8 @@ object JsonUtils extends LazyLogging {
attributes,
hidden,
maxLength,
minLength
minLength,
decimalDigits
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ class StructureRouter(override val config: TableauxConfig, val controller: Struc
optHidden,
maxLength,
minLength,
showMemberColumns
showMemberColumns,
decimalDigits
) =
toColumnChanges(json)

Expand All @@ -293,7 +294,8 @@ class StructureRouter(override val config: TableauxConfig, val controller: Struc
optHidden,
maxLength,
minLength,
showMemberColumns
showMemberColumns,
decimalDigits
)
}
)
Expand Down

0 comments on commit 16c8503

Please sign in to comment.