update description properties json format

This commit is contained in:
Efstratios Giannopoulos 2024-02-01 16:40:11 +02:00
parent 1fc4e8add5
commit 46c19f61a1
30 changed files with 641 additions and 103 deletions

View File

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

View File

@ -1,15 +1,18 @@
package eu.eudat.commons.types.description;
import java.util.List;
import java.util.Map;
public class PropertyDefinitionEntity {
private List<FieldEntity> fields;
private Map<String, PropertyDefinitionFieldSetEntity> fieldSets;
public List<FieldEntity> getFields() {
return fields;
public Map<String, PropertyDefinitionFieldSetEntity> getFieldSets() {
return fieldSets;
}
public void setFields(List<FieldEntity> fields) {
this.fields = fields;
public void setFieldSets(Map<String, PropertyDefinitionFieldSetEntity> fieldSets) {
this.fieldSets = fieldSets;
}
}

View File

@ -0,0 +1,15 @@
package eu.eudat.commons.types.description;
import java.util.List;
public class PropertyDefinitionFieldSetEntity {
private List<PropertyDefinitionFieldSetItemEntity> items;
public List<PropertyDefinitionFieldSetItemEntity> getItems() {
return items;
}
public void setItems(List<PropertyDefinitionFieldSetItemEntity> items) {
this.items = items;
}
}

View File

@ -0,0 +1,33 @@
package eu.eudat.commons.types.description;
import java.util.Map;
public class PropertyDefinitionFieldSetItemEntity {
private Map<String, FieldEntity> fields;
private String comment;
private int ordinal;
public Map<String, FieldEntity> getFields() {
return fields;
}
public void setFields(Map<String, FieldEntity> 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;
}
}

View File

@ -30,6 +30,15 @@ public class DefinitionEntity {
return fieldEntities;
}
public List<FieldSetEntity> getAllFieldSets(){
List<FieldSetEntity> fieldSetsEntities = new ArrayList<>();
if (this.getPages() != null){
for (PageEntity sectionEntity: this.getPages()) {
fieldSetsEntities.addAll(sectionEntity.getAllFieldSets());
}
}
return fieldSetsEntities;
}
public List<FieldEntity> getFieldById(String id) {
return this.getAllField().stream().filter(x-> id.equals(x.getId())).toList();
}

View File

@ -62,4 +62,14 @@ public class PageEntity implements DatabaseViewStyleDefinition {
}
return fieldEntities;
}
public List<FieldSetEntity> getAllFieldSets(){
List<FieldSetEntity> fieldSetsEntities = new ArrayList<>();
if (this.getSections() != null){
for (SectionEntity sectionEntity: this.getSections()) {
fieldSetsEntities.addAll(sectionEntity.getAllFieldSets());
}
}
return fieldSetsEntities;
}
}

View File

@ -126,4 +126,17 @@ public class SectionEntity implements DatabaseViewStyleDefinition{
}
return fieldEntities;
}
public List<FieldSetEntity> getAllFieldSets(){
List<FieldSetEntity> 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;
}
}

View File

@ -71,8 +71,9 @@ public class DescriptionDepositBuilder extends BaseDepositBuilder<DescriptionDep
m.setLabel(d.getLabel());
m.setDescription(d.getDescription());
if (d.getProperties() != null){
PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties());
if (definitionMap != null && definitionMap.containsKey(d.getDescriptionTemplateId()) && propertyDefinition != null && !this.conventionService.isListNullOrEmpty(propertyDefinition.getFields())) m.setFields(this.builderFactory.builder(DescriptionFieldDepositBuilder.class).authorize(this.authorize).setDefinition(definitionMap.get(d.getDescriptionTemplateId())).build(propertyDefinition.getFields()));
//TODO Update with the new logic of property definition
// PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties());
// if (definitionMap != null && definitionMap.containsKey(d.getDescriptionTemplateId()) && propertyDefinition != null && !this.conventionService.isListNullOrEmpty(propertyDefinition.getFields())) m.setFields(this.builderFactory.builder(DescriptionFieldDepositBuilder.class).authorize(this.authorize).setDefinition(definitionMap.get(d.getDescriptionTemplateId())).build(propertyDefinition.getFields()));
}
models.add(new DepositBuilderItemResponse<>(m, d));
}

View File

@ -58,7 +58,10 @@ public class DescriptionFieldDepositBuilder extends BaseDepositBuilder<Descripti
for (FieldEntity d : data) {
DescriptionFieldDepositModel m = new DescriptionFieldDepositModel();
if (definition != null){
List<eu.eudat.commons.types.descriptiontemplate.FieldEntity> fieldEntities = definition.getFieldById(d.getKey());
//TODO Update with the new logic of property definition
//List<eu.eudat.commons.types.descriptiontemplate.FieldEntity> fieldEntities = definition.getFieldById(d.getKey());
List<eu.eudat.commons.types.descriptiontemplate.FieldEntity> fieldEntities = new ArrayList<>();
if (!this.conventionService.isListNullOrEmpty(fieldEntities)){
eu.eudat.commons.types.descriptiontemplate.FieldEntity field = fieldEntities.getFirst();
m.setSchematics(field.getSchematics());

View File

@ -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<Field, FieldEntity> {
private final BuilderFactory builderFactory;
private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider;
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
@ -51,7 +47,6 @@ public class FieldBuilder extends BaseBuilder<Field, FieldEntity> {
List<Field> 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);

View File

@ -47,12 +47,17 @@ public class PropertyDefinitionBuilder extends BaseBuilder<PropertyDefinition, P
return new ArrayList<>();
//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<PropertyDefinition> 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));

View File

@ -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<PropertyDefinitionFieldSet, PropertyDefinitionFieldSetEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<PropertyDefinitionFieldSet> build(FieldSet fields, List<PropertyDefinitionFieldSetEntity> 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<PropertyDefinitionFieldSet> 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;
}
}

View File

@ -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<PropertyDefinitionFieldSetItem, PropertyDefinitionFieldSetItemEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<PropertyDefinitionFieldSetItem> build(FieldSet fields, List<PropertyDefinitionFieldSetItemEntity> 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<PropertyDefinitionFieldSetItem> 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;
}
}

View File

@ -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) {

View File

@ -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()));

View File

@ -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 {

View File

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

View File

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

View File

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

View File

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

View File

@ -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<Field> fields;
public final static String _fieldSets = "fieldSets";
public List<Field> getFields() {
return fields;
private Map<String, PropertyDefinitionFieldSet> fieldSets;
public Map<String, PropertyDefinitionFieldSet> getFieldSets() {
return fieldSets;
}
public void setFields(List<Field> fields) {
this.fields = fields;
public void setFieldSets(Map<String, PropertyDefinitionFieldSet> fieldSets) {
this.fieldSets = fieldSets;
}
}

View File

@ -0,0 +1,17 @@
package eu.eudat.model.descriptionproperties;
import java.util.List;
public class PropertyDefinitionFieldSet {
public final static String _items = "items";
private List<PropertyDefinitionFieldSetItem> items;
public List<PropertyDefinitionFieldSetItem> getItems() {
return items;
}
public void setItems(List<PropertyDefinitionFieldSetItem> items) {
this.items = items;
}
}

View File

@ -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<String, Field> fields;
public final static String _comment = "comment";
private String comment;
public final static String _ordinal = "ordinal";
private Integer ordinal;
public Map<String, Field> getFields() {
return fields;
}
public void setFields(Map<String, Field> 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;
}
}

View File

@ -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<FieldPersist> {
@Component(PersistValidator.ValidatorName)
public static class PersistValidator extends BaseValidator<FieldPersist> {
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<Specification> 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()))

View File

@ -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<String, FieldPersist> fields;
public final static String _comment = "comment";
private String comment;
public final static String _ordinal = "ordinal";
private Integer ordinal = null;
public Map<String, FieldPersist> getFields() {
return fields;
}
public void setFields(Map<String, FieldPersist> 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<PropertyDefinitionFieldSetItemPersist> {
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<PropertyDefinitionFieldSetItemPersist> modelClass() {
return PropertyDefinitionFieldSetItemPersist.class;
}
@Override
protected List<Specification> 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))
);
}
}
}

View File

@ -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<PropertyDefinitionFieldSetItemPersist> items;
public List<PropertyDefinitionFieldSetItemPersist> getItems() {
return items;
}
public void setItems(List<PropertyDefinitionFieldSetItemPersist> items) {
this.items = items;
}
@Component(PersistValidator.ValidatorName)
public static class PersistValidator extends BaseValidator<PropertyDefinitionFieldSetPersist> {
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<PropertyDefinitionFieldSetPersist> modelClass() {
return PropertyDefinitionFieldSetPersist.class;
}
@Override
protected List<Specification> 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))
);
}
}
}

View File

@ -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<FieldPersist> fields;
public final static String _fieldSets = "fieldSets";
public static final String _fields = "fields";
private Map<String, PropertyDefinitionFieldSetPersist> fieldSets;
public List<FieldPersist> getFields() {
return fields;
public Map<String, PropertyDefinitionFieldSetPersist> getFieldSets() {
return fieldSets;
}
public void setFields(List<FieldPersist> fields) {
this.fields = fields;
public void setFieldSets(Map<String, PropertyDefinitionFieldSetPersist> 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))
);
}

View File

@ -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,10 +360,34 @@ 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;
@ -369,7 +397,6 @@ public class DescriptionServiceImpl implements DescriptionService {
FieldEntity data = new FieldEntity();
if (persist == null) return data;
data.setKey(persist.getKey());
data.setValue(persist.getValue());
return data;
}

View File

@ -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<FieldEntity> 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<FieldEntity> 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<FieldSetEntity> 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<FieldEntity> 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<FieldEntity> 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<>());
List<FieldSetEntity> 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<FieldEntity> fieldEntities = fieldSetEntity.getAllField().stream().filter(x-> x.getSchematics() != null && x.getSchematics().contains(prefillingMapping.getSemanticTarget())).toList();
if (!this.conventionService.isListNullOrEmpty(fieldEntities)) {
this.ensureFieldSetEntity(description, fieldSetEntity);
description.getProperties().getFields().add(buildFieldValue(fieldEntity, parsedValue, parsedValues, type));
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<String> parsedValues){
switch (prefillingMapping.getTarget()){
@ -277,10 +294,11 @@ public class PrefillingServiceImpl implements PrefillingService {
}
}
private Field buildFieldValue(FieldEntity fieldEntity, String parsedValue, List<String> parsedValues, String type){
private PropertyDefinitionFieldSetItem buildPropertyDefinitionFieldSetItemValue(FieldEntity fieldEntity, String parsedValue, List<String> 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<String> getValueAsStringArray(PrefillingMapping prefillingMapping, Object value){