add dateValue to dmp blueprint value

This commit is contained in:
amentis 2024-05-23 16:58:12 +03:00
parent 27d899dec2
commit 750f109b7d
12 changed files with 210 additions and 52 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<DmpBlueprintValue, Dmp
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private DefinitionEntity definition;
@Autowired
public DmpBlueprintValueBuilder(
ConventionService conventionService) {
@ -34,6 +41,11 @@ public class DmpBlueprintValueBuilder extends BaseBuilder<DmpBlueprintValue, Dmp
return this;
}
public DmpBlueprintValueBuilder withDefinition(DefinitionEntity definition) {
this.definition = definition;
return this;
}
@Override
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));
@ -44,11 +56,21 @@ public class DmpBlueprintValueBuilder extends BaseBuilder<DmpBlueprintValue, Dmp
List<DmpBlueprintValue> 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;

View File

@ -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<Dmp, DmpEntity> {
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<Dmp, DmpEntity> {
@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<Dmp, DmpEntity> {
FieldSet otherDmpVersionsFields = fields.extractPrefixed(this.asPrefix(Dmp._otherDmpVersions));
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());
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) {
Dmp m = new Dmp();
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.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<Dmp, DmpEntity> {
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 {
if (fields.isEmpty() || data.isEmpty())
return null;

View File

@ -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<DmpProperties, DmpProperti
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private DefinitionEntity definition;
@Autowired
public DmpPropertiesBuilder(
@ -32,6 +34,11 @@ public class DmpPropertiesBuilder extends BaseBuilder<DmpProperties, DmpProperti
this.builderFactory = builderFactory;
}
public DmpPropertiesBuilder withDefinition(DefinitionEntity definition) {
this.definition = definition;
return this;
}
public DmpPropertiesBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
@ -51,7 +58,7 @@ public class DmpPropertiesBuilder extends BaseBuilder<DmpProperties, DmpProperti
List<DmpProperties> 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);
}

View File

@ -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;
}
}

View File

@ -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<ReferencePersist> 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<ReferencePersist> 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<Specification> 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()))

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.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<ReferencePersist> referencePersists, Boolean multipleSelect){
private @NotNull DmpBlueprintValuePersist buildDmpBlueprintValuePersist(UUID fieldId, String fieldValue, Instant dateValue, List<ReferencePersist> 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<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()) {
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();
@ -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<UUID, DmpBlueprintValuePersist> dmpBlueprintValues = new HashMap<>();
// reference
if (!this.conventionService.isListNullOrEmpty(importXml.getBlueprint().getDmpBlueprintDefinition().getSections())) {
List<BlueprintSectionImportExport> 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<DmpReferenceImportExport> 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;
}

View File

@ -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;
}

View File

@ -295,11 +295,11 @@
<div *ngIf="field.dataType === dmpBlueprintExtraFieldDataTypeEnum.Date">
<mat-form-field class="w-100">
<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 #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('fieldValue').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</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('dateValue').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<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(
{
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<Validation>();
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);

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.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.firstName)].join('.'),
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.lastName)].join('.'),