From 3b426db49c751e3d5e13cd03b8ef1cb9e01823fd Mon Sep 17 00:00:00 2001 From: amentis Date: Tue, 18 Jun 2024 17:32:06 +0300 Subject: [PATCH] fix multiplicity issue --- .../descriptiontemplate/MultiplicityEntity.java | 12 ++++++------ .../MultiplicityPersist.java | 2 +- .../DescriptionTemplateServiceImpl.java | 5 +---- .../form-field-set/form-field-set.component.html | 6 +++--- .../form-field-set/form-field-set.component.ts | 6 ++++++ 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/MultiplicityEntity.java b/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/MultiplicityEntity.java index 728d817a9..6a01e4e4e 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/MultiplicityEntity.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/MultiplicityEntity.java @@ -8,27 +8,27 @@ import jakarta.xml.bind.annotation.XmlAttribute; public class MultiplicityEntity { @XmlAttribute(name="min") - private int min; + private Integer min; @XmlAttribute(name="max") - private int max; + private Integer max; @XmlAttribute(name="placeholder") private String placeholder; @XmlAttribute(name="tableView") private boolean tableView; - public int getMin() { + public Integer getMin() { return min; } - public void setMin(int min) { + public void setMin(Integer min) { this.min = min; } - public int getMax() { + public Integer getMax() { return max; } - public void setMax(int max) { + public void setMax(Integer max) { this.max = max; } diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/MultiplicityPersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/MultiplicityPersist.java index 4f1f2cb35..f5d75bd5a 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/MultiplicityPersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/MultiplicityPersist.java @@ -85,7 +85,7 @@ public class MultiplicityPersist { .failOn(MultiplicityPersist._min).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{MultiplicityPersist._min}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> !this.isNull(item.getMax())) - .must(() -> item.getMax() >= 0) + .must(() -> item.getMax() > 0) .failOn(MultiplicityPersist._max).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{MultiplicityPersist._max}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> !this.isNull(item.getMax())) diff --git a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java index 737cb674f..e20609c5c 100644 --- a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java @@ -354,10 +354,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic data.setHasMultiplicity(persist.getHasMultiplicity()); data.setAdditionalInformation(persist.getAdditionalInformation()); data.setExtendedDescription(persist.getExtendedDescription()); - if (persist.getMultiplicity() != null && persist.getHasMultiplicity() && ( - (persist.getMultiplicity().getMin() != null && persist.getMultiplicity().getMin() != 0) - || (persist.getMultiplicity().getMax() != null && persist.getMultiplicity().getMax() != 0) - )) { + if (persist.getMultiplicity() != null && persist.getHasMultiplicity()) { data.setMultiplicity(this.buildMultiplicityEntity(persist.getMultiplicity())); } data.setHasCommentField(persist.getHasCommentField()); diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.html b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.html index 7ce63b90d..656c4d9cc 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.html +++ b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.html @@ -32,7 +32,7 @@ -
+
{{'GENERAL.VALIDATION.MULTIPLICITY.MIN' | translate: { min: fieldSet.multiplicity.min} }} {{'GENERAL.VALIDATION,MULTIPLICITY.MAX' | translate: { max: fieldSet.multiplicity.max} }} @@ -40,7 +40,7 @@ add_circle {{fieldSet.multiplicity.placeholder}} - {{('DESCRIPTION-EDITOR.ACTIONS.MULTIPLICITY-ADD-ONE-FIELD' + (fieldSet.multiplicity.tableView?'-TABLEVIEW':'')) | translate}} + {{('DESCRIPTION-EDITOR.ACTIONS.MULTIPLICITY-ADD-ONE-FIELD' + (fieldSet.multiplicity?.tableView?'-TABLEVIEW':'')) | translate}}
@@ -70,7 +70,7 @@ - + {{'GENERAL.VALIDATION.MULTIPLICITY.MIN' | translate: { min: fieldSet.multiplicity.min} }} {{'GENERAL.VALIDATION,MULTIPLICITY.MAX' | translate: { max: fieldSet.multiplicity.max} }} diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts index 09fe51322..6da5f3057 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.ts @@ -71,6 +71,12 @@ export class DescriptionFormFieldSetComponent extends BaseComponent { }); } + canAddMultiplicityField(): boolean{ + if (!this.fieldSet.hasMultiplicity) return false; + if (this.fieldSet?.multiplicity?.max) return this.fieldSet.multiplicity.max > (this.propertiesFormGroup.get('items') as UntypedFormArray).length; + return true; + } + addMultiplicityField() { const formArray = this.propertiesFormGroup?.get('items') as UntypedFormArray; if (formArray.disabled) {