From e7a500e3ec57f3d68b6880fe5a12137cb78ee98b Mon Sep 17 00:00:00 2001 From: amentis Date: Tue, 23 Apr 2024 17:59:42 +0300 Subject: [PATCH] description validation changes --- .../persist/descriptionproperties/FieldPersist.java | 4 ++-- .../PropertyDefinitionFieldSetPersist.java | 10 ++++++---- .../rich-text-editor/rich-text-editor.component.ts | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/FieldPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/FieldPersist.java index 0752dc4d2..88abd5a5f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/FieldPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/FieldPersist.java @@ -134,10 +134,10 @@ public class FieldPersist { .failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> FieldType.isReferenceType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && required) - .must(() -> !this.isListNullOrEmpty(item.getTextListValue())) + .must(() -> !this.isListNullOrEmpty(item.getReferences()) || !this.isNull(item.getReference())) .failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), this.spec() - .iff(()-> !this.isEmpty(item.getTextValue()) && fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.BOOLEAN_DECISION) ) + .iff(()-> !this.isEmpty(item.getTextValue()) && (fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.BOOLEAN_DECISION)) ) .must(() -> this.isBoolean(item.getTextValue())) .failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())), this.spec() diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionFieldSetPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionFieldSetPersist.java index 5875332c7..73469b1f0 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionFieldSetPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionFieldSetPersist.java @@ -50,6 +50,8 @@ public class PropertyDefinitionFieldSetPersist { protected List specifications(PropertyDefinitionFieldSetPersist item) { Integer min = fieldSetEntity != null && fieldSetEntity.getMultiplicity() != null ? fieldSetEntity.getMultiplicity().getMin() : null; Integer max = fieldSetEntity != null && fieldSetEntity.getMultiplicity() != null ? fieldSetEntity.getMultiplicity().getMax() : null; + if(min == 0 && max == 0) max = null; + Integer finalMax = max; return Arrays.asList( this.navSpec() @@ -59,12 +61,12 @@ public class PropertyDefinitionFieldSetPersist { .using((itm) -> this.validatorFactory.validator(PropertyDefinitionFieldSetItemPersist.PersistValidator.class).withFieldSetEntity(this.fieldSetEntity).setStatus(this.status)), this.spec() .iff(() -> DescriptionStatus.Finalized.equals(this.status) && min != null) - .must(() -> !this.isNull(item.getItems()) && min >= item.getItems().size()) + .must(() -> !this.isListNullOrEmpty(item.getItems()) && min <= item.getItems().size()) .failOn(PropertyDefinitionFieldSetPersist._items).failWith(messageSource.getMessage("Validation.LargerThenEqual", new Object[]{PropertyDefinitionFieldSetPersist._items, min}, LocaleContextHolder.getLocale())), this.spec() - .iff(() -> DescriptionStatus.Finalized.equals(this.status) && max != null) - .must(() -> !this.isNull(item.getItems()) && max <= item.getItems().size()) - .failOn(PropertyDefinitionFieldSetPersist._items).failWith(messageSource.getMessage("Validation.LessThenEqual", new Object[]{PropertyDefinitionFieldSetPersist._items, max}, LocaleContextHolder.getLocale())) + .iff(() -> DescriptionStatus.Finalized.equals(this.status) && finalMax != null) + .must(() -> !this.isListNullOrEmpty(item.getItems()) && finalMax >= item.getItems().size()) + .failOn(PropertyDefinitionFieldSetPersist._items).failWith(messageSource.getMessage("Validation.LessThenEqual", new Object[]{PropertyDefinitionFieldSetPersist._items, finalMax}, LocaleContextHolder.getLocale())) ); } diff --git a/dmp-frontend/src/app/library/rich-text-editor/rich-text-editor.component.ts b/dmp-frontend/src/app/library/rich-text-editor/rich-text-editor.component.ts index 7f63b15f3..dcd42c862 100644 --- a/dmp-frontend/src/app/library/rich-text-editor/rich-text-editor.component.ts +++ b/dmp-frontend/src/app/library/rich-text-editor/rich-text-editor.component.ts @@ -8,7 +8,7 @@ import { Subscription } from "rxjs"; template: `
close