From ae543324a450e0cf3ce9a24d9fb50ff3ef213d5b Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Thu, 25 Jan 2024 18:08:47 +0200 Subject: [PATCH] dmp blueprint editor changes --- .../errorcode/ErrorThesaurusProperties.java | 10 ++++ .../DefinitionPersist.java | 11 ++++- .../DescriptionTemplatePersist.java | 11 +---- .../ExtraFieldPersist.java | 8 +++- .../dmpblueprintdefinition/FieldPersist.java | 6 --- .../SectionPersist.java | 14 +----- .../dmpblueprint/DmpBlueprintServiceImpl.java | 4 ++ .../GlobalExceptionHandler.java | 19 +++----- .../web/src/main/resources/config/errors.yml | 3 ++ .../common/enum/dmp-blueprint-field-type.ts | 8 ++-- .../services/utilities/enum-utils.service.ts | 17 ++----- .../dmp-blueprint-editor.component.html | 15 +++--- .../dmp-blueprint-editor.component.scss | 9 ++++ .../editor/dmp-blueprint-editor.component.ts | 2 +- .../editor/dmp-blueprint-editor.model.ts | 48 ++++++++++--------- dmp-frontend/src/assets/i18n/en.json | 2 +- .../forms/validation/validation-context.ts | 9 ++++ 17 files changed, 104 insertions(+), 92 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/errorcode/ErrorThesaurusProperties.java b/dmp-backend/core/src/main/java/eu/eudat/errorcode/ErrorThesaurusProperties.java index 7ae85ad8d..b4d1135e2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/errorcode/ErrorThesaurusProperties.java +++ b/dmp-backend/core/src/main/java/eu/eudat/errorcode/ErrorThesaurusProperties.java @@ -114,4 +114,14 @@ public class ErrorThesaurusProperties { public void setDescriptionIsFinalized(ErrorDescription descriptionIsFinalized) { this.descriptionIsFinalized = descriptionIsFinalized; } + + private ErrorDescription dmpBlueprintHasNoDescriptionTemplates; + + public ErrorDescription getDmpBlueprintHasNoDescriptionTemplates() { + return dmpBlueprintHasNoDescriptionTemplates; + } + + public void setDmpBlueprintHasNoDescriptionTemplates(ErrorDescription dmpBlueprintHasNoDescriptionTemplates) { + this.dmpBlueprintHasNoDescriptionTemplates = dmpBlueprintHasNoDescriptionTemplates; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/DefinitionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/DefinitionPersist.java index ef58a6976..658042b69 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/DefinitionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/DefinitionPersist.java @@ -28,6 +28,9 @@ public class DefinitionPersist { this.sections = sections; } + public static final String _hasAnyDescriptionTemplatesError = "hasAnyDescriptionTemplates"; + + @Component(DefinitionPersistValidator.ValidatorName) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public static class DefinitionPersistValidator extends BaseValidator { @@ -60,8 +63,14 @@ public class DefinitionPersist { .on(DefinitionPersist._sections) .over(item.getSections()) .using((itm) -> this.validatorFactory.validator(SectionPersist.SectionPersistValidator.class)) - ); + //TODO: We need to add a validation that check if hasTemplates boolean is true in at least one section. +// this.spec() +// .must(() -> !this.isListNullOrEmpty(item.getSections()) && item.sections.stream().anyMatch(x -> x.getHasTemplates())) +// .failOn(DefinitionPersist._hasAnyDescriptionTemplatesError).failWith(messageSource.getMessage("Validation_Required", null, LocaleContextHolder.getLocale())), + ); } + + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/DescriptionTemplatePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/DescriptionTemplatePersist.java index 617651266..672a329c8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/DescriptionTemplatePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/DescriptionTemplatePersist.java @@ -102,16 +102,7 @@ public class DescriptionTemplatePersist { .failOn(DescriptionTemplatePersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._id}, LocaleContextHolder.getLocale())), this.spec() .must(() -> this.isValidGuid(item.getDescriptionTemplateId())) - .failOn(DescriptionTemplatePersist._descriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._descriptionTemplateId}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isEmpty(item.getLabel())) - .failOn(DescriptionTemplatePersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isNull(item.getMinMultiplicity())) - .failOn(DescriptionTemplatePersist._minMultiplicity).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._minMultiplicity}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isNull(item.getMaxMultiplicity())) - .failOn(DescriptionTemplatePersist._maxMultiplicity).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._maxMultiplicity}, LocaleContextHolder.getLocale())) + .failOn(DescriptionTemplatePersist._descriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._descriptionTemplateId}, LocaleContextHolder.getLocale())) ); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/ExtraFieldPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/ExtraFieldPersist.java index cd9aecef0..1bdf913b8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/ExtraFieldPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/ExtraFieldPersist.java @@ -10,6 +10,7 @@ import org.springframework.context.annotation.Scope; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Component; +import java.util.Arrays; import java.util.List; public class ExtraFieldPersist extends FieldPersist { @@ -44,11 +45,14 @@ public class ExtraFieldPersist extends FieldPersist { @Override protected List specifications(ExtraFieldPersist item) { List specifications = getBaseSpecifications(item); - specifications.add( + specifications.addAll(Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getLabel())) + .failOn(FieldPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._label}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isNull(item.getDataType())) .failOn(ExtraFieldPersist._dataType).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExtraFieldPersist._dataType}, LocaleContextHolder.getLocale())) - ); + )); return specifications; } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/FieldPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/FieldPersist.java index 3aeaf1840..ef4778cbe 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/FieldPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/FieldPersist.java @@ -126,12 +126,6 @@ public abstract class FieldPersist { this.spec() .must(() -> !this.isNull(item.getCategory())) .failOn(FieldPersist._category).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._category}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isEmpty(item.getLabel())) - .failOn(FieldPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._label}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isEmpty(item.getPlaceholder())) - .failOn(FieldPersist._placeholder).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._placeholder}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isNull(item.getOrdinal())) .failOn(FieldPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._ordinal}, LocaleContextHolder.getLocale())), diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/SectionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/SectionPersist.java index e6163be3b..44b8165b4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/SectionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpblueprintdefinition/SectionPersist.java @@ -136,24 +136,14 @@ public class SectionPersist { this.spec() .must(() -> !this.isNull(item.getHasTemplates())) .failOn(SectionPersist._hasTemplates).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._hasTemplates}, LocaleContextHolder.getLocale())), - this.spec() .must(() -> !this.isListNullOrEmpty(item.getFields())) .failOn(SectionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{eu.eudat.model.persist.descriptiontemplatedefinition.SectionPersist._fieldSets}, LocaleContextHolder.getLocale())), this.navSpec() .iff(() -> !this.isListNullOrEmpty(item.getFields())) .on(SectionPersist._fields) - .over(item.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.System).toList()) - .using((itm) -> this.validatorFactory.validator(SystemFieldPersist.SystemFieldPersistValidator.class)), - this.navSpec() - .iff(() -> !this.isListNullOrEmpty(item.getFields())) - .on(SectionPersist._fields) - .over(item.getFields().stream().filter(x -> x.getCategory() == DmpBlueprintFieldCategory.Extra).toList()) - .using((itm) -> this.validatorFactory.validator(ExtraFieldPersist.ExtraFieldPersistValidator.class)), - this.spec() - .iff(() -> (item.getHasTemplates())) - .must(() -> !this.isListNullOrEmpty(item.getDescriptionTemplates())) - .failOn(SectionPersist._descriptionTemplates).failWith(messageSource.getMessage("Validation_Required", new Object[]{SectionPersist._descriptionTemplates}, LocaleContextHolder.getLocale())), + .over(item.getFields()) + .using((itm) -> ((FieldPersist) itm).getCategory() == DmpBlueprintFieldCategory.Extra ? this.validatorFactory.validator(ExtraFieldPersist.ExtraFieldPersistValidator.class) : this.validatorFactory.validator(SystemFieldPersist.SystemFieldPersistValidator.class)), this.navSpec() .iff(() -> !this.isListNullOrEmpty(item.getDescriptionTemplates())) .on(SectionPersist._descriptionTemplates) diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java index 948b30d73..d1ca20e0f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java @@ -134,6 +134,10 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { data.setCreatedAt(Instant.now()); } + if (model.getDefinition() != null && !model.getDefinition().getSections().stream().anyMatch(x -> x.getHasTemplates())) { + throw new MyValidationException(this.errors.getDmpBlueprintHasNoDescriptionTemplates().getCode(), this.errors.getDmpBlueprintHasNoDescriptionTemplates().getMessage()); + } + data.setLabel(model.getLabel()); data.setStatus(model.getStatus()); data.setUpdatedAt(Instant.now()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/controllerhandler/GlobalExceptionHandler.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/controllerhandler/GlobalExceptionHandler.java index a28826f3a..352f0ae8c 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/controllerhandler/GlobalExceptionHandler.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/controllerhandler/GlobalExceptionHandler.java @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.WebRequest; import java.text.MessageFormat; +import java.util.HashMap; import java.util.Map; @RestControllerAdvice @@ -111,19 +112,11 @@ public class GlobalExceptionHandler { logLevel = System.Logger.Level.DEBUG; statusCode = HttpStatus.BAD_REQUEST; int code = myValidationException.getCode(); - if (code > 0) { - result = Map.ofEntries( - Map.entry("code", code), - Map.entry("error", myValidationException.getMessage()), - Map.entry("message", myValidationException.getErrors()) - ); - } - else { - result = Map.ofEntries( - Map.entry("error", myValidationException.getMessage()), - Map.entry("message", myValidationException.getErrors()) - ); - } + + result = new HashMap<>(); + if (code > 0) result.put("code", code); + if (myValidationException.getMessage() != null) result.put("error", myValidationException.getMessage()); + if (myValidationException.getErrors() != null) result.put("message", myValidationException.getErrors()); } case MyApplicationException myApplicationException -> { logLevel = System.Logger.Level.ERROR; diff --git a/dmp-backend/web/src/main/resources/config/errors.yml b/dmp-backend/web/src/main/resources/config/errors.yml index e3600eae7..dd9fd1292 100644 --- a/dmp-backend/web/src/main/resources/config/errors.yml +++ b/dmp-backend/web/src/main/resources/config/errors.yml @@ -47,3 +47,6 @@ error-thesaurus: description-is-finalized: code: 119 message: To perform this action you will need to revert description finalisation + dmp-blueprint-has-no-description-templates: + code: 120 + message: You need to select Has Description Templates field to at least one Section. diff --git a/dmp-frontend/src/app/core/common/enum/dmp-blueprint-field-type.ts b/dmp-frontend/src/app/core/common/enum/dmp-blueprint-field-type.ts index 730f76e04..9ac699b68 100644 --- a/dmp-frontend/src/app/core/common/enum/dmp-blueprint-field-type.ts +++ b/dmp-frontend/src/app/core/common/enum/dmp-blueprint-field-type.ts @@ -1,6 +1,6 @@ export enum DmpBlueprintExtraFieldDataType { - Date = 0, - Number = 1, - Text = 2, - ExternalAutocomplete = 3 + Text = 0, + RichTex = 1, + Date = 2, + Number = 3 } diff --git a/dmp-frontend/src/app/core/services/utilities/enum-utils.service.ts b/dmp-frontend/src/app/core/services/utilities/enum-utils.service.ts index c403def60..0933e4ac2 100644 --- a/dmp-frontend/src/app/core/services/utilities/enum-utils.service.ts +++ b/dmp-frontend/src/app/core/services/utilities/enum-utils.service.ts @@ -67,15 +67,6 @@ export class EnumUtils { } } - toDmpBlueprintFieldDataTypeString(type: DmpBlueprintExtraFieldDataType): string { - switch (type) { - case DmpBlueprintExtraFieldDataType.Date: return this.language.instant('TYPES.DMP-PROFILE-FIELD.DATA-TYPE.DATE'); - case DmpBlueprintExtraFieldDataType.Number: return this.language.instant('TYPES.DMP-PROFILE-FIELD.DATA-TYPE.NUMBER'); - case DmpBlueprintExtraFieldDataType.Text: return this.language.instant('TYPES.DMP-PROFILE-FIELD.DATA-TYPE.TEXT'); - case DmpBlueprintExtraFieldDataType.ExternalAutocomplete: return this.language.instant('TYPES.DMP-PROFILE-FIELD.DATA-TYPE.EXTERNAL-AUTOCOMPLETE'); - } - } - toDmpBlueprintTypeString(type: DmpBlueprintType): string { switch (type) { case DmpBlueprintType.Input: return this.language.instant('TYPES.DMP-PROFILE-FIELD.TYPE.INPUT'); @@ -154,10 +145,10 @@ export class EnumUtils { toDmpBlueprintExtraFieldDataTypeString(status: DmpBlueprintExtraFieldDataType): string { switch (status) { - case DmpBlueprintExtraFieldDataType.Date: return this.language.instant('TYPES.DMP-BLUEPRINT-EXTRA-FIELD-DATA-TYPE.DATE'); - case DmpBlueprintExtraFieldDataType.Number: return this.language.instant('TYPES.DMP-BLUEPRINT-EXTRA-FIELD-DATA-TYPE.NUMBER'); - case DmpBlueprintExtraFieldDataType.Text: return this.language.instant('TYPES.DMP-BLUEPRINT-EXTRA-FIELD-DATA-TYPE.TEXT'); - case DmpBlueprintExtraFieldDataType.ExternalAutocomplete: return this.language.instant('TYPES.DMP-BLUEPRINT-EXTRA-FIELD-DATA-TYPE.EXTERNAL-AUTOCOMPLETE'); + case DmpBlueprintExtraFieldDataType.Text: return this.language.instant('TYPES.DMP-PROFILE-FIELD.DATA-TYPE.TEXT'); + case DmpBlueprintExtraFieldDataType.RichTex: return this.language.instant('TYPES.DMP-PROFILE-FIELD.DATA-TYPE.RICH-TEXT'); + case DmpBlueprintExtraFieldDataType.Date: return this.language.instant('TYPES.DMP-PROFILE-FIELD.DATA-TYPE.DATE'); + case DmpBlueprintExtraFieldDataType.Number: return this.language.instant('TYPES.DMP-PROFILE-FIELD.DATA-TYPE.NUMBER'); } } diff --git a/dmp-frontend/src/app/ui/admin/dmp-blueprint/editor/dmp-blueprint-editor.component.html b/dmp-frontend/src/app/ui/admin/dmp-blueprint/editor/dmp-blueprint-editor.component.html index 837c7b385..be178cfb1 100644 --- a/dmp-frontend/src/app/ui/admin/dmp-blueprint/editor/dmp-blueprint-editor.component.html +++ b/dmp-frontend/src/app/ui/admin/dmp-blueprint/editor/dmp-blueprint-editor.component.html @@ -54,7 +54,7 @@
{{'DMP-BLUEPRINT-EDITOR.FIELDS.SECTION-PREFIX' | translate}} {{sectionIndex + 1}}
-
drag_indicator
+
drag_indicator