change description properties definition

This commit is contained in:
Efstratios Giannopoulos 2024-02-06 12:27:47 +02:00
parent fc756a1780
commit fd974d3ee4
38 changed files with 1075 additions and 283 deletions

View File

@ -32,7 +32,7 @@
<dependency>
<groupId>gr.cite</groupId>
<artifactId>validation</artifactId>
<version>3.0.2</version>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>gr.cite</groupId>

View File

@ -81,4 +81,34 @@ public enum FieldType implements DatabaseEnum<String> {
public static FieldType of(String i) {
return map.get(i);
}
public static boolean isNotImplemented(FieldType fieldType){
return fieldType.equals(FieldType.EXTERNAL_SELECT) || fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_RESEARCHERS) || fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DMPS) ||
fieldType.equals(FieldType.INTERNAL_DMP_ENTRIES_DATASETS);
}
public static boolean isReferenceType(FieldType fieldType){
return fieldType.equals(FieldType.ORGANIZATIONS) || fieldType.equals(FieldType.RESEARCHERS) || fieldType.equals(FieldType.SERVICES) ||
fieldType.equals(FieldType.REGISTRIES) || fieldType.equals(FieldType.PUBLICATIONS) || fieldType.equals(FieldType.TAXONOMIES)||
fieldType.equals(FieldType.LICENSES) || fieldType.equals(FieldType.DATA_REPOSITORIES) || fieldType.equals(FieldType.PUB_REPOSITORIES)||
fieldType.equals(FieldType.JOURNAL_REPOSITORIES) || fieldType.equals(FieldType.EXTERNAL_DATASETS);
}
public static boolean isTextType(FieldType fieldType){
return fieldType.equals(FieldType.FREE_TEXT) || fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.TEXT_AREA) ||
fieldType.equals(FieldType.RICH_TEXT_AREA) || fieldType.equals(FieldType.UPLOAD) || fieldType.equals(FieldType.BOOLEAN_DECISION) ||
fieldType.equals(FieldType.RADIO_BOX) || fieldType.equals(FieldType.CURRENCY);
}
public static boolean isTextListType(FieldType fieldType){
return fieldType.equals(FieldType.SELECT) || fieldType.equals(FieldType.TAGS);
}
public static boolean isDateType(FieldType fieldType){
return fieldType.equals(FieldType.DATE_PICKER);
}
public static boolean isExternalIdentifierType(FieldType fieldType){
return fieldType.equals(FieldType.VALIDATION) || fieldType.equals(FieldType.DATASET_IDENTIFIER) ;
}
}

View File

@ -0,0 +1,25 @@
package eu.eudat.commons.types.description;
public class ExternalIdentifierEntity {
private String identifier;
private String type;
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

View File

@ -1,13 +1,44 @@
package eu.eudat.commons.types.description;
public class FieldEntity {
private String value;
public String getValue() {
return value;
import java.time.Instant;
import java.util.List;
public class FieldEntity {
private String textValue;
private List<String> textListValue;
private Instant dateValue;
private ExternalIdentifierEntity externalIdentifier;
public String getTextValue() {
return textValue;
}
public void setValue(String value) {
this.value = value;
public void setTextValue(String textValue) {
this.textValue = textValue;
}
public List<String> getTextListValue() {
return textListValue;
}
public void setTextListValue(List<String> textListValue) {
this.textListValue = textListValue;
}
public Instant getDateValue() {
return dateValue;
}
public void setDateValue(Instant dateValue) {
this.dateValue = dateValue;
}
public ExternalIdentifierEntity getExternalIdentifier() {
return externalIdentifier;
}
public void setExternalIdentifier(ExternalIdentifierEntity externalIdentifier) {
this.externalIdentifier = externalIdentifier;
}
}

View File

@ -0,0 +1,15 @@
package eu.eudat.commons.types.descriptionreference;
import java.util.UUID;
public class DescriptionReferenceDataEntity {
private String fieldId;
public String getFieldId() {
return fieldId;
}
public void setFieldId(String fieldId) {
this.fieldId = fieldId;
}
}

View File

@ -39,6 +39,11 @@ public class DefinitionEntity {
}
return fieldSetsEntities;
}
public List<FieldSetEntity> getFieldSetById(String id) {
return this.getAllFieldSets().stream().filter(x-> id.equals(x.getId())).toList();
}
public List<FieldEntity> getFieldById(String id) {
return this.getAllField().stream().filter(x-> id.equals(x.getId())).toList();
}

View File

@ -104,4 +104,8 @@ public class FieldSetEntity {
public List<FieldEntity> getAllField() {
return this.getFields() == null ? new ArrayList<>() : this.getFields();
}
public List<FieldEntity> getFieldById(String id) {
return this.getAllField().stream().filter(x-> id.equals(x.getId())).toList();
}
}

View File

@ -49,6 +49,20 @@ public abstract class BaseValidator<T> extends AbstractValidator<T> {
return value == null;
}
protected boolean isBoolean(String value) {
return value != null && Arrays.stream(new String[]{"true", "false"})
.anyMatch(b -> b.equalsIgnoreCase(value));
}
protected boolean isUUID(String value) {
try {
UUID.fromString(value);
return true;
} catch (Exception e){
return false;
}
}
protected Boolean isNull(Collection<?> value) {
return value == null;
}

View File

@ -1,6 +1,8 @@
package eu.eudat.model;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.model.descriptionreference.DescriptionReferenceData;
import eu.eudat.model.dmpreference.DmpReferenceData;
import java.time.Instant;
import java.util.UUID;
@ -35,6 +37,9 @@ public class DescriptionReference {
public static final String _hash = "hash";
private DescriptionReferenceData data;
public static final String _data = "data";
public UUID getId() {
return id;
}
@ -83,6 +88,14 @@ public class DescriptionReference {
this.isActive = isActive;
}
public DescriptionReferenceData getData() {
return data;
}
public void setData(DescriptionReferenceData data) {
this.data = data;
}
public String getHash() {
return hash;
}

View File

@ -2,9 +2,12 @@ package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.types.description.PropertyDefinitionEntity;
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.UserRoleEntity;
import eu.eudat.model.*;
import eu.eudat.model.builder.descriptionpropertiesdefinition.PropertyDefinitionBuilder;
@ -33,18 +36,20 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
private final BuilderFactory builderFactory;
private final JsonHandlingService jsonHandlingService;
private final XmlHandlingService xmlHandlingService;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DescriptionBuilder(
ConventionService conventionService,
QueryFactory queryFactory,
BuilderFactory builderFactory, JsonHandlingService jsonHandlingService) {
ConventionService conventionService,
QueryFactory queryFactory,
BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionBuilder.class)));
this.queryFactory = queryFactory;
this.builderFactory = builderFactory;
this.jsonHandlingService = jsonHandlingService;
this.xmlHandlingService = xmlHandlingService;
}
public DescriptionBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -78,6 +83,9 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data);
FieldSet definitionPropertiesFields = fields.extractPrefixed(this.asPrefix(Description._properties));
Map<UUID, DefinitionEntity> definitionEntityMap = !definitionPropertiesFields.isEmpty() ? this.collectDescriptionTemplateDefinitions(data) : null;
List<Description> models = new ArrayList<>();
for (DescriptionEntity d : data) {
Description m = new Description();
@ -98,7 +106,7 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getCreatedById())) m.setCreatedBy(userItemsMap.get(d.getCreatedById()));
if (!definitionPropertiesFields.isEmpty() && d.getProperties() != null){
PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties());
m.setProperties(this.builderFactory.builder(PropertyDefinitionBuilder.class).authorize(this.authorize).build(definitionPropertiesFields, propertyDefinition));
m.setProperties(this.builderFactory.builder(PropertyDefinitionBuilder.class).withDefinition(definitionEntityMap != null ? definitionEntityMap.getOrDefault(d.getDescriptionTemplateId(), null) : null).authorize(this.authorize).build(definitionPropertiesFields, propertyDefinition));
}
models.add(m);
}
@ -198,6 +206,22 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
return itemMap;
}
private Map<UUID, DefinitionEntity> collectDescriptionTemplateDefinitions(List<DescriptionEntity> data) throws MyApplicationException {
if (data.isEmpty())
return null;
this.logger.debug("checking related - {}", DefinitionEntity.class.getSimpleName());
Map<java.util.UUID, DefinitionEntity> itemMap = new HashMap<>();
DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
List<DescriptionTemplateEntity> items = q.collectAs(new BaseFieldSet().ensure(eu.eudat.model.DescriptionTemplate._id).ensure(DescriptionTemplate._definition));
for (DescriptionTemplateEntity item : items){
DefinitionEntity definition =this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, item.getDefinition());
itemMap.put(item.getId(), definition);
}
return itemMap;
}
private Map<UUID, Dmp> collectDmps(FieldSet fields, List<DescriptionEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;

View File

@ -1,11 +1,17 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.types.descriptionreference.DescriptionReferenceDataEntity;
import eu.eudat.commons.types.dmpreference.DmpReferenceDataEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionReferenceEntity;
import eu.eudat.model.Description;
import eu.eudat.model.DescriptionReference;
import eu.eudat.model.DmpReference;
import eu.eudat.model.Reference;
import eu.eudat.model.builder.descriptionreference.DescriptionReferenceDataBuilder;
import eu.eudat.model.builder.dmpreference.DmpReferenceDataBuilder;
import eu.eudat.query.DescriptionQuery;
import eu.eudat.query.ReferenceQuery;
import gr.cite.tools.data.builder.BuilderFactory;
@ -33,14 +39,16 @@ public class DescriptionReferenceBuilder extends BaseBuilder<DescriptionReferenc
private final QueryFactory queryFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final JsonHandlingService jsonHandlingService;
@Autowired
public DescriptionReferenceBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory) {
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory, JsonHandlingService jsonHandlingService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionReferenceBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
this.jsonHandlingService = jsonHandlingService;
}
public DescriptionReferenceBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -61,8 +69,9 @@ public class DescriptionReferenceBuilder extends BaseBuilder<DescriptionReferenc
FieldSet descriptionFields = fields.extractPrefixed(this.asPrefix(DescriptionReference._description));
Map<UUID, Description> descriptionItemsMap = this.collectDescriptions(descriptionFields, data);
List<DescriptionReference> models = new ArrayList<>();
FieldSet dataFields = fields.extractPrefixed(this.asPrefix(DescriptionReference._data));
List<DescriptionReference> models = new ArrayList<>();
for (DescriptionReferenceEntity d : data) {
DescriptionReference m = new DescriptionReference();
if (fields.hasField(this.asIndexer(DescriptionReference._id))) m.setId(d.getId());
@ -72,7 +81,10 @@ public class DescriptionReferenceBuilder extends BaseBuilder<DescriptionReferenc
if (fields.hasField(this.asIndexer(DescriptionReference._isActive))) m.setIsActive(d.getIsActive());
if (!referenceFields.isEmpty() && referenceItemsMap != null && referenceItemsMap.containsKey(d.getReferenceId())) m.setReference(referenceItemsMap.get(d.getReferenceId()));
if (!descriptionFields.isEmpty() && descriptionItemsMap != null && descriptionItemsMap.containsKey(d.getDescriptionId())) m.setDescription(descriptionItemsMap.get(d.getDescriptionId()));
if (!dataFields.isEmpty() && d.getData() != null){
DescriptionReferenceDataEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(DescriptionReferenceDataEntity.class, d.getData());
m.setData(this.builderFactory.builder(DescriptionReferenceDataBuilder.class).authorize(this.authorize).build(dataFields, propertyDefinition));
}
models.add(m);
}

View File

@ -67,11 +67,11 @@ public class DescriptionFieldDepositBuilder extends BaseDepositBuilder<Descripti
m.setSchematics(field.getSchematics());
if (field.getData() != null) {
boolean isMultiValue = fieldDataHelperServiceProvider.get(field.getData().getFieldType()).isMultiValue(field.getData());
if (!isMultiValue) m.setValues(List.of(d.getValue()));
if (!isMultiValue) m.setValues(List.of(d.getTextValue()));
else {
try {
//TODO: Find better Solution
List<Object> values = objectMapper.readValue(d.getValue(), new TypeReference<List<Object>>() {});
List<Object> values = objectMapper.readValue(d.getTextValue(), new TypeReference<List<Object>>() {});
m.setValues(values);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);

View File

@ -0,0 +1,60 @@
package eu.eudat.model.builder.descriptionpropertiesdefinition;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.description.ExternalIdentifierEntity;
import eu.eudat.commons.types.description.FieldEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.descriptionproperties.ExternalIdentifier;
import eu.eudat.model.descriptionproperties.Field;
import eu.eudat.service.fielddatahelper.FieldDataHelperServiceProvider;
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.ExternalIdentifierBuilder")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ExternalIdentifierBuilder extends BaseBuilder<ExternalIdentifier, ExternalIdentifierEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public ExternalIdentifierBuilder(
ConventionService conventionService, BuilderFactory builderFactory, FieldDataHelperServiceProvider fieldDataHelperServiceProvider) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ExternalIdentifierBuilder.class)));
}
public ExternalIdentifierBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<ExternalIdentifier> build(FieldSet fields, List<ExternalIdentifierEntity> 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<>();
List<ExternalIdentifier> models = new ArrayList<>();
for (ExternalIdentifierEntity d : data) {
ExternalIdentifier m = new ExternalIdentifier();
if (fields.hasField(this.asIndexer(ExternalIdentifier._identifier))) m.setIdentifier(d.getIdentifier());
if (fields.hasField(this.asIndexer(ExternalIdentifier._type))) m.setType(d.getType());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -1,13 +1,23 @@
package eu.eudat.model.builder.descriptionpropertiesdefinition;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.FieldType;
import eu.eudat.commons.types.description.FieldEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionReferenceEntity;
import eu.eudat.model.DescriptionReference;
import eu.eudat.model.Reference;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.builder.ReferenceBuilder;
import eu.eudat.model.descriptionproperties.Field;
import eu.eudat.model.descriptionproperties.PropertyDefinition;
import eu.eudat.model.persist.descriptionproperties.FieldPersist;
import eu.eudat.query.ReferenceQuery;
import eu.eudat.service.fielddatahelper.FieldDataHelperServiceProvider;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
@ -18,17 +28,23 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
@Component("description.FieldBuilder")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class FieldBuilder extends BaseBuilder<Field, FieldEntity> {
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity;
@Autowired
public FieldBuilder(
ConventionService conventionService, BuilderFactory builderFactory, FieldDataHelperServiceProvider fieldDataHelperServiceProvider) {
ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
}
public FieldBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -36,22 +52,71 @@ public class FieldBuilder extends BaseBuilder<Field, FieldEntity> {
return this;
}
public FieldBuilder withFieldEntity(eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity) {
this.fieldEntity = fieldEntity;
return this;
}
@Override
public List<Field> build(FieldSet fields, List<FieldEntity> 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<>();
FieldSet externalIdentifierFields = fields.extractPrefixed(this.asPrefix(Field._externalIdentifier));
FieldType fieldType = this.fieldEntity != null && this.fieldEntity.getData() != null ? this.fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT;
FieldSet referenceFields = fields.extractPrefixed(this.asPrefix(Field._references));
Map<UUID, Reference> referenceItemsMap = FieldType.isReferenceType(fieldType) ? this.collectReferences(referenceFields, data) : null;
List<Field> models = new ArrayList<>();
for (FieldEntity d : data) {
Field m = new Field();
if (fields.hasField(this.asIndexer(Field._value))) m.setValue(d.getValue());
if (fields.hasField(this.asIndexer(Field._dateValue)) && FieldType.isDateType(fieldType)) m.setDateValue(d.getDateValue());
if (fields.hasField(this.asIndexer(Field._textValue)) && FieldType.isTextType(fieldType)) m.setTextValue(d.getTextValue());
if (fields.hasField(this.asIndexer(Field._textListValue)) && FieldType.isTextListType(fieldType)) m.setTextListValue(d.getTextListValue());
if (!referenceFields.isEmpty() && FieldType.isReferenceType(fieldType) && referenceItemsMap != null && d.getTextListValue() != null && !d.getTextListValue().isEmpty()) {
m.setReferences(new ArrayList<>());
for (UUID referenceId : d.getTextListValue().stream().map(UUID::fromString).toList()){
if (referenceItemsMap.containsKey(referenceId)) m.getReferences().add(referenceItemsMap.get(referenceId));
}
}
if (!externalIdentifierFields.isEmpty() && d.getExternalIdentifier() != null && FieldType.isExternalIdentifierType(fieldType)) m.setExternalIdentifier(this.builderFactory.builder(ExternalIdentifierBuilder.class).authorize(this.authorize).build(externalIdentifierFields, d.getExternalIdentifier()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, Reference> collectReferences(FieldSet fields, List<FieldEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", Reference.class.getSimpleName());
Map<UUID, Reference> itemMap;
if (!fields.hasOtherField(this.asIndexer(Reference._id))) {
itemMap = this.asEmpty(
data.stream().map(FieldEntity::getTextListValue).flatMap(List::stream).map(UUID::fromString).distinct().collect(Collectors.toList()),
x -> {
Reference item = new Reference();
item.setId(x);
return item;
},
Reference::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Reference._id);
ReferenceQuery q = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(FieldEntity::getTextListValue).flatMap(List::stream).map(UUID::fromString).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(ReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Reference::getId);
}
if (!fields.hasField(Reference._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
}

View File

@ -3,9 +3,11 @@ package eu.eudat.model.builder.descriptionpropertiesdefinition;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.description.PropertyDefinitionEntity;
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.descriptiontemplatedefinition.Definition;
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
@ -26,6 +28,7 @@ public class PropertyDefinitionBuilder extends BaseBuilder<PropertyDefinition, P
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private DefinitionEntity definition;
@Autowired
public PropertyDefinitionBuilder(
@ -34,6 +37,11 @@ public class PropertyDefinitionBuilder extends BaseBuilder<PropertyDefinition, P
this.builderFactory = builderFactory;
}
public PropertyDefinitionBuilder withDefinition(DefinitionEntity definition) {
this.definition = definition;
return this;
}
public PropertyDefinitionBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
@ -55,7 +63,8 @@ public class PropertyDefinitionBuilder extends BaseBuilder<PropertyDefinition, P
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)));
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById(key).stream().findFirst().orElse(null) : null;
m.getFieldSets().put(key, this.builderFactory.builder(PropertyDefinitionFieldSetBuilder.class).authorize(this.authorize).withFieldSetEntity(fieldSetEntity).build(fieldsFields, d.getFieldSets().get(key)));
}
}
models.add(m);

View File

@ -2,9 +2,11 @@ package eu.eudat.model.builder.descriptionpropertiesdefinition;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.description.PropertyDefinitionFieldSetEntity;
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.descriptionproperties.PropertyDefinitionFieldSet;
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionFieldSetPersist;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
@ -24,6 +26,7 @@ public class PropertyDefinitionFieldSetBuilder extends BaseBuilder<PropertyDefin
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private FieldSetEntity fieldSetEntity;
@Autowired
public PropertyDefinitionFieldSetBuilder(
@ -37,6 +40,11 @@ public class PropertyDefinitionFieldSetBuilder extends BaseBuilder<PropertyDefin
return this;
}
public PropertyDefinitionFieldSetBuilder withFieldSetEntity(FieldSetEntity fieldSetEntity) {
this.fieldSetEntity = fieldSetEntity;
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));
@ -50,7 +58,7 @@ public class PropertyDefinitionFieldSetBuilder extends BaseBuilder<PropertyDefin
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()));
if (!itemsFields.isEmpty() && d.getItems() != null) m.setItems(this.builderFactory.builder(PropertyDefinitionFieldSetItemBuilder.class).withFieldSetEntity(this.fieldSetEntity).authorize(this.authorize).build(itemsFields, d.getItems()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));

View File

@ -3,11 +3,14 @@ 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.commons.types.descriptiontemplate.FieldEntity;
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
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 eu.eudat.model.persist.descriptionproperties.PropertyDefinitionFieldSetItemPersist;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
@ -26,6 +29,7 @@ import java.util.*;
public class PropertyDefinitionFieldSetItemBuilder extends BaseBuilder<PropertyDefinitionFieldSetItem, PropertyDefinitionFieldSetItemEntity> {
private final BuilderFactory builderFactory;
private FieldSetEntity fieldSetEntity;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
@ -40,6 +44,11 @@ public class PropertyDefinitionFieldSetItemBuilder extends BaseBuilder<PropertyD
return this;
}
public PropertyDefinitionFieldSetItemBuilder withFieldSetEntity(FieldSetEntity fieldSetEntity) {
this.fieldSetEntity = fieldSetEntity;
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));
@ -58,7 +67,8 @@ public class PropertyDefinitionFieldSetItemBuilder extends BaseBuilder<PropertyD
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)));
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getAllField().stream().findFirst().orElse(null) : null;
m.getFields().put(key, this.builderFactory.builder(FieldBuilder.class).authorize(this.authorize).withFieldEntity(fieldEntity).build(fieldsFields, d.getFields().get(key)));
}
}
models.add(m);

View File

@ -0,0 +1,55 @@
package eu.eudat.model.builder.descriptionreference;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.descriptionreference.DescriptionReferenceDataEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.descriptionreference.DescriptionReferenceData;
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("referencedescriptionreferencedatabuilder")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionReferenceDataBuilder extends BaseBuilder<DescriptionReferenceData, DescriptionReferenceDataEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DescriptionReferenceDataBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionReferenceDataBuilder.class)));
}
public DescriptionReferenceDataBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<DescriptionReferenceData> build(FieldSet fields, List<DescriptionReferenceDataEntity> 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
List<DescriptionReferenceData> models = new ArrayList<>();
for (DescriptionReferenceDataEntity d : data) {
DescriptionReferenceData m = new DescriptionReferenceData();
if (fields.hasField(this.asIndexer(DescriptionReferenceData._fieldId))) m.setFieldId(d.getFieldId());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -66,10 +66,10 @@ public class DescriptionFieldFileTransformerBuilder extends BaseFileTransformerB
if (fieldEntity.getData() != null) {
/*boolean isMultiValue = fieldDataHelperServiceProvider.get(eu.eudat.commons.enums.FieldType.of(fieldEntity.getData().getFieldType().getValue())).isMultiValue(fieldEntity.getData());
if (!isMultiValue) fieldEntity.getData().setValue(List.of(d.getValue());
else*/ {
else {
fieldEntity.getData().setValue(d.getValue());
}
*/
/*switch (field.getData().getFieldType()) {
case AUTO_COMPLETE -> m.setFieldType(FieldType.AUTO_COMPLETE);
case WORD_LIST -> m.setFieldType(FieldType.WORD_LIST);

View File

@ -3,6 +3,7 @@ package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.DescriptionReference;
import eu.eudat.model.censorship.descriptionreference.DescriptionReferenceDataCensor;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
@ -45,6 +46,8 @@ public class DescriptionReferenceCensor extends BaseCensor {
this.censorFactory.censor(DescriptionCensor.class).censor(descriptionFields, userId);
FieldSet referenceFields = fields.extractPrefixed(this.asIndexerPrefix(DescriptionReference._reference));
this.censorFactory.censor(ReferenceCensor.class).censor(referenceFields, userId);
FieldSet dataFields = fields.extractPrefixed(this.asIndexerPrefix(DescriptionReference._data));
this.censorFactory.censor(DescriptionReferenceDataCensor.class).censor(dataFields, userId);
}
}

View File

@ -0,0 +1,42 @@
package eu.eudat.model.censorship.descriptionreference;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.censorship.BaseCensor;
import gr.cite.commons.web.authz.service.AuthorizationService;
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.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionReferenceDataCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionReferenceDataCensor.class));
protected final AuthorizationService authService;
@Autowired
public DescriptionReferenceDataCensor(ConventionService conventionService,
AuthorizationService authService) {
super(conventionService);
this.authService = authService;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseDescriptionReference);
}
}

View File

@ -0,0 +1,27 @@
package eu.eudat.model.descriptionproperties;
public class ExternalIdentifier {
private String identifier;
public static final String _identifier = "identifier";
private String type;
public static final String _type = "type";
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

View File

@ -1,19 +1,67 @@
package eu.eudat.model.descriptionproperties;
import eu.eudat.commons.enums.FieldType;
import eu.eudat.model.Reference;
import java.time.Instant;
import java.util.List;
public class Field {
private String textValue;
public static final String _textValue = "textValue";
public final static String _value = "value";
private String value;
private List<String> textListValue;
public static final String _textListValue = "textListValue";
public String getValue() {
return value;
private Instant dateValue;
public static final String _dateValue = "dateValue";
private List<Reference> references;
public static final String _references = "references";
private ExternalIdentifier externalIdentifier;
public static final String _externalIdentifier = "externalIdentifier";
public String getTextValue() {
return textValue;
}
public void setValue(String value) {
this.value = value;
public void setTextValue(String textValue) {
this.textValue = textValue;
}
public List<String> getTextListValue() {
return textListValue;
}
public void setTextListValue(List<String> textListValue) {
this.textListValue = textListValue;
}
public Instant getDateValue() {
return dateValue;
}
public void setDateValue(Instant dateValue) {
this.dateValue = dateValue;
}
public List<Reference> getReferences() {
return references;
}
public void setReferences(List<Reference> references) {
this.references = references;
}
public ExternalIdentifier getExternalIdentifier() {
return externalIdentifier;
}
public void setExternalIdentifier(ExternalIdentifier externalIdentifier) {
this.externalIdentifier = externalIdentifier;
}
}

View File

@ -0,0 +1,16 @@
package eu.eudat.model.descriptionreference;
import java.util.UUID;
public class DescriptionReferenceData {
private String fieldId;
public final static String _fieldId = "fieldId";
public String getFieldId() {
return fieldId;
}
public void setFieldId(String fieldId) {
this.fieldId = fieldId;
}
}

View File

@ -1,13 +1,19 @@
package eu.eudat.model.persist;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.model.DescriptionTemplate;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
import jakarta.persistence.EntityManager;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
@ -52,9 +58,6 @@ public class DescriptionPersist {
public static final String _tags = "tags";
private List<DescriptionReferencePersist> references;
public static final String _references = "references";
private String hash;
@ -124,14 +127,6 @@ public class DescriptionPersist {
this.tags = tags;
}
public List<DescriptionReferencePersist> getReferences() {
return references;
}
public void setReferences(List<DescriptionReferencePersist> references) {
this.references = references;
}
public String getHash() {
return hash;
}
@ -157,11 +152,15 @@ public class DescriptionPersist {
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
private final EntityManager entityManager;
private final XmlHandlingService xmlHandlingService;
protected DescriptionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
protected DescriptionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory, EntityManager entityManager, XmlHandlingService xmlHandlingService) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
this.entityManager = entityManager;
this.xmlHandlingService = xmlHandlingService;
}
@Override
@ -171,6 +170,8 @@ public class DescriptionPersist {
@Override
protected List<Specification> specifications(DescriptionPersist item) {
DescriptionTemplateEntity descriptionTemplate = this.isValidGuid(item.getDescriptionTemplateId()) ? this.entityManager.find(DescriptionTemplateEntity.class, item.getDescriptionTemplateId()) : null;
DefinitionEntity definition = descriptionTemplate == null ? null : this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, descriptionTemplate.getDefinition());
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
@ -214,16 +215,7 @@ public class DescriptionPersist {
.iff(() -> !this.isNull(item.getProperties()))
.on(DescriptionPersist._properties)
.over(item.getProperties())
.using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class).setStatus(item.getStatus())),
this.spec()
.iff(() -> item.getStatus() == DescriptionStatus.Finalized)
.must(() -> !this.isListNullOrEmpty(item.getReferences()))
.failOn(DescriptionPersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._references}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getReferences()))
.on(DescriptionPersist._references)
.over(item.getReferences())
.using((itm) -> this.validatorFactory.validator(DescriptionReferencePersist.DescriptionReferencePersistValidator.class))
.using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class).setStatus(item.getStatus()).withDefinition(definition))
);
}
}

View File

@ -1,6 +1,8 @@
package eu.eudat.model.persist;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.model.persist.descriptionreference.DescriptionReferenceDataPersist;
import eu.eudat.model.persist.dmpreference.DmpReferenceDataPersist;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
@ -17,23 +19,15 @@ import java.util.UUID;
public class DescriptionReferencePersist {
private UUID id;
private ReferencePersist reference = null;
public static final String _reference = "reference";
private String hash;
public static final String _hash = "hash";
private DescriptionReferenceDataPersist data;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public static final String _data = "data";
public ReferencePersist getReference() {
return reference;
@ -43,12 +37,12 @@ public class DescriptionReferencePersist {
this.reference = reference;
}
public String getHash() {
return hash;
public DescriptionReferenceDataPersist getData() {
return data;
}
public void setHash(String hash) {
this.hash = hash;
public void setData(DescriptionReferenceDataPersist data) {
this.data = data;
}
@Component(DescriptionReferencePersistValidator.ValidatorName)
@ -75,15 +69,6 @@ public class DescriptionReferencePersist {
@Override
protected List<Specification> specifications(DescriptionReferencePersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(DescriptionReferencePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(DescriptionReferencePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getReference()))
.failOn(DescriptionReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._reference}, LocaleContextHolder.getLocale())),
@ -91,7 +76,15 @@ public class DescriptionReferencePersist {
.iff(() -> !this.isNull(item.getReference()))
.on(DescriptionReferencePersist._reference)
.over(item.getReference())
.using(() -> this.validatorFactory.validator(ReferencePersist.ReferencePersistValidator.class))
.using(() -> this.validatorFactory.validator(ReferencePersist.ReferencePersistValidator.class)),
this.spec()
.must(() -> !this.isNull(item.getData()))
.failOn(DescriptionReferencePersist._data).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferencePersist._data}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getData()))
.on(DescriptionReferencePersist._data)
.over(item.getData())
.using(() -> this.validatorFactory.validator(DmpReferenceDataPersist.DmpReferenceDataPersistValidator.class))
);
}
}

View File

@ -67,9 +67,6 @@ public class DmpReferencePersist {
@Override
protected List<Specification> specifications(DmpReferencePersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getData()))
.failOn(DmpReferencePersist._data).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpReferencePersist._data}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getReference()))
.failOn(DmpReferencePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpReferencePersist._reference}, LocaleContextHolder.getLocale())),

View File

@ -0,0 +1,68 @@
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.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;
public class ExternalIdentifierPersist {
private String identifier;
public static final String _identifier = "identifier";
private String type;
public static final String _type = "type";
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Component(PersistValidator.ValidatorName)
public static class PersistValidator extends BaseValidator<ExternalIdentifierPersist> {
public static final String ValidatorName = "Description.ExternalIdentifierPersistPersistValidator";
private final MessageSource messageSource;
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<ExternalIdentifierPersist> modelClass() {
return ExternalIdentifierPersist.class;
}
@Override
protected List<Specification> specifications(ExternalIdentifierPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getIdentifier()))
.failOn(ExternalIdentifierPersist._identifier).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalIdentifierPersist._identifier}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getType()))
.failOn(ExternalIdentifierPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ExternalIdentifierPersist._type}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -1,6 +1,11 @@
package eu.eudat.model.persist.descriptionproperties;
import eu.eudat.commons.enums.FieldType;
import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.model.descriptionproperties.Field;
import eu.eudat.model.persist.ReferencePersist;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
@ -8,33 +13,81 @@ import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class FieldPersist {
private String value;
private String textValue;
public static final String _textValue = "textValue";
public static final String _value = "value";
private List<String> textListValue;
public static final String _textListValue = "textListValue";
public String getValue() {
return value;
private Instant dateValue;
public static final String _dateValue = "dateValue";
private List<ReferencePersist> references;
public static final String _references = "references";
private ExternalIdentifierPersist externalIdentifier;
public static final String _externalIdentifier = "externalIdentifier";
public String getTextValue() {
return textValue;
}
public void setValue(String value) {
this.value = value;
public void setTextValue(String textValue) {
this.textValue = textValue;
}
public List<String> getTextListValue() {
return textListValue;
}
public void setTextListValue(List<String> textListValue) {
this.textListValue = textListValue;
}
public Instant getDateValue() {
return dateValue;
}
public void setDateValue(Instant dateValue) {
this.dateValue = dateValue;
}
public List<ReferencePersist> getReferences() {
return references;
}
public void setReferences(List<ReferencePersist> references) {
this.references = references;
}
public ExternalIdentifierPersist getExternalIdentifier() {
return externalIdentifier;
}
public void setExternalIdentifier(ExternalIdentifierPersist externalIdentifier) {
this.externalIdentifier = externalIdentifier;
}
@Component(PersistValidator.ValidatorName)
public static class PersistValidator extends BaseValidator<FieldPersist> {
public static final String ValidatorName = "Description.FieldPersistValidator";
private final ValidatorFactory validatorFactory;
private final MessageSource messageSource;
private FieldEntity fieldEntity;
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
this.messageSource = messageSource;
}
@Override
@ -44,12 +97,61 @@ public class FieldPersist {
@Override
protected List<Specification> specifications(FieldPersist item) {
return Arrays.asList(
FieldType fieldType = this.fieldEntity != null && this.fieldEntity.getData() != null ? this.fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT;
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getValue()))
.failOn(FieldPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._value}, LocaleContextHolder.getLocale()))
.iff(()-> FieldType.isNotImplemented(fieldType))
.must(() -> false)
.failOn(FieldPersist._textValue).failWith("Field Not implemented yet!!"),
this.spec()
.iff(()-> FieldType.isTextType(fieldType))
.must(() -> !this.isEmpty(item.getTextValue()))
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
this.spec()
.iff(()-> FieldType.isDateType(fieldType))
.must(() -> !this.isNull(item.getDateValue()))
.failOn(FieldPersist._dateValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._dateValue}, LocaleContextHolder.getLocale())),
this.spec()
.iff(()-> FieldType.isExternalIdentifierType(fieldType))
.must(() -> !this.isNull(item.getExternalIdentifier()))
.failOn(FieldPersist._externalIdentifier).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._externalIdentifier}, LocaleContextHolder.getLocale())),
this.spec()
.iff(()-> FieldType.isTextListType(fieldType))
.must(() -> !this.isNull(item.getTextListValue()))
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
this.spec()
.iff(()-> FieldType.isReferenceType(fieldType))
.must(() -> !this.isNull(item.getTextListValue()))
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
this.spec()
.iff(()-> !this.isEmpty(item.getTextValue()) && fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.BOOLEAN_DECISION))
.must(() -> this.isBoolean(item.getTextValue()))
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
this.spec()
.iff(()-> !this.isEmpty(item.getTextValue()) && fieldType.equals(FieldType.CURRENCY))
.must(() -> this.isUUID(item.getTextValue()))
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
this.spec()
.iff(()-> !this.isNull(item.getTextListValue()) && fieldType.equals(FieldType.TAGS))
.must(() -> item.getTextListValue().stream().allMatch(this::isUUID))
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> FieldType.isReferenceType(fieldType) && !this.isListNullOrEmpty(item.getReferences()))
.on(FieldPersist._references)
.over(item.getReferences())
.using((itm) -> this.validatorFactory.validator(ReferencePersist.ReferencePersistValidator.class)),
this.refSpec()
.iff(() -> FieldType.isExternalIdentifierType(fieldType) && !this.isNull(item.getExternalIdentifier()))
.on(FieldPersist._externalIdentifier)
.over(item.getExternalIdentifier())
.using(() -> this.validatorFactory.validator(ExternalIdentifierPersist.PersistValidator.class))
);
}
public PersistValidator withFieldEntity(FieldEntity fieldEntity) {
this.fieldEntity = fieldEntity;
return this;
}
}
}

View File

@ -1,5 +1,7 @@
package eu.eudat.model.persist.descriptionproperties;
import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
@ -56,7 +58,7 @@ public class PropertyDefinitionFieldSetItemPersist {
private final ValidatorFactory validatorFactory;
private final MessageSource messageSource;
private FieldSetEntity fieldSetEntity;
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) {
super(conventionService, errors);
this.validatorFactory = validatorFactory;
@ -79,10 +81,19 @@ public class PropertyDefinitionFieldSetItemPersist {
.on(PropertyDefinitionFieldSetItemPersist._fields)
.over(item.getFields())
.mapKey((k) -> ((String)k))
.using((itm) -> this.validatorFactory.validator(FieldPersist.PersistValidator.class))
.using((itm) ->
{
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById((String)itm.getKey()).stream().findFirst().orElse(null) : null;
return this.validatorFactory.validator(FieldPersist.PersistValidator.class).withFieldEntity(fieldEntity);
})
);
}
public PersistValidator withFieldSetEntity(FieldSetEntity fieldSetEntity) {
this.fieldSetEntity = fieldSetEntity;
return this;
}
}
}

View File

@ -1,5 +1,6 @@
package eu.eudat.model.persist.descriptionproperties;
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
@ -29,13 +30,10 @@ public class PropertyDefinitionFieldSetPersist {
public static final String ValidatorName = "Description.PropertyDefinitionFieldSetPersistValidator";
private final ValidatorFactory validatorFactory;
private final MessageSource messageSource;
private FieldSetEntity fieldSetEntity;
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) {
super(conventionService, errors);
this.validatorFactory = validatorFactory;
this.messageSource = messageSource;
}
@Override
@ -46,13 +44,18 @@ public class PropertyDefinitionFieldSetPersist {
@Override
protected List<Specification> specifications(PropertyDefinitionFieldSetPersist item) {
return Arrays.asList(
this.refSpec()
this.navSpec()
.iff(() -> !this.isNull(item.getItems()))
.on(PropertyDefinitionFieldSetPersist._items)
.over(item.getItems())
.using(() -> this.validatorFactory.validator(PropertyDefinitionFieldSetItemPersist.PersistValidator.class))
.using((itm) -> this.validatorFactory.validator(PropertyDefinitionFieldSetItemPersist.PersistValidator.class).withFieldSetEntity(this.fieldSetEntity))
);
}
public PersistValidator withFieldSetEntity(FieldSetEntity fieldSetEntity) {
this.fieldSetEntity = fieldSetEntity;
return this;
}
}
}

View File

@ -1,6 +1,8 @@
package eu.eudat.model.persist.descriptionproperties;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
@ -42,6 +44,7 @@ public class PropertyDefinitionPersist {
private final ValidatorFactory validatorFactory;
private DescriptionStatus status;
private DefinitionEntity definition;
protected PropertyDefinitionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
@ -67,7 +70,10 @@ public class PropertyDefinitionPersist {
.on(PropertyDefinitionPersist._fieldSets)
.over(item.getFieldSets())
.mapKey((k) -> ((String)k))
.using((itm) -> this.validatorFactory.validator(PropertyDefinitionFieldSetPersist.PersistValidator.class))
.using((itm) -> {
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById((String)itm.getKey()).stream().findFirst().orElse(null) : null;
return this.validatorFactory.validator(PropertyDefinitionFieldSetPersist.PersistValidator.class).withFieldSetEntity(fieldSetEntity);
})
);
}
@ -76,6 +82,11 @@ public class PropertyDefinitionPersist {
this.status = status;
return this;
}
public PropertyDefinitionPersistValidator withDefinition(DefinitionEntity definition) {
this.definition = definition;
return this;
}
}
}

View File

@ -0,0 +1,58 @@
package eu.eudat.model.persist.descriptionreference;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class DescriptionReferenceDataPersist {
private String fieldId;
public static final String _fieldId = "fieldId";
public String getFieldId() {
return fieldId;
}
public void setFieldId(String fieldId) {
this.fieldId = fieldId;
}
@Component(DescriptionReferenceDataPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DescriptionReferenceDataPersistValidator extends BaseValidator<DescriptionReferenceDataPersist> {
public static final String ValidatorName = "DescriptionReferenceDataPersistValidator";
private final MessageSource messageSource;
protected DescriptionReferenceDataPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<DescriptionReferenceDataPersist> modelClass() {
return DescriptionReferenceDataPersist.class;
}
@Override
protected List<Specification> specifications(DescriptionReferenceDataPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getFieldId()))
.failOn(DescriptionReferenceDataPersist._fieldId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionReferenceDataPersist._fieldId}, LocaleContextHolder.getLocale()))
);
}
}
}

View File

@ -4,16 +4,13 @@ import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.ContactInfoType;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.*;
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.description.*;
import eu.eudat.commons.types.descriptionreference.DescriptionReferenceDataEntity;
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
import eu.eudat.commons.types.dmpreference.DmpReferenceDataEntity;
import eu.eudat.commons.types.notification.*;
import eu.eudat.commons.types.reference.DefinitionEntity;
import eu.eudat.configurations.notification.NotificationProperties;
@ -34,10 +31,9 @@ import eu.eudat.model.persist.DescriptionPersist;
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.descriptionproperties.*;
import eu.eudat.model.persist.descriptionreference.DescriptionReferenceDataPersist;
import eu.eudat.model.persist.dmpreference.DmpReferenceDataPersist;
import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
import eu.eudat.query.*;
import eu.eudat.service.elastic.ElasticService;
@ -146,7 +142,7 @@ public class DescriptionServiceImpl implements DescriptionService {
@Override
public Description persist(DescriptionPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, IOException {
logger.debug(new MapLogEntry("persisting data dmp").And("model", model).And("fields", fields));
logger.debug(new MapLogEntry("persisting data description").And("model", model).And("fields", fields));
this.authorizationService.authorizeForce(Permission.EditDescription);
@ -183,7 +179,6 @@ public class DescriptionServiceImpl implements DescriptionService {
if (dmp.getStatus().equals(DmpStatus.Finalized) && isUpdate) throw new MyValidationException(this.errors.getDmpIsFinalized().getCode(), this.errors.getDmpIsFinalized().getMessage());
data.setLabel(model.getLabel());
data.setProperties(this.jsonHandlingService.toJson(this.buildPropertyDefinitionEntity(model.getProperties())));
data.setStatus(model.getStatus());
data.setDescription(model.getDescription());
data.setDescriptionTemplateId(model.getDescriptionTemplateId());
@ -191,11 +186,21 @@ public class DescriptionServiceImpl implements DescriptionService {
if (isUpdate) this.entityManager.merge(data);
else this.entityManager.persist(data);
this.persistTags(data.getId(), model.getTags());
this.persistDescriptionReferences(data.getId(), model.getReferences());
this.entityManager.flush();
eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition());
Map<String, List<UUID>> fieldToReferenceMap = this.patchAndSaveReferences(this.buildDescriptionReferencePersists(model.getProperties()), data.getId());
this.entityManager.flush();
data.setProperties(this.jsonHandlingService.toJson(this.buildPropertyDefinitionEntity(model.getProperties(), definition, fieldToReferenceMap)));
this.entityManager.merge(data);
this.entityManager.flush();
this.persistTags(data.getId(), model.getTags());
if (isUpdate){
this.sendNotification(data);
}
@ -357,50 +362,191 @@ public class DescriptionServiceImpl implements DescriptionService {
return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(BaseFieldSet.build(fields, Description._id), data);
}
private @NotNull PropertyDefinitionEntity buildPropertyDefinitionEntity(PropertyDefinitionPersist persist){
private @NotNull PropertyDefinitionEntity buildPropertyDefinitionEntity(PropertyDefinitionPersist persist, eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition, Map<String, List<UUID>> fieldToReferenceMap){
PropertyDefinitionEntity data = new PropertyDefinitionEntity();
if (persist == null) return data;
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)));
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById(key).stream().findFirst().orElse(null) : null;
data.getFieldSets().put(key, this.buildPropertyDefinitionFieldSetEntity(persist.getFieldSets().get(key), fieldSetEntity, fieldToReferenceMap));
}
}
return data;
}
private @NotNull PropertyDefinitionFieldSetEntity buildPropertyDefinitionFieldSetEntity(PropertyDefinitionFieldSetPersist persist){
private @NotNull PropertyDefinitionFieldSetEntity buildPropertyDefinitionFieldSetEntity(PropertyDefinitionFieldSetPersist persist, FieldSetEntity fieldSetEntity, Map<String, List<UUID>> fieldToReferenceMap){
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));
for (PropertyDefinitionFieldSetItemPersist itemsPersist: persist.getItems()) {
data.getItems().add(this.buildPropertyDefinitionFieldSetItemEntity(itemsPersist, fieldSetEntity, fieldToReferenceMap));
}
}
return data;
}
private @NotNull PropertyDefinitionFieldSetItemEntity buildPropertyDefinitionFieldSetItemEntity(PropertyDefinitionFieldSetItemPersist persist){
private @NotNull PropertyDefinitionFieldSetItemEntity buildPropertyDefinitionFieldSetItemEntity(PropertyDefinitionFieldSetItemPersist persist, FieldSetEntity fieldSetEntity, Map<String, List<UUID>> fieldToReferenceMap){
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)));
eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getAllField().stream().findFirst().orElse(null) : null;
data.getFields().put(key, this.buildFieldEntity(persist.getFields().get(key), fieldEntity, fieldToReferenceMap));
}
}
return data;
}
private @NotNull FieldEntity buildFieldEntity(FieldPersist persist){
private @NotNull FieldEntity buildFieldEntity(FieldPersist persist, eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity, Map<String, List<UUID>> fieldToReferenceMap){
FieldType fieldType = fieldEntity != null && fieldEntity.getData() != null ? fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT;
FieldEntity data = new FieldEntity();
if (persist == null) return data;
data.setValue(persist.getValue());
if (FieldType.isTextType(fieldType)) data.setTextValue(persist.getTextValue());
else if (FieldType.isDateType(fieldType)) data.setDateValue(persist.getDateValue());
else if (FieldType.isTextListType(fieldType)) data.setTextListValue(persist.getTextListValue());
else if (FieldType.isExternalIdentifierType(fieldType) && persist.getExternalIdentifier() != null) data.setExternalIdentifier(this.buildExternalIdentifierEntity(persist.getExternalIdentifier()));
else if (FieldType.isReferenceType(fieldType) && fieldEntity != null ) {
List<UUID> referenceIds = fieldToReferenceMap.getOrDefault(fieldEntity.getId(), null);
if (referenceIds != null) data.setTextListValue(referenceIds.stream().map(UUID::toString).toList());
}
return data;
}
private @NotNull ExternalIdentifierEntity buildExternalIdentifierEntity(ExternalIdentifierPersist persist){
ExternalIdentifierEntity data = new ExternalIdentifierEntity();
if (persist == null) return data;
data.setIdentifier(persist.getIdentifier());
data.setType(persist.getType());
return data;
}
private @NotNull List<DescriptionReferencePersist> buildDescriptionReferencePersists(PropertyDefinitionPersist persist){
List<DescriptionReferencePersist> descriptionReferencePersists = new ArrayList<>();
if (persist.getFieldSets() != null && !persist.getFieldSets().isEmpty()){
for (PropertyDefinitionFieldSetPersist propertyDefinitionFieldSetPersist: persist.getFieldSets().values()) {
if (this.conventionService.isListNullOrEmpty( propertyDefinitionFieldSetPersist.getItems())) {
for (PropertyDefinitionFieldSetItemPersist definitionFieldSetItemPersist : propertyDefinitionFieldSetPersist.getItems()) {
if (definitionFieldSetItemPersist.getFields() != null && !definitionFieldSetItemPersist.getFields().isEmpty()) {
for (String key : definitionFieldSetItemPersist.getFields().keySet()) {
FieldPersist fieldPersist = definitionFieldSetItemPersist.getFields().get(key);
BuildDescriptionReferencePersist(key, fieldPersist, descriptionReferencePersists);
}
}
}
}
}
}
return descriptionReferencePersists;
}
private void BuildDescriptionReferencePersist(String fieldId, FieldPersist fieldPersist, List<DescriptionReferencePersist> descriptionReferencePersists) {
if (this.conventionService.isListNullOrEmpty(fieldPersist.getReferences())) {
for (ReferencePersist referencePersist : fieldPersist.getReferences()) {
DescriptionReferencePersist descriptionReferencePersist = new DescriptionReferencePersist();
descriptionReferencePersist.setData(new DescriptionReferenceDataPersist());
descriptionReferencePersist.getData().setFieldId(fieldId);
descriptionReferencePersist.setReference(referencePersist);
descriptionReferencePersists.add(descriptionReferencePersist);
}
}
}
private Map<String, List<UUID>> patchAndSaveReferences(List<DescriptionReferencePersist> models, UUID descriptionId) throws InvalidApplicationException {
if (models == null) models = new ArrayList<>();
Map<String, List<UUID>> fieldToReferenceMap = new HashMap<>();
List<DescriptionReferenceEntity> descriptionReferences = this.queryFactory.query(DescriptionReferenceQuery.class).descriptionIds(descriptionId).collect();
Map<UUID, List<DescriptionReferenceEntity>> descriptionReferenceEntityByReferenceId = new HashMap<>();
for (DescriptionReferenceEntity descriptionReferenceEntity : descriptionReferences){
List<DescriptionReferenceEntity> descriptionReferenceEntities = descriptionReferenceEntityByReferenceId.getOrDefault(descriptionReferenceEntity.getReferenceId(), null);
if (descriptionReferenceEntities == null) {
descriptionReferenceEntities = new ArrayList<>();
descriptionReferenceEntityByReferenceId.put(descriptionReferenceEntity.getReferenceId(), descriptionReferenceEntities);
}
descriptionReferenceEntities.add(descriptionReferenceEntity);
}
Map<UUID, DescriptionReferenceDataEntity> descriptionReferenceDataEntityMap = new HashMap<>();
for (DescriptionReferenceEntity descriptionReferenceEntity : descriptionReferences){
descriptionReferenceDataEntityMap.put(descriptionReferenceEntity.getId(), this.jsonHandlingService.fromJsonSafe(DescriptionReferenceDataEntity.class, descriptionReferenceEntity.getData()));
}
List<UUID> updatedCreatedIds = new ArrayList<>();
for (DescriptionReferencePersist model : models) {
ReferencePersist referencePersist = model.getReference();
ReferenceEntity referenceEntity = null;
if (this.conventionService.isValidGuid(referencePersist.getId())){
referenceEntity = this.entityManager.find(ReferenceEntity.class, referencePersist.getId());
if (referenceEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referencePersist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
} else {
referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).references(referencePersist.getReference()).first();
if (referenceEntity == null){
referenceEntity = new ReferenceEntity();
referenceEntity.setId(UUID.randomUUID());
referenceEntity.setIsActive(IsActive.Active);
referenceEntity.setCreatedAt(Instant.now());
referenceEntity.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(referencePersist.getDefinition())));
referenceEntity.setUpdatedAt(Instant.now());
referenceEntity.setReference(referencePersist.getReference());
referenceEntity.setAbbreviation(referencePersist.getAbbreviation());
referenceEntity.setSource(referencePersist.getSource());
referenceEntity.setSourceType(referencePersist.getSourceType());
this.entityManager.persist(referenceEntity);
}
}
DescriptionReferenceEntity data = null;
List<DescriptionReferenceEntity> descriptionReferenceEntities = descriptionReferenceEntityByReferenceId.getOrDefault(referenceEntity.getId(), new ArrayList<>());
for (DescriptionReferenceEntity descriptionReferenceEntity : descriptionReferenceEntities){
DescriptionReferenceDataEntity descriptionReferenceDataEntity = descriptionReferenceDataEntityMap.getOrDefault(descriptionReferenceEntity.getId(), new DescriptionReferenceDataEntity());
if (Objects.equals(descriptionReferenceDataEntity.getFieldId(), model.getData().getFieldId())){
data = descriptionReferenceEntity;
break;
}
}
boolean isUpdate = data != null;
if (!isUpdate) {
data = new DescriptionReferenceEntity();
data.setId(UUID.randomUUID());
data.setReferenceId(referenceEntity.getId());
data.setDescriptionId(descriptionId);
data.setCreatedAt(Instant.now());
data.setIsActive(IsActive.Active);
data.setData(this.jsonHandlingService.toJsonSafe(this.buildDescriptionReferenceDataEntity(model.getData())));
}
updatedCreatedIds.add(data.getId());
if (model.getData() != null){
if (!fieldToReferenceMap.containsKey(model.getData().getFieldId())) fieldToReferenceMap.put(model.getData().getFieldId(), new ArrayList<>());
fieldToReferenceMap.get(model.getData().getFieldId()).add(referenceEntity.getId());
}
data.setUpdatedAt(Instant.now());
if (isUpdate) this.entityManager.merge(data);
else this.entityManager.persist(data);
}
List<DescriptionReferenceEntity> toDelete = descriptionReferences.stream().filter(x-> updatedCreatedIds.stream().noneMatch(y-> y.equals(x.getId()))).collect(Collectors.toList());
this.deleterFactory.deleter(DescriptionReferenceDeleter.class).delete(toDelete);
this.entityManager.flush();
return fieldToReferenceMap;
}
private @NotNull DescriptionReferenceDataEntity buildDescriptionReferenceDataEntity(DescriptionReferenceDataPersist persist){
DescriptionReferenceDataEntity data = new DescriptionReferenceDataEntity();
if (persist == null) return data;
data.setFieldId(persist.getFieldId());
return data;
}
private void persistTags(UUID id, List<String> tagLabels) throws InvalidApplicationException {
if (tagLabels == null) tagLabels = new ArrayList<>();
@ -444,75 +590,6 @@ public class DescriptionServiceImpl implements DescriptionService {
this.deleterFactory.deleter(DescriptionTagDeleter.class).delete(toDelete);
}
private void persistDescriptionReferences(UUID id, List<DescriptionReferencePersist> persists) throws InvalidApplicationException {
if (persists == null) persists = new ArrayList<>();
List<DescriptionReferenceEntity> existingItems = this.queryFactory.query(DescriptionReferenceQuery.class).isActive(IsActive.Active).descriptionIds(id).collect();
Map<UUID, ReferenceEntity> existingReferencesMap = this.queryFactory.query(ReferenceQuery.class).isActive(IsActive.Active).ids(persists.stream().filter(x-> x.getReference().getId() != null).map(x-> x.getReference().getId()).toList()).collect()
.stream()
.collect(Collectors.toMap(ReferenceEntity::getId, x-> x));;
List<UUID> updatedCreatedIds = new ArrayList<>();
for (DescriptionReferencePersist persist : persists) {
Boolean isUpdate = this.conventionService.isValidGuid(persist.getId());
DescriptionReferenceEntity data;
if (isUpdate) {
data = this.entityManager.find(DescriptionReferenceEntity.class, persist.getId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{persist.getId(), DescriptionReference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(persist.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
if (!data.getReferenceId().equals(persist.getReference().getId())) throw new MyValidationException("reference can not changed");
} else {
data = new DescriptionReferenceEntity();
data.setId(UUID.randomUUID());
data.setDescriptionId(id);
data.setCreatedAt(Instant.now());
data.setIsActive(IsActive.Active);
}
ReferenceEntity reference = this.persistReference(existingReferencesMap, persist.getReference());
data.setReferenceId(reference.getId());
data.setUpdatedAt(Instant.now());
if (isUpdate) this.entityManager.merge(data);
else this.entityManager.persist(data);
updatedCreatedIds.add(data.getId());
}
List<DescriptionReferenceEntity> toDelete = existingItems.stream().filter(x-> updatedCreatedIds.stream().noneMatch(y-> y.equals(x.getId()))).collect(Collectors.toList());
this.deleterFactory.deleter(DescriptionReferenceDeleter.class).delete(toDelete);
}
private ReferenceEntity persistReference(Map<UUID, ReferenceEntity> existingReferencesMap , ReferencePersist persist){
Boolean isUpdate = this.conventionService.isValidGuid(persist.getId());
ReferenceEntity data;
if (isUpdate) {
data = this.entityManager.find(ReferenceEntity.class, persist.getId());
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{persist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(persist.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
} else {
data = new ReferenceEntity();
data.setId(UUID.randomUUID());
data.setCreatedAt(Instant.now());
data.setIsActive(IsActive.Active);
}
data.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(persist.getDefinition())));
data.setUpdatedAt(Instant.now());
data.setReference(persist.getReference());
data.setAbbreviation(persist.getAbbreviation());
data.setSource(persist.getSource());
data.setSourceType(persist.getSourceType());
data.setUpdatedAt(Instant.now());
if (isUpdate) this.entityManager.merge(data);
else this.entityManager.persist(data);
return data;
}
private @NotNull DefinitionEntity buildDefinitionEntity(DefinitionPersist persist){
DefinitionEntity data = new DefinitionEntity();
if (persist == null) return data;
@ -556,7 +633,7 @@ public class DescriptionServiceImpl implements DescriptionService {
@Override
public void clone(UUID dmpId, UUID descriptionId) throws InvalidApplicationException, IOException {
logger.debug("cloning description: {} with dmp: {}", descriptionId, dmpId);
logger.debug("cloning description: {} with description: {}", descriptionId, dmpId);
this.authorizationService.authorizeForce(Permission.CloneDescription);

View File

@ -215,7 +215,7 @@ public class DmpServiceImpl implements DmpService {
event.setContactHint(jsonHandlingService.toJsonSafe(contactData));
event.setContactTypeHint(type);
event = this.applyNotificationType(dmp.getStatus(), event);
this.applyNotificationType(dmp.getStatus(), event);
NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{recipient}", DataType.String, user.getName()));
@ -228,14 +228,14 @@ public class DmpServiceImpl implements DmpService {
eventHandler.handle(event);
}
private NotifyIntegrationEvent applyNotificationType(DmpStatus status, NotifyIntegrationEvent event) {
private void applyNotificationType(DmpStatus status, NotifyIntegrationEvent event) {
switch (status) {
case Draft:
event.setNotificationType(notificationProperties.getDmpModifiedType());
return event;
break;
case Finalized:
event.setNotificationType(notificationProperties.getDmpFinalisedType());
return event;
break;
default:
throw new MyApplicationException("Unsupported Dmp Status.");
}

View File

@ -223,7 +223,7 @@ public class PrefillingServiceImpl implements PrefillingService {
if(this.conventionService.isListNullOrEmpty(issuedFieldEntities)){
String issuedIdNode = issuedFieldEntities.getFirst().getId();
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
.filter(x-> x.getFields() != null && x.getFields().containsKey(issuedIdNode)).map(x-> x.getFields().get(issuedIdNode).getTextValue()).findFirst().orElse(null); //TODO Update with the new logic of property definition
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();
@ -299,48 +299,49 @@ public class PrefillingServiceImpl implements PrefillingService {
PropertyDefinitionFieldSetItem fieldSetItem = new PropertyDefinitionFieldSetItem();
fieldSetItem.setFields(new HashMap<>());
Field field = new Field();
switch (fieldEntity.getData().getFieldType()) {
case EXTERNAL_SELECT:
case SELECT: {
if (!parsedValues.stream().allMatch(Objects::isNull)) {
field.setValue(this.jsonHandlingService.toJsonSafe(parseComboBoxValues(fieldEntity, parsedValues)));
}
break;
}
case TAGS: {
if (!parsedValues.isEmpty()) {
field.setValue(jsonHandlingService.toJsonSafe(parseTags(String.join(", ", parsedValues))));
}
break;
}
case DATASET_IDENTIFIER: {
JSONObject datasetID = new JSONObject();
datasetID.put("identifier", parsedValue);
if (type.equals(PrefillingServiceImpl.Zenodo)) {
datasetID.put("type", "doi");
}
field.setValue(datasetID.toString());
break;
}
case LICENSES: {
List<ReferenceEntity> licenses = this.queryFactory.query(ReferenceQuery.class).references(parsedValues).collect();
LabelAndMultiplicityDataEntity licenseDataEntity = (LabelAndMultiplicityDataEntity) fieldEntity.getData();
if (licenses != null && !licenses.isEmpty() && licenseDataEntity != null) {
boolean isMultiAutocomplete = licenseDataEntity.getMultipleSelect();
List<Reference> licenseModels = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(new BaseFieldSet(), licenses);
if (isMultiAutocomplete) {
field.setValue(jsonHandlingService.toJsonSafe(licenseModels));
} else {
field.setValue(jsonHandlingService.toJsonSafe(licenseModels.getFirst()));
}
}
break;
}
default:
field.setValue(parsedValue);
break;
}
//TODO Update with the new logic of property definition
// switch (fieldEntity.getData().getFieldType()) {
// case EXTERNAL_SELECT:
// case SELECT: {
// if (!parsedValues.stream().allMatch(Objects::isNull)) {
// field.setValue(this.jsonHandlingService.toJsonSafe(parseComboBoxValues(fieldEntity, parsedValues)));
// }
// break;
// }
// case TAGS: {
// if (!parsedValues.isEmpty()) {
// field.setValue(jsonHandlingService.toJsonSafe(parseTags(String.join(", ", parsedValues))));
// }
// break;
// }
// case DATASET_IDENTIFIER: {
// JSONObject datasetID = new JSONObject();
// datasetID.put("identifier", parsedValue);
// if (type.equals(PrefillingServiceImpl.Zenodo)) {
// datasetID.put("type", "doi");
// }
// field.setValue(datasetID.toString());
// break;
// }
// case LICENSES: {
// List<ReferenceEntity> licenses = this.queryFactory.query(ReferenceQuery.class).references(parsedValues).collect();
// LabelAndMultiplicityDataEntity licenseDataEntity = (LabelAndMultiplicityDataEntity) fieldEntity.getData();
// if (licenses != null && !licenses.isEmpty() && licenseDataEntity != null) {
// boolean isMultiAutocomplete = licenseDataEntity.getMultipleSelect();
// List<Reference> licenseModels = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(new BaseFieldSet(), licenses);
// if (isMultiAutocomplete) {
// field.setValue(jsonHandlingService.toJsonSafe(licenseModels));
// } else {
// field.setValue(jsonHandlingService.toJsonSafe(licenseModels.getFirst()));
// }
// }
//
// break;
// }
// default:
// field.setValue(parsedValue);
// break;
// }
fieldSetItem.getFields().put(fieldEntity.getId(), field);
return fieldSetItem;
}

View File

@ -330,7 +330,7 @@
<dependency>
<groupId>gr.cite</groupId>
<artifactId>validation</artifactId>
<version>3.0.2</version>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>gr.cite</groupId>

View File

@ -1,37 +0,0 @@
package eu.eudat.controllers;
import eu.eudat.logic.managers.CommonsManager;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.models.data.externalurl.ExternalSourcesConfiguration;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.service.remotefetcher.ExternalUrlConfigProvider;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* Created by ikalyvas on 3/28/2018.
*/
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/common"})
public class CommonController {
private ConfigLoader configLoader;
private final ExternalUrlConfigProvider externalUrlConfigProvider;
@Autowired
public CommonController(ConfigLoader configLoader, ExternalUrlConfigProvider externalUrlConfigProvider) {
this.configLoader = configLoader;
this.externalUrlConfigProvider = externalUrlConfigProvider;
}
@RequestMapping(method = RequestMethod.GET, value = {"/externalSourcesConfiguration"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<ExternalSourcesConfiguration>> getExternalSourcesConfiguration() {
ExternalSourcesConfiguration configuration = CommonsManager.getExternalSourcesConfiguration(configLoader, externalUrlConfigProvider);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalSourcesConfiguration>().status(ApiMessageCode.NO_MESSAGE).payload(configuration));
}
}