Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 22ff23ea by Tony Chemit at 2024-12-10T15:57:59+01:00 Rename method ObjectMaterialDto.isCodeValid to ObjectMaterialDto.isCodeCompliantWithParent and improve it - - - - - 981ba480 by Tony Chemit at 2024-12-10T15:58:36+01:00 Rename method ObjectMaterialDto.isCodeValid to ObjectMaterialDto.isCodeCompliantWithParent and improve it - - - - - c8f2b90f by Tony Chemit at 2024-12-10T15:59:18+01:00 Only validate code if material has a parent - - - - - 13479925 by Tony Chemit at 2024-12-10T15:59:31+01:00 Merge branch 'feature/issue_2952' into develop Problème dans la consultation des données de référence Objet flottant matériel - Closes #2952 - - - - - 5 changed files: - core/api/dto/src/main/java/fr/ird/observe/dto/referential/ps/common/ObjectMaterialDto.java - core/api/validation/src/main/resources/fr/ird/observe/dto/referential/ps/common/ObjectMaterialDto-create-error-validation.json - core/api/validation/src/main/resources/fr/ird/observe/dto/referential/ps/common/ObjectMaterialDto-update-error-validation.json - core/api/validation/src/main/validation/fr/ird/observe/dto/referential/ps/common/ObjectMaterialDto-create-error-validation.json - core/api/validation/src/main/validation/fr/ird/observe/dto/referential/ps/common/ObjectMaterialDto-update-error-validation.json Changes: ===================================== core/api/dto/src/main/java/fr/ird/observe/dto/referential/ps/common/ObjectMaterialDto.java ===================================== @@ -45,16 +45,28 @@ public class ObjectMaterialDto extends GeneratedObjectMaterialDto { return objectMaterialType != null && ProtectedIdsPs.PS_COMMON_OBJECT_MATERIAL_TYPE_FLOAT.equals(objectMaterialType.getId()); } - public boolean isCodeValid() { + /** + * @return {@code true} if code is compliant with his associated parent code, {@code false} otherwise. + * @see #getParent() + * @see #getCode() + */ + public boolean isCodeCompliantWithParent() { ObjectMaterialReference parent = getParent(); + String code = getCode(); if (parent == null) { + // If no parent, then accept anything here return true; } + if (code == null || code.trim().isEmpty()) { + // If a parent is defined, code can not be null nor empty + return false; + } String parentCode = parent.getCode(); - if (parentCode == null || parentCode.isEmpty()) { + if (parentCode == null || parentCode.trim().isEmpty()) { + // if parent code is null or empty, then accept any code (even if we might only accept code without any «-» inside it) return true; } - String code = getCode(); + // In any other cases, code must starts with «parentCode-» return code.startsWith(parentCode + "-"); } ===================================== core/api/validation/src/main/resources/fr/ird/observe/dto/referential/ps/common/ObjectMaterialDto-create-error-validation.json ===================================== @@ -16,7 +16,8 @@ "validator": "io.ultreia.java4all.validation.impl.java.validator.FieldExpressionValidator", "comment": "code must be compliant with his parent code", "parameters": { - "expression": "$o.codeValid" + "skip": "$o.parent == null", + "expression": "$o.codeCompliantWithParent" }, "message": "observe.referential.ps.common.ObjectMaterial.validation.bad.parentCode##$o.parent.code" } ===================================== core/api/validation/src/main/resources/fr/ird/observe/dto/referential/ps/common/ObjectMaterialDto-update-error-validation.json ===================================== @@ -16,7 +16,8 @@ "validator": "io.ultreia.java4all.validation.impl.java.validator.FieldExpressionValidator", "comment": "code must be compliant with his parent code", "parameters": { - "expression": "$o.codeValid" + "skip": "$o.parent == null", + "expression": "$o.codeCompliantWithParent" }, "message": "observe.referential.ps.common.ObjectMaterial.validation.bad.parentCode##$o.parent.code" } ===================================== core/api/validation/src/main/validation/fr/ird/observe/dto/referential/ps/common/ObjectMaterialDto-create-error-validation.json ===================================== @@ -4,7 +4,8 @@ "validator": "io.ultreia.java4all.validation.impl.java.validator.FieldExpressionValidator", "comment": "code must be compliant with his parent code", "parameters": { - "expression": "$o.codeValid" + "skip" : "$o.parent == null", + "expression": "$o.codeCompliantWithParent" }, "message": "observe.referential.ps.common.ObjectMaterial.validation.bad.parentCode##$o.parent.code" } ===================================== core/api/validation/src/main/validation/fr/ird/observe/dto/referential/ps/common/ObjectMaterialDto-update-error-validation.json ===================================== @@ -4,7 +4,8 @@ "validator": "io.ultreia.java4all.validation.impl.java.validator.FieldExpressionValidator", "comment": "code must be compliant with his parent code", "parameters": { - "expression": "$o.codeValid" + "skip" : "$o.parent == null", + "expression": "$o.codeCompliantWithParent" }, "message": "observe.referential.ps.common.ObjectMaterial.validation.bad.parentCode##$o.parent.code" } View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/4d2d332a0d5e8e195959f23f9... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/4d2d332a0d5e8e195959f23f9... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT (@tchemit)