diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/FieldEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/FieldEntity.java index 7ffdd64a8..e8e060723 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/FieldEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/FieldEntity.java @@ -1,17 +1,8 @@ package eu.eudat.commons.types.description; public class FieldEntity { - private String key; private String value; - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public String getValue() { return value; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/PropertyDefinitionEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/PropertyDefinitionEntity.java index c0623c4fe..f086f0903 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/PropertyDefinitionEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/PropertyDefinitionEntity.java @@ -1,15 +1,18 @@ package eu.eudat.commons.types.description; -import java.util.List; +import java.util.Map; public class PropertyDefinitionEntity { - private List fields; + private Map fieldSets; - public List getFields() { - return fields; + public Map getFieldSets() { + return fieldSets; } - public void setFields(List fields) { - this.fields = fields; + public void setFieldSets(Map fieldSets) { + this.fieldSets = fieldSets; } } + + + diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/PropertyDefinitionFieldSetEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/PropertyDefinitionFieldSetEntity.java new file mode 100644 index 000000000..a9275b4dc --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/PropertyDefinitionFieldSetEntity.java @@ -0,0 +1,15 @@ +package eu.eudat.commons.types.description; + +import java.util.List; + +public class PropertyDefinitionFieldSetEntity { + private List items; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/PropertyDefinitionFieldSetItemEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/PropertyDefinitionFieldSetItemEntity.java new file mode 100644 index 000000000..6d943a4b2 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/description/PropertyDefinitionFieldSetItemEntity.java @@ -0,0 +1,33 @@ +package eu.eudat.commons.types.description; + +import java.util.Map; + +public class PropertyDefinitionFieldSetItemEntity { + private Map fields; + private String comment; + private int ordinal; + + public Map getFields() { + return fields; + } + + public void setFields(Map fields) { + this.fields = fields; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public int getOrdinal() { + return ordinal; + } + + public void setOrdinal(int ordinal) { + this.ordinal = ordinal; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/DefinitionEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/DefinitionEntity.java index a53f450dc..e88d6bc3e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/DefinitionEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/DefinitionEntity.java @@ -30,6 +30,15 @@ public class DefinitionEntity { return fieldEntities; } + public List getAllFieldSets(){ + List fieldSetsEntities = new ArrayList<>(); + if (this.getPages() != null){ + for (PageEntity sectionEntity: this.getPages()) { + fieldSetsEntities.addAll(sectionEntity.getAllFieldSets()); + } + } + return fieldSetsEntities; + } public List getFieldById(String id) { return this.getAllField().stream().filter(x-> id.equals(x.getId())).toList(); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/FieldSetEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/FieldSetEntity.java index 618d03734..36fee13fc 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/FieldSetEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/FieldSetEntity.java @@ -101,7 +101,7 @@ public class FieldSetEntity implements DatabaseViewStyleDefinition { this.additionalInformation = additionalInformation; } - + public List getAllField() { return this.getFields() == null ? new ArrayList<>() : this.getFields(); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/PageEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/PageEntity.java index c993f43d5..6bbd33a68 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/PageEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/PageEntity.java @@ -62,4 +62,14 @@ public class PageEntity implements DatabaseViewStyleDefinition { } return fieldEntities; } + + public List getAllFieldSets(){ + List fieldSetsEntities = new ArrayList<>(); + if (this.getSections() != null){ + for (SectionEntity sectionEntity: this.getSections()) { + fieldSetsEntities.addAll(sectionEntity.getAllFieldSets()); + } + } + return fieldSetsEntities; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/SectionEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/SectionEntity.java index 6260484e8..9a0e0af8e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/SectionEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/SectionEntity.java @@ -126,4 +126,17 @@ public class SectionEntity implements DatabaseViewStyleDefinition{ } return fieldEntities; } + + public List getAllFieldSets(){ + List fieldSetEntities = new ArrayList<>(); + if (this.getFieldSets() != null){ + fieldSetEntities.addAll(this.getFieldSets()); + } + if (this.getSections() != null){ + for (SectionEntity sectionEntity: this.getSections()) { + fieldSetEntities.addAll(sectionEntity.getAllFieldSets()); + } + } + return fieldSetEntities; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionDepositBuilder.java index 110d54af2..70d8e9d93 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionDepositBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionDepositBuilder.java @@ -71,8 +71,9 @@ public class DescriptionDepositBuilder extends BaseDepositBuilder(m, d)); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionFieldDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionFieldDepositBuilder.java index 5548e9d61..4f8b7961c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionFieldDepositBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionFieldDepositBuilder.java @@ -58,7 +58,10 @@ public class DescriptionFieldDepositBuilder extends BaseDepositBuilder fieldEntities = definition.getFieldById(d.getKey()); + + //TODO Update with the new logic of property definition + //List fieldEntities = definition.getFieldById(d.getKey()); + List fieldEntities = new ArrayList<>(); if (!this.conventionService.isListNullOrEmpty(fieldEntities)){ eu.eudat.commons.types.descriptiontemplate.FieldEntity field = fieldEntities.getFirst(); m.setSchematics(field.getSchematics()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/FieldBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/FieldBuilder.java index aaa506ecd..0b1387f96 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/FieldBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/FieldBuilder.java @@ -19,20 +19,16 @@ import org.springframework.stereotype.Component; import java.util.*; -@Component("descriptionpropertiesdefinitionFieldbuilder") +@Component("description.FieldBuilder") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class FieldBuilder extends BaseBuilder { - private final BuilderFactory builderFactory; - private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider; private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); @Autowired public FieldBuilder( ConventionService conventionService, BuilderFactory builderFactory, FieldDataHelperServiceProvider fieldDataHelperServiceProvider) { super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldBuilder.class))); - this.builderFactory = builderFactory; - this.fieldDataHelperServiceProvider = fieldDataHelperServiceProvider; } public FieldBuilder authorize(EnumSet values) { @@ -51,7 +47,6 @@ public class FieldBuilder extends BaseBuilder { List models = new ArrayList<>(); for (FieldEntity d : data) { Field m = new Field(); - if (fields.hasField(this.asIndexer(Field._key))) m.setKey(d.getKey()); if (fields.hasField(this.asIndexer(Field._value))) m.setValue(d.getValue()); models.add(m); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionBuilder.java index 6346f306c..271585133 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionBuilder.java @@ -47,12 +47,17 @@ public class PropertyDefinitionBuilder extends BaseBuilder(); //Not Bulk Build because is XML no interaction with db - FieldSet fieldsFields = fields.extractPrefixed(this.asPrefix(PropertyDefinition._fields)); + FieldSet fieldsFields = fields.extractPrefixed(this.asPrefix(PropertyDefinition._fieldSets)); List models = new ArrayList<>(); for (PropertyDefinitionEntity d : data) { PropertyDefinition m = new PropertyDefinition(); - if (!fieldsFields.isEmpty() && d.getFields() != null) m.setFields(this.builderFactory.builder(FieldBuilder.class).authorize(this.authorize).build(fieldsFields, d.getFields())); + if (!fieldsFields.isEmpty() && d.getFieldSets() != null && !d.getFieldSets().isEmpty()) { + m.setFieldSets(new HashMap<>()); + for (String key : d.getFieldSets().keySet()){ + m.getFieldSets().put(key, this.builderFactory.builder(PropertyDefinitionFieldSetBuilder.class).authorize(this.authorize).build(fieldsFields, d.getFieldSets().get(key))); + } + } models.add(m); } this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionFieldSetBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionFieldSetBuilder.java new file mode 100644 index 000000000..8c10f96d4 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionFieldSetBuilder.java @@ -0,0 +1,59 @@ +package eu.eudat.model.builder.descriptionpropertiesdefinition; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.types.description.PropertyDefinitionFieldSetEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.BaseBuilder; +import eu.eudat.model.descriptionproperties.PropertyDefinitionFieldSet; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component("description.PropertyDefinitionFieldSet") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class PropertyDefinitionFieldSetBuilder extends BaseBuilder { + + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public PropertyDefinitionFieldSetBuilder( + ConventionService conventionService, BuilderFactory builderFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(PropertyDefinitionFieldSetBuilder.class))); + this.builderFactory = builderFactory; + } + + public PropertyDefinitionFieldSetBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (fields == null || data == null || fields.isEmpty()) + return new ArrayList<>(); + + //Not Bulk Build because is XML no interaction with db + FieldSet itemsFields = fields.extractPrefixed(this.asPrefix(PropertyDefinitionFieldSet._items)); + + List models = new ArrayList<>(); + for (PropertyDefinitionFieldSetEntity d : data) { + PropertyDefinitionFieldSet m = new PropertyDefinitionFieldSet(); + if (!itemsFields.isEmpty() && d.getItems() != null) m.setItems(this.builderFactory.builder(PropertyDefinitionFieldSetItemBuilder.class).authorize(this.authorize).build(itemsFields, d.getItems())); + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionFieldSetItemBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionFieldSetItemBuilder.java new file mode 100644 index 000000000..9959d09b8 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionFieldSetItemBuilder.java @@ -0,0 +1,69 @@ +package eu.eudat.model.builder.descriptionpropertiesdefinition; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.types.description.PropertyDefinitionEntity; +import eu.eudat.commons.types.description.PropertyDefinitionFieldSetItemEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.DescriptionTemplate; +import eu.eudat.model.builder.BaseBuilder; +import eu.eudat.model.descriptionproperties.PropertyDefinition; +import eu.eudat.model.descriptionproperties.PropertyDefinitionFieldSetItem; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component("description.PropertyDefinitionFieldSetItemBuilder") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class PropertyDefinitionFieldSetItemBuilder extends BaseBuilder { + + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public PropertyDefinitionFieldSetItemBuilder( + ConventionService conventionService, BuilderFactory builderFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(PropertyDefinitionFieldSetItemBuilder.class))); + this.builderFactory = builderFactory; + } + + public PropertyDefinitionFieldSetItemBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (fields == null || data == null || fields.isEmpty()) + return new ArrayList<>(); + + //Not Bulk Build because is XML no interaction with db + FieldSet fieldsFields = fields.extractPrefixed(this.asPrefix(PropertyDefinitionFieldSetItem._fields)); + + List models = new ArrayList<>(); + for (PropertyDefinitionFieldSetItemEntity d : data) { + PropertyDefinitionFieldSetItem m = new PropertyDefinitionFieldSetItem(); + if (fields.hasField(this.asIndexer(PropertyDefinitionFieldSetItem._comment))) m.setComment(d.getComment()); + if (fields.hasField(this.asIndexer(PropertyDefinitionFieldSetItem._ordinal))) m.setOrdinal(d.getOrdinal()); + if (!fieldsFields.isEmpty() && d.getFields() != null && !d.getFields().isEmpty()) { + m.setFields(new HashMap<>()); + for (String key : d.getFields().keySet()){ + m.getFields().put(key, this.builderFactory.builder(FieldBuilder.class).authorize(this.authorize).build(fieldsFields, d.getFields().get(key))); + } + } + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFieldFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFieldFileTransformerBuilder.java index 7561bb6bc..4e9d4a460 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFieldFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFieldFileTransformerBuilder.java @@ -58,7 +58,9 @@ public class DescriptionFieldFileTransformerBuilder extends BaseFileTransformerB for (FieldEntity d : data) { // DescriptionFieldDepositModel m = new DescriptionFieldDepositModel(); if (definition != null){ - FieldFileTransformerModel fieldEntity = findFieldById(d.getKey()); + //TODO Update with the new logic of property definition +// FieldFileTransformerModel fieldEntity = findFieldById(d.getKey()); + FieldFileTransformerModel fieldEntity = new FieldFileTransformerModel(); if (fieldEntity != null){ //m.setSchematics(fieldEntity.getSchematics()); if (fieldEntity.getData() != null) { diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFileTransformerBuilder.java index 8eaf4380e..bfa133dfd 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFileTransformerBuilder.java @@ -93,7 +93,8 @@ public class DescriptionFileTransformerBuilder extends BaseFileTransformerBuilde if (d.getProperties() != null){ PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties()); - if (definitionMap != null && definitionMap.stream().anyMatch(dt -> dt.getId().equals(d.getDescriptionTemplateId())) && propertyDefinition != null && !this.conventionService.isListNullOrEmpty(propertyDefinition.getFields())) m.setDescriptionTemplate(this.builderFactory.builder(DescriptionFieldFileTransformerBuilder.class).authorize(this.authorize).setDefinition(definitionMap.stream().filter(dm -> dm.getId().equals(d.getDescriptionTemplateId())).findFirst().get()).build(propertyDefinition.getFields()).get(0)); + //TODO Update with the new logic of property definition +// if (definitionMap != null && definitionMap.stream().anyMatch(dt -> dt.getId().equals(d.getDescriptionTemplateId())) && propertyDefinition != null && !this.conventionService.isListNullOrEmpty(propertyDefinition.getFields())) m.setDescriptionTemplate(this.builderFactory.builder(DescriptionFieldFileTransformerBuilder.class).authorize(this.authorize).setDefinition(definitionMap.stream().filter(dm -> dm.getId().equals(d.getDescriptionTemplateId())).findFirst().get()).build(propertyDefinition.getFields()).get(0)); } if (referenceMap != null && !referenceMap.isEmpty() && referenceMap.containsKey(d.getId())) m.setDescriptionReferenceFileTransformerModels(referenceMap.get(d.getId())); if (tagMap != null && !tagMap.isEmpty() && tagMap.containsKey(d.getId())) m.setDescriptionTagFileTransformerModels(tagMap.get(d.getId())); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/FieldCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/FieldCensor.java index 1e3e9eef0..216b385b7 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/FieldCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/FieldCensor.java @@ -14,7 +14,7 @@ import org.springframework.stereotype.Component; import java.util.UUID; -@Component("descriptionpropertiesfieldcensor") +@Component("description.FieldCensor") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class FieldCensor extends BaseCensor { diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionCensor.java index 2436ebf5e..963d5d703 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionCensor.java @@ -19,7 +19,7 @@ import org.springframework.stereotype.Component; import java.util.UUID; -@Component("descriptionpropertiescensor") +@Component("description.PropertyDefinitionCensor") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class PropertyDefinitionCensor extends BaseCensor { @@ -42,8 +42,8 @@ public class PropertyDefinitionCensor extends BaseCensor { return; this.authService.authorizeForce(Permission.BrowseDescription); - FieldSet fieldFields = fields.extractPrefixed(this.asIndexerPrefix(PropertyDefinition._fields)); - this.censorFactory.censor(FieldCensor.class).censor(fieldFields, userId); + FieldSet fieldSetFields = fields.extractPrefixed(this.asIndexerPrefix(PropertyDefinition._fieldSets)); + this.censorFactory.censor(PropertyDefinitionFieldSetCensor.class).censor(fieldSetFields, userId); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionFieldSetCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionFieldSetCensor.java new file mode 100644 index 000000000..fedc16ff4 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionFieldSetCensor.java @@ -0,0 +1,47 @@ +package eu.eudat.model.censorship.descriptionproperties; + +import eu.eudat.authorization.Permission; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.censorship.BaseCensor; +import eu.eudat.model.descriptionproperties.PropertyDefinition; +import eu.eudat.model.descriptionproperties.PropertyDefinitionFieldSet; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.data.censor.CensorFactory; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component("description.PropertyDefinitionFieldSetCensor") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class PropertyDefinitionFieldSetCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PropertyDefinitionFieldSetCensor.class)); + + protected final AuthorizationService authService; + protected final CensorFactory censorFactory; + + public PropertyDefinitionFieldSetCensor(ConventionService conventionService, + AuthorizationService authService, + CensorFactory censorFactory) { + super(conventionService); + this.authService = authService; + this.censorFactory = censorFactory; + } + + public void censor(FieldSet fields, UUID userId) { + logger.debug(new DataLogEntry("censoring fields", fields)); + if (fields == null || fields.isEmpty()) + return; + + this.authService.authorizeForce(Permission.BrowseDescription); + FieldSet itemsFields = fields.extractPrefixed(this.asIndexerPrefix(PropertyDefinitionFieldSet._items)); + this.censorFactory.censor(PropertyDefinitionFieldSetItemCensor.class).censor(itemsFields, userId); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionFieldSetItemCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionFieldSetItemCensor.java new file mode 100644 index 000000000..950311c4d --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionFieldSetItemCensor.java @@ -0,0 +1,47 @@ +package eu.eudat.model.censorship.descriptionproperties; + +import eu.eudat.authorization.Permission; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.censorship.BaseCensor; +import eu.eudat.model.descriptionproperties.PropertyDefinition; +import eu.eudat.model.descriptionproperties.PropertyDefinitionFieldSetItem; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.data.censor.CensorFactory; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component("description.PropertyDefinitionFieldSetItemCensor") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class PropertyDefinitionFieldSetItemCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PropertyDefinitionFieldSetItemCensor.class)); + + protected final AuthorizationService authService; + protected final CensorFactory censorFactory; + + public PropertyDefinitionFieldSetItemCensor(ConventionService conventionService, + AuthorizationService authService, + CensorFactory censorFactory) { + super(conventionService); + this.authService = authService; + this.censorFactory = censorFactory; + } + + public void censor(FieldSet fields, UUID userId) { + logger.debug(new DataLogEntry("censoring fields", fields)); + if (fields == null || fields.isEmpty()) + return; + + this.authService.authorizeForce(Permission.BrowseDescription); + FieldSet fieldFields = fields.extractPrefixed(this.asIndexerPrefix(PropertyDefinitionFieldSetItem._fields)); + this.censorFactory.censor(FieldCensor.class).censor(fieldFields, userId); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/Field.java b/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/Field.java index d12151353..654f605fb 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/Field.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/Field.java @@ -3,20 +3,10 @@ package eu.eudat.model.descriptionproperties; public class Field { - public final static String _key = "key"; - private String key; public final static String _value = "value"; private String value; - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public String getValue() { return value; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinition.java b/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinition.java index 853a8f1c3..f23b98157 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinition.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinition.java @@ -1,17 +1,20 @@ package eu.eudat.model.descriptionproperties; + import java.util.List; +import java.util.Map; public class PropertyDefinition { - public final static String _fields = "fields"; - private List fields; + public final static String _fieldSets = "fieldSets"; - public List getFields() { - return fields; + private Map fieldSets; + + public Map getFieldSets() { + return fieldSets; } - public void setFields(List fields) { - this.fields = fields; + public void setFieldSets(Map fieldSets) { + this.fieldSets = fieldSets; } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinitionFieldSet.java b/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinitionFieldSet.java new file mode 100644 index 000000000..24a0a7bc7 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinitionFieldSet.java @@ -0,0 +1,17 @@ +package eu.eudat.model.descriptionproperties; + +import java.util.List; + +public class PropertyDefinitionFieldSet { + + public final static String _items = "items"; + private List items; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinitionFieldSetItem.java b/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinitionFieldSetItem.java new file mode 100644 index 000000000..541c269ce --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinitionFieldSetItem.java @@ -0,0 +1,41 @@ +package eu.eudat.model.descriptionproperties; + +import eu.eudat.commons.types.description.FieldEntity; + +import java.util.Map; + +public class PropertyDefinitionFieldSetItem { + + public final static String _fields = "fields"; + private Map fields; + + public final static String _comment = "comment"; + private String comment; + + public final static String _ordinal = "ordinal"; + private Integer ordinal; + + public Map getFields() { + return fields; + } + + public void setFields(Map fields) { + this.fields = fields; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public Integer getOrdinal() { + return ordinal; + } + + public void setOrdinal(Integer ordinal) { + this.ordinal = ordinal; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/FieldPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/FieldPersist.java index 098ad3b21..e95e6a584 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/FieldPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/FieldPersist.java @@ -13,22 +13,10 @@ import java.util.List; public class FieldPersist { - private String key; - - public static final String _key = "key"; - private String value; public static final String _value = "value"; - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public String getValue() { return value; } @@ -37,14 +25,14 @@ public class FieldPersist { this.value = value; } - @Component(FieldPersistValidator.ValidatorName) - public static class FieldPersistValidator extends BaseValidator { + @Component(PersistValidator.ValidatorName) + public static class PersistValidator extends BaseValidator { public static final String ValidatorName = "Description.FieldPersistValidator"; private final MessageSource messageSource; - protected FieldPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { super(conventionService, errors); this.messageSource = messageSource; } @@ -57,9 +45,6 @@ public class FieldPersist { @Override protected List specifications(FieldPersist item) { return Arrays.asList( - this.spec() - .must(() -> !this.isEmpty(item.getKey())) - .failOn(FieldPersist._key).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._key}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isEmpty(item.getValue())) .failOn(FieldPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._value}, LocaleContextHolder.getLocale())) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionFieldSetItemPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionFieldSetItemPersist.java new file mode 100644 index 000000000..98dd1f2c1 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionFieldSetItemPersist.java @@ -0,0 +1,90 @@ +package eu.eudat.model.persist.descriptionproperties; + +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; +import eu.eudat.model.persist.DescriptionPersist; +import gr.cite.tools.validation.ValidatorFactory; +import gr.cite.tools.validation.specification.Specification; +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class PropertyDefinitionFieldSetItemPersist { + + public final static String _fields = "fields"; + private Map fields; + + public final static String _comment = "comment"; + private String comment; + + public final static String _ordinal = "ordinal"; + private Integer ordinal = null; + + public Map getFields() { + return fields; + } + + public void setFields(Map fields) { + this.fields = fields; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public Integer getOrdinal() { + return ordinal; + } + + public void setOrdinal(Integer ordinal) { + this.ordinal = ordinal; + } + + @Component(PersistValidator.ValidatorName) + public static class PersistValidator extends BaseValidator { + + public static final String ValidatorName = "Description.PropertyDefinitionFieldSetItemPersistValidator"; + private final ValidatorFactory validatorFactory; + + private final MessageSource messageSource; + + protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) { + super(conventionService, errors); + this.validatorFactory = validatorFactory; + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return PropertyDefinitionFieldSetItemPersist.class; + } + + @Override + protected List specifications(PropertyDefinitionFieldSetItemPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isNull(item.getOrdinal())) + .failOn(PropertyDefinitionFieldSetItemPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionFieldSetItemPersist._ordinal}, LocaleContextHolder.getLocale())), + this.mapSpec() + .iff(() -> !this.isNull(item.getFields())) + .on(PropertyDefinitionFieldSetItemPersist._fields) + .over(item.getFields()) + .mapKey((k) -> ((String)k)) + .using((itm) -> this.validatorFactory.validator(FieldPersist.PersistValidator.class)) + + ); + } + } + +} + + diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionFieldSetPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionFieldSetPersist.java new file mode 100644 index 000000000..a2a75ec93 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionFieldSetPersist.java @@ -0,0 +1,60 @@ +package eu.eudat.model.persist.descriptionproperties; + +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; +import gr.cite.tools.validation.ValidatorFactory; +import gr.cite.tools.validation.specification.Specification; +import org.springframework.context.MessageSource; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; + +public class PropertyDefinitionFieldSetPersist { + + public final static String _items = "items"; + private List items; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + @Component(PersistValidator.ValidatorName) + public static class PersistValidator extends BaseValidator { + + public static final String ValidatorName = "Description.PropertyDefinitionFieldSetPersistValidator"; + private final ValidatorFactory validatorFactory; + + private final MessageSource messageSource; + + protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) { + super(conventionService, errors); + this.validatorFactory = validatorFactory; + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return PropertyDefinitionFieldSetPersist.class; + } + + @Override + protected List specifications(PropertyDefinitionFieldSetPersist item) { + return Arrays.asList( + this.refSpec() + .iff(() -> !this.isNull(item.getItems())) + .on(PropertyDefinitionFieldSetPersist._items) + .over(item.getItems()) + .using(() -> this.validatorFactory.validator(PropertyDefinitionFieldSetItemPersist.PersistValidator.class)) + ); + } + } + +} + + diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionPersist.java index 3baa050cf..a9c90114f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/descriptionproperties/PropertyDefinitionPersist.java @@ -15,19 +15,20 @@ import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; +import java.util.Map; public class PropertyDefinitionPersist { - private List fields; + public final static String _fieldSets = "fieldSets"; - public static final String _fields = "fields"; + private Map fieldSets; - public List getFields() { - return fields; + public Map getFieldSets() { + return fieldSets; } - public void setFields(List fields) { - this.fields = fields; + public void setFieldSets(Map fieldSets) { + this.fieldSets = fieldSets; } @Component(PropertyDefinitionPersistValidator.ValidatorName) @@ -58,13 +59,15 @@ public class PropertyDefinitionPersist { return Arrays.asList( this.spec() .iff(() -> this.status == DescriptionStatus.Finalized) - .must(() -> !this.isListNullOrEmpty(item.getFields())) - .failOn(PropertyDefinitionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fields}, LocaleContextHolder.getLocale())), - this.navSpec() - .iff(() -> !this.isListNullOrEmpty(item.getFields())) - .on(PropertyDefinitionPersist._fields) - .over(item.getFields()) - .using((itm) -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class)) + .must(() -> !this.isNull(item.getFieldSets()) && !item.getFieldSets().isEmpty()) + .failOn(PropertyDefinitionPersist._fieldSets).failWith(messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fieldSets}, LocaleContextHolder.getLocale())), + + this.mapSpec() + .iff(() -> !this.isNull(item.getFieldSets())) + .on(PropertyDefinitionPersist._fieldSets) + .over(item.getFieldSets()) + .mapKey((k) -> ((String)k)) + .using((itm) -> this.validatorFactory.validator(PropertyDefinitionFieldSetPersist.PersistValidator.class)) ); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java index 9e2351c22..69c295b06 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java @@ -12,6 +12,8 @@ import eu.eudat.commons.enums.notification.NotificationContactType; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.types.description.FieldEntity; import eu.eudat.commons.types.description.PropertyDefinitionEntity; +import eu.eudat.commons.types.description.PropertyDefinitionFieldSetEntity; +import eu.eudat.commons.types.description.PropertyDefinitionFieldSetItemEntity; import eu.eudat.commons.types.notification.*; import eu.eudat.commons.types.reference.DefinitionEntity; import eu.eudat.configurations.notification.NotificationProperties; @@ -33,6 +35,8 @@ import eu.eudat.model.persist.DescriptionReferencePersist; import eu.eudat.model.persist.DescriptionStatusPersist; import eu.eudat.model.persist.ReferencePersist; import eu.eudat.model.persist.descriptionproperties.FieldPersist; +import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionFieldSetItemPersist; +import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionFieldSetPersist; import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist; import eu.eudat.model.persist.referencedefinition.DefinitionPersist; import eu.eudat.query.*; @@ -356,20 +360,43 @@ public class DescriptionServiceImpl implements DescriptionService { private @NotNull PropertyDefinitionEntity buildPropertyDefinitionEntity(PropertyDefinitionPersist persist){ PropertyDefinitionEntity data = new PropertyDefinitionEntity(); if (persist == null) return data; - if (!this.conventionService.isListNullOrEmpty(persist.getFields())){ - data.setFields(new ArrayList<>()); - for (FieldPersist sectionPersist: persist.getFields()) { - data.getFields().add(this.buildFieldEntity(sectionPersist)); + if (persist.getFieldSets() != null && !persist.getFieldSets().isEmpty()){ + data.setFieldSets(new HashMap<>()); + for (String key: persist.getFieldSets().keySet()) { + data.getFieldSets().put(key, this.buildPropertyDefinitionFieldSetEntity(persist.getFieldSets().get(key))); } } return data; } + private @NotNull PropertyDefinitionFieldSetEntity buildPropertyDefinitionFieldSetEntity(PropertyDefinitionFieldSetPersist persist){ + PropertyDefinitionFieldSetEntity data = new PropertyDefinitionFieldSetEntity(); + if (persist == null) return data; + if (!this.conventionService.isListNullOrEmpty(persist.getItems())){ + data.setItems(new ArrayList<>()); + for (PropertyDefinitionFieldSetItemPersist sectionPersist: persist.getItems()) { + data.getItems().add(this.buildPropertyDefinitionFieldSetItemEntity(sectionPersist)); + } + } + return data; + } + + private @NotNull PropertyDefinitionFieldSetItemEntity buildPropertyDefinitionFieldSetItemEntity(PropertyDefinitionFieldSetItemPersist persist){ + PropertyDefinitionFieldSetItemEntity data = new PropertyDefinitionFieldSetItemEntity(); + if (persist == null) return data; + if (persist.getFields() != null && !persist.getFields().isEmpty()){ + data.setFields(new HashMap<>()); + for (String key: persist.getFields().keySet()) { + data.getFields().put(key, this.buildFieldEntity(persist.getFields().get(key))); + } + } + return data; + } + private @NotNull FieldEntity buildFieldEntity(FieldPersist persist){ FieldEntity data = new FieldEntity(); if (persist == null) return data; - data.setKey(persist.getKey()); data.setValue(persist.getValue()); return data; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/prefilling/PrefillingServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/prefilling/PrefillingServiceImpl.java index 6f98fc74e..82429be9c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/prefilling/PrefillingServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/prefilling/PrefillingServiceImpl.java @@ -7,6 +7,7 @@ import eu.eudat.commons.JsonHandlingService; import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.enums.FieldType; import eu.eudat.commons.types.descriptiontemplate.FieldEntity; +import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.ExternalSelectDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.SelectDataEntity; @@ -20,6 +21,8 @@ import eu.eudat.model.builder.PrefillingBuilder; import eu.eudat.model.builder.ReferenceBuilder; import eu.eudat.model.descriptionproperties.Field; import eu.eudat.model.descriptionproperties.PropertyDefinition; +import eu.eudat.model.descriptionproperties.PropertyDefinitionFieldSet; +import eu.eudat.model.descriptionproperties.PropertyDefinitionFieldSetItem; import eu.eudat.model.persist.DescriptionProfilingRequest; import eu.eudat.model.persist.DescriptionProfilingWithDataRequest; import eu.eudat.query.ReferenceQuery; @@ -219,15 +222,19 @@ public class PrefillingServiceImpl implements PrefillingService { List issuedFieldEntities = definition.getAllField().stream().filter(x-> x.getSchematics() != null && x.getSchematics().contains("rda.dataset.issued")).toList(); if(this.conventionService.isListNullOrEmpty(issuedFieldEntities)){ String issuedIdNode = issuedFieldEntities.getFirst().getId(); - String issuedValue = description.getProperties().getFields().stream().filter(x-> x.getKey().equals(issuedIdNode)).map(Field::getValue).findFirst().orElse(null);//TODO - List licStartEntities = definition.getAllField().stream().filter(x-> x.getSchematics() != null && x.getSchematics().contains("rda.dataset.distribution.license.start_date")).toList(); - if(this.conventionService.isListNullOrEmpty(licStartEntities)) { - for (FieldEntity licStartDateNode : licStartEntities) { - String licStartDateId = licStartDateNode.getId(); - Field field = new Field(); - field.setKey(licStartDateId); - field.setValue(issuedValue); - description.getProperties().getFields().add(field); + String issuedValue = description.getProperties().getFieldSets().values().stream().map(PropertyDefinitionFieldSet::getItems).flatMap(List::stream) + .filter(x-> x.getFields() != null && x.getFields().containsKey(issuedIdNode)).map(x-> x.getFields().get(issuedIdNode).getValue()).findFirst().orElse(null);//TODO + + + List licStartFieldSetsEntities = definition.getAllFieldSets().stream().filter(x-> x.getAllField() != null && x.getAllField().stream().anyMatch(y-> y.getSchematics() != null && y.getSchematics().contains("rda.dataset.distribution.license.start_date"))).toList(); + for (FieldSetEntity licStartFieldSetEntity: licStartFieldSetsEntities) { + List licStartEntities = licStartFieldSetEntity.getAllField().stream().filter(x -> x.getSchematics() != null && x.getSchematics().contains("rda.dataset.distribution.license.start_date")).toList(); + if (!this.conventionService.isListNullOrEmpty(licStartEntities)) { + this.ensureFieldSetEntity(description, licStartFieldSetEntity); + + for (FieldEntity licStartDateNode : licStartEntities) { + description.getProperties().getFieldSets().get(licStartFieldSetEntity.getId()).getItems().add(buildPropertyDefinitionFieldSetItemValue(licStartDateNode, issuedValue, parsedValues, type)); + } } } } @@ -242,15 +249,25 @@ public class PrefillingServiceImpl implements PrefillingService { } } - List fieldEntities = definition.getAllField().stream().filter(x-> x.getSchematics() != null && x.getSchematics().contains(prefillingMapping.getSemanticTarget())).toList(); - for (FieldEntity fieldEntity: fieldEntities) { - if (description.getProperties() == null) description.setProperties(new PropertyDefinition()); - if (description.getProperties().getFields() == null) description.getProperties().setFields(new ArrayList<>()); - - description.getProperties().getFields().add(buildFieldValue(fieldEntity, parsedValue, parsedValues, type)); + List fieldSetsEntities = definition.getAllFieldSets().stream().filter(x-> x.getAllField() != null && x.getAllField().stream().anyMatch(y-> y.getSchematics() != null && y.getSchematics().contains(prefillingMapping.getSemanticTarget()))).toList(); + for (FieldSetEntity fieldSetEntity: fieldSetsEntities) { + List fieldEntities = fieldSetEntity.getAllField().stream().filter(x-> x.getSchematics() != null && x.getSchematics().contains(prefillingMapping.getSemanticTarget())).toList(); + if (!this.conventionService.isListNullOrEmpty(fieldEntities)) { + this.ensureFieldSetEntity(description, fieldSetEntity); + + for (FieldEntity fieldEntity : fieldEntities){ + description.getProperties().getFieldSets().get(fieldSetEntity.getId()).getItems().add(buildPropertyDefinitionFieldSetItemValue(fieldEntity, parsedValue, parsedValues, type)); + } + } } } } + private void ensureFieldSetEntity(Description description, FieldSetEntity fieldSetEntity){ + if (description.getProperties() == null) description.setProperties(new PropertyDefinition()); + if (description.getProperties().getFieldSets() == null) description.getProperties().setFieldSets(new HashMap<>()); + if (!description.getProperties().getFieldSets().containsKey(fieldSetEntity.getId())) description.getProperties().getFieldSets().put(fieldSetEntity.getId(), new PropertyDefinitionFieldSet()); + if (description.getProperties().getFieldSets().get(fieldSetEntity.getId()).getItems() == null) description.getProperties().getFieldSets().get(fieldSetEntity.getId()).setItems(new ArrayList<>()); + } private void applyValueToDescriptionObject(Description description, PrefillingMapping prefillingMapping, String parsedValue, List parsedValues){ switch (prefillingMapping.getTarget()){ @@ -277,10 +294,11 @@ public class PrefillingServiceImpl implements PrefillingService { } } - private Field buildFieldValue(FieldEntity fieldEntity, String parsedValue, List parsedValues, String type){ + private PropertyDefinitionFieldSetItem buildPropertyDefinitionFieldSetItemValue(FieldEntity fieldEntity, String parsedValue, List parsedValues, String type){ String id = fieldEntity.getId(); + PropertyDefinitionFieldSetItem fieldSetItem = new PropertyDefinitionFieldSetItem(); + fieldSetItem.setFields(new HashMap<>()); Field field = new Field(); - field.setKey(id); switch (fieldEntity.getData().getFieldType()) { case EXTERNAL_SELECT: case SELECT: { @@ -323,7 +341,8 @@ public class PrefillingServiceImpl implements PrefillingService { field.setValue(parsedValue); break; } - return field; + fieldSetItem.getFields().put(fieldEntity.getId(), field); + return fieldSetItem; } private List getValueAsStringArray(PrefillingMapping prefillingMapping, Object value){