From 06060eca8980f9ef449177de5b3f0c7288bec668 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Tue, 9 Mar 2021 20:17:22 -0500 Subject: [PATCH 1/3] =?UTF-8?q?L'=C3=A9chantillon=20d'une=20recette=20n'es?= =?UTF-8?q?t=20plus=20obligatoire.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../colorrecipesexplorer/model/Recipe.kt | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/model/Recipe.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/model/Recipe.kt index 4b904c1..3180f4e 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/model/Recipe.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/model/Recipe.kt @@ -29,7 +29,7 @@ data class Recipe( val description: String, - val sample: Int, + val sample: Int?, @Column(name = "approbation_date") val approbationDate: LocalDate?, @@ -106,9 +106,8 @@ open class RecipeSaveDto( @field:NotBlank(message = RECIPE_DESCRIPTION_NULL_MESSAGE) val description: String, - @field:NotNull(message = RECIPE_SAMPLE_NULL_MESSAGE) @field:Min(value = 0, message = RECIPE_SAMPLE_TOO_SMALL_MESSAGE) - val sample: Int, + val sample: Int?, val approbationDate: LocalDate?, @@ -145,24 +144,14 @@ open class RecipeUpdateDto( val remark: String?, val steps: List? -) : EntityDto { - override fun toEntity(): Recipe = recipe( - id, - name = name ?: "name", - description = description ?: "description", - sample = sample ?: -1, - approbationDate = approbationDate ?: LocalDate.MIN, - remark = remark ?: "remark", - steps = steps?.toMutableList() ?: mutableListOf() - ) -} +) : EntityDto // ==== DSL ==== fun recipe( id: Long? = null, name: String = "name", description: String = "description", - sample: Int = -1, + sample: Int? = -1, approbationDate: LocalDate? = LocalDate.MIN, remark: String = "remark", note: String = "", @@ -182,7 +171,7 @@ fun recipePublicDataDto( fun recipeSaveDto( name: String = "name", description: String = "description", - sample: Int = -1, + sample: Int? = -1, approbationDate: LocalDate? = LocalDate.MIN, remark: String = "remark", companyId: Long = 0L, @@ -191,11 +180,11 @@ fun recipeSaveDto( fun recipeUpdateDto( id: Long = 0L, - name: String = "name", - description: String = "description", - sample: Int = -1, + name: String? = "name", + description: String? = "description", + sample: Int? = -1, approbationDate: LocalDate? = LocalDate.MIN, remark: String? = "remark", - steps: List = listOf(), + steps: List? = listOf(), op: RecipeUpdateDto.() -> Unit = {} ) = RecipeUpdateDto(id, name, description, sample, approbationDate, remark, steps).apply(op) From 3cdc8f442542e3211605160456b68e1a89fbb1a8 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Wed, 10 Mar 2021 17:01:52 -0500 Subject: [PATCH 2/3] Ajout de la couleur et du lustre d'une recette. --- .../model/dto/RecipeEditorFormDto.java | 4 +- .../colorrecipesexplorer/model/Recipe.kt | 61 ++++++++++++++++--- .../service/RecipeService.kt | 12 ++-- 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/model/dto/RecipeEditorFormDto.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/model/dto/RecipeEditorFormDto.java index 74a05e5..90e617d 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/model/dto/RecipeEditorFormDto.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/model/dto/RecipeEditorFormDto.java @@ -29,11 +29,11 @@ public class RecipeEditorFormDto { private List step; public Recipe getRecipe() { - return new Recipe(id, name, company, description, sample, approbationDate, remark, note); + return new Recipe(id, name, company, description, "ffffff", (byte) 0, sample, approbationDate, remark, note); } public Recipe update(Recipe original) { - return new Recipe(original.getId(), name, company, description, sample, approbationDate, remark, note); + return new Recipe(original.getId(), name, company, description, "ffffff", (byte) 0, sample, approbationDate, remark, note); } } diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/model/Recipe.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/model/Recipe.kt index 3180f4e..e11db17 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/model/Recipe.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/model/Recipe.kt @@ -6,13 +6,14 @@ import dev.fyloz.trial.colorrecipesexplorer.model.validation.NullOrSize import java.time.LocalDate import java.util.* import javax.persistence.* -import javax.validation.constraints.Min -import javax.validation.constraints.NotBlank -import javax.validation.constraints.NotNull +import javax.validation.constraints.* private const val RECIPE_ID_NULL_MESSAGE = "Un identifiant est requis" private const val RECIPE_NAME_NULL_MESSAGE = "Un nom est requis" private const val RECIPE_DESCRIPTION_NULL_MESSAGE = "Une description est requise" +private const val RECIPE_COLOR_NULL_MESSAGE = "Une couleur est requise" +private const val RECIPE_GLOSS_NULL_MESSAGE = "Le lustre de la couleur est requis" +private const val RECIPE_GLOSS_OUTSIDE_RANGE_MESSAGE = "Le lustre doit être entre 0 et 100" private const val RECIPE_SAMPLE_NULL_MESSAGE = "Un numéro d'échantillon est requis" private const val RECIPE_SAMPLE_TOO_SMALL_MESSAGE = "Le numéro d'échantillon doit être supérieur ou égal à 0" private const val RECIPE_COMPANY_NULL_MESSAGE = "Une bannière est requise" @@ -29,6 +30,12 @@ data class Recipe( val description: String, + /** The color produced by the recipe. The string should be formatted as a hexadecimal color without the sharp (#). */ + val color: String, + + /** The gloss of the color in percents. (0-100) */ + val gloss: Byte, + val sample: Int?, @Column(name = "approbation_date") @@ -54,6 +61,8 @@ data class Recipe( null, "name", "description", + "#ffffff", + 0, 0, null, "remark", @@ -68,11 +77,26 @@ data class Recipe( name: String, company: Company, description: String, + color: String, + gloss: Byte, sample: Int, approbationDate: LocalDate?, remark: String, note: String - ) : this(id, name, description, sample, approbationDate, remark, note, company, mutableListOf(), mutableListOf()) + ) : this( + id, + name, + description, + color, + gloss, + sample, + approbationDate, + remark, + note, + company, + mutableListOf(), + mutableListOf() + ) val mixesSortedById: Collection @JsonIgnore @@ -106,6 +130,15 @@ open class RecipeSaveDto( @field:NotBlank(message = RECIPE_DESCRIPTION_NULL_MESSAGE) val description: String, + @field:NotBlank(message = RECIPE_COLOR_NULL_MESSAGE) + @field:Pattern(regexp = "^#([0-9a-f]{6})$") + val color: String, + + @field:NotNull(message = RECIPE_GLOSS_NULL_MESSAGE) + @field:Min(value = 0, message = RECIPE_GLOSS_OUTSIDE_RANGE_MESSAGE) + @field:Max(value = 100, message = RECIPE_GLOSS_OUTSIDE_RANGE_MESSAGE) + val gloss: Byte, + @field:Min(value = 0, message = RECIPE_SAMPLE_TOO_SMALL_MESSAGE) val sample: Int?, @@ -136,6 +169,14 @@ open class RecipeUpdateDto( @field:NullOrNotBlank(message = RECIPE_DESCRIPTION_NULL_MESSAGE) val description: String?, + @field:NullOrNotBlank(message = RECIPE_COLOR_NULL_MESSAGE) + @field:Pattern(regexp = "^#([0-9a-f]{6})$") + val color: String?, + + @field:Min(value = 0, message = RECIPE_GLOSS_OUTSIDE_RANGE_MESSAGE) + @field:Max(value = 100, message = RECIPE_GLOSS_OUTSIDE_RANGE_MESSAGE) + val gloss: Byte?, + @field:NullOrSize(min = 0, message = RECIPE_SAMPLE_TOO_SMALL_MESSAGE) val sample: Int?, @@ -151,6 +192,8 @@ fun recipe( id: Long? = null, name: String = "name", description: String = "description", + color: String = "ffffff", + gloss: Byte = 0, sample: Int? = -1, approbationDate: LocalDate? = LocalDate.MIN, remark: String = "remark", @@ -159,7 +202,7 @@ fun recipe( mixes: MutableCollection = mutableListOf(), steps: MutableCollection = mutableListOf(), op: Recipe.() -> Unit = {} -) = Recipe(id, name, description, sample, approbationDate, remark, note, company, mixes, steps).apply(op) +) = Recipe(id, name, description, color, gloss, sample, approbationDate, remark, note, company, mixes, steps).apply(op) fun recipePublicDataDto( id: Long = 0L, @@ -171,20 +214,24 @@ fun recipePublicDataDto( fun recipeSaveDto( name: String = "name", description: String = "description", + color: String = "ffffff", + gloss: Byte = 0, sample: Int? = -1, approbationDate: LocalDate? = LocalDate.MIN, remark: String = "remark", companyId: Long = 0L, op: RecipeSaveDto.() -> Unit = {} -) = RecipeSaveDto(name, description, sample, approbationDate, remark, companyId).apply(op) +) = RecipeSaveDto(name, description, color, gloss, sample, approbationDate, remark, companyId).apply(op) fun recipeUpdateDto( id: Long = 0L, name: String? = "name", description: String? = "description", + color: String? = "ffffff", + gloss: Byte? = 0, sample: Int? = -1, approbationDate: LocalDate? = LocalDate.MIN, remark: String? = "remark", steps: List? = listOf(), op: RecipeUpdateDto.() -> Unit = {} -) = RecipeUpdateDto(id, name, description, sample, approbationDate, remark, steps).apply(op) +) = RecipeUpdateDto(id, name, description, color, gloss, sample, approbationDate, remark, steps).apply(op) diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/RecipeService.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/RecipeService.kt index 0b05c70..3190407 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/RecipeService.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/RecipeService.kt @@ -46,6 +46,8 @@ class RecipeServiceImpl( recipe( name = name, description = description, + color = color, + gloss = gloss, sample = sample, approbationDate = approbationDate, remark = remark ?: "", @@ -61,11 +63,13 @@ class RecipeServiceImpl( return update(with(entity) { recipe( id = id, - name = name.or(persistedRecipe.name), - description = description.or(persistedRecipe.description), - sample = if (sample != null && sample >= 0) sample else persistedRecipe.sample, + name = name or persistedRecipe.name, + description = description or persistedRecipe.description, + color = color or persistedRecipe.color, + gloss = gloss ?: persistedRecipe.gloss, + sample = sample ?: persistedRecipe.sample, approbationDate = approbationDate ?: persistedRecipe.approbationDate, - remark = remark.or(persistedRecipe.remark), + remark = remark or persistedRecipe.remark, note = persistedRecipe.note, company = persistedRecipe.company, mixes = persistedRecipe.mixes, From 472a802191088bd6ede410f9d3668b7056e44ccb Mon Sep 17 00:00:00 2001 From: FyloZ Date: Wed, 10 Mar 2021 17:17:19 -0500 Subject: [PATCH 3/3] =?UTF-8?q?Mise=20=C3=A0=20jour=20du=20gestionnaire=20?= =?UTF-8?q?de=20base=20de=20donn=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../dev/fyloz/trial/colorrecipesexplorer/DatabaseVersioning.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index cb2dc1b..7ddcd0f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,7 +31,7 @@ dependencies { implementation("org.apache.pdfbox:pdfbox:2.0.4") implementation("com.atlassian.commonmark:commonmark:0.13.1") implementation("commons-io:commons-io:2.6") - implementation("dev.fyloz.colorrecipesexplorer:database-manager:1.0.1") + implementation("dev.fyloz.colorrecipesexplorer:database-manager:1.1.0") implementation("org.springframework.boot:spring-boot-starter-data-jpa:2.3.4.RELEASE") implementation("org.springframework.boot:spring-boot-starter-jdbc:2.3.4.RELEASE") diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/DatabaseVersioning.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/DatabaseVersioning.kt index 73eda92..1155551 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/DatabaseVersioning.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/DatabaseVersioning.kt @@ -11,7 +11,7 @@ import org.springframework.context.annotation.Configuration import org.springframework.core.env.Environment import javax.sql.DataSource -const val SUPPORTED_DATABASE_VERSION = 2 +const val SUPPORTED_DATABASE_VERSION = 3 const val ENV_VAR_ENABLE_DATABASE_UPDATE_NAME = "CRE_ENABLE_DB_UPDATE" val DATABASE_NAME_REGEX = Regex("(\\w+)$")