Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
22ff23ea
by Tony Chemit at 2024-12-10T15:57:59+01:00
-
981ba480
by Tony Chemit at 2024-12-10T15:58:36+01:00
-
c8f2b90f
by Tony Chemit at 2024-12-10T15:59:18+01:00
-
13479925
by Tony Chemit at 2024-12-10T15:59:31+01:00
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:
| ... | ... | @@ -45,16 +45,28 @@ public class ObjectMaterialDto extends GeneratedObjectMaterialDto { |
| 45 | 45 | return objectMaterialType != null && ProtectedIdsPs.PS_COMMON_OBJECT_MATERIAL_TYPE_FLOAT.equals(objectMaterialType.getId());
|
| 46 | 46 | }
|
| 47 | 47 | |
| 48 | - public boolean isCodeValid() {
|
|
| 48 | + /**
|
|
| 49 | + * @return {@code true} if code is compliant with his associated parent code, {@code false} otherwise.
|
|
| 50 | + * @see #getParent()
|
|
| 51 | + * @see #getCode()
|
|
| 52 | + */
|
|
| 53 | + public boolean isCodeCompliantWithParent() {
|
|
| 49 | 54 | ObjectMaterialReference parent = getParent();
|
| 55 | + String code = getCode();
|
|
| 50 | 56 | if (parent == null) {
|
| 57 | + // If no parent, then accept anything here
|
|
| 51 | 58 | return true;
|
| 52 | 59 | }
|
| 60 | + if (code == null || code.trim().isEmpty()) {
|
|
| 61 | + // If a parent is defined, code can not be null nor empty
|
|
| 62 | + return false;
|
|
| 63 | + }
|
|
| 53 | 64 | String parentCode = parent.getCode();
|
| 54 | - if (parentCode == null || parentCode.isEmpty()) {
|
|
| 65 | + if (parentCode == null || parentCode.trim().isEmpty()) {
|
|
| 66 | + // if parent code is null or empty, then accept any code (even if we might only accept code without any «-» inside it)
|
|
| 55 | 67 | return true;
|
| 56 | 68 | }
|
| 57 | - String code = getCode();
|
|
| 69 | + // In any other cases, code must starts with «parentCode-»
|
|
| 58 | 70 | return code.startsWith(parentCode + "-");
|
| 59 | 71 | }
|
| 60 | 72 |
| ... | ... | @@ -16,7 +16,8 @@ |
| 16 | 16 | "validator": "io.ultreia.java4all.validation.impl.java.validator.FieldExpressionValidator",
|
| 17 | 17 | "comment": "code must be compliant with his parent code",
|
| 18 | 18 | "parameters": {
|
| 19 | - "expression": "$o.codeValid"
|
|
| 19 | + "skip": "$o.parent == null",
|
|
| 20 | + "expression": "$o.codeCompliantWithParent"
|
|
| 20 | 21 | },
|
| 21 | 22 | "message": "observe.referential.ps.common.ObjectMaterial.validation.bad.parentCode##$o.parent.code"
|
| 22 | 23 | }
|
| ... | ... | @@ -16,7 +16,8 @@ |
| 16 | 16 | "validator": "io.ultreia.java4all.validation.impl.java.validator.FieldExpressionValidator",
|
| 17 | 17 | "comment": "code must be compliant with his parent code",
|
| 18 | 18 | "parameters": {
|
| 19 | - "expression": "$o.codeValid"
|
|
| 19 | + "skip": "$o.parent == null",
|
|
| 20 | + "expression": "$o.codeCompliantWithParent"
|
|
| 20 | 21 | },
|
| 21 | 22 | "message": "observe.referential.ps.common.ObjectMaterial.validation.bad.parentCode##$o.parent.code"
|
| 22 | 23 | }
|
| ... | ... | @@ -4,7 +4,8 @@ |
| 4 | 4 | "validator": "io.ultreia.java4all.validation.impl.java.validator.FieldExpressionValidator",
|
| 5 | 5 | "comment": "code must be compliant with his parent code",
|
| 6 | 6 | "parameters": {
|
| 7 | - "expression": "$o.codeValid"
|
|
| 7 | + "skip" : "$o.parent == null",
|
|
| 8 | + "expression": "$o.codeCompliantWithParent"
|
|
| 8 | 9 | },
|
| 9 | 10 | "message": "observe.referential.ps.common.ObjectMaterial.validation.bad.parentCode##$o.parent.code"
|
| 10 | 11 | }
|
| ... | ... | @@ -4,7 +4,8 @@ |
| 4 | 4 | "validator": "io.ultreia.java4all.validation.impl.java.validator.FieldExpressionValidator",
|
| 5 | 5 | "comment": "code must be compliant with his parent code",
|
| 6 | 6 | "parameters": {
|
| 7 | - "expression": "$o.codeValid"
|
|
| 7 | + "skip" : "$o.parent == null",
|
|
| 8 | + "expression": "$o.codeCompliantWithParent"
|
|
| 8 | 9 | },
|
| 9 | 10 | "message": "observe.referential.ps.common.ObjectMaterial.validation.bad.parentCode##$o.parent.code"
|
| 10 | 11 | }
|