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

This commit is contained in:
Sofia Papacharalampous 2024-04-09 13:19:46 +03:00
commit 29836cf362
8 changed files with 87 additions and 17 deletions

View File

@ -2,11 +2,11 @@ package eu.eudat.model.persist;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.*;
import eu.eudat.commons.types.dmpblueprint.DefinitionEntity;
import eu.eudat.commons.types.dmpblueprint.FieldEntity;
import eu.eudat.commons.types.dmpblueprint.SectionEntity;
import eu.eudat.commons.types.dmpblueprint.SystemFieldEntity;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.data.*;
import eu.eudat.query.DescriptionQuery;
@ -27,6 +27,7 @@ import javax.management.InvalidApplicationException;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class DmpPersist {
@ -199,6 +200,14 @@ public class DmpPersist {
DmpBlueprintEntity finalDmpBlueprintEntity = dmpBlueprintEntity;
DefinitionEntity definition = dmpBlueprintEntity == null ? null : this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, dmpBlueprintEntity.getDefinition());
String languageFieldLabel = null;
String accessFieldLabel = null;
if (definition != null){
languageFieldLabel = this.getSystemFieldLabel(definition, DmpBlueprintSystemFieldType.Language);
accessFieldLabel = this.getSystemFieldLabel(definition, DmpBlueprintSystemFieldType.AccessRights);
}
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
@ -230,7 +239,7 @@ public class DmpPersist {
this.spec()
.iff(() -> item.getStatus() == DmpStatus.Finalized)
.must(() -> this.isDescriptionTemplateMultiplicityValid(finalDmpBlueprintEntity, item.getId()))
.failOn(DmpPersist._descriptionTemplates).failWith(messageSource.getMessage("Validation.InvalidDescriptionTemplateMultiplicity", new Object[]{DmpPersist._descriptionTemplates}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._descriptionTemplates).failWith(messageSource.getMessage("Validation.InvalidDescriptionTemplateMultiplicityOnDMP", new Object[]{DmpPersist._descriptionTemplates}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getProperties()))
.on(DmpPersist._properties)
@ -239,11 +248,11 @@ public class DmpPersist {
this.spec()
.iff(() -> item.getStatus() == DmpStatus.Finalized)
.must(() -> !this.isNull(item.getLanguage()))
.failOn(DmpPersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._language}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{languageFieldLabel != null ? languageFieldLabel : DmpBlueprintSystemFieldType.Language.name()}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> item.getStatus() == DmpStatus.Finalized)
.must(() -> !this.isNull(item.getAccessType()))
.failOn(DmpPersist._accessType).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpPersist._accessType}, LocaleContextHolder.getLocale())),
.failOn(DmpPersist._accessType).failWith(messageSource.getMessage("Validation_Required", new Object[]{accessFieldLabel != null ? accessFieldLabel : DmpBlueprintSystemFieldType.AccessRights.name()}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> item.getStatus() == DmpStatus.Finalized)
.must(() -> !this.isListNullOrEmpty(item.getDescriptionTemplates()))
@ -296,6 +305,28 @@ public class DmpPersist {
}
return true;
}
private String getSystemFieldLabel(DefinitionEntity definition, DmpBlueprintSystemFieldType type){
if (this.isListNullOrEmpty(definition.getSections())) return null;
for (SectionEntity section: definition.getSections()) {
if (!this.isListNullOrEmpty(section.getFields())) {
List<FieldEntity> fields = section.getFields().stream().filter(x -> x.getCategory().equals(DmpBlueprintFieldCategory.System)).collect(Collectors.toList());
if (!this.isListNullOrEmpty(fields)){
List<SystemFieldEntity> systemFields = (List<SystemFieldEntity>)(List<?>) fields;
if (!this.isListNullOrEmpty(systemFields)){
List<SystemFieldEntity> contactSystemFields = systemFields.stream().filter(x -> x.getType().equals(type) && x.isRequired()).collect(Collectors.toList());
if(!this.isListNullOrEmpty(contactSystemFields)) {
return contactSystemFields.getFirst().getLabel() != null ? contactSystemFields.getFirst().getLabel() : type.name();
}
}
}
}
}
return null;
}
}
}

View File

@ -6,7 +6,6 @@ import eu.eudat.commons.types.dmpblueprint.DefinitionEntity;
import eu.eudat.commons.types.dmpblueprint.FieldEntity;
import eu.eudat.commons.types.dmpblueprint.ReferenceTypeFieldEntity;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.model.DmpDescriptionTemplate;
import eu.eudat.model.ReferenceType;
import eu.eudat.query.ReferenceTypeQuery;
import gr.cite.tools.data.query.QueryFactory;
@ -101,7 +100,7 @@ public class DmpBlueprintValuePersist {
.iff(() -> fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType) && this.isEmpty(item.getFieldValue()) && required)
.must(() -> !this.isListNullOrEmpty(item.getReferences()))
// TODO: Cast Exception
// .failOn(DmpBlueprintValuePersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(fieldEntity.getLabel()) ? fieldEntity.getLabel() : this.getReferenceTypeName(((ReferenceTypeFieldEntity) fieldEntity).getReferenceTypeId())}, LocaleContextHolder.getLocale())),
// .failOn(DmpBlueprintValuePersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(fieldEntity.getLabel()) ? fieldEntity.getLabel() : this.getReferenceTypeName(fieldEntity)}, LocaleContextHolder.getLocale())),
.failOn(DmpBlueprintValuePersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(fieldEntity.getLabel()) ? fieldEntity.getLabel() : DmpBlueprintValuePersist._references}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getReferences()))
@ -116,8 +115,11 @@ public class DmpBlueprintValuePersist {
return this;
}
private String getReferenceTypeName(UUID referenceTypeId){
return this.queryFactory.query(ReferenceTypeQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(referenceTypeId).firstAs(new BaseFieldSet().ensure(ReferenceType._name)).getName();
private String getReferenceTypeName(FieldEntity fieldEntity){
if (fieldEntity instanceof ReferenceTypeFieldEntity) {
return this.queryFactory.query(ReferenceTypeQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(((ReferenceTypeFieldEntity)fieldEntity).getReferenceTypeId()).firstAs(new BaseFieldSet().ensure(ReferenceType._name)).getName();
}
return "";
}
}

View File

@ -1,7 +1,12 @@
package eu.eudat.model.persist.dmpproperties;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import eu.eudat.commons.enums.DmpBlueprintSystemFieldType;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.types.dmpblueprint.DefinitionEntity;
import eu.eudat.commons.types.dmpblueprint.FieldEntity;
import eu.eudat.commons.types.dmpblueprint.SectionEntity;
import eu.eudat.commons.types.dmpblueprint.SystemFieldEntity;
import eu.eudat.commons.validation.BaseValidator;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
@ -18,6 +23,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
public class DmpPropertiesPersist {
@ -70,6 +76,7 @@ public class DmpPropertiesPersist {
@Override
protected List<Specification> specifications(DmpPropertiesPersist item) {
String contactField = this.getContactFieldLabel();
return Arrays.asList(
this.mapSpec()
.iff(() ->this.status == DmpStatus.Finalized && !this.isNull(item.getDmpBlueprintValues()))
@ -77,6 +84,10 @@ public class DmpPropertiesPersist {
.over(item.getDmpBlueprintValues())
.mapKey((k) -> ((UUID)k).toString())
.using((itm) -> this.validatorFactory.validator(DmpBlueprintValuePersist.DmpBlueprintValuePersistValidator.class).withDefinition(definition)),
this.spec()
.iff(() -> this.status == DmpStatus.Finalized && contactField != null)
.must(() -> !this.isListNullOrEmpty(item.getContacts()))
.failOn(DmpPropertiesPersist._contacts).failWith(messageSource.getMessage("Validation_Required", new Object[]{contactField}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> this.status == DmpStatus.Finalized && !this.isListNullOrEmpty(item.getContacts()))
.on(DmpPropertiesPersist._contacts)
@ -96,6 +107,28 @@ public class DmpPropertiesPersist {
return this;
}
private String getContactFieldLabel(){
if (this.isListNullOrEmpty(definition.getSections())) return null;
for (SectionEntity section: definition.getSections()) {
if (!this.isListNullOrEmpty(section.getFields())) {
List<FieldEntity> fields = section.getFields().stream().filter(x -> x.getCategory().equals(DmpBlueprintFieldCategory.System)).collect(Collectors.toList());
if (!this.isListNullOrEmpty(fields)){
List<SystemFieldEntity> systemFields = (List<SystemFieldEntity>)(List<?>) fields;
if (!this.isListNullOrEmpty(systemFields)){
List<SystemFieldEntity> contactSystemFields = systemFields.stream().filter(x -> x.getType().equals(DmpBlueprintSystemFieldType.Contact) && x.isRequired()).collect(Collectors.toList());
if(!this.isListNullOrEmpty(contactSystemFields)) {
return contactSystemFields.getFirst().getLabel() != null ? contactSystemFields.getFirst().getLabel() : DmpBlueprintSystemFieldType.Contact.name();
}
}
}
}
}
return null;
}
}
}

View File

@ -347,7 +347,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
data.setNumbering(persist.getNumbering());
data.setAdditionalInformation(persist.getAdditionalInformation());
data.setExtendedDescription(persist.getExtendedDescription());
if (persist.getMultiplicity() != null)
if (persist.getMultiplicity() != null && persist.getMultiplicity().getMin() != 0 && persist.getMultiplicity().getMax() != 0)
data.setMultiplicity(this.buildMultiplicityEntity(persist.getMultiplicity()));
data.setHasCommentField(persist.getHasCommentField());

View File

@ -1053,9 +1053,8 @@ public class DmpServiceImpl implements DmpService {
referencesFromAllFields = this.queryFactory.query(ReferenceQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(dmpReferenceEntities.stream().map(x-> x.getReferenceId()).collect(Collectors.toList())).isActive(IsActive.Active).collect();
}
if (!this.conventionService.isListNullOrEmpty(sectionEntities)){
Map<UUID, DmpBlueprintValuePersist> dmpBlueprintValues = new HashMap<>();
if (!this.conventionService.isListNullOrEmpty(sectionEntities)){
for (SectionEntity sectionEntity: sectionEntities) {
if (!this.conventionService.isListNullOrEmpty(sectionEntity.getFields())){
for (eu.eudat.commons.types.dmpblueprint.FieldEntity fieldEntity: sectionEntity.getFields()) {
@ -1072,17 +1071,19 @@ public class DmpServiceImpl implements DmpService {
dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), null, referencePersists));
}
}
}
if (!this.conventionService.isListNullOrEmpty(data.getDmpBlueprintValues())) {
} 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));
} else {
dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), null, null));
}
}
} else {
dmpBlueprintValues.put(fieldEntity.getId(), this.buildDmpBlueprintValuePersist(fieldEntity.getId(), null, null));
}
}
}

View File

@ -26,3 +26,4 @@ Validation.LessThenEqual= value {0} must be equal or less than {1}
Validation.LargerThenEqual= value {0} must be equal or larger than {1}
Validation.MissingFields= missing fields: {0}
Validation.InvalidDescriptionTemplateMultiplicity= {0} can not be used
Validation.InvalidDescriptionTemplateMultiplicityOnDMP= Description Templates has multiplicity errors

View File

@ -204,6 +204,8 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
route.push('../..');
} else if (this.isNew) {
route.push('../' + id);
} else if (this.isNewVersion || this.isClone) {
route.push('/description-templates');
} else {
route.push('..');
}

View File

@ -567,7 +567,7 @@ export class DescriptionTemplateFieldSetEditorModel implements DescriptionTempla
baseValidationArray.push({ key: 'id', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}id`)] });
baseValidationArray.push({ key: 'ordinal', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}ordinal`)] });
baseValidationArray.push({ key: 'numbering', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}numbering`)] });
baseValidationArray.push({ key: 'title', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}title`)] });
baseValidationArray.push({ key: 'title', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}title`)] });
baseValidationArray.push({ key: 'description', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}description`)] });
baseValidationArray.push({ key: 'extendedDescription', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}extendedDescription`)] });
baseValidationArray.push({ key: 'additionalInformation', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}additionalInformation`)] });