From 16a80c79de595353b328446606b01acea4a1b647 Mon Sep 17 00:00:00 2001 From: Maxime Robert Date: Mon, 29 Jul 2024 17:55:06 +0200 Subject: [PATCH] Story #13135 (pastis): add "comment" on regex --- .../vitamui/pastis/common/dto/PuaData.java | 4 +- .../pastis/common/service/JsonFromPUA.java | 4 +- .../pastis/common/service/PuaFromJSON.java | 4 +- .../common/service/PuaPastisValidator.java | 9 +- .../common/service/JsonFromPuaTest.java | 7 +- .../test/resources/pua/profile_Expected.json | 16 +- .../pua/profile_Expected_with_management.json | 16 +- .../test/resources/pua/profile_Expected.json | 12 +- .../pua/profile_Expected_with_management.json | 16 +- .../pastis/src/app/models/pua-data.ts | 4 +- .../file-tree-metadata.component.html | 63 ++++-- .../file-tree-metadata.component.scss | 1 - .../file-tree-metadata.component.ts | 195 ++++++------------ .../projects/pastis/src/assets/i18n/en.json | 1 + .../projects/pastis/src/assets/i18n/fr.json | 1 + .../editable-textarea.component.html | 2 +- .../editable-textarea.component.ts | 2 + 17 files changed, 154 insertions(+), 203 deletions(-) diff --git a/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/dto/PuaData.java b/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/dto/PuaData.java index b02db2a7730..529ea6e193a 100644 --- a/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/dto/PuaData.java +++ b/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/dto/PuaData.java @@ -49,8 +49,8 @@ public class PuaData implements Serializable { Boolean additionalProperties; List Enum; String pattern; - Integer minLenght; - Integer maxLenght; + Integer minLength; + Integer maxLength; Integer minimum; Integer maximum; Boolean exclusiveMinimum; diff --git a/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/JsonFromPUA.java b/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/JsonFromPUA.java index 80dd2f9f076..a429eae801d 100644 --- a/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/JsonFromPUA.java +++ b/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/JsonFromPUA.java @@ -391,11 +391,11 @@ private ElementProperties getElementProperties( break; case MIN_LENGTH: addPuaDataToElementIfNotPresent(childProfile); - childProfile.getPuaData().setMinLenght(childPua.getInt(k)); + childProfile.getPuaData().setMinLength(childPua.getInt(k)); break; case MAX_LENGTH: addPuaDataToElementIfNotPresent(childProfile); - childProfile.getPuaData().setMaxLenght(childPua.getInt(k)); + childProfile.getPuaData().setMaxLength(childPua.getInt(k)); break; case MINIMUM: addPuaDataToElementIfNotPresent(childProfile); diff --git a/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/PuaFromJSON.java b/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/PuaFromJSON.java index 17472b09004..212097018cb 100644 --- a/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/PuaFromJSON.java +++ b/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/PuaFromJSON.java @@ -77,8 +77,8 @@ public String getControlSchemaFromElementProperties(ElementProperties elementPro // 4. Check if tree contains Management metadata addPatternPropertiesForManagement(elementProperties, controlSchema); List elementsForTree = puaPastisValidator.ignoreMetadata(elementProperties); - List rerquiredElements = puaPastisValidator.getHeadRequired(elementsForTree); - if (CollectionUtils.isNotEmpty(rerquiredElements)) { + List requiredElements = puaPastisValidator.getHeadRequired(elementsForTree); + if (CollectionUtils.isNotEmpty(requiredElements)) { controlSchema.put(PuaPastisValidator.REQUIRED, puaPastisValidator.getHeadRequired(elementsForTree)); } diff --git a/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/PuaPastisValidator.java b/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/PuaPastisValidator.java index f626f26d068..360603a6b08 100644 --- a/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/PuaPastisValidator.java +++ b/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/PuaPastisValidator.java @@ -1049,14 +1049,7 @@ public void getMetaDataFromSeda(ElementProperties el, PuaMetadataDetails puaMeta if (el.getCardinality() != null && puaMetadataDetails.getType().equals("array")) { getMinAndMAxItems(el, puaMetadataDetails); } - if ( - !sedaElement.getElement().equals(COMPLEX) && el.getPuaData() != null && el.getPuaData().getPattern() != null - ) { - puaMetadataDetails.setPattern(el.getPuaData().getPattern()); - } - if (el.getPuaData() != null && el.getPuaData().getPattern() != null) { - puaMetadataDetails.setPattern(el.getPuaData().getPattern()); - } + Optional.ofNullable(el.getPuaData()).map(PuaData::getPattern).ifPresent(puaMetadataDetails::setPattern); if (el.getPuaData() != null && el.getPuaData().getEnum() != null) { puaMetadataDetails.setEnums(el.getPuaData().getEnum()); } else { diff --git a/api/api-pastis/pastis-commons/src/test/java/fr/gouv/vitamui/pastis/common/service/JsonFromPuaTest.java b/api/api-pastis/pastis-commons/src/test/java/fr/gouv/vitamui/pastis/common/service/JsonFromPuaTest.java index 41ee6598b66..d2fc6222fcb 100644 --- a/api/api-pastis/pastis-commons/src/test/java/fr/gouv/vitamui/pastis/common/service/JsonFromPuaTest.java +++ b/api/api-pastis/pastis-commons/src/test/java/fr/gouv/vitamui/pastis/common/service/JsonFromPuaTest.java @@ -45,7 +45,6 @@ import org.json.JSONTokener; import org.junit.Test; import org.junit.runner.RunWith; -import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -54,6 +53,8 @@ import java.io.InputStream; import java.io.InputStreamReader; +import static org.skyscreamer.jsonassert.JSONAssert.assertEquals; + @RunWith(SpringRunner.class) @TestPropertySource(locations = "/application-test.yml") public class JsonFromPuaTest { @@ -72,7 +73,7 @@ public void testImportOK() throws IOException { InputStream inputStreamExpected = getClass().getClassLoader().getResourceAsStream("pua/profile_Expected.json"); tokener = new JSONTokener(inputStreamExpected); JSONObject fileNodeJSONExpected = new JSONObject(tokener); - JSONAssert.assertEquals(fileNodeJSONActual, fileNodeJSONExpected, JSONCompareMode.STRICT); + assertEquals(fileNodeJSONExpected, fileNodeJSONActual, JSONCompareMode.STRICT); } @Test @@ -90,7 +91,7 @@ public void testImportOK_with_management() throws IOException { .getResourceAsStream("pua/profile_Expected_with_management.json"); tokener = new JSONTokener(inputStreamExpected); JSONObject fileNodeJSONExpected = new JSONObject(tokener); - JSONAssert.assertEquals(fileNodeJSONActual, fileNodeJSONExpected, JSONCompareMode.STRICT); + assertEquals(fileNodeJSONExpected, fileNodeJSONActual, JSONCompareMode.STRICT); } @Test diff --git a/api/api-pastis/pastis-commons/src/test/resources/pua/profile_Expected.json b/api/api-pastis/pastis-commons/src/test/resources/pua/profile_Expected.json index 73768b10476..b069cee1d97 100644 --- a/api/api-pastis/pastis-commons/src/test/resources/pua/profile_Expected.json +++ b/api/api-pastis/pastis-commons/src/test/resources/pua/profile_Expected.json @@ -96,8 +96,8 @@ { "additionalProperties": false, "pattern": null, - "minLenght": null, - "maxLenght": null, + "minLength": null, + "maxLength": null, "minimum": null, "maximum": null, "exclusiveMinimum": null, @@ -145,8 +145,8 @@ { "additionalProperties": null, "pattern": null, - "minLenght": null, - "maxLenght": null, + "minLength": null, + "maxLength": null, "minimum": null, "maximum": null, "exclusiveMinimum": null, @@ -270,8 +270,8 @@ { "additionalProperties": false, "pattern": null, - "minLenght": null, - "maxLenght": null, + "minLength": null, + "maxLength": null, "minimum": null, "maximum": null, "exclusiveMinimum": null, @@ -322,8 +322,8 @@ { "additionalProperties": false, "pattern": null, - "minLenght": null, - "maxLenght": null, + "minLength": null, + "maxLength": null, "minimum": null, "maximum": null, "exclusiveMinimum": null, diff --git a/api/api-pastis/pastis-commons/src/test/resources/pua/profile_Expected_with_management.json b/api/api-pastis/pastis-commons/src/test/resources/pua/profile_Expected_with_management.json index a6541816d2b..ec0a299968d 100644 --- a/api/api-pastis/pastis-commons/src/test/resources/pua/profile_Expected_with_management.json +++ b/api/api-pastis/pastis-commons/src/test/resources/pua/profile_Expected_with_management.json @@ -156,8 +156,8 @@ "puaData": { "additionalProperties": false, "pattern": null, - "minLenght": null, - "maxLenght": null, + "minLength": null, + "maxLength": null, "minimum": null, "maximum": null, "exclusiveMinimum": null, @@ -203,8 +203,8 @@ "puaData": { "additionalProperties": null, "pattern": null, - "minLenght": null, - "maxLenght": null, + "minLength": null, + "maxLength": null, "minimum": null, "maximum": null, "exclusiveMinimum": null, @@ -316,8 +316,8 @@ "puaData": { "additionalProperties": false, "pattern": null, - "minLenght": null, - "maxLenght": null, + "minLength": null, + "maxLength": null, "minimum": null, "maximum": null, "exclusiveMinimum": null, @@ -363,8 +363,8 @@ "puaData": { "additionalProperties": false, "pattern": null, - "minLenght": null, - "maxLenght": null, + "minLength": null, + "maxLength": null, "minimum": null, "maximum": null, "exclusiveMinimum": null, diff --git a/api/api-pastis/pastis-external/src/test/resources/pua/profile_Expected.json b/api/api-pastis/pastis-external/src/test/resources/pua/profile_Expected.json index adc3180e313..c0a295d9ad2 100644 --- a/api/api-pastis/pastis-external/src/test/resources/pua/profile_Expected.json +++ b/api/api-pastis/pastis-external/src/test/resources/pua/profile_Expected.json @@ -102,8 +102,8 @@ ], "pattern": null, "minimum": null, - "minLenght": null, - "maxLenght": null, + "minLength": null, + "maxLength": null, "maximum": null, "additionalProperties": null, "exclusiveMaximum": null, @@ -193,8 +193,8 @@ "enum": null, "pattern": null, "minimum": null, - "minLenght": null, - "maxLenght": null, + "minLength": null, + "maxLength": null, "maximum": null, "additionalProperties": false, "exclusiveMaximum": null, @@ -236,8 +236,8 @@ "enum": null, "pattern": null, "minimum": null, - "minLenght": null, - "maxLenght": null, + "minLength": null, + "maxLength": null, "maximum": null, "additionalProperties": false, "exclusiveMaximum": null, diff --git a/api/api-pastis/pastis-external/src/test/resources/pua/profile_Expected_with_management.json b/api/api-pastis/pastis-external/src/test/resources/pua/profile_Expected_with_management.json index 095740c54c0..4fe51ae89ef 100644 --- a/api/api-pastis/pastis-external/src/test/resources/pua/profile_Expected_with_management.json +++ b/api/api-pastis/pastis-external/src/test/resources/pua/profile_Expected_with_management.json @@ -143,8 +143,8 @@ "exclusiveMinimum": null, "pattern": null, "enum": null, - "minLenght": null, - "maxLenght": null + "minLength": null, + "maxLength": null } } ], @@ -198,8 +198,8 @@ "Item", "OtherLevel" ], - "minLenght": null, - "maxLenght": null + "minLength": null, + "maxLength": null } }, { @@ -289,8 +289,8 @@ "exclusiveMinimum": null, "pattern": null, "enum": null, - "minLenght": null, - "maxLenght": null + "minLength": null, + "maxLength": null } }, { @@ -332,8 +332,8 @@ "exclusiveMinimum": null, "pattern": null, "enum": null, - "minLenght": null, - "maxLenght": null + "minLength": null, + "maxLength": null } } ], diff --git a/ui/ui-frontend/projects/pastis/src/app/models/pua-data.ts b/ui/ui-frontend/projects/pastis/src/app/models/pua-data.ts index 7bc90648f4d..2f104cbb064 100644 --- a/ui/ui-frontend/projects/pastis/src/app/models/pua-data.ts +++ b/ui/ui-frontend/projects/pastis/src/app/models/pua-data.ts @@ -2,8 +2,8 @@ export interface PuaData { additionalProperties?: boolean; enum?: string[]; pattern?: string; - minLenght?: number; - maxLenght?: number; + minLength?: number; + maxLength?: number; minimum?: number; maximum?: number; exclusiveMinimum?: boolean; diff --git a/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.html b/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.html index c1bd906295f..51b6852bdb5 100644 --- a/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.html +++ b/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.html @@ -26,7 +26,7 @@
class="panel-buttons" matTooltip="{{ 'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA.ADDITIONAL_PROPERTIES_TOOLTIP' | translate }}" > - + @@ -178,7 +178,7 @@
- + {{ 'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA.COMMENTAIRE' | translate }} @@ -190,6 +190,7 @@
[maxlength]="120" [ngModel]="element.commentaire" class="commentaire-pastis" + [required]="hasCustomRegex(element)" > @@ -291,7 +292,7 @@
{{ 'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA.SUPPRIMER' | translate }} - + {{ 'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA.CONTROLE_METADONNEE' | translate }} - +

-
-
+
+
{{ item }} @@ -428,21 +429,22 @@

-
+
-
+
{{ 'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA.FORMATAGE_PREDEFINI' | translate }}:
-
-
+
+
{{ predefiniElement.label }} @@ -466,18 +468,32 @@

-
-
-
+
+
+
-
- - +
+
+ + +
+
+ + +
@@ -489,7 +505,10 @@

edit diff --git a/ui/ui-frontend/projects/vitamui-library/src/app/modules/components/editable-field/editable-textarea/editable-textarea.component.ts b/ui/ui-frontend/projects/vitamui-library/src/app/modules/components/editable-field/editable-textarea/editable-textarea.component.ts index a0a31be928a..1adf9f37175 100644 --- a/ui/ui-frontend/projects/vitamui-library/src/app/modules/components/editable-field/editable-textarea/editable-textarea.component.ts +++ b/ui/ui-frontend/projects/vitamui-library/src/app/modules/components/editable-field/editable-textarea/editable-textarea.component.ts @@ -38,6 +38,7 @@ import { Component, ElementRef, forwardRef, Input, ViewChild } from '@angular/co import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { EditableFieldComponent } from '../editable-field.component'; +import { coerceBooleanProperty } from '@angular/cdk/coercion'; export const EDITABLE_TEXTAREA_VALUE_ACCESSOR: any = { provide: NG_VALUE_ACCESSOR, @@ -53,6 +54,7 @@ export const EDITABLE_TEXTAREA_VALUE_ACCESSOR: any = { }) export class EditableTextareaComponent extends EditableFieldComponent { @Input() maxlength: number; + @Input({ transform: coerceBooleanProperty }) required = false; @ViewChild('input') private input: ElementRef; constructor(elementRef: ElementRef) {