prefilling changes

This commit is contained in:
Efstratios Giannopoulos 2024-04-18 17:12:41 +03:00
parent d268d9b435
commit 804ba2d537
4 changed files with 49 additions and 16 deletions

View File

@ -24,6 +24,7 @@ import eu.eudat.model.builder.DescriptionTemplateBuilder;
import eu.eudat.model.builder.PrefillingSourceBuilder; import eu.eudat.model.builder.PrefillingSourceBuilder;
import eu.eudat.model.deleter.PrefillingSourceDeleter; import eu.eudat.model.deleter.PrefillingSourceDeleter;
import eu.eudat.model.descriptionproperties.*; import eu.eudat.model.descriptionproperties.*;
import eu.eudat.model.descriptionreference.DescriptionReferenceData;
import eu.eudat.model.persist.PrefillingSearchRequest; import eu.eudat.model.persist.PrefillingSearchRequest;
import eu.eudat.model.persist.DescriptionPrefillingRequest; import eu.eudat.model.persist.DescriptionPrefillingRequest;
import eu.eudat.model.persist.PrefillingSourcePersist; 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<String, String> externalData){ private Description mapPrefilledEntityToDescription(Description description, DefinitionEntity descriptionTemplateDefinition, PrefillingSourceDefinitionEntity prefillingSourceDefinition, String type, Map<String, String> externalData){
List<DescriptionReference> descriptionReferences = new ArrayList<>();
if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFields())) { if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFields())) {
for (PrefillingSourceDefinitionFieldEntity field : prefillingSourceDefinition.getFields()) { for (PrefillingSourceDefinitionFieldEntity field : prefillingSourceDefinition.getFields()) {
String sourceValue = externalData.get(field.getCode()); String sourceValue = externalData.get(field.getCode());
this.prefillSystemValueToDescription(description, field.getSystemFieldTarget(), sourceValue); 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())){ if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFixedValueFields())){
for (PrefillingSourceDefinitionFixedValueFieldEntity field: prefillingSourceDefinition.getFixedValueFields()) { for (PrefillingSourceDefinitionFixedValueFieldEntity field: prefillingSourceDefinition.getFixedValueFields()) {
this.prefillSystemValueToDescription(description, field.getSystemFieldTarget(), field.getFixedValue()); 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())) { if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFields())) {
for (PrefillingSourceDefinitionFieldEntity field : prefillingSourceDefinition.getFields()) { for (PrefillingSourceDefinitionFieldEntity field : prefillingSourceDefinition.getFields()) {
String sourceValue = externalData.get(field.getCode()); 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())) { if (!this.conventionService.isListNullOrEmpty(prefillingSourceDefinition.getFixedValueFields())) {
for (PrefillingSourceDefinitionFixedValueFieldEntity field : 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; return description;
} }
private void ensureZenodoFields(Description description, String semanticTarget, String value, DefinitionEntity definition, String type) { private void ensureZenodoFields(Description description, List<DescriptionReference> 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 (!this.conventionService.isNullOrEmpty(type) && !this.conventionService.isNullOrEmpty(semanticTarget) && !this.conventionService.isNullOrEmpty(value) && type.equals(Zenodo)) {
if (semanticTarget.equals("rda.dataset.distribution.data_access")) { if (semanticTarget.equals("rda.dataset.distribution.data_access")) {
if (value.equals("open")) { if (value.equals("open")) {
@ -421,7 +424,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
this.ensureFieldSetEntity(description, licStartFieldSetEntity); this.ensureFieldSetEntity(description, licStartFieldSetEntity);
for (FieldEntity licStartDateNode : licStartEntities) { 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); 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<DescriptionReference> descriptionReferences, String semanticTarget, String parsedValue, DefinitionEntity definition, String type) {
if (this.conventionService.isNullOrEmpty(semanticTarget) || this.conventionService.isNullOrEmpty(parsedValue)) return; if (this.conventionService.isNullOrEmpty(semanticTarget) || this.conventionService.isNullOrEmpty(parsedValue)) return;
List<FieldSetEntity> fieldSetsEntities = definition.getAllFieldSets().stream().filter(x-> x.getAllField() != null && x.getAllField().stream().anyMatch(y-> !this.conventionService.isListNullOrEmpty(y.getSchematics()) && y.getSchematics().contains(semanticTarget))).toList(); List<FieldSetEntity> 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) { for (FieldSetEntity fieldSetEntity: fieldSetsEntities) {
@ -450,7 +453,7 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
if (!this.conventionService.isListNullOrEmpty(fieldEntities)) { if (!this.conventionService.isListNullOrEmpty(fieldEntities)) {
this.ensureFieldSetEntity(description, fieldSetEntity); this.ensureFieldSetEntity(description, fieldSetEntity);
for (FieldEntity fieldEntity : fieldEntities){ 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<DescriptionReference> descriptionReferences, FieldEntity fieldEntity, String semanticTarget, String value, String type) {
Field field = new Field(); Field field = new Field();
if (fieldEntity == null || fieldEntity.getData() == null || fieldEntity.getData().getFieldType() == null || this.conventionService.isNullOrEmpty(value)) return field; if (fieldEntity == null || fieldEntity.getData() == null || fieldEntity.getData().getFieldType() == null || this.conventionService.isNullOrEmpty(value)) return field;
try{ try{
@ -517,9 +520,11 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
SelectDataEntity selectDataEntity = (SelectDataEntity) fieldEntity.getData(); SelectDataEntity selectDataEntity = (SelectDataEntity) fieldEntity.getData();
if (selectDataEntity == null || selectDataEntity.getOptions() == null) throw new MyApplicationException("Can not cast fieldEntity data"); if (selectDataEntity == null || selectDataEntity.getOptions() == null) throw new MyApplicationException("Can not cast fieldEntity data");
field.setTextListValue(new ArrayList<>()); field.setTextListValue(new ArrayList<>());
for (SelectDataEntity.OptionEntity entity : selectDataEntity.getOptions()){ for (SelectDataEntity.OptionEntity entity : selectDataEntity.getOptions()){
if (finalValue.contains(entity.getValue()) || finalValue.contains(entity.getLabel())){ 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._id)
.ensure(Reference._label) .ensure(Reference._label)
.ensure(Reference._type) .ensure(Reference._type)
.ensure(this.conventionService.asIndexer(Reference._type, ReferenceType._id))
.ensure(Reference._description) .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._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._dataType))
.ensure(this.conventionService.asIndexer(Reference._description, Definition._fields, eu.eudat.model.referencedefinition.Field._value)) .ensure(this.conventionService.asIndexer(Reference._description, Definition._fields, eu.eudat.model.referencedefinition.Field._value))
.ensure(Reference._reference) .ensure(Reference._reference)
.ensure(Reference._sourceType)
.ensure(Reference._abbreviation) .ensure(Reference._abbreviation)
.ensure(Reference._source) .ensure(Reference._source)
.ensure(Reference._isActive) .ensure(Reference._isActive)
@ -559,6 +566,13 @@ public class PrefillingSourceServiceImpl implements PrefillingSourceService {
for (Reference reference : references){ for (Reference reference : references){
if (reference.getReference().equals(like) || reference.getLabel().toUpperCase(Locale.ROOT).contains(like.toUpperCase(Locale.ROOT))) { if (reference.getReference().equals(like) || reference.getLabel().toUpperCase(Locale.ROOT).contains(like.toUpperCase(Locale.ROOT))) {
field.getReferences().add(reference); 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);
} }
} }
} }

View File

@ -232,6 +232,25 @@ export class DescriptionPropertyDefinitionEditorModel implements DescriptionProp
} as DescriptionPropertyDefinitionFieldSetItem] } 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); return new DescriptionPropertyDefinitionFieldSetEditorModel(this.validationErrorModel).fromModel(fieldSetValue, descriptionReferences, definitionFieldSet);
} }

View File

@ -12,7 +12,7 @@ export class VisibilityRulesService {
private form: AbstractControl; private form: AbstractControl;
private definition: DescriptionTemplateDefinition; private definition: DescriptionTemplateDefinition;
private rulesBySources: Map<String, RuleWithTarget[]> ; private rulesBySources: Map<String, RuleWithTarget[]> ;
public isVisibleMap: { [key: string]: boolean } = null; public isVisibleMap: { [key: string]: boolean } = {};
private _isVisibleMap: { [key: string]: boolean } = null; private _isVisibleMap: { [key: string]: boolean } = null;
private allDescriptionTemplateFields: DescriptionTemplateField[] = null; private allDescriptionTemplateFields: DescriptionTemplateField[] = null;

View File

@ -46,8 +46,8 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit, On
) { super(); } ) { super(); }
ngOnInit() { ngOnInit() {
this.referenceDepedencyIds = this.referenceType.definition.sources.filter(x => x.referenceTypeDependencies).flatMap(x => x.referenceTypeDependencies).filter(x => x).map(x => x.id); 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) { if (this.referenceDepedencyIds && this.referenceDepedencyIds.length > 0) {
this.resolveReferenceDepedency(true); this.resolveReferenceDepedency(true);
} else { } else {
if (this.multiple) { if (this.multiple) {
@ -60,8 +60,8 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit, On
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {
if ((changes['dependencies'] || changes['referenceType']) && this.dependencies != null && this.referenceType != null) { 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); 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) { if (this.referenceDepedencyIds && this.referenceDepedencyIds.length > 0) {
if (this.dependenciesSubscription != null) this.dependenciesSubscription.unsubscribe(); if (this.dependenciesSubscription != null) this.dependenciesSubscription.unsubscribe();
this.resolveReferenceDepedency(true); this.resolveReferenceDepedency(true);
this.dependenciesSubscription = this.dependencies.valueChanges.pipe(takeUntil(this._destroyed)).subscribe(changes => { this.dependenciesSubscription = this.dependencies.valueChanges.pipe(takeUntil(this._destroyed)).subscribe(changes => {