From 23d3d82ff02fcb6e76671511df224a843665a3bf Mon Sep 17 00:00:00 2001 From: Daniel Radeau Date: Wed, 28 Aug 2024 17:19:02 +0200 Subject: [PATCH 1/2] story #13004 fix: schema element mapping --- ...chemaModelToSchemaElementDtoConverter.java | 28 ++++++++++++------- .../internal/server/schema/SchemaService.java | 3 -- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/api/api-referential/referential-internal/src/main/java/fr/gouv/vitamui/referential/internal/server/schema/CombinedSchemaModelToSchemaElementDtoConverter.java b/api/api-referential/referential-internal/src/main/java/fr/gouv/vitamui/referential/internal/server/schema/CombinedSchemaModelToSchemaElementDtoConverter.java index db4d8249758..89d94cb2829 100644 --- a/api/api-referential/referential-internal/src/main/java/fr/gouv/vitamui/referential/internal/server/schema/CombinedSchemaModelToSchemaElementDtoConverter.java +++ b/api/api-referential/referential-internal/src/main/java/fr/gouv/vitamui/referential/internal/server/schema/CombinedSchemaModelToSchemaElementDtoConverter.java @@ -37,22 +37,29 @@ import fr.gouv.vitamui.referential.common.model.ControlType; import fr.gouv.vitamui.referential.common.model.DataType; import fr.gouv.vitamui.referential.common.model.EffectiveCardinality; +import lombok.extern.slf4j.Slf4j; import java.util.Objects; import java.util.Optional; import static java.util.Objects.isNull; +@Slf4j public class CombinedSchemaModelToSchemaElementDtoConverter extends StdConverter { @Override public SchemaElementDto convert(CombinedSchemaModel schemaModel) { - final SchemaStringSizeType stringTypeSize = SchemaStringSizeType.fromValue(schemaModel.getStringSize().name()); + SchemaStringSizeType stringTypeSize = null; + + if (schemaModel.getStringSize() != null) { + stringTypeSize = SchemaStringSizeType.fromValue(schemaModel.getStringSize().name()); + } + final SchemaElementDto schemaElementDto = (SchemaElementDto) new SchemaElementDto() .setPath(schemaModel.getPath()) .setStringSize(Optional.ofNullable(stringTypeSize).map(SchemaStringSizeType::value).orElse(null)) - .setCardinality(Cardinality.of(schemaModel.getCardinality().name())) + .setCardinality(Cardinality.valueOf(schemaModel.getCardinality().name())) .setFieldName(schemaModel.getFieldName()) .setShortName(schemaModel.getShortName()) .setDescription(schemaModel.getDescription()) @@ -66,18 +73,19 @@ public SchemaElementDto convert(CombinedSchemaModel schemaModel) { .setApiPath(Optional.ofNullable(schemaModel.getApiPath()).orElse(schemaModel.getPath())) .setDataType(convertFromIndexationType(schemaModel.getType().name())); - if (schemaModel.getControl() != null) { - final ControlDto controlDto = new ControlDto(); + schemaElementDto.setEffectiveCardinality(EffectiveCardinality.valueOf(schemaModel.getEffectiveCardinality())); - controlDto.setType(ControlType.valueOf(schemaModel.getControl().getType())); - controlDto.setValue(schemaModel.getControl().getValue()); - controlDto.setValues(schemaModel.getControl().getValues()); - controlDto.setComment(schemaModel.getControl().getComment()); + if (schemaModel.getControl() == null) return schemaElementDto; - schemaElementDto.setControl(controlDto); + final ControlDto controlDto = new ControlDto(); + if (schemaModel.getControl().getType() != null) { + controlDto.setType(ControlType.valueOf(schemaModel.getControl().getType())); } + controlDto.setValue(schemaModel.getControl().getValue()); + controlDto.setValues(schemaModel.getControl().getValues()); + controlDto.setComment(schemaModel.getControl().getComment()); - schemaElementDto.setEffectiveCardinality(EffectiveCardinality.valueOf(schemaModel.getEffectiveCardinality())); + schemaElementDto.setControl(controlDto); return schemaElementDto; } diff --git a/api/api-referential/referential-internal/src/main/java/fr/gouv/vitamui/referential/internal/server/schema/SchemaService.java b/api/api-referential/referential-internal/src/main/java/fr/gouv/vitamui/referential/internal/server/schema/SchemaService.java index e63b03a20f6..23e1fb12c26 100644 --- a/api/api-referential/referential-internal/src/main/java/fr/gouv/vitamui/referential/internal/server/schema/SchemaService.java +++ b/api/api-referential/referential-internal/src/main/java/fr/gouv/vitamui/referential/internal/server/schema/SchemaService.java @@ -37,8 +37,6 @@ import fr.gouv.vitamui.iam.security.service.InternalSecurityService; import fr.gouv.vitamui.referential.common.dto.SchemaDto; import fr.gouv.vitamui.referential.common.model.Collection; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -51,7 +49,6 @@ @Service public class SchemaService { - private static final Logger log = LoggerFactory.getLogger(SchemaService.class); private final InternalSecurityService internalSecurityService; private final AdminExternalClient adminExternalClient; From 4377ff21ef2772d29395a6bd5ad71b56baea17b0 Mon Sep 17 00:00:00 2001 From: Daniel Radeau Date: Wed, 28 Aug 2024 17:19:56 +0200 Subject: [PATCH 2/2] story #13004 fix: hide cardinality zero edit objects --- .../archive-unit/archive-unit-edit-object.service.ts | 8 ++++++++ .../archive-unit-editor/archive-unit-editor.service.ts | 1 + 2 files changed, 9 insertions(+) diff --git a/ui/ui-frontend/projects/vitamui-library/src/app/modules/archive-unit/archive-unit-edit-object.service.ts b/ui/ui-frontend/projects/vitamui-library/src/app/modules/archive-unit/archive-unit-edit-object.service.ts index 14be6e2262a..193858b9e96 100644 --- a/ui/ui-frontend/projects/vitamui-library/src/app/modules/archive-unit/archive-unit-edit-object.service.ts +++ b/ui/ui-frontend/projects/vitamui-library/src/app/modules/archive-unit/archive-unit-edit-object.service.ts @@ -189,6 +189,14 @@ export class ArchiveUnitEditObjectService { } } + public hideCardinalityZero(editObject: EditObject): void { + if (editObject.cardinality === 'ZERO') { + editObject.displayRule = { ...editObject.displayRule, ui: { ...editObject.displayRule.ui, display: false } }; + } + + editObject.children.forEach((child) => this.hideCardinalityZero(child)); + } + public setMissingTypes(editObject: EditObject): void { const { kind } = editObject; diff --git a/ui/ui-frontend/projects/vitamui-library/src/app/modules/archive-unit/components/archive-unit-editor/archive-unit-editor.service.ts b/ui/ui-frontend/projects/vitamui-library/src/app/modules/archive-unit/components/archive-unit-editor/archive-unit-editor.service.ts index 271ea64bfc1..ffdadadb8ee 100644 --- a/ui/ui-frontend/projects/vitamui-library/src/app/modules/archive-unit/components/archive-unit-editor/archive-unit-editor.service.ts +++ b/ui/ui-frontend/projects/vitamui-library/src/app/modules/archive-unit/components/archive-unit-editor/archive-unit-editor.service.ts @@ -139,6 +139,7 @@ export class ArchiveUnitEditorService { this.archiveUnitEditObjectService.expand('', editObject); this.archiveUnitEditObjectService.expand('Generalities', editObject); this.archiveUnitEditObjectService.hideSpsFieldWithOneValue(editObject); + this.archiveUnitEditObjectService.hideCardinalityZero(editObject); return editObject; }