From 750f109b7ded59847cad5f1d4b717fdd7f54049e Mon Sep 17 00:00:00 2001 From: amentis Date: Thu, 23 May 2024 16:58:12 +0300 Subject: [PATCH] add dateValue to dmp blueprint value --- .../types/dmp/DmpBlueprintValueEntity.java | 10 ++ .../DmpBlueprintValueImportExport.java | 12 ++ .../builder/dmp/DmpBlueprintValueBuilder.java | 32 ++++- .../model/builder/dmp/DmpBuilder.java | 33 ++++- .../builder/dmp/DmpPropertiesBuilder.java | 9 +- .../opencdmp/model/dmp/DmpBlueprintValue.java | 11 ++ .../DmpBlueprintValuePersist.java | 23 +++- .../opencdmp/service/dmp/DmpServiceImpl.java | 114 ++++++++++++------ dmp-frontend/src/app/core/model/dmp/dmp.ts | 2 + .../dmp-editor.component.html | 6 +- .../dmp-editor-blueprint/dmp-editor.model.ts | 9 +- .../dmp-editor.resolver.ts | 1 + 12 files changed, 210 insertions(+), 52 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/dmp/DmpBlueprintValueEntity.java b/backend/core/src/main/java/org/opencdmp/commons/types/dmp/DmpBlueprintValueEntity.java index efe8775d4..f90e3ffbb 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/dmp/DmpBlueprintValueEntity.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/dmp/DmpBlueprintValueEntity.java @@ -1,5 +1,6 @@ package org.opencdmp.commons.types.dmp; +import java.time.Instant; import java.util.UUID; public class DmpBlueprintValueEntity { @@ -8,6 +9,8 @@ public class DmpBlueprintValueEntity { private String value; + private Instant dateValue; + public UUID getFieldId() { return fieldId; } @@ -24,4 +27,11 @@ public class DmpBlueprintValueEntity { this.value = value; } + public Instant getDateValue() { + return dateValue; + } + + public void setDateValue(Instant dateValue) { + this.dateValue = dateValue; + } } diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/dmp/importexport/DmpBlueprintValueImportExport.java b/backend/core/src/main/java/org/opencdmp/commons/types/dmp/importexport/DmpBlueprintValueImportExport.java index 8970bab98..08e148ec1 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/dmp/importexport/DmpBlueprintValueImportExport.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/dmp/importexport/DmpBlueprintValueImportExport.java @@ -5,6 +5,7 @@ import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlElement; +import java.time.Instant; import java.util.UUID; @XmlAccessorType(XmlAccessType.FIELD) @@ -17,6 +18,9 @@ public class DmpBlueprintValueImportExport { @XmlElement(name = "value") private String value; + @XmlElement(name = "dateValue") + private Instant dateValue; + public UUID getFieldId() { return this.fieldId; } @@ -32,4 +36,12 @@ public class DmpBlueprintValueImportExport { public void setValue(String value) { this.value = value; } + + public Instant getDateValue() { + return dateValue; + } + + public void setDateValue(Instant dateValue) { + this.dateValue = dateValue; + } } diff --git a/backend/core/src/main/java/org/opencdmp/model/builder/dmp/DmpBlueprintValueBuilder.java b/backend/core/src/main/java/org/opencdmp/model/builder/dmp/DmpBlueprintValueBuilder.java index 04c18a361..918ce05e4 100644 --- a/backend/core/src/main/java/org/opencdmp/model/builder/dmp/DmpBlueprintValueBuilder.java +++ b/backend/core/src/main/java/org/opencdmp/model/builder/dmp/DmpBlueprintValueBuilder.java @@ -5,7 +5,12 @@ 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.DmpBlueprintExtraFieldDataType; +import org.opencdmp.commons.enums.DmpBlueprintFieldCategory; import org.opencdmp.commons.types.dmp.DmpBlueprintValueEntity; +import org.opencdmp.commons.types.dmpblueprint.DefinitionEntity; +import org.opencdmp.commons.types.dmpblueprint.ExtraFieldEntity; +import org.opencdmp.commons.types.dmpblueprint.FieldEntity; import org.opencdmp.convention.ConventionService; import org.opencdmp.model.builder.BaseBuilder; import org.opencdmp.model.dmp.DmpBlueprintValue; @@ -23,6 +28,8 @@ public class DmpBlueprintValueBuilder extends BaseBuilder authorize = EnumSet.of(AuthorizationFlags.None); + private DefinitionEntity definition; + @Autowired public DmpBlueprintValueBuilder( ConventionService conventionService) { @@ -34,6 +41,11 @@ public class DmpBlueprintValueBuilder extends BaseBuilder build(FieldSet DmpBlueprintValues, List data) throws MyApplicationException { this.logger.debug("building for {} items requesting {} DmpBlueprintValues", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(DmpBlueprintValues).map(FieldSet::getFields).map(Set::size).orElse(0)); @@ -44,11 +56,21 @@ public class DmpBlueprintValueBuilder extends BaseBuilder models = new ArrayList<>(); for (DmpBlueprintValueEntity d : data) { - DmpBlueprintValue m = new DmpBlueprintValue(); - if (DmpBlueprintValues.hasField(this.asIndexer(DmpBlueprintValue._fieldValue))) m.setFieldValue(d.getValue()); - if (DmpBlueprintValues.hasField(this.asIndexer(DmpBlueprintValue._fieldId))) m.setFieldId(d.getFieldId()); - - models.add(m); + FieldEntity fieldEntity = this.definition != null ? this.definition.getFieldById(d.getFieldId()).stream().findFirst().orElse(null) : null; + + if (fieldEntity != null && fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) { + ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity; + DmpBlueprintValue m = new DmpBlueprintValue(); + if (DmpBlueprintValues.hasField(this.asIndexer(DmpBlueprintValue._fieldId))) m.setFieldId(d.getFieldId()); + if (extraFieldEntity != null && extraFieldEntity.getType().equals(DmpBlueprintExtraFieldDataType.Date)){ + if (DmpBlueprintValues.hasField(this.asIndexer(DmpBlueprintValue._dateValue))) m.setDateValue(d.getDateValue()); + } else { + if (DmpBlueprintValues.hasField(this.asIndexer(DmpBlueprintValue._fieldValue))) m.setFieldValue(d.getValue()); + } + + models.add(m); + } + } this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); return models; diff --git a/backend/core/src/main/java/org/opencdmp/model/builder/dmp/DmpBuilder.java b/backend/core/src/main/java/org/opencdmp/model/builder/dmp/DmpBuilder.java index 0c06bd05c..745521b8d 100644 --- a/backend/core/src/main/java/org/opencdmp/model/builder/dmp/DmpBuilder.java +++ b/backend/core/src/main/java/org/opencdmp/model/builder/dmp/DmpBuilder.java @@ -14,10 +14,13 @@ import org.opencdmp.authorization.AffiliatedResource; import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.authorizationcontentresolver.AuthorizationContentResolver; import org.opencdmp.commons.JsonHandlingService; +import org.opencdmp.commons.XmlHandlingService; import org.opencdmp.commons.enums.EntityType; import org.opencdmp.commons.scope.tenant.TenantScope; import org.opencdmp.commons.types.dmp.DmpPropertiesEntity; +import org.opencdmp.commons.types.dmpblueprint.DefinitionEntity; import org.opencdmp.convention.ConventionService; +import org.opencdmp.data.DmpBlueprintEntity; import org.opencdmp.data.DmpEntity; import org.opencdmp.model.DmpDescriptionTemplate; import org.opencdmp.model.DmpUser; @@ -52,6 +55,7 @@ public class DmpBuilder extends BaseBuilder { private final BuilderFactory builderFactory; private final JsonHandlingService jsonHandlingService; + private final XmlHandlingService xmlHandlingService; private final AuthorizationService authorizationService; private final AuthorizationContentResolver authorizationContentResolver; private final TenantScope tenantScope; @@ -61,12 +65,13 @@ public class DmpBuilder extends BaseBuilder { @Autowired public DmpBuilder(ConventionService conventionService, QueryFactory queryFactory, - BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, AuthorizationService authorizationService, AuthorizationContentResolver authorizationContentResolver, TenantScope tenantScope) { + BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService, AuthorizationService authorizationService, AuthorizationContentResolver authorizationContentResolver, TenantScope tenantScope) { super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBuilder.class))); this.queryFactory = queryFactory; this.builderFactory = builderFactory; this.jsonHandlingService = jsonHandlingService; - this.authorizationService = authorizationService; + this.xmlHandlingService = xmlHandlingService; + this.authorizationService = authorizationService; this.authorizationContentResolver = authorizationContentResolver; this.tenantScope = tenantScope; } @@ -109,10 +114,12 @@ public class DmpBuilder extends BaseBuilder { FieldSet otherDmpVersionsFields = fields.extractPrefixed(this.asPrefix(Dmp._otherDmpVersions)); Map> otherDmpVersionsMap = this.collectOtherDmpVersions(otherDmpVersionsFields, data); + FieldSet dmpPropertiesFields = fields.extractPrefixed(this.asPrefix(Dmp._properties)); + Map definitionEntityMap = !dmpPropertiesFields.isEmpty() ? this.collectDmpBlueprintDefinitions(data) : null; + Set authorizationFlags = this.extractAuthorizationFlags(fields, Dmp._authorizationFlags, this.authorizationContentResolver.getPermissionNames()); Map affiliatedResourceMap = authorizationFlags == null || authorizationFlags.isEmpty() ? null : this.authorizationContentResolver.dmpsAffiliation(data.stream().map(DmpEntity::getId).collect(Collectors.toList())); - FieldSet propertiesFields = fields.extractPrefixed(this.asPrefix(Dmp._properties)); for (DmpEntity d : data) { Dmp m = new Dmp(); if (fields.hasField(this.asIndexer(Dmp._id))) m.setId(d.getId()); @@ -142,9 +149,9 @@ public class DmpBuilder extends BaseBuilder { m.setOtherDmpVersions(otherDmpVersionsMap.get(d.getGroupId())); m.getOtherDmpVersions().sort(Comparator.comparing(Dmp::getVersion)); } - if (!propertiesFields.isEmpty() && d.getProperties() != null){ + if (!dmpPropertiesFields.isEmpty() && d.getProperties() != null){ DmpPropertiesEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(DmpPropertiesEntity.class, d.getProperties()); - m.setProperties(this.builderFactory.builder(DmpPropertiesBuilder.class).authorize(this.authorize).build(propertiesFields, propertyDefinition)); + m.setProperties(this.builderFactory.builder(DmpPropertiesBuilder.class).withDefinition(definitionEntityMap != null ? definitionEntityMap.getOrDefault(d.getBlueprintId(), null) : null).authorize(this.authorize).build(dmpPropertiesFields, propertyDefinition)); } if (affiliatedResourceMap != null && !authorizationFlags.isEmpty()) m.setAuthorizationFlags(this.evaluateAuthorizationFlags(this.authorizationService, authorizationFlags, affiliatedResourceMap.getOrDefault(d.getId(), null))); models.add(m); @@ -220,6 +227,22 @@ public class DmpBuilder extends BaseBuilder { return itemMap; } + private Map collectDmpBlueprintDefinitions(List data) throws MyApplicationException { + if (data.isEmpty()) + return null; + this.logger.debug("checking related - {}", DefinitionEntity.class.getSimpleName()); + + Map itemMap = new HashMap<>(); + DmpBlueprintQuery q = this.queryFactory.query(DmpBlueprintQuery.class).disableTracking().authorize(this.authorize).ids(data.stream().map(DmpEntity::getBlueprintId).distinct().collect(Collectors.toList())); + List items = q.collectAs(new BaseFieldSet().ensure(DmpBlueprint._id).ensure(DmpBlueprint._definition)); + for (DmpBlueprintEntity item : items){ + DefinitionEntity definition =this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, item.getDefinition()); + itemMap.put(item.getId(), definition); + } + + return itemMap; + } + private Map collectUsers(FieldSet fields, List data) throws MyApplicationException { if (fields.isEmpty() || data.isEmpty()) return null; diff --git a/backend/core/src/main/java/org/opencdmp/model/builder/dmp/DmpPropertiesBuilder.java b/backend/core/src/main/java/org/opencdmp/model/builder/dmp/DmpPropertiesBuilder.java index c6129dfb3..a36cebb01 100644 --- a/backend/core/src/main/java/org/opencdmp/model/builder/dmp/DmpPropertiesBuilder.java +++ b/backend/core/src/main/java/org/opencdmp/model/builder/dmp/DmpPropertiesBuilder.java @@ -7,6 +7,7 @@ import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.LoggerService; import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.commons.types.dmp.DmpPropertiesEntity; +import org.opencdmp.commons.types.dmpblueprint.DefinitionEntity; import org.opencdmp.convention.ConventionService; import org.opencdmp.model.builder.BaseBuilder; import org.opencdmp.model.dmp.DmpProperties; @@ -24,6 +25,7 @@ public class DmpPropertiesBuilder extends BaseBuilder authorize = EnumSet.of(AuthorizationFlags.None); + private DefinitionEntity definition; @Autowired public DmpPropertiesBuilder( @@ -32,6 +34,11 @@ public class DmpPropertiesBuilder extends BaseBuilder values) { this.authorize = values; return this; @@ -51,7 +58,7 @@ public class DmpPropertiesBuilder extends BaseBuilder models = new ArrayList<>(); for (DmpPropertiesEntity d : data) { DmpProperties m = new DmpProperties(); - if (!dmpBlueprintValuesFields.isEmpty() && d.getDmpBlueprintValues() != null) m.setDmpBlueprintValues(this.builderFactory.builder(DmpBlueprintValueBuilder.class).authorize(this.authorize).build(dmpBlueprintValuesFields, d.getDmpBlueprintValues())); + if (!dmpBlueprintValuesFields.isEmpty() && d.getDmpBlueprintValues() != null) m.setDmpBlueprintValues(this.builderFactory.builder(DmpBlueprintValueBuilder.class).withDefinition(definition).authorize(this.authorize).build(dmpBlueprintValuesFields, d.getDmpBlueprintValues())); if (!contactsFields.isEmpty() && d.getContacts() != null) m.setContacts(this.builderFactory.builder(DmpContactBuilder.class).authorize(this.authorize).build(contactsFields, d.getContacts())); models.add(m); } diff --git a/backend/core/src/main/java/org/opencdmp/model/dmp/DmpBlueprintValue.java b/backend/core/src/main/java/org/opencdmp/model/dmp/DmpBlueprintValue.java index d8f4495a1..b27197c66 100644 --- a/backend/core/src/main/java/org/opencdmp/model/dmp/DmpBlueprintValue.java +++ b/backend/core/src/main/java/org/opencdmp/model/dmp/DmpBlueprintValue.java @@ -1,5 +1,6 @@ package org.opencdmp.model.dmp; +import java.time.Instant; import java.util.UUID; public class DmpBlueprintValue { @@ -8,6 +9,9 @@ public class DmpBlueprintValue { public static final String _fieldId = "fieldId"; private String fieldValue; public static final String _fieldValue = "fieldValue"; + + private Instant dateValue; + public static final String _dateValue = "dateValue"; public UUID getFieldId() { return fieldId; } @@ -24,4 +28,11 @@ public class DmpBlueprintValue { this.fieldValue = fieldValue; } + public Instant getDateValue() { + return dateValue; + } + + public void setDateValue(Instant dateValue) { + this.dateValue = dateValue; + } } diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/dmpproperties/DmpBlueprintValuePersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/dmpproperties/DmpBlueprintValuePersist.java index ce242958d..fb82f3235 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/dmpproperties/DmpBlueprintValuePersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/dmpproperties/DmpBlueprintValuePersist.java @@ -5,8 +5,10 @@ import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.specification.Specification; import org.opencdmp.authorization.AuthorizationFlags; +import org.opencdmp.commons.enums.DmpBlueprintExtraFieldDataType; import org.opencdmp.commons.enums.DmpBlueprintFieldCategory; import org.opencdmp.commons.types.dmpblueprint.DefinitionEntity; +import org.opencdmp.commons.types.dmpblueprint.ExtraFieldEntity; import org.opencdmp.commons.types.dmpblueprint.FieldEntity; import org.opencdmp.commons.types.dmpblueprint.ReferenceTypeFieldEntity; import org.opencdmp.commons.validation.BaseValidator; @@ -21,6 +23,7 @@ import org.springframework.context.annotation.Scope; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Component; +import java.time.Instant; import java.util.Arrays; import java.util.List; import java.util.UUID; @@ -31,6 +34,10 @@ public class DmpBlueprintValuePersist { public static final String _fieldId = "fieldId"; private String fieldValue; public static final String _fieldValue = "fieldValue"; + + private Instant dateValue; + public static final String _dateValue = "dateValue"; + private List references; public static final String _references = "references"; private ReferencePersist reference; @@ -52,6 +59,14 @@ public class DmpBlueprintValuePersist { this.fieldValue = fieldValue; } + public Instant getDateValue() { + return dateValue; + } + + public void setDateValue(Instant dateValue) { + this.dateValue = dateValue; + } + public List getReferences() { return this.references; } @@ -80,6 +95,7 @@ public class DmpBlueprintValuePersist { private DefinitionEntity definition; private FieldEntity fieldEntity; + private ExtraFieldEntity extraFieldEntity; protected DmpBlueprintValuePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, QueryFactory queryFactory, MessageSource messageSource) { super(conventionService, errors); @@ -97,15 +113,20 @@ public class DmpBlueprintValuePersist { protected List specifications(DmpBlueprintValuePersist item) { this.fieldEntity = this.definition != null && this.isValidGuid(item.getFieldId())? this.definition.getFieldById(item.getFieldId()).stream().findFirst().orElse(null) : null; boolean required = this.fieldEntity != null && this.fieldEntity.isRequired(); + if (this.fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) this.extraFieldEntity = (ExtraFieldEntity) fieldEntity; return Arrays.asList( this.spec() .must(() -> this.isValidGuid(item.getFieldId())) .failOn(DmpBlueprintValuePersist._fieldId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintValuePersist._fieldId}, LocaleContextHolder.getLocale())), this.spec() - .iff(() -> this.fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra) && this.isListNullOrEmpty(item.getReferences()) && required) + .iff(() -> this.extraFieldEntity != null && !extraFieldEntity.getType().equals(DmpBlueprintExtraFieldDataType.Date) && this.isListNullOrEmpty(item.getReferences()) && required) .must(() -> !this.isEmpty(item.getFieldValue())) .failOn(DmpBlueprintValuePersist._fieldValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> this.extraFieldEntity != null && extraFieldEntity.getType().equals(DmpBlueprintExtraFieldDataType.Date) && this.isListNullOrEmpty(item.getReferences()) && required) + .must(() -> !this.isNull(item.getDateValue())) + .failOn(DmpBlueprintValuePersist._dateValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())), this.spec() .iff(() -> this.fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType) && this.isEmpty(item.getFieldValue()) && ((ReferenceTypeFieldEntity) this.fieldEntity).getMultipleSelect() && required) .must(() -> !this.isListNullOrEmpty(item.getReferences())) diff --git a/backend/core/src/main/java/org/opencdmp/service/dmp/DmpServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/dmp/DmpServiceImpl.java index ef4c6d24b..83fc25d3e 100644 --- a/backend/core/src/main/java/org/opencdmp/service/dmp/DmpServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/dmp/DmpServiceImpl.java @@ -46,8 +46,10 @@ import org.opencdmp.commons.types.dmp.DmpBlueprintValueEntity; import org.opencdmp.commons.types.dmp.DmpContactEntity; import org.opencdmp.commons.types.dmp.DmpPropertiesEntity; import org.opencdmp.commons.types.dmp.importexport.*; +import org.opencdmp.commons.types.dmpblueprint.ExtraFieldEntity; import org.opencdmp.commons.types.dmpblueprint.ReferenceTypeFieldEntity; import org.opencdmp.commons.types.dmpblueprint.SectionEntity; +import org.opencdmp.commons.types.dmpblueprint.importexport.BlueprintExtraFieldImportExport; import org.opencdmp.commons.types.dmpblueprint.importexport.BlueprintReferenceTypeFieldImportExport; import org.opencdmp.commons.types.dmpblueprint.importexport.BlueprintSectionImportExport; import org.opencdmp.commons.types.dmpreference.DmpReferenceDataEntity; @@ -808,9 +810,14 @@ public class DmpServiceImpl implements DmpService { } DmpStatus previousStatus = data.getStatus(); + DmpBlueprintEntity dmpBlueprintEntity = this.entityManager.find(DmpBlueprintEntity.class, model.getBlueprint(), true); + if (dmpBlueprintEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getBlueprint(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale())); + + org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.dmpblueprint.DefinitionEntity.class, dmpBlueprintEntity.getDefinition()); + data.setLabel(model.getLabel()); data.setLanguage(model.getLanguage()); - data.setProperties(this.jsonHandlingService.toJson(this.buildDmpPropertiesEntity(model.getProperties()))); + data.setProperties(this.jsonHandlingService.toJson(this.buildDmpPropertiesEntity(model.getProperties(), definition))); data.setDescription(model.getDescription()); data.setAccessType(model.getAccessType()); data.setUpdatedAt(Instant.now()); @@ -829,7 +836,7 @@ public class DmpServiceImpl implements DmpService { return data; } - private @NotNull DmpPropertiesEntity buildDmpPropertiesEntity(DmpPropertiesPersist persist){ + private @NotNull DmpPropertiesEntity buildDmpPropertiesEntity(DmpPropertiesPersist persist, org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition){ DmpPropertiesEntity data = new DmpPropertiesEntity(); if (persist == null) return data; if (!this.conventionService.isListNullOrEmpty(persist.getContacts())){ @@ -841,7 +848,7 @@ public class DmpServiceImpl implements DmpService { if (persist.getDmpBlueprintValues() != null && !persist.getDmpBlueprintValues().isEmpty()){ data.setDmpBlueprintValues(new ArrayList<>()); for (DmpBlueprintValuePersist fieldValuePersist: persist.getDmpBlueprintValues().values()) { - if (!this.conventionService.isNullOrEmpty(fieldValuePersist.getFieldValue())) data.getDmpBlueprintValues().add(this.buildDmpBlueprintValueEntity(fieldValuePersist)); + if (!this.conventionService.isNullOrEmpty(fieldValuePersist.getFieldValue()) || fieldValuePersist.getDateValue() != null) data.getDmpBlueprintValues().add(this.buildDmpBlueprintValueEntity(fieldValuePersist, definition)); } } return data; @@ -858,12 +865,24 @@ public class DmpServiceImpl implements DmpService { return data; } - private @NotNull DmpBlueprintValueEntity buildDmpBlueprintValueEntity(DmpBlueprintValuePersist persist){ + private @NotNull DmpBlueprintValueEntity buildDmpBlueprintValueEntity(DmpBlueprintValuePersist persist, org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition){ DmpBlueprintValueEntity data = new DmpBlueprintValueEntity(); - if (persist == null) return data; + if (persist == null || definition == null) return data; + + org.opencdmp.commons.types.dmpblueprint.FieldEntity fieldEntity = definition.getFieldById(persist.getFieldId()).stream().findFirst().orElse(null); + if (fieldEntity == null) return data; + + if (fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) { + ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity; + if (extraFieldEntity == null) return data; + if (extraFieldEntity.getType().equals(DmpBlueprintExtraFieldDataType.Date)){ + data.setDateValue(persist.getDateValue()); + } else { + data.setValue(persist.getFieldValue()); + } + data.setFieldId(persist.getFieldId()); + } - data.setValue(persist.getFieldValue()); - data.setFieldId(persist.getFieldId()); return data; } @@ -875,7 +894,7 @@ public class DmpServiceImpl implements DmpService { if (fieldValuePersist.getReferences() == null) fieldValuePersist.setReferences(new ArrayList<>()); fieldValuePersist.getReferences().add(fieldValuePersist.getReference()); } - if (this.conventionService.isNullOrEmpty(fieldValuePersist.getFieldValue()) && !this.conventionService.isListNullOrEmpty( fieldValuePersist.getReferences())) { + if (this.conventionService.isNullOrEmpty(fieldValuePersist.getFieldValue()) && fieldValuePersist.getDateValue() == null && !this.conventionService.isListNullOrEmpty( fieldValuePersist.getReferences())) { for (ReferencePersist referencePersist : fieldValuePersist.getReferences()) { DmpReferencePersist dmpReferencePersist = new DmpReferencePersist(); dmpReferencePersist.setData(new DmpReferenceDataPersist()); @@ -1220,19 +1239,25 @@ public class DmpServiceImpl implements DmpService { referencePersists.add(this.buildReferencePersist(reference)); } // put references - dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), null, referencePersists, ((ReferenceTypeFieldEntity)fieldEntity).getMultipleSelect())); + dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), null, null, referencePersists, ((ReferenceTypeFieldEntity)fieldEntity).getMultipleSelect())); } } else if (!this.conventionService.isListNullOrEmpty(data.getDmpBlueprintValues())) { for (DmpBlueprintValueEntity value : data.getDmpBlueprintValues()) { if (value.getFieldId().equals(fieldEntity.getId())) { - // found value - dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), value.getValue(), null, null)); - } else { - dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), null, null, null)); + if (value.getDateValue() != null) { + dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), null, value.getDateValue(), null,null)); + } else if (!this.conventionService.isNullOrEmpty(value.getValue())) { + dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), value.getValue(), null, null,null)); + } else { + dmpBlueprintValues.put(fieldEntity.getId(), null); + } } } - } else { - dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), null, null, null)); + } + + // fill fields with no values + if (dmpBlueprintValues.get(fieldEntity.getId()) == null){ + dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), null, null, null,null)); } } @@ -1293,7 +1318,7 @@ public class DmpServiceImpl implements DmpService { return persist; } - private @NotNull DmpBlueprintValuePersist buildDmpBlueprintValuePersist(UUID fieldId, String fieldValue, List referencePersists, Boolean multipleSelect){ + private @NotNull DmpBlueprintValuePersist buildDmpBlueprintValuePersist(UUID fieldId, String fieldValue, Instant dateValue, List referencePersists, Boolean multipleSelect){ DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist(); persist.setFieldId(fieldId); @@ -1302,8 +1327,10 @@ public class DmpServiceImpl implements DmpService { persist.setReferences(referencePersists); }else if (!this.conventionService.isListNullOrEmpty(referencePersists)){ persist.setReference(referencePersists.getFirst()); - }else if (fieldValue != null){ + }else if (!this.conventionService.isNullOrEmpty(fieldValue)){ persist.setFieldValue(fieldValue); + }else if (dateValue != null){ + persist.setDateValue(dateValue); } return persist; @@ -1527,11 +1554,12 @@ public class DmpServiceImpl implements DmpService { } if (propertiesEntity != null && !this.conventionService.isListNullOrEmpty(propertiesEntity.getDmpBlueprintValues())) { - List dmpDescriptionTemplateImportExports = new LinkedList<>(); + List dmpBlueprintValueImportExports = new LinkedList<>(); + org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.dmpblueprint.DefinitionEntity.class, blueprintEntity.getDefinition()); for (DmpBlueprintValueEntity dmpBlueprintValueEntity : propertiesEntity.getDmpBlueprintValues()) { - dmpDescriptionTemplateImportExports.add(this.dmpBlueprintValueToExport(dmpBlueprintValueEntity)); + dmpBlueprintValueImportExports.add(this.dmpBlueprintValueToExport(dmpBlueprintValueEntity, definition)); } - xml.setBlueprintValues(dmpDescriptionTemplateImportExports); + xml.setBlueprintValues(dmpBlueprintValueImportExports); } List dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).disableTracking().dmpIds(data.getId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActives(IsActive.Active).collect(); @@ -1585,12 +1613,23 @@ public class DmpServiceImpl implements DmpService { return xml; } - private DmpBlueprintValueImportExport dmpBlueprintValueToExport(DmpBlueprintValueEntity entity) { + private DmpBlueprintValueImportExport dmpBlueprintValueToExport(DmpBlueprintValueEntity entity, org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition) { DmpBlueprintValueImportExport xml = new DmpBlueprintValueImportExport(); if (entity == null) return xml; - xml.setFieldId(entity.getFieldId()); - xml.setValue(entity.getValue()); + org.opencdmp.commons.types.dmpblueprint.FieldEntity fieldEntity = definition.getFieldById(entity.getFieldId()).stream().findFirst().orElse(null); + if (fieldEntity == null) return xml; + + if (fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) { + ExtraFieldEntity extraFieldEntity = (ExtraFieldEntity) fieldEntity; + if (extraFieldEntity == null) return xml; + if (extraFieldEntity.getType().equals(DmpBlueprintExtraFieldDataType.Date)){ + xml.setDateValue(entity.getDateValue()); + } else { + xml.setValue(entity.getValue()); + } + xml.setFieldId(entity.getFieldId()); + } return xml; } @@ -1717,11 +1756,11 @@ public class DmpServiceImpl implements DmpService { Map dmpBlueprintValues = new HashMap<>(); - // reference if (!this.conventionService.isListNullOrEmpty(importXml.getBlueprint().getDmpBlueprintDefinition().getSections())) { List sections = importXml.getBlueprint().getDmpBlueprintDefinition().getSections(); if (!this.conventionService.isListNullOrEmpty(sections)){ for (BlueprintSectionImportExport section : importXml.getBlueprint().getDmpBlueprintDefinition().getSections()) { + // reference if (!this.conventionService.isListNullOrEmpty(section.getReferenceFields()) && !this.conventionService.isListNullOrEmpty(importXml.getReferences())){ for (BlueprintReferenceTypeFieldImportExport blueprintReferenceTypeField : section.getReferenceFields()) { List dmpReferencesByField = importXml.getReferences().stream().filter(x -> x.getFieldId().equals(blueprintReferenceTypeField.getId())).collect(Collectors.toList()); @@ -1730,19 +1769,20 @@ public class DmpServiceImpl implements DmpService { } } } + // custom fields + if (!this.conventionService.isListNullOrEmpty(section.getExtraFields()) && !this.conventionService.isListNullOrEmpty(importXml.getBlueprintValues())){ + for (DmpBlueprintValueImportExport value : importXml.getBlueprintValues()) { + if (value.getFieldId() != null ) { + BlueprintExtraFieldImportExport extraFieldImportExport = section.getExtraFields().stream().filter(x -> x.getId().equals(value.getFieldId())).findFirst().orElse(null); + if (extraFieldImportExport != null) dmpBlueprintValues.put(value.getFieldId(), this.xmlDmpBlueprintValueToPersist(value, extraFieldImportExport)); + } + } + } } } } - - // custom fields - if (!this.conventionService.isListNullOrEmpty(importXml.getBlueprintValues())){ - for (DmpBlueprintValueImportExport value : importXml.getBlueprintValues()) { - if (value.getFieldId() != null) dmpBlueprintValues.put(value.getFieldId(), this.xmlDmpBlueprintValueToPersist(value)); - } - } - persist.setContacts(contacts); persist.setDmpBlueprintValues(dmpBlueprintValues); @@ -1782,14 +1822,18 @@ public class DmpServiceImpl implements DmpService { return persist; } - private DmpBlueprintValuePersist xmlDmpBlueprintValueToPersist(DmpBlueprintValueImportExport importXml) { - if (importXml == null) + private DmpBlueprintValuePersist xmlDmpBlueprintValueToPersist(DmpBlueprintValueImportExport importXml, BlueprintExtraFieldImportExport extraFieldImportExport) { + if (importXml == null || extraFieldImportExport == null) return null; DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist(); persist.setFieldId(importXml.getFieldId()); - persist.setFieldValue(importXml.getValue()); + if (extraFieldImportExport.getType().equals(DmpBlueprintExtraFieldDataType.Date)){ + persist.setDateValue(importXml.getDateValue()); + } else { + persist.setFieldValue(importXml.getValue()); + } return persist; } diff --git a/dmp-frontend/src/app/core/model/dmp/dmp.ts b/dmp-frontend/src/app/core/model/dmp/dmp.ts index 06ae719d8..bc87fb7b7 100644 --- a/dmp-frontend/src/app/core/model/dmp/dmp.ts +++ b/dmp-frontend/src/app/core/model/dmp/dmp.ts @@ -47,6 +47,7 @@ export interface DmpProperties { export interface DmpBlueprintValue { fieldId: Guid; fieldValue: string; + dateValue: Date; } export interface DmpContact { @@ -95,6 +96,7 @@ export interface DmpPropertiesPersist { export interface DmpBlueprintValuePersist { fieldId: Guid; fieldValue: string; + dateValue: Date; references: DmpReferencePersist[]; reference: DmpReferencePersist; } diff --git a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.component.html b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.component.html index 915fcd9c9..1de2dea05 100644 --- a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.component.html +++ b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.component.html @@ -295,11 +295,11 @@
{{field.label}} - + - {{formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('fieldValue').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} + {{formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('dateValue').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}}
diff --git a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.model.ts b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.model.ts index ce05a6a66..c6ee98bdc 100644 --- a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.model.ts +++ b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.model.ts @@ -218,7 +218,8 @@ export class DmpPropertiesEditorModel implements DmpPropertiesPersist { this.dmpBlueprintValues.set(field.id, new DmpBlueprintValueEditorModel(this.validationErrorModel).fromModel( { fieldId: field.id, - fieldValue: item?.dmpBlueprintValues?.find(x => x.fieldId == field.id)?.fieldValue, + fieldValue: item?.dmpBlueprintValues?.find(x => x.fieldId == field.id)?.fieldValue || undefined, + dateValue: item?.dmpBlueprintValues?.find(x => x.fieldId == field.id)?.dateValue || undefined, }, dmpReferences, field)); } }); @@ -315,6 +316,7 @@ export class DmpPropertiesEditorModel implements DmpPropertiesPersist { export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist { fieldId: Guid; fieldValue: string; + dateValue: Date; references: DmpReferencePersist[] = []; reference: DmpReferencePersist; isRequired: boolean = false; @@ -330,6 +332,7 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist { fromModel(item: DmpBlueprintValue, dmpReferences: DmpReference[], field: FieldInSection): DmpBlueprintValueEditorModel { this.fieldId = item.fieldId; this.fieldValue = item.fieldValue; + this.dateValue = item.dateValue; const references = dmpReferences?.filter(x => x.data.blueprintFieldId == this.fieldId && x.isActive == IsActive.Active).map(x => { return { data: x.data, @@ -390,6 +393,7 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist { case DmpBlueprintFieldCategory.System: case DmpBlueprintFieldCategory.Extra: formGroup.addControl('fieldValue', new FormControl({ value: this.fieldValue, disabled: disabled }, context.getValidation('fieldValue').validators)); + formGroup.addControl('dateValue', new FormControl({ value: this.dateValue, disabled: disabled }, context.getValidation('dateValue').validators)); break; } @@ -408,6 +412,7 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist { const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'fieldId', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}fieldId`)] }); baseValidationArray.push({ key: 'fieldValue', validators: params.isRequired ? [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}fieldValue`)] : [BackendErrorValidator(validationErrorModel, `${rootPath}fieldValue`)] }); + baseValidationArray.push({ key: 'dateValue', validators: params.isRequired ? [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}dateValue`)] : [BackendErrorValidator(validationErrorModel, `${rootPath}dateValue`)] }); baseValidationArray.push({ key: 'references', validators: params.isRequired && params.multipleSelect ? [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}references`)] : [BackendErrorValidator(validationErrorModel, `${rootPath}references`)] }); baseValidationArray.push({ key: 'reference', validators: params.isRequired && !params.multipleSelect ? [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}reference`)] : [BackendErrorValidator(validationErrorModel, `${rootPath}reference`)] }); @@ -431,7 +436,7 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist { multipleSelect: params.multipleSelect }); - ['fieldId', 'fieldValue', 'references'].forEach(keyField => { + ['fieldId', 'fieldValue', 'dateValue', 'references'].forEach(keyField => { const control = formGroup?.get(keyField); control?.clearValidators(); control?.addValidators(context.getValidation(keyField).validators); diff --git a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.resolver.ts b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.resolver.ts index 2eccf2624..7f16d9bc3 100644 --- a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.resolver.ts +++ b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor.resolver.ts @@ -47,6 +47,7 @@ export class DmpEditorResolver extends BaseEditorResolver { [nameof(x => x.properties), nameof(x => x.dmpBlueprintValues), nameof(x => x.fieldId)].join('.'), [nameof(x => x.properties), nameof(x => x.dmpBlueprintValues), nameof(x => x.fieldValue)].join('.'), + [nameof(x => x.properties), nameof(x => x.dmpBlueprintValues), nameof(x => x.dateValue)].join('.'), [nameof(x => x.properties), nameof(x => x.contacts), nameof(x => x.user), nameof(x => x.id)].join('.'), [nameof(x => x.properties), nameof(x => x.contacts), nameof(x => x.firstName)].join('.'), [nameof(x => x.properties), nameof(x => x.contacts), nameof(x => x.lastName)].join('.'),