Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Sofia Papacharalampous 2024-05-23 16:59:08 +03:00
commit ada249eb61
12 changed files with 210 additions and 52 deletions

View File

@ -1,5 +1,6 @@
package org.opencdmp.commons.types.dmp; package org.opencdmp.commons.types.dmp;
import java.time.Instant;
import java.util.UUID; import java.util.UUID;
public class DmpBlueprintValueEntity { public class DmpBlueprintValueEntity {
@ -8,6 +9,8 @@ public class DmpBlueprintValueEntity {
private String value; private String value;
private Instant dateValue;
public UUID getFieldId() { public UUID getFieldId() {
return fieldId; return fieldId;
} }
@ -24,4 +27,11 @@ public class DmpBlueprintValueEntity {
this.value = value; this.value = value;
} }
public Instant getDateValue() {
return dateValue;
}
public void setDateValue(Instant dateValue) {
this.dateValue = dateValue;
}
} }

View File

@ -5,6 +5,7 @@ import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElement;
import java.time.Instant;
import java.util.UUID; import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@ -17,6 +18,9 @@ public class DmpBlueprintValueImportExport {
@XmlElement(name = "value") @XmlElement(name = "value")
private String value; private String value;
@XmlElement(name = "dateValue")
private Instant dateValue;
public UUID getFieldId() { public UUID getFieldId() {
return this.fieldId; return this.fieldId;
} }
@ -32,4 +36,12 @@ public class DmpBlueprintValueImportExport {
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;
} }
public Instant getDateValue() {
return dateValue;
}
public void setDateValue(Instant dateValue) {
this.dateValue = dateValue;
}
} }

View File

@ -5,7 +5,12 @@ import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags; 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.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.convention.ConventionService;
import org.opencdmp.model.builder.BaseBuilder; import org.opencdmp.model.builder.BaseBuilder;
import org.opencdmp.model.dmp.DmpBlueprintValue; import org.opencdmp.model.dmp.DmpBlueprintValue;
@ -23,6 +28,8 @@ public class DmpBlueprintValueBuilder extends BaseBuilder<DmpBlueprintValue, Dmp
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private DefinitionEntity definition;
@Autowired @Autowired
public DmpBlueprintValueBuilder( public DmpBlueprintValueBuilder(
ConventionService conventionService) { ConventionService conventionService) {
@ -34,6 +41,11 @@ public class DmpBlueprintValueBuilder extends BaseBuilder<DmpBlueprintValue, Dmp
return this; return this;
} }
public DmpBlueprintValueBuilder withDefinition(DefinitionEntity definition) {
this.definition = definition;
return this;
}
@Override @Override
public List<DmpBlueprintValue> build(FieldSet DmpBlueprintValues, List<DmpBlueprintValueEntity> data) throws MyApplicationException { public List<DmpBlueprintValue> build(FieldSet DmpBlueprintValues, List<DmpBlueprintValueEntity> 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)); 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,12 +56,22 @@ public class DmpBlueprintValueBuilder extends BaseBuilder<DmpBlueprintValue, Dmp
List<DmpBlueprintValue> models = new ArrayList<>(); List<DmpBlueprintValue> models = new ArrayList<>();
for (DmpBlueprintValueEntity d : data) { for (DmpBlueprintValueEntity d : data) {
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(); 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()); 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); models.add(m);
} }
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models; return models;
} }

View File

@ -14,10 +14,13 @@ import org.opencdmp.authorization.AffiliatedResource;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.authorizationcontentresolver.AuthorizationContentResolver; import org.opencdmp.authorization.authorizationcontentresolver.AuthorizationContentResolver;
import org.opencdmp.commons.JsonHandlingService; import org.opencdmp.commons.JsonHandlingService;
import org.opencdmp.commons.XmlHandlingService;
import org.opencdmp.commons.enums.EntityType; import org.opencdmp.commons.enums.EntityType;
import org.opencdmp.commons.scope.tenant.TenantScope; import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.types.dmp.DmpPropertiesEntity; import org.opencdmp.commons.types.dmp.DmpPropertiesEntity;
import org.opencdmp.commons.types.dmpblueprint.DefinitionEntity;
import org.opencdmp.convention.ConventionService; import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.DmpBlueprintEntity;
import org.opencdmp.data.DmpEntity; import org.opencdmp.data.DmpEntity;
import org.opencdmp.model.DmpDescriptionTemplate; import org.opencdmp.model.DmpDescriptionTemplate;
import org.opencdmp.model.DmpUser; import org.opencdmp.model.DmpUser;
@ -52,6 +55,7 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private final JsonHandlingService jsonHandlingService; private final JsonHandlingService jsonHandlingService;
private final XmlHandlingService xmlHandlingService;
private final AuthorizationService authorizationService; private final AuthorizationService authorizationService;
private final AuthorizationContentResolver authorizationContentResolver; private final AuthorizationContentResolver authorizationContentResolver;
private final TenantScope tenantScope; private final TenantScope tenantScope;
@ -61,11 +65,12 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
@Autowired @Autowired
public DmpBuilder(ConventionService conventionService, public DmpBuilder(ConventionService conventionService,
QueryFactory queryFactory, 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))); super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBuilder.class)));
this.queryFactory = queryFactory; this.queryFactory = queryFactory;
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.jsonHandlingService = jsonHandlingService; this.jsonHandlingService = jsonHandlingService;
this.xmlHandlingService = xmlHandlingService;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
this.authorizationContentResolver = authorizationContentResolver; this.authorizationContentResolver = authorizationContentResolver;
this.tenantScope = tenantScope; this.tenantScope = tenantScope;
@ -109,10 +114,12 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
FieldSet otherDmpVersionsFields = fields.extractPrefixed(this.asPrefix(Dmp._otherDmpVersions)); FieldSet otherDmpVersionsFields = fields.extractPrefixed(this.asPrefix(Dmp._otherDmpVersions));
Map<UUID, List<Dmp>> otherDmpVersionsMap = this.collectOtherDmpVersions(otherDmpVersionsFields, data); Map<UUID, List<Dmp>> otherDmpVersionsMap = this.collectOtherDmpVersions(otherDmpVersionsFields, data);
FieldSet dmpPropertiesFields = fields.extractPrefixed(this.asPrefix(Dmp._properties));
Map<UUID, DefinitionEntity> definitionEntityMap = !dmpPropertiesFields.isEmpty() ? this.collectDmpBlueprintDefinitions(data) : null;
Set<String> authorizationFlags = this.extractAuthorizationFlags(fields, Dmp._authorizationFlags, this.authorizationContentResolver.getPermissionNames()); Set<String> authorizationFlags = this.extractAuthorizationFlags(fields, Dmp._authorizationFlags, this.authorizationContentResolver.getPermissionNames());
Map<UUID, AffiliatedResource> affiliatedResourceMap = authorizationFlags == null || authorizationFlags.isEmpty() ? null : this.authorizationContentResolver.dmpsAffiliation(data.stream().map(DmpEntity::getId).collect(Collectors.toList())); Map<UUID, AffiliatedResource> 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) { for (DmpEntity d : data) {
Dmp m = new Dmp(); Dmp m = new Dmp();
if (fields.hasField(this.asIndexer(Dmp._id))) m.setId(d.getId()); if (fields.hasField(this.asIndexer(Dmp._id))) m.setId(d.getId());
@ -142,9 +149,9 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
m.setOtherDmpVersions(otherDmpVersionsMap.get(d.getGroupId())); m.setOtherDmpVersions(otherDmpVersionsMap.get(d.getGroupId()));
m.getOtherDmpVersions().sort(Comparator.comparing(Dmp::getVersion)); 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()); 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))); if (affiliatedResourceMap != null && !authorizationFlags.isEmpty()) m.setAuthorizationFlags(this.evaluateAuthorizationFlags(this.authorizationService, authorizationFlags, affiliatedResourceMap.getOrDefault(d.getId(), null)));
models.add(m); models.add(m);
@ -220,6 +227,22 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
return itemMap; return itemMap;
} }
private Map<UUID, DefinitionEntity> collectDmpBlueprintDefinitions(List<DmpEntity> data) throws MyApplicationException {
if (data.isEmpty())
return null;
this.logger.debug("checking related - {}", DefinitionEntity.class.getSimpleName());
Map<java.util.UUID, DefinitionEntity> 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<DmpBlueprintEntity> 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<UUID, User> collectUsers(FieldSet fields, List<DmpEntity> data) throws MyApplicationException { private Map<UUID, User> collectUsers(FieldSet fields, List<DmpEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) if (fields.isEmpty() || data.isEmpty())
return null; return null;

View File

@ -7,6 +7,7 @@ import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.types.dmp.DmpPropertiesEntity; import org.opencdmp.commons.types.dmp.DmpPropertiesEntity;
import org.opencdmp.commons.types.dmpblueprint.DefinitionEntity;
import org.opencdmp.convention.ConventionService; import org.opencdmp.convention.ConventionService;
import org.opencdmp.model.builder.BaseBuilder; import org.opencdmp.model.builder.BaseBuilder;
import org.opencdmp.model.dmp.DmpProperties; import org.opencdmp.model.dmp.DmpProperties;
@ -24,6 +25,7 @@ public class DmpPropertiesBuilder extends BaseBuilder<DmpProperties, DmpProperti
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private DefinitionEntity definition;
@Autowired @Autowired
public DmpPropertiesBuilder( public DmpPropertiesBuilder(
@ -32,6 +34,11 @@ public class DmpPropertiesBuilder extends BaseBuilder<DmpProperties, DmpProperti
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
} }
public DmpPropertiesBuilder withDefinition(DefinitionEntity definition) {
this.definition = definition;
return this;
}
public DmpPropertiesBuilder authorize(EnumSet<AuthorizationFlags> values) { public DmpPropertiesBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values; this.authorize = values;
return this; return this;
@ -51,7 +58,7 @@ public class DmpPropertiesBuilder extends BaseBuilder<DmpProperties, DmpProperti
List<DmpProperties> models = new ArrayList<>(); List<DmpProperties> models = new ArrayList<>();
for (DmpPropertiesEntity d : data) { for (DmpPropertiesEntity d : data) {
DmpProperties m = new DmpProperties(); 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())); if (!contactsFields.isEmpty() && d.getContacts() != null) m.setContacts(this.builderFactory.builder(DmpContactBuilder.class).authorize(this.authorize).build(contactsFields, d.getContacts()));
models.add(m); models.add(m);
} }

View File

@ -1,5 +1,6 @@
package org.opencdmp.model.dmp; package org.opencdmp.model.dmp;
import java.time.Instant;
import java.util.UUID; import java.util.UUID;
public class DmpBlueprintValue { public class DmpBlueprintValue {
@ -8,6 +9,9 @@ public class DmpBlueprintValue {
public static final String _fieldId = "fieldId"; public static final String _fieldId = "fieldId";
private String fieldValue; private String fieldValue;
public static final String _fieldValue = "fieldValue"; public static final String _fieldValue = "fieldValue";
private Instant dateValue;
public static final String _dateValue = "dateValue";
public UUID getFieldId() { public UUID getFieldId() {
return fieldId; return fieldId;
} }
@ -24,4 +28,11 @@ public class DmpBlueprintValue {
this.fieldValue = fieldValue; this.fieldValue = fieldValue;
} }
public Instant getDateValue() {
return dateValue;
}
public void setDateValue(Instant dateValue) {
this.dateValue = dateValue;
}
} }

View File

@ -5,8 +5,10 @@ import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification; import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.authorization.AuthorizationFlags; import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.enums.DmpBlueprintExtraFieldDataType;
import org.opencdmp.commons.enums.DmpBlueprintFieldCategory; import org.opencdmp.commons.enums.DmpBlueprintFieldCategory;
import org.opencdmp.commons.types.dmpblueprint.DefinitionEntity; 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.FieldEntity;
import org.opencdmp.commons.types.dmpblueprint.ReferenceTypeFieldEntity; import org.opencdmp.commons.types.dmpblueprint.ReferenceTypeFieldEntity;
import org.opencdmp.commons.validation.BaseValidator; 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.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -31,6 +34,10 @@ public class DmpBlueprintValuePersist {
public static final String _fieldId = "fieldId"; public static final String _fieldId = "fieldId";
private String fieldValue; private String fieldValue;
public static final String _fieldValue = "fieldValue"; public static final String _fieldValue = "fieldValue";
private Instant dateValue;
public static final String _dateValue = "dateValue";
private List<ReferencePersist> references; private List<ReferencePersist> references;
public static final String _references = "references"; public static final String _references = "references";
private ReferencePersist reference; private ReferencePersist reference;
@ -52,6 +59,14 @@ public class DmpBlueprintValuePersist {
this.fieldValue = fieldValue; this.fieldValue = fieldValue;
} }
public Instant getDateValue() {
return dateValue;
}
public void setDateValue(Instant dateValue) {
this.dateValue = dateValue;
}
public List<ReferencePersist> getReferences() { public List<ReferencePersist> getReferences() {
return this.references; return this.references;
} }
@ -80,6 +95,7 @@ public class DmpBlueprintValuePersist {
private DefinitionEntity definition; private DefinitionEntity definition;
private FieldEntity fieldEntity; private FieldEntity fieldEntity;
private ExtraFieldEntity extraFieldEntity;
protected DmpBlueprintValuePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, QueryFactory queryFactory, MessageSource messageSource) { protected DmpBlueprintValuePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, QueryFactory queryFactory, MessageSource messageSource) {
super(conventionService, errors); super(conventionService, errors);
@ -97,15 +113,20 @@ public class DmpBlueprintValuePersist {
protected List<Specification> specifications(DmpBlueprintValuePersist item) { protected List<Specification> specifications(DmpBlueprintValuePersist item) {
this.fieldEntity = this.definition != null && this.isValidGuid(item.getFieldId())? this.definition.getFieldById(item.getFieldId()).stream().findFirst().orElse(null) : null; 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(); boolean required = this.fieldEntity != null && this.fieldEntity.isRequired();
if (this.fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.Extra)) this.extraFieldEntity = (ExtraFieldEntity) fieldEntity;
return Arrays.asList( return Arrays.asList(
this.spec() this.spec()
.must(() -> this.isValidGuid(item.getFieldId())) .must(() -> this.isValidGuid(item.getFieldId()))
.failOn(DmpBlueprintValuePersist._fieldId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintValuePersist._fieldId}, LocaleContextHolder.getLocale())), .failOn(DmpBlueprintValuePersist._fieldId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintValuePersist._fieldId}, LocaleContextHolder.getLocale())),
this.spec() 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())) .must(() -> !this.isEmpty(item.getFieldValue()))
.failOn(DmpBlueprintValuePersist._fieldValue).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{this.fieldEntity.getLabel()}, LocaleContextHolder.getLocale())), .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() this.spec()
.iff(() -> this.fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType) && this.isEmpty(item.getFieldValue()) && ((ReferenceTypeFieldEntity) this.fieldEntity).getMultipleSelect() && required) .iff(() -> this.fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType) && this.isEmpty(item.getFieldValue()) && ((ReferenceTypeFieldEntity) this.fieldEntity).getMultipleSelect() && required)
.must(() -> !this.isListNullOrEmpty(item.getReferences())) .must(() -> !this.isListNullOrEmpty(item.getReferences()))

View File

@ -46,8 +46,10 @@ import org.opencdmp.commons.types.dmp.DmpBlueprintValueEntity;
import org.opencdmp.commons.types.dmp.DmpContactEntity; import org.opencdmp.commons.types.dmp.DmpContactEntity;
import org.opencdmp.commons.types.dmp.DmpPropertiesEntity; import org.opencdmp.commons.types.dmp.DmpPropertiesEntity;
import org.opencdmp.commons.types.dmp.importexport.*; 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.ReferenceTypeFieldEntity;
import org.opencdmp.commons.types.dmpblueprint.SectionEntity; 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.BlueprintReferenceTypeFieldImportExport;
import org.opencdmp.commons.types.dmpblueprint.importexport.BlueprintSectionImportExport; import org.opencdmp.commons.types.dmpblueprint.importexport.BlueprintSectionImportExport;
import org.opencdmp.commons.types.dmpreference.DmpReferenceDataEntity; import org.opencdmp.commons.types.dmpreference.DmpReferenceDataEntity;
@ -808,9 +810,14 @@ public class DmpServiceImpl implements DmpService {
} }
DmpStatus previousStatus = data.getStatus(); 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.setLabel(model.getLabel());
data.setLanguage(model.getLanguage()); 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.setDescription(model.getDescription());
data.setAccessType(model.getAccessType()); data.setAccessType(model.getAccessType());
data.setUpdatedAt(Instant.now()); data.setUpdatedAt(Instant.now());
@ -829,7 +836,7 @@ public class DmpServiceImpl implements DmpService {
return data; 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(); DmpPropertiesEntity data = new DmpPropertiesEntity();
if (persist == null) return data; if (persist == null) return data;
if (!this.conventionService.isListNullOrEmpty(persist.getContacts())){ if (!this.conventionService.isListNullOrEmpty(persist.getContacts())){
@ -841,7 +848,7 @@ public class DmpServiceImpl implements DmpService {
if (persist.getDmpBlueprintValues() != null && !persist.getDmpBlueprintValues().isEmpty()){ if (persist.getDmpBlueprintValues() != null && !persist.getDmpBlueprintValues().isEmpty()){
data.setDmpBlueprintValues(new ArrayList<>()); data.setDmpBlueprintValues(new ArrayList<>());
for (DmpBlueprintValuePersist fieldValuePersist: persist.getDmpBlueprintValues().values()) { 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; return data;
@ -858,12 +865,24 @@ public class DmpServiceImpl implements DmpService {
return data; 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(); 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.setValue(persist.getFieldValue());
}
data.setFieldId(persist.getFieldId()); data.setFieldId(persist.getFieldId());
}
return data; return data;
} }
@ -875,7 +894,7 @@ public class DmpServiceImpl implements DmpService {
if (fieldValuePersist.getReferences() == null) fieldValuePersist.setReferences(new ArrayList<>()); if (fieldValuePersist.getReferences() == null) fieldValuePersist.setReferences(new ArrayList<>());
fieldValuePersist.getReferences().add(fieldValuePersist.getReference()); 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()) { for (ReferencePersist referencePersist : fieldValuePersist.getReferences()) {
DmpReferencePersist dmpReferencePersist = new DmpReferencePersist(); DmpReferencePersist dmpReferencePersist = new DmpReferencePersist();
dmpReferencePersist.setData(new DmpReferenceDataPersist()); dmpReferencePersist.setData(new DmpReferenceDataPersist());
@ -1220,19 +1239,25 @@ public class DmpServiceImpl implements DmpService {
referencePersists.add(this.buildReferencePersist(reference)); referencePersists.add(this.buildReferencePersist(reference));
} }
// put references // 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())) { } else if (!this.conventionService.isListNullOrEmpty(data.getDmpBlueprintValues())) {
for (DmpBlueprintValueEntity value : data.getDmpBlueprintValues()) { for (DmpBlueprintValueEntity value : data.getDmpBlueprintValues()) {
if (value.getFieldId().equals(fieldEntity.getId())) { if (value.getFieldId().equals(fieldEntity.getId())) {
// found value if (value.getDateValue() != null) {
dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), value.getValue(), null, 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 { } else {
dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), null, null, null)); 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; return persist;
} }
private @NotNull DmpBlueprintValuePersist buildDmpBlueprintValuePersist(UUID fieldId, String fieldValue, List<ReferencePersist> referencePersists, Boolean multipleSelect){ private @NotNull DmpBlueprintValuePersist buildDmpBlueprintValuePersist(UUID fieldId, String fieldValue, Instant dateValue, List<ReferencePersist> referencePersists, Boolean multipleSelect){
DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist(); DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist();
persist.setFieldId(fieldId); persist.setFieldId(fieldId);
@ -1302,8 +1327,10 @@ public class DmpServiceImpl implements DmpService {
persist.setReferences(referencePersists); persist.setReferences(referencePersists);
}else if (!this.conventionService.isListNullOrEmpty(referencePersists)){ }else if (!this.conventionService.isListNullOrEmpty(referencePersists)){
persist.setReference(referencePersists.getFirst()); persist.setReference(referencePersists.getFirst());
}else if (fieldValue != null){ }else if (!this.conventionService.isNullOrEmpty(fieldValue)){
persist.setFieldValue(fieldValue); persist.setFieldValue(fieldValue);
}else if (dateValue != null){
persist.setDateValue(dateValue);
} }
return persist; return persist;
@ -1527,11 +1554,12 @@ public class DmpServiceImpl implements DmpService {
} }
if (propertiesEntity != null && !this.conventionService.isListNullOrEmpty(propertiesEntity.getDmpBlueprintValues())) { if (propertiesEntity != null && !this.conventionService.isListNullOrEmpty(propertiesEntity.getDmpBlueprintValues())) {
List<DmpBlueprintValueImportExport> dmpDescriptionTemplateImportExports = new LinkedList<>(); List<DmpBlueprintValueImportExport> 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()) { for (DmpBlueprintValueEntity dmpBlueprintValueEntity : propertiesEntity.getDmpBlueprintValues()) {
dmpDescriptionTemplateImportExports.add(this.dmpBlueprintValueToExport(dmpBlueprintValueEntity)); dmpBlueprintValueImportExports.add(this.dmpBlueprintValueToExport(dmpBlueprintValueEntity, definition));
} }
xml.setBlueprintValues(dmpDescriptionTemplateImportExports); xml.setBlueprintValues(dmpBlueprintValueImportExports);
} }
List<DmpReferenceEntity> dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).disableTracking().dmpIds(data.getId()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).isActives(IsActive.Active).collect(); List<DmpReferenceEntity> 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; return xml;
} }
private DmpBlueprintValueImportExport dmpBlueprintValueToExport(DmpBlueprintValueEntity entity) { private DmpBlueprintValueImportExport dmpBlueprintValueToExport(DmpBlueprintValueEntity entity, org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition) {
DmpBlueprintValueImportExport xml = new DmpBlueprintValueImportExport(); DmpBlueprintValueImportExport xml = new DmpBlueprintValueImportExport();
if (entity == null) return xml; if (entity == null) return xml;
xml.setFieldId(entity.getFieldId()); 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.setValue(entity.getValue());
}
xml.setFieldId(entity.getFieldId());
}
return xml; return xml;
} }
@ -1717,11 +1756,11 @@ public class DmpServiceImpl implements DmpService {
Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues = new HashMap<>(); Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues = new HashMap<>();
// reference
if (!this.conventionService.isListNullOrEmpty(importXml.getBlueprint().getDmpBlueprintDefinition().getSections())) { if (!this.conventionService.isListNullOrEmpty(importXml.getBlueprint().getDmpBlueprintDefinition().getSections())) {
List<BlueprintSectionImportExport> sections = importXml.getBlueprint().getDmpBlueprintDefinition().getSections(); List<BlueprintSectionImportExport> sections = importXml.getBlueprint().getDmpBlueprintDefinition().getSections();
if (!this.conventionService.isListNullOrEmpty(sections)){ if (!this.conventionService.isListNullOrEmpty(sections)){
for (BlueprintSectionImportExport section : importXml.getBlueprint().getDmpBlueprintDefinition().getSections()) { for (BlueprintSectionImportExport section : importXml.getBlueprint().getDmpBlueprintDefinition().getSections()) {
// reference
if (!this.conventionService.isListNullOrEmpty(section.getReferenceFields()) && !this.conventionService.isListNullOrEmpty(importXml.getReferences())){ if (!this.conventionService.isListNullOrEmpty(section.getReferenceFields()) && !this.conventionService.isListNullOrEmpty(importXml.getReferences())){
for (BlueprintReferenceTypeFieldImportExport blueprintReferenceTypeField : section.getReferenceFields()) { for (BlueprintReferenceTypeFieldImportExport blueprintReferenceTypeField : section.getReferenceFields()) {
List<DmpReferenceImportExport> dmpReferencesByField = importXml.getReferences().stream().filter(x -> x.getFieldId().equals(blueprintReferenceTypeField.getId())).collect(Collectors.toList()); List<DmpReferenceImportExport> dmpReferencesByField = importXml.getReferences().stream().filter(x -> x.getFieldId().equals(blueprintReferenceTypeField.getId())).collect(Collectors.toList());
@ -1730,18 +1769,19 @@ public class DmpServiceImpl implements DmpService {
} }
} }
} }
}
}
}
// custom fields // custom fields
if (!this.conventionService.isListNullOrEmpty(importXml.getBlueprintValues())){ if (!this.conventionService.isListNullOrEmpty(section.getExtraFields()) && !this.conventionService.isListNullOrEmpty(importXml.getBlueprintValues())){
for (DmpBlueprintValueImportExport value : importXml.getBlueprintValues()) { for (DmpBlueprintValueImportExport value : importXml.getBlueprintValues()) {
if (value.getFieldId() != null) dmpBlueprintValues.put(value.getFieldId(), this.xmlDmpBlueprintValueToPersist(value)); 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));
} }
} }
}
}
}
}
persist.setContacts(contacts); persist.setContacts(contacts);
persist.setDmpBlueprintValues(dmpBlueprintValues); persist.setDmpBlueprintValues(dmpBlueprintValues);
@ -1782,14 +1822,18 @@ public class DmpServiceImpl implements DmpService {
return persist; return persist;
} }
private DmpBlueprintValuePersist xmlDmpBlueprintValueToPersist(DmpBlueprintValueImportExport importXml) { private DmpBlueprintValuePersist xmlDmpBlueprintValueToPersist(DmpBlueprintValueImportExport importXml, BlueprintExtraFieldImportExport extraFieldImportExport) {
if (importXml == null) if (importXml == null || extraFieldImportExport == null)
return null; return null;
DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist(); DmpBlueprintValuePersist persist = new DmpBlueprintValuePersist();
persist.setFieldId(importXml.getFieldId()); persist.setFieldId(importXml.getFieldId());
if (extraFieldImportExport.getType().equals(DmpBlueprintExtraFieldDataType.Date)){
persist.setDateValue(importXml.getDateValue());
} else {
persist.setFieldValue(importXml.getValue()); persist.setFieldValue(importXml.getValue());
}
return persist; return persist;
} }

View File

@ -47,6 +47,7 @@ export interface DmpProperties {
export interface DmpBlueprintValue { export interface DmpBlueprintValue {
fieldId: Guid; fieldId: Guid;
fieldValue: string; fieldValue: string;
dateValue: Date;
} }
export interface DmpContact { export interface DmpContact {
@ -95,6 +96,7 @@ export interface DmpPropertiesPersist {
export interface DmpBlueprintValuePersist { export interface DmpBlueprintValuePersist {
fieldId: Guid; fieldId: Guid;
fieldValue: string; fieldValue: string;
dateValue: Date;
references: DmpReferencePersist[]; references: DmpReferencePersist[];
reference: DmpReferencePersist; reference: DmpReferencePersist;
} }

View File

@ -295,11 +295,11 @@
<div *ngIf="field.dataType === dmpBlueprintExtraFieldDataTypeEnum.Date"> <div *ngIf="field.dataType === dmpBlueprintExtraFieldDataTypeEnum.Date">
<mat-form-field class="w-100"> <mat-form-field class="w-100">
<mat-label>{{field.label}}</mat-label> <mat-label>{{field.label}}</mat-label>
<input matInput placeholder="{{field.placeholder ?? field.label}}" name="value" [formControl]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('fieldValue')" [matDatepicker]="date" [required]="field.required"> <input matInput placeholder="{{field.placeholder ?? field.label}}" name="value" [formControl]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('dateValue')" [matDatepicker]="date" [required]="field.required">
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle> <mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
<mat-datepicker #date></mat-datepicker> <mat-datepicker #date></mat-datepicker>
<mat-error *ngIf="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('fieldValue').hasError('backendError')">{{formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('fieldValue').getError('backendError').message}}</mat-error> <mat-error *ngIf="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('dateValue').hasError('backendError')">{{formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('dateValue').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('fieldValue').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error> <mat-error *ngIf="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('dateValue').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field> </mat-form-field>
</div> </div>
<div *ngIf="field.dataType === dmpBlueprintExtraFieldDataTypeEnum.Number"> <div *ngIf="field.dataType === dmpBlueprintExtraFieldDataTypeEnum.Number">

View File

@ -218,7 +218,8 @@ export class DmpPropertiesEditorModel implements DmpPropertiesPersist {
this.dmpBlueprintValues.set(field.id, new DmpBlueprintValueEditorModel(this.validationErrorModel).fromModel( this.dmpBlueprintValues.set(field.id, new DmpBlueprintValueEditorModel(this.validationErrorModel).fromModel(
{ {
fieldId: field.id, 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)); }, dmpReferences, field));
} }
}); });
@ -315,6 +316,7 @@ export class DmpPropertiesEditorModel implements DmpPropertiesPersist {
export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist { export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist {
fieldId: Guid; fieldId: Guid;
fieldValue: string; fieldValue: string;
dateValue: Date;
references: DmpReferencePersist[] = []; references: DmpReferencePersist[] = [];
reference: DmpReferencePersist; reference: DmpReferencePersist;
isRequired: boolean = false; isRequired: boolean = false;
@ -330,6 +332,7 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist {
fromModel(item: DmpBlueprintValue, dmpReferences: DmpReference[], field: FieldInSection): DmpBlueprintValueEditorModel { fromModel(item: DmpBlueprintValue, dmpReferences: DmpReference[], field: FieldInSection): DmpBlueprintValueEditorModel {
this.fieldId = item.fieldId; this.fieldId = item.fieldId;
this.fieldValue = item.fieldValue; this.fieldValue = item.fieldValue;
this.dateValue = item.dateValue;
const references = dmpReferences?.filter(x => x.data.blueprintFieldId == this.fieldId && x.isActive == IsActive.Active).map(x => { const references = dmpReferences?.filter(x => x.data.blueprintFieldId == this.fieldId && x.isActive == IsActive.Active).map(x => {
return { return {
data: x.data, data: x.data,
@ -390,6 +393,7 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist {
case DmpBlueprintFieldCategory.System: case DmpBlueprintFieldCategory.System:
case DmpBlueprintFieldCategory.Extra: case DmpBlueprintFieldCategory.Extra:
formGroup.addControl('fieldValue', new FormControl({ value: this.fieldValue, disabled: disabled }, context.getValidation('fieldValue').validators)); 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; break;
} }
@ -408,6 +412,7 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist {
const baseValidationArray: Validation[] = new Array<Validation>(); const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'fieldId', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}fieldId`)] }); 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: '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: '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`)] }); 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 multipleSelect: params.multipleSelect
}); });
['fieldId', 'fieldValue', 'references'].forEach(keyField => { ['fieldId', 'fieldValue', 'dateValue', 'references'].forEach(keyField => {
const control = formGroup?.get(keyField); const control = formGroup?.get(keyField);
control?.clearValidators(); control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators); control?.addValidators(context.getValidation(keyField).validators);

View File

@ -47,6 +47,7 @@ export class DmpEditorResolver extends BaseEditorResolver {
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.dmpBlueprintValues), nameof<DmpBlueprintValue>(x => x.fieldId)].join('.'), [nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.dmpBlueprintValues), nameof<DmpBlueprintValue>(x => x.fieldId)].join('.'),
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.dmpBlueprintValues), nameof<DmpBlueprintValue>(x => x.fieldValue)].join('.'), [nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.dmpBlueprintValues), nameof<DmpBlueprintValue>(x => x.fieldValue)].join('.'),
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.dmpBlueprintValues), nameof<DmpBlueprintValue>(x => x.dateValue)].join('.'),
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.user), nameof<DmpAssociatedUser>(x => x.id)].join('.'), [nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.user), nameof<DmpAssociatedUser>(x => x.id)].join('.'),
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.firstName)].join('.'), [nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.firstName)].join('.'),
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.lastName)].join('.'), [nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.lastName)].join('.'),