From 804ba2d537ecd8dc31831b4e6e07d9f4ac6e88a4 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 18 Apr 2024 17:12:41 +0300 Subject: [PATCH] prefilling changes --- .../PrefillingSourceServiceImpl.java | 34 +++++++++++++------ .../editor/description-editor.model.ts | 21 +++++++++++- .../visibility-rules.service.ts | 2 +- .../reference-field.component.ts | 8 ++--- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java index 8d7cad65d..22d292815 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/prefillingsource/PrefillingSourceServiceImpl.java @@ -24,6 +24,7 @@ import eu.eudat.model.builder.DescriptionTemplateBuilder; import eu.eudat.model.builder.PrefillingSourceBuilder; import eu.eudat.model.deleter.PrefillingSourceDeleter; import eu.eudat.model.descriptionproperties.*; +import eu.eudat.model.descriptionreference.DescriptionReferenceData; import eu.eudat.model.persist.PrefillingSearchRequest; import eu.eudat.model.persist.DescriptionPrefillingRequest; import eu.eudat.model.persist.PrefillingSourcePersist; @@ -372,38 +373,40 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { } private Description mapPrefilledEntityToDescription(Description description, DefinitionEntity descriptionTemplateDefinition, PrefillingSourceDefinitionEntity prefillingSourceDefinition, String type, Map externalData){ + List descriptionReferences = new ArrayList<>(); if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFields())) { for (PrefillingSourceDefinitionFieldEntity field : prefillingSourceDefinition.getFields()) { String sourceValue = externalData.get(field.getCode()); this.prefillSystemValueToDescription(description, field.getSystemFieldTarget(), sourceValue); - this.prefillSemanticValueToDescription(description, field.getSemanticTarget(), sourceValue, descriptionTemplateDefinition, type); + this.prefillSemanticValueToDescription(description, descriptionReferences, field.getSemanticTarget(), sourceValue, descriptionTemplateDefinition, type); } } if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFixedValueFields())){ for (PrefillingSourceDefinitionFixedValueFieldEntity field: prefillingSourceDefinition.getFixedValueFields()) { this.prefillSystemValueToDescription(description, field.getSystemFieldTarget(), field.getFixedValue()); - this.prefillSemanticValueToDescription(description, field.getSemanticTarget(), field.getFixedValue(), descriptionTemplateDefinition, type); + this.prefillSemanticValueToDescription(description, descriptionReferences, field.getSemanticTarget(), field.getFixedValue(), descriptionTemplateDefinition, type); } } if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFields())) { for (PrefillingSourceDefinitionFieldEntity field : prefillingSourceDefinition.getFields()) { String sourceValue = externalData.get(field.getCode()); - this.ensureZenodoFields(description, field.getSemanticTarget(), sourceValue, descriptionTemplateDefinition, type); + this.ensureZenodoFields(description, descriptionReferences, field.getSemanticTarget(), sourceValue, descriptionTemplateDefinition, type); } } if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFixedValueFields())) { for (PrefillingSourceDefinitionFixedValueFieldEntity field : prefillingSourceDefinition.getFixedValueFields()) { - this.ensureZenodoFields(description, field.getSemanticTarget(), field.getFixedValue(), descriptionTemplateDefinition, type); + this.ensureZenodoFields(description, descriptionReferences, field.getSemanticTarget(), field.getFixedValue(), descriptionTemplateDefinition, type); } } + description.setDescriptionReferences(descriptionReferences); return description; } - private void ensureZenodoFields(Description description, String semanticTarget, String value, DefinitionEntity definition, String type) { + private void ensureZenodoFields(Description description, List descriptionReferences,String semanticTarget, String value, DefinitionEntity definition, String type) { if (!this.conventionService.isNullOrEmpty(type) && !this.conventionService.isNullOrEmpty(semanticTarget) && !this.conventionService.isNullOrEmpty(value) && type.equals(Zenodo)) { if (semanticTarget.equals("rda.dataset.distribution.data_access")) { if (value.equals("open")) { @@ -421,7 +424,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { this.ensureFieldSetEntity(description, licStartFieldSetEntity); for (FieldEntity licStartDateNode : licStartEntities) { - description.getProperties().getFieldSets().get(licStartFieldSetEntity.getId()).getItems().getFirst().getFields().put(licStartDateNode.getId(), buildPropertyDefinitionFieldItemValue(licStartDateNode, semanticTarget, issuedValue, type)); + description.getProperties().getFieldSets().get(licStartFieldSetEntity.getId()).getItems().getFirst().getFields().put(licStartDateNode.getId(), buildPropertyDefinitionFieldItemValue(descriptionReferences,licStartDateNode, semanticTarget, issuedValue, type)); } } } @@ -442,7 +445,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { if (description.getProperties().getFieldSets().get(fieldSetEntity.getId()).getItems().getFirst().getOrdinal() == null) description.getProperties().getFieldSets().get(fieldSetEntity.getId()).getItems().getFirst().setOrdinal(0); } - private void prefillSemanticValueToDescription(Description description, String semanticTarget, String parsedValue, DefinitionEntity definition, String type) { + private void prefillSemanticValueToDescription(Description description, List descriptionReferences, String semanticTarget, String parsedValue, DefinitionEntity definition, String type) { if (this.conventionService.isNullOrEmpty(semanticTarget) || this.conventionService.isNullOrEmpty(parsedValue)) return; List fieldSetsEntities = definition.getAllFieldSets().stream().filter(x-> x.getAllField() != null && x.getAllField().stream().anyMatch(y-> !this.conventionService.isListNullOrEmpty(y.getSchematics()) && y.getSchematics().contains(semanticTarget))).toList(); for (FieldSetEntity fieldSetEntity: fieldSetsEntities) { @@ -450,7 +453,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { if (!this.conventionService.isListNullOrEmpty(fieldEntities)) { this.ensureFieldSetEntity(description, fieldSetEntity); for (FieldEntity fieldEntity : fieldEntities){ - description.getProperties().getFieldSets().get(fieldSetEntity.getId()).getItems().getFirst().getFields().put(fieldEntity.getId() , buildPropertyDefinitionFieldItemValue(fieldEntity, semanticTarget, parsedValue, type)); + description.getProperties().getFieldSets().get(fieldSetEntity.getId()).getItems().getFirst().getFields().put(fieldEntity.getId() , buildPropertyDefinitionFieldItemValue(descriptionReferences, fieldEntity, semanticTarget, parsedValue, type)); } } } @@ -479,7 +482,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { } } - private Field buildPropertyDefinitionFieldItemValue(FieldEntity fieldEntity, String semanticTarget, String value, String type) { + private Field buildPropertyDefinitionFieldItemValue(List descriptionReferences, FieldEntity fieldEntity, String semanticTarget, String value, String type) { Field field = new Field(); if (fieldEntity == null || fieldEntity.getData() == null || fieldEntity.getData().getFieldType() == null || this.conventionService.isNullOrEmpty(value)) return field; try{ @@ -517,9 +520,11 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { SelectDataEntity selectDataEntity = (SelectDataEntity) fieldEntity.getData(); if (selectDataEntity == null || selectDataEntity.getOptions() == null) throw new MyApplicationException("Can not cast fieldEntity data"); field.setTextListValue(new ArrayList<>()); + for (SelectDataEntity.OptionEntity entity : selectDataEntity.getOptions()){ if (finalValue.contains(entity.getValue()) || finalValue.contains(entity.getLabel())){ - field.getTextListValue().add(entity.getValue()); + if (selectDataEntity.getMultipleSelect()) field.getTextListValue().add(entity.getValue()); + else field.setTextValue(entity.getValue()); } } } @@ -542,11 +547,13 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { .ensure(Reference._id) .ensure(Reference._label) .ensure(Reference._type) + .ensure(this.conventionService.asIndexer(Reference._type, ReferenceType._id)) .ensure(Reference._description) .ensure(this.conventionService.asIndexer(Reference._description, Definition._fields, eu.eudat.model.referencedefinition.Field._code)) .ensure(this.conventionService.asIndexer(Reference._description, Definition._fields, eu.eudat.model.referencedefinition.Field._dataType)) .ensure(this.conventionService.asIndexer(Reference._description, Definition._fields, eu.eudat.model.referencedefinition.Field._value)) .ensure(Reference._reference) + .ensure(Reference._sourceType) .ensure(Reference._abbreviation) .ensure(Reference._source) .ensure(Reference._isActive) @@ -559,6 +566,13 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService { for (Reference reference : references){ if (reference.getReference().equals(like) || reference.getLabel().toUpperCase(Locale.ROOT).contains(like.toUpperCase(Locale.ROOT))) { field.getReferences().add(reference); + DescriptionReference descriptionReference = new DescriptionReference(); + descriptionReference.setReference(reference); + DescriptionReferenceData descriptionReferenceData = new DescriptionReferenceData(); + descriptionReferenceData.setFieldId(fieldEntity.getId()); + descriptionReference.setData(descriptionReferenceData); + descriptionReference.setIsActive(IsActive.Active); + descriptionReferences.add(descriptionReference); } } } diff --git a/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts b/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts index 4f70e929b..c1699a4a6 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts @@ -232,6 +232,25 @@ export class DescriptionPropertyDefinitionEditorModel implements DescriptionProp } as DescriptionPropertyDefinitionFieldSetItem] } + // preffiling item case we ned to ensure tha all fields of fieldset are contained + for (let i = 0; i < definitionFieldSet.fields.length; i++) { + const definitionField = definitionFieldSet.fields[i]; + for (let j = 0; j < fieldSetValue.items.length; j++) { + const fieldSetValueItem = fieldSetValue.items[j]; + const descriptionField = fieldSetValueItem.fields[definitionField.id]; + if (!descriptionField) { + fieldSetValueItem.fields[definitionField.id] = { + textValue: undefined, + textListValue: undefined, + dateValue: undefined, + externalIdentifier: undefined, + references: undefined + }; + } + } + + } + return new DescriptionPropertyDefinitionFieldSetEditorModel(this.validationErrorModel).fromModel(fieldSetValue, descriptionReferences, definitionFieldSet); } @@ -671,4 +690,4 @@ export class DescriptionReferenceEditorModel implements DescriptionReferencePers control?.addValidators(context.getValidation(keyField).validators); }); } -} \ No newline at end of file +} diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts b/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts index 9e5ee6323..c55d4b16a 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts @@ -12,7 +12,7 @@ export class VisibilityRulesService { private form: AbstractControl; private definition: DescriptionTemplateDefinition; private rulesBySources: Map ; - public isVisibleMap: { [key: string]: boolean } = null; + public isVisibleMap: { [key: string]: boolean } = {}; private _isVisibleMap: { [key: string]: boolean } = null; private allDescriptionTemplateFields: DescriptionTemplateField[] = null; diff --git a/dmp-frontend/src/app/ui/reference/reference-field/reference-field.component.ts b/dmp-frontend/src/app/ui/reference/reference-field/reference-field.component.ts index 4114fa5a5..7bf905924 100644 --- a/dmp-frontend/src/app/ui/reference/reference-field/reference-field.component.ts +++ b/dmp-frontend/src/app/ui/reference/reference-field/reference-field.component.ts @@ -46,8 +46,8 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit, On ) { super(); } ngOnInit() { - this.referenceDepedencyIds = this.referenceType.definition.sources.filter(x => x.referenceTypeDependencies).flatMap(x => x.referenceTypeDependencies).filter(x => x).map(x => x.id); - if (this.referenceDepedencyIds.length > 0) { + this.referenceDepedencyIds = this.referenceType?.definition?.sources?.filter(x => x.referenceTypeDependencies).flatMap(x => x.referenceTypeDependencies).filter(x => x).map(x => x.id); + if (this.referenceDepedencyIds && this.referenceDepedencyIds.length > 0) { this.resolveReferenceDepedency(true); } else { if (this.multiple) { @@ -60,8 +60,8 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit, On ngOnChanges(changes: SimpleChanges) { if ((changes['dependencies'] || changes['referenceType']) && this.dependencies != null && this.referenceType != null) { - this.referenceDepedencyIds = this.referenceType.definition.sources.filter(x => x.referenceTypeDependencies).flatMap(x => x.referenceTypeDependencies).filter(x => x).map(x => x.id); - if (this.referenceDepedencyIds.length > 0) { + this.referenceDepedencyIds = this.referenceType?.definition?.sources?.filter(x => x.referenceTypeDependencies).flatMap(x => x.referenceTypeDependencies).filter(x => x).map(x => x.id); + if (this.referenceDepedencyIds && this.referenceDepedencyIds.length > 0) { if (this.dependenciesSubscription != null) this.dependenciesSubscription.unsubscribe(); this.resolveReferenceDepedency(true); this.dependenciesSubscription = this.dependencies.valueChanges.pipe(takeUntil(this._destroyed)).subscribe(changes => {