diff --git a/backend/core/src/main/java/org/opencdmp/commons/enums/FieldType.java b/backend/core/src/main/java/org/opencdmp/commons/enums/FieldType.java index 9046c5e3a..799481bf0 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/enums/FieldType.java +++ b/backend/core/src/main/java/org/opencdmp/commons/enums/FieldType.java @@ -47,7 +47,7 @@ public enum FieldType implements DatabaseEnum { @JsonValue public String getValue() { - return value; + return this.value; } private static final Map map = EnumUtils.getEnumValueMap(FieldType.class); @@ -62,8 +62,8 @@ public enum FieldType implements DatabaseEnum { } public static boolean isTextType(FieldType fieldType){ - return fieldType.equals(FieldType.FREE_TEXT) || fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.TEXT_AREA) || - fieldType.equals(FieldType.RICH_TEXT_AREA) || fieldType.equals(FieldType.UPLOAD) || fieldType.equals(FieldType.BOOLEAN_DECISION) || + return fieldType.equals(FieldType.FREE_TEXT) || fieldType.equals(FieldType.TEXT_AREA) || + fieldType.equals(FieldType.RICH_TEXT_AREA) || fieldType.equals(FieldType.UPLOAD) || fieldType.equals(FieldType.RADIO_BOX); } @@ -75,6 +75,9 @@ public enum FieldType implements DatabaseEnum { public static boolean isDateType(FieldType fieldType){ return fieldType.equals(FieldType.DATE_PICKER); } + public static boolean isBooleanType(FieldType fieldType){ + return fieldType.equals(FieldType.BOOLEAN_DECISION) || fieldType.equals(FieldType.CHECK_BOX); + } public static boolean isExternalIdentifierType(FieldType fieldType){ return fieldType.equals(FieldType.VALIDATION) || fieldType.equals(FieldType.DATASET_IDENTIFIER) ; diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/description/FieldEntity.java b/backend/core/src/main/java/org/opencdmp/commons/types/description/FieldEntity.java index a748ac2ad..d37664909 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/description/FieldEntity.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/description/FieldEntity.java @@ -8,6 +8,7 @@ public class FieldEntity { private String textValue; private List textListValue; private Instant dateValue; + private Boolean booleanValue; private ExternalIdentifierEntity externalIdentifier; public String getTextValue() { @@ -41,4 +42,12 @@ public class FieldEntity { public void setExternalIdentifier(ExternalIdentifierEntity externalIdentifier) { this.externalIdentifier = externalIdentifier; } + + public Boolean getBooleanValue() { + return this.booleanValue; + } + + public void setBooleanValue(Boolean booleanValue) { + this.booleanValue = booleanValue; + } } diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/description/importexport/DescriptionFieldImportExport.java b/backend/core/src/main/java/org/opencdmp/commons/types/description/importexport/DescriptionFieldImportExport.java index 6467afd43..e42ace773 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/description/importexport/DescriptionFieldImportExport.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/description/importexport/DescriptionFieldImportExport.java @@ -21,6 +21,9 @@ public class DescriptionFieldImportExport { private List textListValue; @XmlElement(name = "dateValue") private Instant dateValue; + + @XmlElement(name = "booleanValue") + private Boolean booleanValue; @XmlElement(name = "externalIdentifier") private DescriptionExternalIdentifierImportExport externalIdentifier; @@ -56,6 +59,14 @@ public class DescriptionFieldImportExport { this.dateValue = dateValue; } + public Boolean getBooleanValue() { + return this.booleanValue; + } + + public void setBooleanValue(Boolean booleanValue) { + this.booleanValue = booleanValue; + } + public DescriptionExternalIdentifierImportExport getExternalIdentifier() { return this.externalIdentifier; } diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/RuleEntity.java b/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/RuleEntity.java index cbf0c7ddb..e222b8e39 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/RuleEntity.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/RuleEntity.java @@ -18,11 +18,14 @@ public class RuleEntity { @XmlElement(name = "dateValue") private Instant dateValue; + + @XmlElement(name = "booleanValue") + private Boolean booleanValue; @XmlElement(name="externalIdentifier") private ExternalIdentifierEntity externalIdentifier; public String getTarget() { - return target; + return this.target; } public void setTarget(String target) { @@ -30,7 +33,7 @@ public class RuleEntity { } public String getTextValue() { - return textValue; + return this.textValue; } public void setTextValue(String textValue) { @@ -38,7 +41,7 @@ public class RuleEntity { } public List getTextListValue() { - return textListValue; + return this.textListValue; } public void setTextListValue(List textListValue) { @@ -46,15 +49,23 @@ public class RuleEntity { } public Instant getDateValue() { - return dateValue; + return this.dateValue; } public void setDateValue(Instant dateValue) { this.dateValue = dateValue; } + public Boolean getBooleanValue() { + return this.booleanValue; + } + + public void setBooleanValue(Boolean booleanValue) { + this.booleanValue = booleanValue; + } + public ExternalIdentifierEntity getExternalIdentifier() { - return externalIdentifier; + return this.externalIdentifier; } public void setExternalIdentifier(ExternalIdentifierEntity externalIdentifier) { diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/importexport/DescriptionTemplateRuleImportExport.java b/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/importexport/DescriptionTemplateRuleImportExport.java index f6ec1c133..811edb530 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/importexport/DescriptionTemplateRuleImportExport.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/descriptiontemplate/importexport/DescriptionTemplateRuleImportExport.java @@ -18,12 +18,15 @@ public class DescriptionTemplateRuleImportExport { private List textListValue; @XmlElement(name = "dateValue") private Instant dateValue; + + @XmlElement(name = "booleanValue") + private Boolean booleanValue; @XmlElement(name="externalIdentifier") private DescriptionTemplateExternalIdentifierImportExport externalIdentifier; public String getTarget() { - return target; + return this.target; } public void setTarget(String target) { @@ -31,7 +34,7 @@ public class DescriptionTemplateRuleImportExport { } public String getTextValue() { - return textValue; + return this.textValue; } public void setTextValue(String textValue) { @@ -39,7 +42,7 @@ public class DescriptionTemplateRuleImportExport { } public List getTextListValue() { - return textListValue; + return this.textListValue; } public void setTextListValue(List textListValue) { @@ -47,15 +50,23 @@ public class DescriptionTemplateRuleImportExport { } public Instant getDateValue() { - return dateValue; + return this.dateValue; } public void setDateValue(Instant dateValue) { this.dateValue = dateValue; } + public Boolean getBooleanValue() { + return this.booleanValue; + } + + public void setBooleanValue(Boolean booleanValue) { + this.booleanValue = booleanValue; + } + public DescriptionTemplateExternalIdentifierImportExport getExternalIdentifier() { - return externalIdentifier; + return this.externalIdentifier; } public void setExternalIdentifier(DescriptionTemplateExternalIdentifierImportExport externalIdentifier) { diff --git a/backend/core/src/main/java/org/opencdmp/data/tenant/TenantFilterAspect.java b/backend/core/src/main/java/org/opencdmp/data/tenant/TenantFilterAspect.java index f51c36f38..2aee794cc 100644 --- a/backend/core/src/main/java/org/opencdmp/data/tenant/TenantFilterAspect.java +++ b/backend/core/src/main/java/org/opencdmp/data/tenant/TenantFilterAspect.java @@ -7,6 +7,7 @@ import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.hibernate.Session; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.stereotype.Component; import javax.management.InvalidApplicationException; @@ -14,6 +15,7 @@ import javax.management.InvalidApplicationException; @Aspect @Component +@ConditionalOnMissingBean(TenantScope.class) public class TenantFilterAspect { private final TenantScope tenantScope; diff --git a/backend/core/src/main/java/org/opencdmp/data/tenant/TenantScopedBaseEntity.java b/backend/core/src/main/java/org/opencdmp/data/tenant/TenantScopedBaseEntity.java index 6b3902b75..c416b48d6 100644 --- a/backend/core/src/main/java/org/opencdmp/data/tenant/TenantScopedBaseEntity.java +++ b/backend/core/src/main/java/org/opencdmp/data/tenant/TenantScopedBaseEntity.java @@ -1,11 +1,11 @@ package org.opencdmp.data.tenant; -import org.opencdmp.commons.scope.tenant.TenantScoped; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.MappedSuperclass; import org.hibernate.annotations.Filter; import org.hibernate.annotations.FilterDef; import org.hibernate.annotations.ParamDef; - +import org.opencdmp.commons.scope.tenant.TenantScoped; import java.io.Serializable; import java.util.UUID; @@ -14,11 +14,11 @@ import java.util.UUID; //@Getter //@Setter //@NoArgsConstructor -@FilterDef(name = TenantScopedBaseEntity.TENANT_FILTER, parameters = {@ParamDef(name = TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, type = String.class)}) +@FilterDef(name = TenantScopedBaseEntity.TENANT_FILTER, parameters = @ParamDef(name = TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, type = String.class)) @FilterDef(name = TenantScopedBaseEntity.DEFAULT_TENANT_FILTER) @Filter(name = TenantScopedBaseEntity.DEFAULT_TENANT_FILTER, condition = "(tenant = tenant is null)") @Filter(name = TenantScopedBaseEntity.TENANT_FILTER, condition = "(tenant = (cast(:tenantId as uuid)) or tenant is null)") -@EntityListeners(TenantListener.class) +//@EntityListeners(TenantListener.class) public abstract class TenantScopedBaseEntity implements TenantScoped, Serializable { private static final long serialVersionUID = 1L; public static final String TENANT_FILTER = "tenantFilter"; @@ -29,7 +29,7 @@ public abstract class TenantScopedBaseEntity implements TenantScoped, Serializab private UUID tenantId; public static final String _tenantId = "tenantId"; public UUID getTenantId() { - return tenantId; + return this.tenantId; } @Override diff --git a/backend/core/src/main/java/org/opencdmp/model/builder/commonmodels/description/FieldCommonModelBuilder.java b/backend/core/src/main/java/org/opencdmp/model/builder/commonmodels/description/FieldCommonModelBuilder.java index a30e4c7b6..189994610 100644 --- a/backend/core/src/main/java/org/opencdmp/model/builder/commonmodels/description/FieldCommonModelBuilder.java +++ b/backend/core/src/main/java/org/opencdmp/model/builder/commonmodels/description/FieldCommonModelBuilder.java @@ -1,5 +1,12 @@ package org.opencdmp.model.builder.commonmodels.description; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.BaseFieldSet; +import gr.cite.tools.logging.LoggerService; +import gr.cite.tools.validation.ValidatorFactory; +import org.apache.commons.io.FilenameUtils; import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.commonmodels.models.FileEnvelopeModel; import org.opencdmp.commonmodels.models.description.FieldModel; @@ -21,13 +28,6 @@ import org.opencdmp.query.ReferenceQuery; import org.opencdmp.query.StorageFileQuery; import org.opencdmp.service.storage.StorageFileProperties; import org.opencdmp.service.storage.StorageFileService; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.query.QueryFactory; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.fieldset.BaseFieldSet; -import gr.cite.tools.logging.LoggerService; -import gr.cite.tools.validation.ValidatorFactory; -import org.apache.commons.io.FilenameUtils; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -41,7 +41,7 @@ import java.util.*; import java.util.stream.Collectors; @Component("commonmodels.description") -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class FieldCommonModelBuilder extends BaseCommonModelBuilder { private final BuilderFactory builderFactory; private final QueryFactory queryFactory; @@ -91,8 +91,9 @@ public class FieldCommonModelBuilder extends BaseCommonModelBuilder> models = new ArrayList<>(); for (FieldEntity d : data) { FieldModel m = new FieldModel(); - if (this.fieldEntity != null) m.setId(fieldEntity.getId()); + if (this.fieldEntity != null) m.setId(this.fieldEntity.getId()); if (FieldType.isDateType(fieldType)) m.setDateValue(d.getDateValue()); + //if (FieldType.isBooleanType(fieldType)) m.setDateValue(d.getBooleanValue()); //TODO: Common field if (FieldType.isTextType(fieldType)) m.setTextValue(d.getTextValue()); if (FieldType.isTextListType(fieldType)) m.setTextListValue(d.getTextListValue()); if (FieldType.isReferenceType(fieldType) && referenceItemsMap != null && d.getTextListValue() != null && !d.getTextListValue().isEmpty()) { @@ -110,13 +111,13 @@ public class FieldCommonModelBuilder extends BaseCommonModelBuilder { private final BuilderFactory builderFactory; private final QueryFactory queryFactory; @@ -71,6 +71,7 @@ public class FieldBuilder extends BaseBuilder { for (FieldEntity d : data) { Field m = new Field(); if (fields.hasField(this.asIndexer(Field._dateValue)) && FieldType.isDateType(fieldType)) m.setDateValue(d.getDateValue()); + if (fields.hasField(this.asIndexer(Field._booleanValue)) && FieldType.isBooleanType(fieldType)) m.setBooleanValue(d.getBooleanValue()); if (fields.hasField(this.asIndexer(Field._textValue)) && FieldType.isTextType(fieldType)) m.setTextValue(d.getTextValue()); if (fields.hasField(this.asIndexer(Field._textListValue)) && FieldType.isTextListType(fieldType)) { boolean isMultiSelect = true; @@ -127,7 +128,7 @@ public class FieldBuilder extends BaseBuilder { } FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Reference._id); ReferenceQuery q = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).ids(ids); - itemMap = this.builderFactory.builder(ReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Reference::getId);; + itemMap = this.builderFactory.builder(ReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Reference::getId); } if (!fields.hasField(Reference._id)) { diff --git a/backend/core/src/main/java/org/opencdmp/model/builder/descriptiontemplatedefinition/RuleBuilder.java b/backend/core/src/main/java/org/opencdmp/model/builder/descriptiontemplatedefinition/RuleBuilder.java index ddb465189..2e957f851 100644 --- a/backend/core/src/main/java/org/opencdmp/model/builder/descriptiontemplatedefinition/RuleBuilder.java +++ b/backend/core/src/main/java/org/opencdmp/model/builder/descriptiontemplatedefinition/RuleBuilder.java @@ -1,5 +1,12 @@ package org.opencdmp.model.builder.descriptiontemplatedefinition; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.BaseFieldSet; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.commons.enums.FieldType; import org.opencdmp.commons.types.descriptiontemplate.RuleEntity; @@ -9,13 +16,6 @@ import org.opencdmp.model.builder.BaseBuilder; import org.opencdmp.model.builder.ReferenceBuilder; import org.opencdmp.model.descriptiontemplatedefinition.Rule; import org.opencdmp.query.ReferenceQuery; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.query.QueryFactory; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.fieldset.BaseFieldSet; -import gr.cite.tools.fieldset.FieldSet; -import gr.cite.tools.logging.DataLogEntry; -import gr.cite.tools.logging.LoggerService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -26,7 +26,7 @@ import java.util.*; import java.util.stream.Collectors; @Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class RuleBuilder extends BaseBuilder { private final BuilderFactory builderFactory; @@ -70,6 +70,7 @@ public class RuleBuilder extends BaseBuilder { Rule m = new Rule(); if (fields.hasField(this.asIndexer(Rule._target))) m.setTarget(d.getTarget()); if (fields.hasField(this.asIndexer(Rule._dateValue)) && FieldType.isDateType(fieldType)) m.setDateValue(d.getDateValue()); + if (fields.hasField(this.asIndexer(Rule._booleanValue)) && FieldType.isBooleanType(fieldType)) m.setBooleanValue(d.getBooleanValue()); if (fields.hasField(this.asIndexer(Rule._textValue)) && FieldType.isTextType(fieldType)) m.setTextValue(d.getTextValue()); if (fields.hasField(this.asIndexer(Rule._textListValue)) && FieldType.isTextListType(fieldType)) m.setTextListValue(d.getTextListValue()); if (!referenceFields.isEmpty() && FieldType.isReferenceType(fieldType) && referenceItemsMap != null && d.getTextListValue() != null && !d.getTextListValue().isEmpty()) { diff --git a/backend/core/src/main/java/org/opencdmp/model/descriptionproperties/Field.java b/backend/core/src/main/java/org/opencdmp/model/descriptionproperties/Field.java index 81289551a..1aefc64bf 100644 --- a/backend/core/src/main/java/org/opencdmp/model/descriptionproperties/Field.java +++ b/backend/core/src/main/java/org/opencdmp/model/descriptionproperties/Field.java @@ -1,7 +1,6 @@ package org.opencdmp.model.descriptionproperties; -import org.opencdmp.commons.enums.FieldType; import org.opencdmp.model.Reference; import java.time.Instant; @@ -18,6 +17,9 @@ public class Field { private Instant dateValue; public static final String _dateValue = "dateValue"; + private Boolean booleanValue; + public static final String _booleanValue = "booleanValue"; + private List references; public static final String _references = "references"; @@ -25,7 +27,7 @@ public class Field { public static final String _externalIdentifier = "externalIdentifier"; public String getTextValue() { - return textValue; + return this.textValue; } public void setTextValue(String textValue) { @@ -33,7 +35,7 @@ public class Field { } public List getTextListValue() { - return textListValue; + return this.textListValue; } public void setTextListValue(List textListValue) { @@ -41,15 +43,23 @@ public class Field { } public Instant getDateValue() { - return dateValue; + return this.dateValue; } public void setDateValue(Instant dateValue) { this.dateValue = dateValue; } + public Boolean getBooleanValue() { + return this.booleanValue; + } + + public void setBooleanValue(Boolean booleanValue) { + this.booleanValue = booleanValue; + } + public List getReferences() { - return references; + return this.references; } public void setReferences(List references) { @@ -57,7 +67,7 @@ public class Field { } public ExternalIdentifier getExternalIdentifier() { - return externalIdentifier; + return this.externalIdentifier; } public void setExternalIdentifier(ExternalIdentifier externalIdentifier) { diff --git a/backend/core/src/main/java/org/opencdmp/model/descriptiontemplatedefinition/Rule.java b/backend/core/src/main/java/org/opencdmp/model/descriptiontemplatedefinition/Rule.java index fdf06de67..5d3960959 100644 --- a/backend/core/src/main/java/org/opencdmp/model/descriptiontemplatedefinition/Rule.java +++ b/backend/core/src/main/java/org/opencdmp/model/descriptiontemplatedefinition/Rule.java @@ -20,6 +20,9 @@ public class Rule { private Instant dateValue; public static final String _dateValue = "dateValue"; + private Boolean booleanValue; + public static final String _booleanValue = "booleanValue"; + private List references; public static final String _references = "references"; @@ -28,7 +31,7 @@ public class Rule { public String getTarget() { - return target; + return this.target; } public void setTarget(String target) { @@ -36,7 +39,7 @@ public class Rule { } public String getTextValue() { - return textValue; + return this.textValue; } public void setTextValue(String textValue) { @@ -44,7 +47,7 @@ public class Rule { } public List getTextListValue() { - return textListValue; + return this.textListValue; } public void setTextListValue(List textListValue) { @@ -52,15 +55,23 @@ public class Rule { } public Instant getDateValue() { - return dateValue; + return this.dateValue; } public void setDateValue(Instant dateValue) { this.dateValue = dateValue; } + public Boolean getBooleanValue() { + return this.booleanValue; + } + + public void setBooleanValue(Boolean booleanValue) { + this.booleanValue = booleanValue; + } + public List getReferences() { - return references; + return this.references; } public void setReferences(List references) { @@ -68,7 +79,7 @@ public class Rule { } public ExternalIdentifier getExternalIdentifier() { - return externalIdentifier; + return this.externalIdentifier; } public void setExternalIdentifier(ExternalIdentifier externalIdentifier) { diff --git a/backend/core/src/main/java/org/opencdmp/model/mapper/publicapi/DescriptionFieldToDatasetFieldMapper.java b/backend/core/src/main/java/org/opencdmp/model/mapper/publicapi/DescriptionFieldToDatasetFieldMapper.java index 02c061011..08732590b 100644 --- a/backend/core/src/main/java/org/opencdmp/model/mapper/publicapi/DescriptionFieldToDatasetFieldMapper.java +++ b/backend/core/src/main/java/org/opencdmp/model/mapper/publicapi/DescriptionFieldToDatasetFieldMapper.java @@ -3,9 +3,9 @@ package org.opencdmp.model.mapper.publicapi; import org.opencdmp.commons.types.descriptiontemplate.ExternalIdentifierEntity; import org.opencdmp.commons.types.descriptiontemplate.RuleEntity; import org.opencdmp.model.publicapi.datasetwizard.DefaultValueEntity; +import org.opencdmp.model.publicapi.datasetwizard.Field; import org.opencdmp.model.publicapi.datasetwizard.FieldDescriptionEntity; import org.opencdmp.model.publicapi.datasetwizard.VisibilityEntity; -import org.opencdmp.model.publicapi.datasetwizard.Field; import org.springframework.stereotype.Component; @Component @@ -29,7 +29,7 @@ public class DescriptionFieldToDatasetFieldMapper { visibilityEntity.setRules(field.getVisibilityRules().stream().map(x -> { RuleEntity ruleEntity = new RuleEntity(); ruleEntity.setDateValue(x.getDateValue()); - ruleEntity.setTextValue(x.getTextValue()); + ruleEntity.setBooleanValue(x.getBooleanValue()); ruleEntity.setTextListValue(x.getTextListValue()); if (x.getExternalIdentifier() != null){ ruleEntity.setExternalIdentifier(new ExternalIdentifierEntity()); diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/descriptionproperties/FieldPersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/descriptionproperties/FieldPersist.java index 19323ecf3..c80917440 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/descriptionproperties/FieldPersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/descriptionproperties/FieldPersist.java @@ -1,17 +1,16 @@ package org.opencdmp.model.persist.descriptionproperties; +import gr.cite.tools.validation.ValidatorFactory; +import gr.cite.tools.validation.specification.Specification; import org.opencdmp.commons.enums.DescriptionStatus; import org.opencdmp.commons.enums.FieldType; import org.opencdmp.commons.enums.FieldValidationType; import org.opencdmp.commons.types.descriptiontemplate.FieldEntity; -import org.opencdmp.commons.types.descriptiontemplate.RuleEntity; import org.opencdmp.commons.validation.BaseValidator; -import org.opencdmp.model.persist.ReferencePersist; -import org.opencdmp.service.visibility.VisibilityService; -import gr.cite.tools.validation.ValidatorFactory; -import gr.cite.tools.validation.specification.Specification; import org.opencdmp.convention.ConventionService; import org.opencdmp.errorcode.ErrorThesaurusProperties; +import org.opencdmp.model.persist.ReferencePersist; +import org.opencdmp.service.visibility.VisibilityService; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Component; @@ -30,6 +29,9 @@ public class FieldPersist { private Instant dateValue; public static final String _dateValue = "dateValue"; + + private Boolean booleanValue; + public static final String _booleanValue = "booleanValue"; private List references; public static final String _references = "references"; @@ -41,7 +43,7 @@ public class FieldPersist { public static final String _externalIdentifier = "externalIdentifier"; public String getTextValue() { - return textValue; + return this.textValue; } public void setTextValue(String textValue) { @@ -49,7 +51,7 @@ public class FieldPersist { } public List getTextListValue() { - return textListValue; + return this.textListValue; } public void setTextListValue(List textListValue) { @@ -57,15 +59,23 @@ public class FieldPersist { } public Instant getDateValue() { - return dateValue; + return this.dateValue; } public void setDateValue(Instant dateValue) { this.dateValue = dateValue; } + public Boolean getBooleanValue() { + return this.booleanValue; + } + + public void setBooleanValue(Boolean booleanValue) { + this.booleanValue = booleanValue; + } + public List getReferences() { - return references; + return this.references; } public void setReferences(List references) { @@ -73,7 +83,7 @@ public class FieldPersist { } public ReferencePersist getReference() { - return reference; + return this.reference; } public void setReference(ReferencePersist reference) { @@ -81,7 +91,7 @@ public class FieldPersist { } public ExternalIdentifierPersist getExternalIdentifier() { - return externalIdentifier; + return this.externalIdentifier; } public void setExternalIdentifier(ExternalIdentifierPersist externalIdentifier) { @@ -115,40 +125,40 @@ public class FieldPersist { protected List specifications(FieldPersist item) { FieldType fieldType = this.fieldEntity != null && this.fieldEntity.getData() != null ? this.fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT; boolean required = this.fieldEntity != null && this.fieldEntity.getValidations() != null ? this.fieldEntity.getValidations().contains(FieldValidationType.Required) : false; - boolean isVisible = this.visibilityService.isVisible(fieldEntity.getId(), ordinal); + boolean isVisible = this.fieldEntity != null ? this.visibilityService.isVisible(this.fieldEntity.getId(), this.ordinal) : true; return Arrays.asList( this.spec() - .iff(()-> FieldType.isTextType(fieldType) && !fieldType.equals(FieldType.CHECK_BOX) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required) + .iff(()-> FieldType.isTextType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required) .must(() -> !this.isEmpty(item.getTextValue())) - .failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())), + .failOn(FieldPersist._textValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> FieldType.isDateType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required) .must(() -> !this.isNull(item.getDateValue())) - .failOn(FieldPersist._dateValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._dateValue}, LocaleContextHolder.getLocale())), + .failOn(FieldPersist._dateValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._dateValue}, LocaleContextHolder.getLocale())), + this.spec() + .iff(()-> FieldType.isBooleanType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required) + .must(() -> !this.isNull(item.getBooleanValue())) + .failOn(FieldPersist._booleanValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._booleanValue}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> FieldType.isExternalIdentifierType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required) .must(() -> !this.isNull(item.getExternalIdentifier())) - .failOn(FieldPersist._externalIdentifier).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._externalIdentifier}, LocaleContextHolder.getLocale())), + .failOn(FieldPersist._externalIdentifier).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._externalIdentifier}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> FieldType.isTextListType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required && !fieldType.equals(FieldType.TAGS)) .must(() -> !this.isListNullOrEmpty(item.getTextListValue()) || !this.isEmpty(item.getTextValue())) - .failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), + .failOn(FieldPersist._textListValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> fieldType.equals(FieldType.TAGS) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required) .must(() -> !this.isListNullOrEmpty(item.getTextListValue())) - .failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), + .failOn(FieldPersist._textListValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> FieldType.isReferenceType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required) .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))) - .must(() -> this.isBoolean(item.getTextValue())) - .failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())), + .failOn(FieldPersist._textListValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> !this.isNull(item.getTextListValue()) && (fieldType.equals(FieldType.INTERNAL_ENTRIES_DMPS) || fieldType.equals(FieldType.INTERNAL_ENTRIES_DESCRIPTIONS))) .must(() -> item.getTextListValue().stream().allMatch(this::isUUID)) - .failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), + .failOn(FieldPersist._textListValue).failWith(this.messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), this.navSpec() .iff(() -> FieldType.isReferenceType(fieldType) && !this.isListNullOrEmpty(item.getReferences())) .on(FieldPersist._references) diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/RulePersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/RulePersist.java index 1d7673481..9bce057cd 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/RulePersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/RulePersist.java @@ -1,13 +1,12 @@ package org.opencdmp.model.persist.descriptiontemplatedefinition; -import org.opencdmp.commons.enums.FieldType; -import org.opencdmp.commons.validation.BaseValidator; -import org.opencdmp.model.persist.ReferencePersist; -import org.opencdmp.model.persist.descriptionproperties.FieldPersist; import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.specification.Specification; +import org.opencdmp.commons.enums.FieldType; +import org.opencdmp.commons.validation.BaseValidator; import org.opencdmp.convention.ConventionService; import org.opencdmp.errorcode.ErrorThesaurusProperties; +import org.opencdmp.model.persist.ReferencePersist; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Scope; @@ -20,7 +19,7 @@ import java.util.List; public class RulePersist { - private String target = null; + private String target; public static final String _target = "target"; @@ -33,6 +32,9 @@ public class RulePersist { private Instant dateValue; public static final String _dateValue = "dateValue"; + private Boolean booleanValue; + public static final String _booleanValue = "booleanValue"; + private List references; public static final String _references = "references"; @@ -41,7 +43,7 @@ public class RulePersist { public static final String _externalIdentifier = "externalIdentifier"; public String getTarget() { - return target; + return this.target; } public void setTarget(String target) { @@ -49,7 +51,7 @@ public class RulePersist { } public String getTextValue() { - return textValue; + return this.textValue; } public void setTextValue(String textValue) { @@ -57,7 +59,7 @@ public class RulePersist { } public List getTextListValue() { - return textListValue; + return this.textListValue; } public void setTextListValue(List textListValue) { @@ -65,15 +67,23 @@ public class RulePersist { } public Instant getDateValue() { - return dateValue; + return this.dateValue; } public void setDateValue(Instant dateValue) { this.dateValue = dateValue; } + public Boolean getBooleanValue() { + return this.booleanValue; + } + + public void setBooleanValue(Boolean booleanValue) { + this.booleanValue = booleanValue; + } + public List getReferences() { - return references; + return this.references; } public void setReferences(List references) { @@ -81,7 +91,7 @@ public class RulePersist { } public ExternalIdentifierPersist getExternalIdentifier() { - return externalIdentifier; + return this.externalIdentifier; } public void setExternalIdentifier(ExternalIdentifierPersist externalIdentifier) { @@ -120,43 +130,43 @@ public class RulePersist { return Arrays.asList( this.spec() .must(() -> !this.isEmpty(item.getTarget())) - .failOn(RulePersist._target).failWith(messageSource.getMessage("Validation_Required", new Object[]{RulePersist._target}, LocaleContextHolder.getLocale())), + .failOn(RulePersist._target).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{RulePersist._target}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> FieldType.isTextType(fieldType)) .must(() -> !this.isEmpty(item.getTextValue())) - .failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())), + .failOn(RulePersist._textValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{RulePersist._textValue}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> FieldType.isDateType(fieldType)) .must(() -> !this.isNull(item.getDateValue())) - .failOn(FieldPersist._dateValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._dateValue}, LocaleContextHolder.getLocale())), + .failOn(RulePersist._dateValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{RulePersist._dateValue}, LocaleContextHolder.getLocale())), + this.spec() + .iff(()-> FieldType.isBooleanType(fieldType)) + .must(() -> !this.isNull(item.getBooleanValue())) + .failOn(RulePersist._booleanValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{RulePersist._booleanValue}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> FieldType.isExternalIdentifierType(fieldType)) .must(() -> !this.isNull(item.getExternalIdentifier())) - .failOn(FieldPersist._externalIdentifier).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._externalIdentifier}, LocaleContextHolder.getLocale())), + .failOn(RulePersist._externalIdentifier).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{RulePersist._externalIdentifier}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> FieldType.isTextListType(fieldType)) .must(() -> !this.isNull(item.getTextListValue())) - .failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), + .failOn(RulePersist._textListValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{RulePersist._textListValue}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> FieldType.isReferenceType(fieldType)) .must(() -> !this.isNull(item.getTextListValue())) - .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) ) - .must(() -> this.isBoolean(item.getTextValue())) - .failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())), + .failOn(RulePersist._textListValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{RulePersist._textListValue}, LocaleContextHolder.getLocale())), this.spec() .iff(()-> !this.isNull(item.getTextListValue()) && (fieldType.equals(FieldType.INTERNAL_ENTRIES_DMPS) || fieldType.equals(FieldType.INTERNAL_ENTRIES_DESCRIPTIONS))) .must(() -> item.getTextListValue().stream().allMatch(this::isUUID)) - .failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())), + .failOn(RulePersist._textListValue).failWith(this.messageSource.getMessage("Validation_UnexpectedValue", new Object[]{RulePersist._textListValue}, LocaleContextHolder.getLocale())), this.navSpec() .iff(() -> FieldType.isReferenceType(fieldType) && !this.isListNullOrEmpty(item.getReferences())) - .on(FieldPersist._references) + .on(RulePersist._references) .over(item.getReferences()) .using((itm) -> this.validatorFactory.validator(ReferencePersist.ReferencePersistValidator.class)), this.refSpec() .iff(() -> FieldType.isExternalIdentifierType(fieldType) && !this.isNull(item.getExternalIdentifier())) - .on(FieldPersist._externalIdentifier) + .on(RulePersist._externalIdentifier) .over(item.getExternalIdentifier()) .using(() -> this.validatorFactory.validator(ExternalIdentifierPersist.PersistValidator.class)) ); diff --git a/backend/core/src/main/java/org/opencdmp/model/publicapi/datasetwizard/Rule.java b/backend/core/src/main/java/org/opencdmp/model/publicapi/datasetwizard/Rule.java index b4ce544ad..dbbb62582 100644 --- a/backend/core/src/main/java/org/opencdmp/model/publicapi/datasetwizard/Rule.java +++ b/backend/core/src/main/java/org/opencdmp/model/publicapi/datasetwizard/Rule.java @@ -9,7 +9,7 @@ public class Rule { private String type; public String getSourceField() { - return sourceField; + return this.sourceField; } public void setSourceField(String sourceField) { @@ -17,7 +17,7 @@ public class Rule { } public String getTargetField() { - return targetField; + return this.targetField; } public void setTargetField(String targetField) { @@ -25,7 +25,7 @@ public class Rule { } public String getRequiredValue() { - return requiredValue; + return this.requiredValue; } public void setRequiredValue(String requiredValue) { @@ -33,7 +33,7 @@ public class Rule { } public String getType() { - return type; + return this.type; } public void setType(String type) { @@ -45,6 +45,7 @@ public class Rule { //TODO if (rule.getTextValue() != null && !rule.getTextListValue().isEmpty()) this.requiredValue = rule.getTextValue(); else if (rule.getDateValue() != null) this.requiredValue = rule.getDateValue().toString(); + else if (rule.getBooleanValue() != null) this.requiredValue = rule.getBooleanValue().toString(); else if (rule.getTextListValue() != null) this.requiredValue = String.join(", ", rule.getTextListValue()); else if (rule.getExternalIdentifier() != null) this.requiredValue = rule.getExternalIdentifier().getIdentifier(); return this; diff --git a/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java index 5d34a0964..6354f01e8 100644 --- a/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java @@ -567,6 +567,7 @@ public class DescriptionServiceImpl implements DescriptionService { if (referenceIds != null) data.setTextListValue(referenceIds.stream().map(UUID::toString).toList()); } else if (FieldType.isDateType(fieldType)) data.setDateValue(persist.getDateValue()); + else if (FieldType.isBooleanType(fieldType)) data.setBooleanValue(persist.getBooleanValue()); else if (FieldType.isExternalIdentifierType(fieldType) && persist.getExternalIdentifier() != null) data.setExternalIdentifier(this.buildExternalIdentifierEntity(persist.getExternalIdentifier())); return data; @@ -1068,6 +1069,7 @@ public class DescriptionServiceImpl implements DescriptionService { if (FieldType.isTextType(fieldType)) persist.setTextValue(data.getTextValue()); else if (FieldType.isTextListType(fieldType)) persist.setTextListValue(data.getTextListValue()); else if (FieldType.isDateType(fieldType)) persist.setDateValue(persist.getDateValue()); + else if (FieldType.isBooleanType(fieldType)) persist.setBooleanValue(persist.getBooleanValue()); else if (FieldType.isExternalIdentifierType(fieldType) && data.getExternalIdentifier() != null) persist.setExternalIdentifier(this.buildExternalIdentifierPersist(data.getExternalIdentifier())); else if (FieldType.isReferenceType(fieldType) && fieldEntity != null ) { if (!this.conventionService.isListNullOrEmpty(data.getTextListValue()) && !this.conventionService.isListNullOrEmpty(references)){ @@ -1254,6 +1256,7 @@ public class DescriptionServiceImpl implements DescriptionService { if (entity == null) return xml; xml.setDateValue(entity.getDateValue()); + xml.setBooleanValue(entity.getBooleanValue()); xml.setTextValue(entity.getTextValue()); xml.setTextListValue(entity.getTextListValue()); if (entity.getExternalIdentifier() != null) { 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 b09fbeb73..efc5b3d67 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 @@ -1,39 +1,6 @@ package org.opencdmp.service.descriptiontemplate; import com.fasterxml.jackson.core.JsonProcessingException; -import org.opencdmp.authorization.AuthorizationFlags; -import org.opencdmp.authorization.Permission; -import org.opencdmp.commons.JsonHandlingService; -import org.opencdmp.commons.XmlHandlingService; -import org.opencdmp.commons.enums.*; -import org.opencdmp.commons.scope.tenant.TenantScope; -import org.opencdmp.commons.scope.user.UserScope; -import org.opencdmp.commons.types.descriptiontemplate.*; -import org.opencdmp.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity; -import org.opencdmp.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity; -import org.opencdmp.commons.types.descriptiontemplate.importexport.*; -import org.opencdmp.commons.types.notification.*; -import org.opencdmp.commons.notification.NotificationProperties; -import org.opencdmp.convention.ConventionService; -import org.opencdmp.data.*; -import org.opencdmp.errorcode.ErrorThesaurusProperties; -import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent; -import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler; -import org.opencdmp.model.*; -import org.opencdmp.model.builder.DescriptionTemplateBuilder; -import org.opencdmp.model.deleter.DescriptionTemplateDeleter; -import org.opencdmp.model.deleter.UserDescriptionTemplateDeleter; -import org.opencdmp.model.descriptiontemplatedefinition.Definition; -import org.opencdmp.model.descriptiontemplatedefinition.Field; -import org.opencdmp.model.descriptiontemplatedefinition.Page; -import org.opencdmp.model.descriptiontemplatedefinition.Section; -import org.opencdmp.model.persist.*; -import org.opencdmp.model.persist.descriptiontemplatedefinition.*; -import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist; -import org.opencdmp.query.*; -import org.opencdmp.service.fielddatahelper.FieldDataHelperService; -import org.opencdmp.service.fielddatahelper.FieldDataHelperServiceProvider; -import org.opencdmp.service.responseutils.ResponseUtilsService; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.deleter.DeleterFactory; @@ -51,6 +18,42 @@ import gr.cite.tools.validation.ValidatorFactory; import jakarta.xml.bind.JAXBException; import org.apache.commons.lang3.NotImplementedException; import org.jetbrains.annotations.NotNull; +import org.opencdmp.authorization.AuthorizationFlags; +import org.opencdmp.authorization.Permission; +import org.opencdmp.commons.JsonHandlingService; +import org.opencdmp.commons.XmlHandlingService; +import org.opencdmp.commons.enums.*; +import org.opencdmp.commons.notification.NotificationProperties; +import org.opencdmp.commons.scope.tenant.TenantScope; +import org.opencdmp.commons.scope.user.UserScope; +import org.opencdmp.commons.types.descriptiontemplate.*; +import org.opencdmp.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity; +import org.opencdmp.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity; +import org.opencdmp.commons.types.descriptiontemplate.importexport.*; +import org.opencdmp.commons.types.notification.*; +import org.opencdmp.convention.ConventionService; +import org.opencdmp.data.*; +import org.opencdmp.errorcode.ErrorThesaurusProperties; +import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEvent; +import org.opencdmp.integrationevent.outbox.notification.NotifyIntegrationEventHandler; +import org.opencdmp.model.*; +import org.opencdmp.model.builder.DescriptionTemplateBuilder; +import org.opencdmp.model.deleter.DescriptionTemplateDeleter; +import org.opencdmp.model.deleter.UserDescriptionTemplateDeleter; +import org.opencdmp.model.descriptiontemplatedefinition.Definition; +import org.opencdmp.model.descriptiontemplatedefinition.Field; +import org.opencdmp.model.descriptiontemplatedefinition.Page; +import org.opencdmp.model.descriptiontemplatedefinition.Section; +import org.opencdmp.model.persist.DescriptionTemplatePersist; +import org.opencdmp.model.persist.NewVersionDescriptionTemplatePersist; +import org.opencdmp.model.persist.ReferencePersist; +import org.opencdmp.model.persist.UserDescriptionTemplatePersist; +import org.opencdmp.model.persist.descriptiontemplatedefinition.*; +import org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist; +import org.opencdmp.query.*; +import org.opencdmp.service.fielddatahelper.FieldDataHelperService; +import org.opencdmp.service.fielddatahelper.FieldDataHelperServiceProvider; +import org.opencdmp.service.responseutils.ResponseUtilsService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; @@ -419,6 +422,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic if (!referenceIds.isEmpty()) data.setTextListValue(referenceIds.stream().map(UUID::toString).toList()); } else if (FieldType.isDateType(fieldType)) data.setDateValue(persist.getDateValue()); + else if (FieldType.isBooleanType(fieldType)) data.setBooleanValue(persist.getBooleanValue()); else if (FieldType.isExternalIdentifierType(fieldType) && persist.getExternalIdentifier() != null) data.setExternalIdentifier(this.buildExternalIdentifierEntity(persist.getExternalIdentifier())); return data; @@ -864,6 +868,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic RulePersist ruleEntity = new RulePersist(); ruleEntity.setTarget(importExport.getTarget()); ruleEntity.setDateValue(importExport.getDateValue()); + ruleEntity.setBooleanValue(importExport.getBooleanValue()); //ruleEntity.setReferences(importExport.get()); //TODO ruleEntity.setTextValue(importExport.getTextValue()); ruleEntity.setTextListValue(importExport.getTextListValue()); @@ -1016,6 +1021,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic DescriptionTemplateRuleImportExport xml = new DescriptionTemplateRuleImportExport(); xml.setTarget(entity.getTarget()); xml.setDateValue(entity.getDateValue()); + xml.setBooleanValue(entity.getBooleanValue()); xml.setTextListValue(entity.getTextListValue()); xml.setTextValue(entity.getTextValue()); if (entity.getExternalIdentifier() != null){ diff --git a/backend/core/src/main/java/org/opencdmp/service/prefillingsource/PrefillingSourceServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/prefillingsource/PrefillingSourceServiceImpl.java index 03daa3584..75092c22b 100644 --- a/backend/core/src/main/java/org/opencdmp/service/prefillingsource/PrefillingSourceServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/prefillingsource/PrefillingSourceServiceImpl.java @@ -1,5 +1,20 @@ package org.opencdmp.service.prefillingsource; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.deleter.DeleterFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.exception.MyForbiddenException; +import gr.cite.tools.exception.MyNotFoundException; +import gr.cite.tools.exception.MyValidationException; +import gr.cite.tools.fieldset.BaseFieldSet; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.LoggerService; +import gr.cite.tools.logging.MapLogEntry; +import jakarta.xml.bind.JAXBException; +import org.apache.commons.lang3.StringEscapeUtils; +import org.jetbrains.annotations.NotNull; import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.Permission; import org.opencdmp.commons.JsonHandlingService; @@ -25,8 +40,8 @@ import org.opencdmp.model.builder.PrefillingSourceBuilder; import org.opencdmp.model.deleter.PrefillingSourceDeleter; import org.opencdmp.model.descriptionproperties.*; import org.opencdmp.model.descriptionreference.DescriptionReferenceData; -import org.opencdmp.model.persist.PrefillingSearchRequest; import org.opencdmp.model.persist.DescriptionPrefillingRequest; +import org.opencdmp.model.persist.PrefillingSearchRequest; import org.opencdmp.model.persist.PrefillingSourcePersist; import org.opencdmp.model.persist.externalfetcher.*; import org.opencdmp.model.persist.prefillingsourcedefinition.PrefillingSourceDefinitionFieldPersist; @@ -40,21 +55,6 @@ import org.opencdmp.service.externalfetcher.ExternalFetcherService; import org.opencdmp.service.externalfetcher.criteria.ExternalReferenceCriteria; import org.opencdmp.service.externalfetcher.models.ExternalDataResult; import org.opencdmp.service.reference.ReferenceService; -import gr.cite.commons.web.authz.service.AuthorizationService; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.deleter.DeleterFactory; -import gr.cite.tools.data.query.QueryFactory; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.exception.MyForbiddenException; -import gr.cite.tools.exception.MyNotFoundException; -import gr.cite.tools.exception.MyValidationException; -import gr.cite.tools.fieldset.BaseFieldSet; -import gr.cite.tools.fieldset.FieldSet; -import gr.cite.tools.logging.LoggerService; -import gr.cite.tools.logging.MapLogEntry; -import jakarta.xml.bind.JAXBException; -import org.apache.commons.lang3.StringEscapeUtils; -import org.jetbrains.annotations.NotNull; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; @@ -123,7 +123,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { if (isUpdate) { data = this.entityManager.find(PrefillingSourceEntity.class, model.getId()); if (data == null) - throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale())); + throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); } else { @@ -310,11 +310,11 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { public List searchPrefillings(PrefillingSearchRequest model) { PrefillingSourceEntity prefillingSourceEntity = this.queryFactory.query(PrefillingSourceQuery.class).ids(model.getPrefillingSourceId()).isActive(IsActive.Active).first(); if (prefillingSourceEntity == null) - throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale())); + throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale())); PrefillingSourceDefinitionEntity prefillingSourceDefinition = this.xmlHandlingService.fromXmlSafe(PrefillingSourceDefinitionEntity.class, prefillingSourceEntity.getDefinition()); if (prefillingSourceDefinition == null) - throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSourceDefinition.class.getSimpleName()}, LocaleContextHolder.getLocale())); + throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSourceDefinition.class.getSimpleName()}, LocaleContextHolder.getLocale())); ExternalReferenceCriteria externalReferenceCriteria = new ExternalReferenceCriteria(); externalReferenceCriteria.setLike(model.getLike()); @@ -344,10 +344,10 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { public Description getPrefilledDescription(DescriptionPrefillingRequest model, FieldSet fieldSet) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException { PrefillingSourceEntity prefillingSourceEntity = this.queryFactory.query(PrefillingSourceQuery.class).ids(model.getPrefillingSourceId()).first(); - if (prefillingSourceEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (prefillingSourceEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSource.class.getSimpleName()}, LocaleContextHolder.getLocale())); PrefillingSourceDefinitionEntity prefillingSourceDefinition = this.xmlHandlingService.fromXmlSafe(PrefillingSourceDefinitionEntity.class, prefillingSourceEntity.getDefinition()); - if (prefillingSourceDefinition == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSourceDefinition.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (prefillingSourceDefinition == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getPrefillingSourceId(), PrefillingSourceDefinition.class.getSimpleName()}, LocaleContextHolder.getLocale())); Map data = new HashMap<>(); if (prefillingSourceDefinition.getGetConfiguration() != null){ @@ -362,14 +362,14 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { } DescriptionTemplateEntity descriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, model.getDescriptionTemplateId()); - if (descriptionTemplateEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (descriptionTemplateEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getDescriptionTemplateId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity descriptionTemplateDefinition = this.xmlHandlingService.fromXml(org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition()); Description description = new Description(); FieldSet descriptionTemplateFields = fieldSet.extractPrefixed(this.conventionService.asPrefix(Description._descriptionTemplate)); description.setDescriptionTemplate(this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(descriptionTemplateFields, descriptionTemplateEntity)); - return mapPrefilledEntityToDescription(description, descriptionTemplateDefinition, prefillingSourceDefinition, prefillingSourceEntity.getLabel(), data); + return this.mapPrefilledEntityToDescription(description, descriptionTemplateDefinition, prefillingSourceDefinition, prefillingSourceEntity.getLabel(), data); } private Description mapPrefilledEntityToDescription(Description description, DefinitionEntity descriptionTemplateDefinition, PrefillingSourceDefinitionEntity prefillingSourceDefinition, String type, Map externalData){ @@ -408,8 +408,8 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { private void ensureZenodoFields(Description description, List descriptionReferences,String semanticTarget, String value, DefinitionEntity definition, String type) { if (!this.conventionService.isNullOrEmpty(type) && !this.conventionService.isNullOrEmpty(semanticTarget) && !this.conventionService.isNullOrEmpty(value) && type.equals(Zenodo)) { - if (semanticTarget.equals("rda.dataset.distribution.data_access")) { - if (value.equals("open")) { + if ("rda.dataset.distribution.data_access".equals(semanticTarget)) { + if ("open".equals(value)) { List issuedFieldEntities = definition.getAllField().stream().filter(x -> x.getSchematics() != null && x.getSchematics().contains("rda.dataset.issued")).toList(); if (!this.conventionService.isListNullOrEmpty(issuedFieldEntities)) { String issuedIdNode = issuedFieldEntities.getFirst().getId(); @@ -424,7 +424,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { this.ensureFieldSetEntity(description, licStartFieldSetEntity); for (FieldEntity licStartDateNode : licStartEntities) { - description.getProperties().getFieldSets().get(licStartFieldSetEntity.getId()).getItems().getFirst().getFields().put(licStartDateNode.getId(), buildPropertyDefinitionFieldItemValue(descriptionReferences,licStartDateNode, semanticTarget, issuedValue, type)); + description.getProperties().getFieldSets().get(licStartFieldSetEntity.getId()).getItems().getFirst().getFields().put(licStartDateNode.getId(), this.buildPropertyDefinitionFieldItemValue(descriptionReferences,licStartDateNode, semanticTarget, issuedValue, type)); } } } @@ -453,7 +453,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { if (!this.conventionService.isListNullOrEmpty(fieldEntities)) { this.ensureFieldSetEntity(description, fieldSetEntity); for (FieldEntity fieldEntity : fieldEntities){ - description.getProperties().getFieldSets().get(fieldSetEntity.getId()).getItems().getFirst().getFields().put(fieldEntity.getId() , buildPropertyDefinitionFieldItemValue(descriptionReferences, fieldEntity, semanticTarget, parsedValue, type)); + description.getProperties().getFieldSets().get(fieldSetEntity.getId()).getItems().getFirst().getFields().put(fieldEntity.getId() , this.buildPropertyDefinitionFieldItemValue(descriptionReferences, fieldEntity, semanticTarget, parsedValue, type)); } } } @@ -489,11 +489,15 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { try{ switch (fieldEntity.getData().getFieldType()){ case FREE_TEXT, TEXT_AREA, RICH_TEXT_AREA, RADIO_BOX -> field.setTextValue(value.toLowerCase(Locale.ROOT)); - case CHECK_BOX, BOOLEAN_DECISION -> field.setTextValue(value.trim().toLowerCase(Locale.ROOT)); - case DATE_PICKER ->{ + case CHECK_BOX, BOOLEAN_DECISION ->{ + if (!this.conventionService.isNullOrEmpty(value)) { + field.setBooleanValue("true".equals(value.trim().toLowerCase(Locale.ROOT))); + } + } + case DATE_PICKER -> { Instant instant = null; try { - if (!this.conventionService.isNullOrEmpty(type) && type.equals(Zenodo) && semanticTarget.equals("rda.dataset.distribution.available_until") ) { + if (!this.conventionService.isNullOrEmpty(type) && type.equals(Zenodo) && "rda.dataset.distribution.available_until".equals(semanticTarget) ) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd"); LocalDate date = LocalDate.parse(value, formatter); date = date.plusYears(20); @@ -503,7 +507,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { } } catch (DateTimeParseException ex) { instant = LocalDate.parse(value).atStartOfDay().toInstant(ZoneOffset.UTC); - if (!this.conventionService.isNullOrEmpty(type) && type.equals(Zenodo) && semanticTarget.equals("rda.dataset.distribution.available_until") ) { + if (!this.conventionService.isNullOrEmpty(type) && type.equals(Zenodo) && "rda.dataset.distribution.available_until".equals(semanticTarget) ) { instant.plus(20, ChronoUnit.YEARS); } } diff --git a/backend/core/src/main/java/org/opencdmp/service/visibility/Field.java b/backend/core/src/main/java/org/opencdmp/service/visibility/Field.java index e5379d2fe..e6980043a 100644 --- a/backend/core/src/main/java/org/opencdmp/service/visibility/Field.java +++ b/backend/core/src/main/java/org/opencdmp/service/visibility/Field.java @@ -14,6 +14,7 @@ public class Field { private final List textListValue; private final Instant dateValue; + private final Boolean booleanValue; private final ExternalIdentifier externalIdentifier; @@ -31,6 +32,9 @@ public class Field { return this.dateValue; } + public Boolean getBooleanValue() { + return this.booleanValue; + } public ExternalIdentifier getExternalIdentifier() { return this.externalIdentifier; @@ -41,6 +45,7 @@ public class Field { List tempTextListValue; this.textValue = persist.getTextValue(); this.dateValue = persist.getDateValue(); + this.booleanValue = persist.getBooleanValue(); tempTextListValue = persist.getTextListValue(); if (persist.getExternalIdentifier() != null) this.externalIdentifier = new ExternalIdentifier(persist.getExternalIdentifier()); else this.externalIdentifier = null; @@ -58,6 +63,7 @@ public class Field { public Field(FieldEntity entity){ this.textValue = entity.getTextValue(); this.dateValue = entity.getDateValue(); + this.booleanValue = entity.getBooleanValue(); this.textListValue = entity.getTextListValue(); if (entity.getExternalIdentifier() != null) this.externalIdentifier = new ExternalIdentifier(entity.getExternalIdentifier()); else this.externalIdentifier = null; diff --git a/backend/core/src/main/java/org/opencdmp/service/visibility/RuleWithTarget.java b/backend/core/src/main/java/org/opencdmp/service/visibility/RuleWithTarget.java index 3f532bf30..7dd61fbda 100644 --- a/backend/core/src/main/java/org/opencdmp/service/visibility/RuleWithTarget.java +++ b/backend/core/src/main/java/org/opencdmp/service/visibility/RuleWithTarget.java @@ -12,6 +12,7 @@ public class RuleWithTarget{ private final String textValue; private final List textListValue; private final Instant dateValue; + private final Boolean booleanValue; private final FieldEntity fieldEntity; public RuleWithTarget(String source, RuleEntity rule, FieldEntity fieldEntity) { @@ -21,29 +22,34 @@ public class RuleWithTarget{ this.textValue = rule.getTextValue(); this.textListValue = rule.getTextListValue(); this.dateValue = rule.getDateValue(); + this.booleanValue = rule.getBooleanValue(); } public String getTarget() { - return target; + return this.target; } public String getSource() { - return source; + return this.source; } public String getTextValue() { - return textValue; + return this.textValue; } public List getTextListValue() { - return textListValue; + return this.textListValue; } public Instant getDateValue() { - return dateValue; + return this.dateValue; + } + + public Boolean getBooleanValue() { + return this.booleanValue; } public FieldEntity getFieldEntity() { - return fieldEntity; + return this.fieldEntity; } } diff --git a/backend/core/src/main/java/org/opencdmp/service/visibility/VisibilityServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/visibility/VisibilityServiceImpl.java index bda109caf..08d3e8106 100644 --- a/backend/core/src/main/java/org/opencdmp/service/visibility/VisibilityServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/visibility/VisibilityServiceImpl.java @@ -1,9 +1,9 @@ package org.opencdmp.service.visibility; +import org.apache.commons.lang3.NotImplementedException; import org.opencdmp.commons.types.description.PropertyDefinitionEntity; import org.opencdmp.commons.types.descriptiontemplate.*; import org.opencdmp.model.persist.descriptionproperties.PropertyDefinitionPersist; -import org.apache.commons.lang3.NotImplementedException; import java.util.*; @@ -363,15 +363,11 @@ public class VisibilityServiceImpl implements VisibilityService { new HashSet<>(field.getTextListValue()).containsAll(rule.getTextListValue()); } else if (org.opencdmp.commons.enums.FieldType.isDateType(fieldType) && field.getDateValue() != null) return field.getDateValue().equals(rule.getDateValue()); + else if (org.opencdmp.commons.enums.FieldType.isBooleanType(fieldType) && field.getBooleanValue() != null) return field.getBooleanValue().equals(rule.getBooleanValue()); else if (org.opencdmp.commons.enums.FieldType.isExternalIdentifierType(fieldType) && field.getExternalIdentifier() != null) { throw new NotImplementedException("External identifier rule not supported"); } } return false; } - - - - } - diff --git a/backend/web/src/main/java/org/opencdmp/controllers/publicapi/PublicDatasetsDescriptionDocumentation.java b/backend/web/src/main/java/org/opencdmp/controllers/publicapi/PublicDatasetsDescriptionDocumentation.java index 6bf4867e9..4a7964001 100644 --- a/backend/web/src/main/java/org/opencdmp/controllers/publicapi/PublicDatasetsDescriptionDocumentation.java +++ b/backend/web/src/main/java/org/opencdmp/controllers/publicapi/PublicDatasetsDescriptionDocumentation.java @@ -1,27 +1,5 @@ package org.opencdmp.controllers.publicapi; -import org.opencdmp.authorization.AuthorizationFlags; -import org.opencdmp.commons.enums.IsActive; -import org.opencdmp.controllers.publicapi.request.dataset.DatasetPublicTableRequest; -import org.opencdmp.controllers.publicapi.response.DataTableData; -import org.opencdmp.data.DescriptionEntity; -import org.opencdmp.model.*; -import org.opencdmp.model.builder.DescriptionBuilder; -import org.opencdmp.model.builder.DmpBuilder; -import org.opencdmp.model.descriptiontemplatedefinition.*; -import org.opencdmp.model.descriptiontemplatedefinition.fielddata.BaseFieldData; -import org.opencdmp.model.mapper.publicapi.DescriptionToPublicApiDatasetListingMapper; -import org.opencdmp.model.mapper.publicapi.DescriptionToPublicApiDatasetMapper; -import org.opencdmp.model.mapper.publicapi.DmpToPublicApiDmpListingMapper; -import org.opencdmp.model.publicapi.listingmodels.DatasetPublicListingModel; -import org.opencdmp.model.publicapi.overviewmodels.DatasetPublicModel; -import org.opencdmp.controllers.publicapi.types.ResponseItem; -import org.opencdmp.query.DescriptionQuery; -import org.opencdmp.query.DmpQuery; -import org.opencdmp.query.lookup.DescriptionLookup; -import org.opencdmp.query.lookup.DmpLookup; -import org.opencdmp.service.publicapi.PublicApiProperties; -import org.opencdmp.controllers.publicapi.types.ApiMessageCode; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyNotFoundException; @@ -34,6 +12,28 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.jetbrains.annotations.NotNull; +import org.opencdmp.authorization.AuthorizationFlags; +import org.opencdmp.commons.enums.IsActive; +import org.opencdmp.controllers.publicapi.request.dataset.DatasetPublicTableRequest; +import org.opencdmp.controllers.publicapi.response.DataTableData; +import org.opencdmp.controllers.publicapi.types.ApiMessageCode; +import org.opencdmp.controllers.publicapi.types.ResponseItem; +import org.opencdmp.data.DescriptionEntity; +import org.opencdmp.model.*; +import org.opencdmp.model.builder.DescriptionBuilder; +import org.opencdmp.model.builder.DmpBuilder; +import org.opencdmp.model.descriptiontemplatedefinition.*; +import org.opencdmp.model.descriptiontemplatedefinition.fielddata.BaseFieldData; +import org.opencdmp.model.mapper.publicapi.DescriptionToPublicApiDatasetListingMapper; +import org.opencdmp.model.mapper.publicapi.DescriptionToPublicApiDatasetMapper; +import org.opencdmp.model.mapper.publicapi.DmpToPublicApiDmpListingMapper; +import org.opencdmp.model.publicapi.listingmodels.DatasetPublicListingModel; +import org.opencdmp.model.publicapi.overviewmodels.DatasetPublicModel; +import org.opencdmp.query.DescriptionQuery; +import org.opencdmp.query.DmpQuery; +import org.opencdmp.query.lookup.DescriptionLookup; +import org.opencdmp.query.lookup.DmpLookup; +import org.opencdmp.service.publicapi.PublicApiProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -53,7 +53,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Tag(name = "Datasets Description", description = "Provides Dataset description public API's.") @RestController @CrossOrigin -@RequestMapping(value = {"/api/public/datasets/"}) +@RequestMapping("/api/public/datasets/") public class PublicDatasetsDescriptionDocumentation { private static final Logger logger = LoggerFactory.getLogger(PublicDatasetsDescriptionDocumentation.class); @@ -89,13 +89,11 @@ public class PublicDatasetsDescriptionDocumentation { } @Operation(summary = "This method is used to get a listing of public datasets.", description = PublicApiStaticHelpers.Description.getPagedNotes) - @io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@io.swagger.v3.oas.annotations.responses.ApiResponse( - responseCode = "200", - description = "The following example is generated using body: *{\"criteria\": {},\"length\": 2,\"offset\": 0,\"orderings\": {\"fields\": []} }*", - content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = {@ExampleObject( - value = PublicApiStaticHelpers.Description.getPagedResponseExample - )}) - )}) + @io.swagger.v3.oas.annotations.responses.ApiResponses(@ApiResponse( + responseCode = "200", + description = "The following example is generated using body: *{\"criteria\": {},\"length\": 2,\"offset\": 0,\"orderings\": {\"fields\": []} }*", + content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = @ExampleObject(PublicApiStaticHelpers.Description.getPagedResponseExample)) + )) @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getPaged( @Valid @RequestBody @io.swagger.v3.oas.annotations.parameters.RequestBody(description = PublicApiStaticHelpers.Description.getPagedRequestBodyDescription) DatasetPublicTableRequest datasetTableRequest @@ -113,14 +111,12 @@ public class PublicDatasetsDescriptionDocumentation { } @Operation(summary = "This method is used to get the overview of a public dataset.", description = PublicApiStaticHelpers.Description.getOverviewSinglePublicNotes) - @io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@ApiResponse( - responseCode = "200", - description = "The following example is generated using id: *ef7dfbdc-c5c1-46a7-a37b-c8d8692f1c0e*", - content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = {@ExampleObject( - value = PublicApiStaticHelpers.Description.getOverviewSinglePublicResponseExample - )}) - )}) - @RequestMapping(method = RequestMethod.GET, value = {"/{id}"}, produces = "application/json") + @io.swagger.v3.oas.annotations.responses.ApiResponses(@ApiResponse( + responseCode = "200", + description = "The following example is generated using id: *ef7dfbdc-c5c1-46a7-a37b-c8d8692f1c0e*", + content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = @ExampleObject(PublicApiStaticHelpers.Description.getOverviewSinglePublicResponseExample)) + )) + @RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = "application/json") public @ResponseBody ResponseEntity> getOverviewSinglePublic( @PathVariable @Parameter(description = "fetch the dataset with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id ) { @@ -128,7 +124,7 @@ public class PublicDatasetsDescriptionDocumentation { DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(EnumSet.of(AuthorizationFlags.Public)).ids(UUID.fromString(id)).isActive(IsActive.Active); Description model = this.builderFactory.builder(DescriptionBuilder.class).build(lookup.getProject(), query.firstAs(lookup.getProject())); if (model == null) - throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale())); + throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale())); DmpQuery dmpQuery = this.queryFactory.query(DmpQuery.class).ids(model.getDmp().getId()).isActive(IsActive.Active); DmpLookup dmpLookup = getDmpLookup(); @@ -193,6 +189,7 @@ public class PublicDatasetsDescriptionDocumentation { String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._validations), String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._target), String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._dateValue), + String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._booleanValue), String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._textListValue), String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._textValue), String.join(".", Description._descriptionTemplate, DescriptionTemplate._definition, Definition._pages, Page._sections, Section._fieldSets, FieldSet._fields, Field._visibilityRules, Rule._externalIdentifier), diff --git a/dmp-frontend/src/app/core/model/description-template/description-template-persist.ts b/dmp-frontend/src/app/core/model/description-template/description-template-persist.ts index 1d4981076..298f1bb41 100644 --- a/dmp-frontend/src/app/core/model/description-template/description-template-persist.ts +++ b/dmp-frontend/src/app/core/model/description-template/description-template-persist.ts @@ -86,6 +86,7 @@ export interface DescriptionTemplateRulePersist { textValue: string; textListValue: string[]; dateValue: Date; + booleanValue: boolean; } export interface DescriptionTemplateMultiplicityPersist { diff --git a/dmp-frontend/src/app/core/model/description-template/description-template.ts b/dmp-frontend/src/app/core/model/description-template/description-template.ts index 3ca14a895..aab1b3926 100644 --- a/dmp-frontend/src/app/core/model/description-template/description-template.ts +++ b/dmp-frontend/src/app/core/model/description-template/description-template.ts @@ -84,6 +84,7 @@ export interface DescriptionTemplateRule { textValue: string; textListValue: string[]; dateValue: Date; + booleanValue: boolean; } export interface DescriptionTemplateMultiplicity { diff --git a/dmp-frontend/src/app/core/model/description/description.ts b/dmp-frontend/src/app/core/model/description/description.ts index cd6fd094d..15849e5e3 100644 --- a/dmp-frontend/src/app/core/model/description/description.ts +++ b/dmp-frontend/src/app/core/model/description/description.ts @@ -42,6 +42,7 @@ export interface DescriptionField { textValue: string; textListValue: string[]; dateValue: Date; + booleanValue: boolean; externalIdentifier?: DescriptionExternalIdentifier; references: Reference[]; } @@ -98,6 +99,7 @@ export interface DescriptionFieldPersist { textValue: string; textListValue: string[]; dateValue: Date; + booleanValue: boolean; references: ReferencePersist[]; reference: ReferencePersist; externalIdentifier?: DescriptionExternalIdentifierPersist; diff --git a/dmp-frontend/src/app/core/pipes/field-value.pipe.ts b/dmp-frontend/src/app/core/pipes/field-value.pipe.ts index 68e3e2c67..8211d559b 100644 --- a/dmp-frontend/src/app/core/pipes/field-value.pipe.ts +++ b/dmp-frontend/src/app/core/pipes/field-value.pipe.ts @@ -28,9 +28,9 @@ export class FieldValuePipe implements PipeTransform { if (field?.data?.fieldType && controlValue) { switch (field.data.fieldType) { case DescriptionTemplateFieldType.BOOLEAN_DECISION: - return of(controlValue.textValue == 'true' ? 'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.BOOLEAN-DECISION.YES' : 'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.BOOLEAN-DECISION.NO'); + return of(controlValue.booleanValue ? 'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.BOOLEAN-DECISION.YES' : 'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.BOOLEAN-DECISION.NO'); case DescriptionTemplateFieldType.CHECK_BOX: - return of(controlValue.textValue == 'true' ? 'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.BOOLEAN-DECISION.YES' : 'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.BOOLEAN-DECISION.NO'); + return of(controlValue.booleanValue ? 'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.BOOLEAN-DECISION.YES' : 'DATASET-PROFILE-EDITOR.STEPS.FORM.FIELD.DEFAULT-VALUES.BOOLEAN-DECISION.NO'); case DescriptionTemplateFieldType.RADIO_BOX: { const data = field.data; if (data?.options) { diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.html b/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.html index 723f305be..16316a9e7 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.html +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.html @@ -7,6 +7,9 @@
+
+ +
@@ -48,4 +51,4 @@ delete - \ No newline at end of file + diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts index 00711e1ac..d813a68f4 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/visibility-rule/description-template-editor-visibility-rule.component.ts @@ -40,13 +40,13 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { } isTextType(type: DescriptionTemplateFieldType){ - return type == DescriptionTemplateFieldType.FREE_TEXT || type == DescriptionTemplateFieldType.CHECK_BOX || + return type == DescriptionTemplateFieldType.FREE_TEXT || type == DescriptionTemplateFieldType.TEXT_AREA || type == DescriptionTemplateFieldType.RICH_TEXT_AREA || - type == DescriptionTemplateFieldType.BOOLEAN_DECISION || type == DescriptionTemplateFieldType.RADIO_BOX; + type == DescriptionTemplateFieldType.BOOLEAN_DECISION ; } isTextListType(type: DescriptionTemplateFieldType){ - return type == DescriptionTemplateFieldType.TAGS || type == DescriptionTemplateFieldType.INTERNAL_ENTRIES_DMPS || + return type == DescriptionTemplateFieldType.TAGS || type == DescriptionTemplateFieldType.INTERNAL_ENTRIES_DMPS || type == DescriptionTemplateFieldType.INTERNAL_ENTRIES_DESCRIPTIONS || type == DescriptionTemplateFieldType.SELECT; } @@ -54,6 +54,10 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit { return type == DescriptionTemplateFieldType.DATE_PICKER; } + isBooleanType(type: DescriptionTemplateFieldType){ + return type == DescriptionTemplateFieldType.CHECK_BOX || type == DescriptionTemplateFieldType.RADIO_BOX; + } + isReferenceType(type: DescriptionTemplateFieldType){ return type == DescriptionTemplateFieldType.REFERENCE_TYPES; } @@ -250,4 +254,4 @@ interface OptionItem { parentsIds: string[], form: UntypedFormGroup, hiddenBy: string[] -} \ No newline at end of file +} diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.model.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.model.ts index 347511ba0..1496c2507 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.model.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.model.ts @@ -880,6 +880,7 @@ export class DescriptionTemplateRuleEditorModel implements DescriptionTemplateRu textValue: string; textListValue: string[]; dateValue: Date; + booleanValue: boolean; protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); @@ -893,6 +894,7 @@ export class DescriptionTemplateRuleEditorModel implements DescriptionTemplateRu this.textValue = item.textValue; this.textListValue = item.textListValue; this.dateValue = item.dateValue; + this.booleanValue = item.booleanValue; } return this; } @@ -914,7 +916,8 @@ export class DescriptionTemplateRuleEditorModel implements DescriptionTemplateRu target: [{ value: this.target, disabled: disabled }, context.getValidation('target').validators], textValue: [{ value: this.textValue, disabled: disabled }, context.getValidation('textValue').validators], textListValue: [{ value: this.textListValue, disabled: disabled }, context.getValidation('textListValue').validators], - dateValue: [{ value: this.dateValue, disabled: disabled }, context.getValidation('dateValue').validators] + dateValue: [{ value: this.dateValue, disabled: disabled }, context.getValidation('dateValue').validators], + booleanValue: [{ value: this.booleanValue, disabled: disabled }, context.getValidation('booleanValue').validators] }); } @@ -930,6 +933,7 @@ export class DescriptionTemplateRuleEditorModel implements DescriptionTemplateRu baseValidationArray.push({ key: 'textValue', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}textValue`)] }); baseValidationArray.push({ key: 'textListValue', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}textListValue`)] }); baseValidationArray.push({ key: 'dateValue', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}dateValue`)] }); + baseValidationArray.push({ key: 'booleanValue', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}booleanValue`)] }); baseContext.validation = baseValidationArray; return baseContext; @@ -947,7 +951,7 @@ export class DescriptionTemplateRuleEditorModel implements DescriptionTemplateRu validationErrorModel }); - ['target', 'textValue', 'textListValue', 'dateValue'].forEach(keyField => { + ['target', 'textValue', 'textListValue', 'dateValue', 'booleanValue'].forEach(keyField => { const control = formGroup?.get(keyField); control?.clearValidators(); control?.addValidators(context.getValidation(keyField).validators); diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.resolver.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.resolver.ts index 1c7bb2c84..e5b359826 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.resolver.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/description-template-editor.resolver.ts @@ -70,6 +70,7 @@ export class DescriptionTemplateEditorResolver extends BaseEditorResolver { [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.visibilityRules), nameof(x => x.textValue)].join('.'), [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.visibilityRules), nameof(x => x.textListValue)].join('.'), [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.visibilityRules), nameof(x => x.dateValue)].join('.'), + [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.visibilityRules), nameof(x => x.booleanValue)].join('.'), [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.data), nameof(x => x.label)].join('.'), [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.data), nameof(x => x.fieldType)].join('.'), [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.data), nameof(x => x.multipleSelect)].join('.'), diff --git a/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts b/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts index 02eb5d4ba..8d16700eb 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts @@ -223,6 +223,7 @@ export class DescriptionPropertyDefinitionEditorModel implements DescriptionProp textValue: undefined, textListValue: undefined, dateValue: undefined, + booleanValue: definitionField.defaultValue && definitionField.defaultValue.length > 0 ? definitionField.defaultValue.trim().toLocaleLowerCase() == "true" : false, //TODO: booleanValue default value externalIdentifier: undefined, references: undefined }); @@ -244,6 +245,7 @@ export class DescriptionPropertyDefinitionEditorModel implements DescriptionProp textValue: undefined, textListValue: undefined, dateValue: undefined, + booleanValue: undefined, externalIdentifier: undefined, references: undefined }; @@ -432,6 +434,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist { textValue: string; textListValue: string[]; dateValue: Date; + booleanValue: boolean; references: ReferencePersist[] = []; reference: ReferencePersist; externalIdentifier?: DescriptionExternalIdentifierEditorModel = new DescriptionExternalIdentifierEditorModel(this.validationErrorModel); @@ -447,6 +450,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist { this.textValue = item.textValue; this.textListValue = item.textListValue; this.dateValue = item.dateValue; + this.booleanValue = item.booleanValue; const references = descriptionReferences?.filter(x => x.data?.fieldId == descriptionTemplateField?.id && x.isActive == IsActive.Active).map(x => { return { @@ -494,6 +498,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist { textValue: [{ value: this.textValue, disabled: disabled }, context.getValidation('textValue').validators], textListValue: [{ value: this.textListValue, disabled: disabled }, context.getValidation('textListValue').validators], dateValue: [{ value: this.dateValue, disabled: disabled }, context.getValidation('dateValue').validators], + booleanValue: [{ value: this.booleanValue, disabled: disabled }, context.getValidation('booleanValue').validators], references: [{ value: this.references, disabled: disabled }, context.getValidation('references').validators], reference: [{ value: this.reference, disabled: disabled }, context.getValidation('reference').validators], externalIdentifier: this.externalIdentifier.buildForm({ @@ -513,6 +518,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist { baseValidationArray.push({ key: 'textValue', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}textValue`)] }); baseValidationArray.push({ key: 'textListValue', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}textListValue`)] }); baseValidationArray.push({ key: 'dateValue', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}dateValue`)] }); + baseValidationArray.push({ key: 'booleanValue', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}booleanValue`)] }); baseValidationArray.push({ key: 'references', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}references`)] }); baseValidationArray.push({ key: 'reference', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}references`)] }); baseValidationArray.push({ key: 'externalIdentifier', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}externalIdentifier`)] }); @@ -532,7 +538,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist { validationErrorModel }); - ['textValue', 'textListValue', 'dateValue'].forEach(keyField => { + ['textValue', 'textListValue', 'dateValue', 'booleanValue'].forEach(keyField => { const control = formGroup?.get(keyField); control?.clearValidators(); control?.addValidators(context.getValidation(keyField).validators); @@ -709,8 +715,6 @@ export class DescriptionFieldIndicator { switch (type) { case DescriptionTemplateFieldType.FREE_TEXT: case DescriptionTemplateFieldType.BOOLEAN_DECISION: - case DescriptionTemplateFieldType.CHECK_BOX: - case DescriptionTemplateFieldType.RADIO_BOX: case DescriptionTemplateFieldType.TEXT_AREA: case DescriptionTemplateFieldType.UPLOAD: case DescriptionTemplateFieldType.RICH_TEXT_AREA: @@ -723,6 +727,10 @@ export class DescriptionFieldIndicator { case DescriptionTemplateFieldType.DATE_PICKER: this.type = "dateValue"; break; + case DescriptionTemplateFieldType.CHECK_BOX: + case DescriptionTemplateFieldType.RADIO_BOX: + this.type = "booleanValue"; + break; case DescriptionTemplateFieldType.INTERNAL_ENTRIES_DESCRIPTIONS: if (multipleSelect) this.type = "textListValue"; else this.type = "textValue" diff --git a/dmp-frontend/src/app/ui/description/editor/description-editor.resolver.ts b/dmp-frontend/src/app/ui/description/editor/description-editor.resolver.ts index 0deabe44c..98c01a07a 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-editor.resolver.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-editor.resolver.ts @@ -66,6 +66,7 @@ export class DescriptionEditorResolver extends BaseEditorResolver { [nameof(x => x.properties), nameof(x => x.fieldSets), nameof(x => x.items), nameof(x => x.fields), nameof(x => x.textValue)].join('.'), [nameof(x => x.properties), nameof(x => x.fieldSets), nameof(x => x.items), nameof(x => x.fields), nameof(x => x.textListValue)].join('.'), [nameof(x => x.properties), nameof(x => x.fieldSets), nameof(x => x.items), nameof(x => x.fields), nameof(x => x.dateValue)].join('.'), + [nameof(x => x.properties), nameof(x => x.fieldSets), nameof(x => x.items), nameof(x => x.fields), nameof(x => x.booleanValue)].join('.'), [nameof(x => x.properties), nameof(x => x.fieldSets), nameof(x => x.items), nameof(x => x.fields), nameof(x => x.externalIdentifier), nameof(x => x.identifier)].join('.'), [nameof(x => x.properties), nameof(x => x.fieldSets), nameof(x => x.items), nameof(x => x.fields), nameof(x => x.externalIdentifier), nameof(x => x.type)].join('.'), [nameof(x => x.properties), nameof(x => x.fieldSets), nameof(x => x.items), nameof(x => x.fields), nameof(x => x.references), nameof(x => x.id)].join('.'), @@ -128,6 +129,7 @@ export class DescriptionEditorResolver extends BaseEditorResolver { (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.visibilityRules), nameof(x => x.textValue)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.visibilityRules), nameof(x => x.textListValue)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.visibilityRules), nameof(x => x.dateValue)].join('.'), + (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.visibilityRules), nameof(x => x.booleanValue)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.data), nameof(x => x.label)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.data), nameof(x => x.fieldType)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.sections), nameof(x => x.fieldSets), nameof(x => x.fields), nameof(x => x.data), nameof(x => x.options), nameof(x => x.label)].join('.'), diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.html b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.html index c3e514155..00ce8250c 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.html +++ b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.html @@ -82,9 +82,9 @@
- + {{field.data.label}} - {{propertiesFormGroup?.get(field.id).get('textValue').getError('backendError').message}} + {{propertiesFormGroup?.get(field.id).get('booleanValue').getError('backendError').message}}
@@ -126,14 +126,14 @@
- - {{ "TYPES.DATASET-PROFILE-COMBO-BOX-TYPE.ACTIONS.YES" | translate }} - {{ "TYPES.DATASET-PROFILE-COMBO-BOX-TYPE.ACTIONS.NO" | translate }} - {{propertiesFormGroup?.get(field.id).get('textValue').getError('backendError').message}} + + {{ "TYPES.DATASET-PROFILE-COMBO-BOX-TYPE.ACTIONS.YES" | translate }} + {{ "TYPES.DATASET-PROFILE-COMBO-BOX-TYPE.ACTIONS.NO" | translate }} + {{propertiesFormGroup?.get(field.id).get('booleanValue').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}}
diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.ts b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.ts index d2f1a74a5..a904605f7 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field/form-field.component.ts @@ -162,10 +162,7 @@ export class DescriptionFormFieldComponent extends BaseComponent implements OnIn // this.form.disable(); // } break; - case DescriptionTemplateFieldType.CHECK_BOX: - if (this.propertiesFormGroup?.get(this.field.id).get('textValue').value == undefined) this.propertiesFormGroup?.get(this.field.id).get('textValue').setValue("false"); - this.visibilityRulesService.reloadVisibility(); - break; + } // this.form = this.visibilityRulesService.getFormGroup(this.field.id); diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/models/rule.ts b/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/models/rule.ts index dacbea2a8..4d392ba7f 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/models/rule.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/models/rule.ts @@ -6,6 +6,7 @@ export class RuleWithTarget { textValue: string; textListValue: string[]; dateValue: Date; + booleanValue: boolean; field: DescriptionTemplateField; public constructor(source: string, rule: DescriptionTemplateRule , fieldEntity: DescriptionTemplateField) { @@ -15,5 +16,6 @@ export class RuleWithTarget { this.textValue = rule.textValue; this.textListValue = rule.textListValue; this.dateValue = rule.dateValue; + this.booleanValue = rule.booleanValue; } } diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts b/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts index a4aa7d700..12b241343 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts @@ -270,9 +270,8 @@ export class VisibilityRulesService { private ruleIsTrue(rule: RuleWithTarget, field: DescriptionFieldPersist) :boolean{ if (field != null){ const fieldType: DescriptionTemplateFieldType = rule.field != null && rule.field.data != null ? rule.field.data.fieldType : DescriptionTemplateFieldType.FREE_TEXT; - if ([DescriptionTemplateFieldType.FREE_TEXT, DescriptionTemplateFieldType.CHECK_BOX, DescriptionTemplateFieldType.TEXT_AREA, - DescriptionTemplateFieldType.RICH_TEXT_AREA, DescriptionTemplateFieldType.UPLOAD, DescriptionTemplateFieldType.BOOLEAN_DECISION, - DescriptionTemplateFieldType.RADIO_BOX].includes(fieldType) && field.textValue != null && field.textValue.length > 0) { + if ([DescriptionTemplateFieldType.FREE_TEXT, DescriptionTemplateFieldType.RADIO_BOX, DescriptionTemplateFieldType.TEXT_AREA, + DescriptionTemplateFieldType.RICH_TEXT_AREA, DescriptionTemplateFieldType.UPLOAD].includes(fieldType) && field.textValue != null && field.textValue.length > 0) { if (DescriptionTemplateFieldType.UPLOAD == fieldType){ return false; //not apply visibility logic } else { @@ -287,6 +286,9 @@ export class VisibilityRulesService { else if (DescriptionTemplateFieldType.REFERENCE_TYPES == fieldType) { return false; //not implemented visibility logic } + else if ([DescriptionTemplateFieldType.CHECK_BOX, DescriptionTemplateFieldType.BOOLEAN_DECISION].includes(fieldType)) { + return field.booleanValue == rule.booleanValue; + } else if (DescriptionTemplateFieldType.DATE_PICKER == fieldType && field.dateValue != null) return field.dateValue == rule.dateValue; else if ([DescriptionTemplateFieldType.VALIDATION, DescriptionTemplateFieldType.DATASET_IDENTIFIER].includes(fieldType) && field.externalIdentifier != null) { return false; //not implemented visibility logic diff --git a/dmp-frontend/src/app/ui/description/editor/form-progress-indication/form-progress-indication.component.ts b/dmp-frontend/src/app/ui/description/editor/form-progress-indication/form-progress-indication.component.ts index d73319008..1b62dc6ea 100644 --- a/dmp-frontend/src/app/ui/description/editor/form-progress-indication/form-progress-indication.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/form-progress-indication/form-progress-indication.component.ts @@ -17,7 +17,7 @@ export class FormProgressIndicationComponent extends BaseComponent implements On progressSoFar: number; total: number; percent: number; - fieldTypes: string[] = ['dateValue', 'externalIdentifier.identifier', 'externalIdentifier.type', 'reference', 'references', 'textListValue', 'textValue']; + fieldTypes: string[] = ['dateValue', 'booleanValue', 'externalIdentifier.identifier', 'externalIdentifier.type', 'reference', 'references', 'textListValue', 'textValue']; constructor(private visibilityRulesService: VisibilityRulesService) { super(); } @@ -66,7 +66,7 @@ export class FormProgressIndicationComponent extends BaseComponent implements On return valueCurrent; } - countRequiredFieldsByFieldset(ordinal: number, fieldsFormGroup: UntypedFormGroup, filterValid: boolean = false): number { + countRequiredFieldsByFieldset(ordinal: number, fieldsFormGroup: UntypedFormGroup, filterValid: boolean = false): number { let fieldsCount: number = 0; const fieldNames = Object.keys(fieldsFormGroup.controls); for(let item of fieldNames) { @@ -207,8 +207,8 @@ export class FormProgressIndicationComponent extends BaseComponent implements On if (validator && validator.required) { return true; } - } - + } + return false; } diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java index 23ff5289d..58dac7a92 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java @@ -375,7 +375,11 @@ public class DatasetMigrationService { if (textValue == null || textValue.isEmpty()) return fieldEntity; switch (currentField.getData().getFieldType()){ case FREE_TEXT, TEXT_AREA, RICH_TEXT_AREA, RADIO_BOX -> fieldEntity.setTextValue(textValue.trim()); - case CHECK_BOX, BOOLEAN_DECISION -> fieldEntity.setTextValue(textValue.trim().toLowerCase(Locale.ROOT)); + case CHECK_BOX, BOOLEAN_DECISION -> { + if (!this.conventionService.isNullOrEmpty(textValue)) { + fieldEntity.setBooleanValue("true".equals(textValue.trim().toLowerCase(Locale.ROOT))); + } + } case DATE_PICKER -> { Instant instant = null; if(!this.conventionService.isNullOrEmpty(textValue)) { diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java index 3e9965b5a..0d68d0e77 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DescriptionTemplateXmlMigrationService.java @@ -416,7 +416,11 @@ public class DescriptionTemplateXmlMigrationService { data.setTarget(persist.getTarget()); switch (fieldType){ case FREE_TEXT, TEXT_AREA, RICH_TEXT_AREA, RADIO_BOX -> data.setTextValue(textValue.trim()); - case CHECK_BOX, BOOLEAN_DECISION -> data.setTextValue(textValue.trim().toLowerCase(Locale.ROOT)); + case CHECK_BOX, BOOLEAN_DECISION -> { + if (!this.conventionService.isNullOrEmpty(textValue)) { + data.setBooleanValue("true".equals(textValue.trim().toLowerCase(Locale.ROOT))); + } + } case DATE_PICKER -> { Instant instant = null; if(!this.conventionService.isNullOrEmpty(textValue)) {