#8 Ajout de ConfigurationBase, dont Configuration et SecureConfiguration héritent

This commit is contained in:
FyloZ 2021-08-04 21:54:17 -04:00
parent b14d9049b3
commit ae5c19faca
Signed by: william
GPG Key ID: 835378AE9AF4AE97
1 changed files with 23 additions and 12 deletions

View File

@ -12,20 +12,25 @@ import javax.persistence.Id
import javax.persistence.Table
import javax.validation.constraints.NotBlank
data class Configuration(
sealed class ConfigurationBase(
@JsonIgnore
val type: ConfigurationType,
val content: String,
val lastUpdated: LocalDateTime
) {
val key = type.key
val requireRestart = type.requireRestart
val editable = !type.computed
}
class Configuration(type: ConfigurationType, val content: String, lastUpdated: LocalDateTime) :
ConfigurationBase(type, lastUpdated) {
fun toEntity() =
ConfigurationEntity(key, content, lastUpdated)
}
class SecureConfiguration(type: ConfigurationType, lastUpdated: LocalDateTime) :
ConfigurationBase(type, lastUpdated)
@Entity
@Table(name = "configuration")
data class ConfigurationEntity(
@ -92,7 +97,13 @@ enum class ConfigurationType(
DATABASE_URL("database.url", defaultContent = "mysql://localhost/cre", file = true, requireRestart = true),
DATABASE_USER("database.user", defaultContent = "cre", file = true, requireRestart = true),
DATABASE_PASSWORD("database.password", defaultContent = "asecurepassword", file = true, requireRestart = true, secure = true),
DATABASE_PASSWORD(
"database.password",
defaultContent = "asecurepassword",
file = true,
requireRestart = true,
secure = true
),
DATABASE_SUPPORTED_VERSION("database.version.supported", computed = true),
RECIPE_APPROBATION_EXPIRATION("recipe.approbation.expiration", defaultContent = 4.months),
@ -128,15 +139,15 @@ class InvalidConfigurationKeyException(val key: String) :
)
class InvalidImageConfigurationException(val type: ConfigurationType) :
RestException(
"invalid-configuration-image",
"Invalid image configuration",
HttpStatus.BAD_REQUEST,
"The configuration with the key '${type.key}' does not accept images as content",
mapOf(
"key" to type.key
)
)
RestException(
"invalid-configuration-image",
"Invalid image configuration",
HttpStatus.BAD_REQUEST,
"The configuration with the key '${type.key}' does not accept images as content",
mapOf(
"key" to type.key
)
)
class ConfigurationNotSetException(val type: ConfigurationType) :
RestException(