add references definition xml,builder, persist

This commit is contained in:
amentis 2023-10-27 17:35:35 +03:00
parent 65e8635c2f
commit 92c165e904
23 changed files with 935 additions and 61 deletions

View File

@ -36,9 +36,9 @@ public class AuditableAction {
public static final EventId Description_Persist = new EventId(6002, "Description_Persist");
public static final EventId Description_Delete = new EventId(6003, "Description_Delete");
public static final EventId External_Reference_Query = new EventId(7000, "External_Reference_Query");
public static final EventId External_Reference_Lookup = new EventId(7001, "External_Reference_Lookup");
public static final EventId External_Reference_Persist = new EventId(7002, "External_Reference_Persist");
public static final EventId External_Reference_Delete = new EventId(7003, "External_Reference_Delete");
public static final EventId Reference_Query = new EventId(7000, "Reference_Query");
public static final EventId Reference_Lookup = new EventId(7001, "Reference_Lookup");
public static final EventId Reference_Persist = new EventId(7002, "Reference_Persist");
public static final EventId Reference_Delete = new EventId(7003, "Reference_Delete");
}

View File

@ -0,0 +1,27 @@
package eu.eudat.commons.enums;
import com.fasterxml.jackson.annotation.JsonValue;
import eu.eudat.data.converters.enums.DatabaseEnum;
import java.util.Map;
public enum ReferenceFieldDataType implements DatabaseEnum<Short> {
Text((short) 0),
Date((short) 1);
private final Short value;
ReferenceFieldDataType(Short value) {
this.value = value;
}
@JsonValue
public Short getValue() {
return value;
}
private static final Map<Short, ReferenceFieldDataType> map = EnumUtils.getEnumValueMap(ReferenceFieldDataType.class);
public static ReferenceFieldDataType of(Short i) {
return map.get(i);
}
}

View File

@ -0,0 +1,22 @@
package eu.eudat.commons.types.reference;
import jakarta.xml.bind.annotation.*;
import java.util.List;
@XmlRootElement(name = "definition")
@XmlAccessorType(XmlAccessType.FIELD)
public class DefinitionEntity {
@XmlElementWrapper(name = "fields")
@XmlElement(name = "field")
private List<FieldEntity> fields;
public List<FieldEntity> getFields() {
return fields;
}
public void setFields(List<FieldEntity> fields) {
this.fields = fields;
}
}

View File

@ -0,0 +1,47 @@
package eu.eudat.commons.types.reference;
import eu.eudat.commons.enums.ReferenceFieldDataType;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "field")
@XmlAccessorType(XmlAccessType.FIELD)
public class FieldEntity {
@XmlAttribute(name = "code")
private String code;
@XmlAttribute(name = "dataType")
private ReferenceFieldDataType dataType;
@XmlAttribute(name = "value")
private String value;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public ReferenceFieldDataType getDataType() {
return dataType;
}
public void setDataType(ReferenceFieldDataType dataType) {
this.dataType = dataType;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -0,0 +1,17 @@
package eu.eudat.configurations.referencetype;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties({ReferenceTypeProperties.class})
public class ReferenceTypeConfiguration {
private final ReferenceTypeProperties referenceTypeProperties;
@Autowired
public ReferenceTypeConfiguration(ReferenceTypeProperties referenceTypeProperties) {
this.referenceTypeProperties = referenceTypeProperties;
}
}

View File

@ -0,0 +1,24 @@
package eu.eudat.configurations.referencetype;
public class ReferenceTypeField {
String code;
String dataType;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
}

View File

@ -0,0 +1,163 @@
package eu.eudat.configurations.referencetype;
import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.ConstructorBinding;
import java.util.List;
import java.util.Map;
@ConfigurationProperties(prefix = "reference-type")
public class ReferenceTypeProperties {
private Map<String, List<ReferenceTypeField>> grant;
private Map<String, List<ReferenceTypeField>> funder;
private Map<String, List<ReferenceTypeField>> researcher;
private Map<String, List<ReferenceTypeField>> service;
private Map<String, List<ReferenceTypeField>> registry;
private Map<String, List<ReferenceTypeField>> project;
private Map<String, List<ReferenceTypeField>> organisation;
private Map<String, List<ReferenceTypeField>> dataset;
private Map<String, List<ReferenceTypeField>> dataRepository;
private Map<String, List<ReferenceTypeField>> pubRepository;
private Map<String, List<ReferenceTypeField>> journal;
private Map<String, List<ReferenceTypeField>> publication;
private Map<String, List<ReferenceTypeField>> licence;
private Map<String, List<ReferenceTypeField>> taxonomy;
@ConstructorBinding
public ReferenceTypeProperties(Map<String, List<ReferenceTypeField>> grant, Map<String, List<ReferenceTypeField>> funder,
Map<String, List<ReferenceTypeField>> researcher, Map<String, List<ReferenceTypeField>> service,
Map<String, List<ReferenceTypeField>> registry, Map<String, List<ReferenceTypeField>> project,
Map<String, List<ReferenceTypeField>> organisation, Map<String, List<ReferenceTypeField>> dataset,
Map<String, List<ReferenceTypeField>> dataRepository, Map<String, List<ReferenceTypeField>> pubRepository,
Map<String, List<ReferenceTypeField>> journal, Map<String, List<ReferenceTypeField>> publication,
Map<String, List<ReferenceTypeField>> licence, Map<String, List<ReferenceTypeField>> taxonomy) {
this.grant = grant;
this.funder = funder;
this.researcher = researcher;
this.service = service;
this.registry = registry;
this.project = project;
this.organisation = organisation;
this.dataset = dataset;
this.dataRepository = dataRepository;
this.pubRepository = pubRepository;
this.journal = journal;
this.publication = publication;
this.licence = licence;
this.taxonomy = taxonomy;
}
public Map<String, List<ReferenceTypeField>> getGrant() {
return grant;
}
public void setGrant(Map<String, List<ReferenceTypeField>> grant) {
this.grant = grant;
}
public Map<String, List<ReferenceTypeField>> getFunder() {
return funder;
}
public void setFunder(Map<String, List<ReferenceTypeField>> funder) {
this.funder = funder;
}
public Map<String, List<ReferenceTypeField>> getResearcher() {
return researcher;
}
public void setResearcher(Map<String, List<ReferenceTypeField>> researcher) {
this.researcher = researcher;
}
public Map<String, List<ReferenceTypeField>> getService() {
return service;
}
public void setService(Map<String, List<ReferenceTypeField>> service) {
this.service = service;
}
public Map<String, List<ReferenceTypeField>> getRegistry() {
return registry;
}
public void setRegistry(Map<String, List<ReferenceTypeField>> registry) {
this.registry = registry;
}
public Map<String, List<ReferenceTypeField>> getProject() {
return project;
}
public void setProject(Map<String, List<ReferenceTypeField>> project) {
this.project = project;
}
public Map<String, List<ReferenceTypeField>> getOrganisation() {
return organisation;
}
public void setOrganisation(Map<String, List<ReferenceTypeField>> organisation) {
this.organisation = organisation;
}
public Map<String, List<ReferenceTypeField>> getDataset() {
return dataset;
}
public void setDataset(Map<String, List<ReferenceTypeField>> dataset) {
this.dataset = dataset;
}
public Map<String, List<ReferenceTypeField>> getDataRepository() {
return dataRepository;
}
public void setDataRepository(Map<String, List<ReferenceTypeField>> dataRepository) {
this.dataRepository = dataRepository;
}
public Map<String, List<ReferenceTypeField>> getPubRepository() {
return pubRepository;
}
public void setPubRepository(Map<String, List<ReferenceTypeField>> pubRepository) {
this.pubRepository = pubRepository;
}
public Map<String, List<ReferenceTypeField>> getJournal() {
return journal;
}
public void setJournal(Map<String, List<ReferenceTypeField>> journal) {
this.journal = journal;
}
public Map<String, List<ReferenceTypeField>> getPublication() {
return publication;
}
public void setPublication(Map<String, List<ReferenceTypeField>> publication) {
this.publication = publication;
}
public Map<String, List<ReferenceTypeField>> getLicence() {
return licence;
}
public void setLicence(Map<String, List<ReferenceTypeField>> licence) {
this.licence = licence;
}
public Map<String, List<ReferenceTypeField>> getTaxonomy() {
return taxonomy;
}
public void setTaxonomy(Map<String, List<ReferenceTypeField>> taxonomy) {
this.taxonomy = taxonomy;
}
}

View File

@ -3,6 +3,7 @@ package eu.eudat.model;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.SourceType;
import eu.eudat.model.referencedefinition.Definition;
import java.time.Instant;
import java.util.List;
@ -22,7 +23,7 @@ public class Reference {
private String description;
public static final String _description = "description";
private String definition;
private Definition definition;
public static final String _definition = "definition";
private String reference;
@ -84,11 +85,11 @@ public class Reference {
this.description = description;
}
public String getDefinition() {
public Definition getDefinition() {
return definition;
}
public void setDefinition(String definition) {
public void setDefinition(Definition definition) {
this.definition = definition;
}

View File

@ -1,10 +1,13 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.types.reference.DefinitionEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.DmpReference;
import eu.eudat.model.Reference;
import eu.eudat.model.builder.referencedefinition.DefinitionBuilder;
import eu.eudat.query.DmpReferenceQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
@ -28,15 +31,17 @@ public class ReferenceBuilder extends BaseBuilder<Reference, ReferenceEntity>{
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private final XmlHandlingService xmlHandlingService;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public ReferenceBuilder(
ConventionService conventionService,
BuilderFactory builderFactory, QueryFactory queryFactory) {
BuilderFactory builderFactory, QueryFactory queryFactory, XmlHandlingService xmlHandlingService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceBuilder.class)));
this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
this.xmlHandlingService = xmlHandlingService;
}
public ReferenceBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -51,7 +56,8 @@ public class ReferenceBuilder extends BaseBuilder<Reference, ReferenceEntity>{
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
//FieldSet userInfoFields = fields.extractPrefixed(this.asPrefix(Reference._createdBy));
//ToDo FieldSet userInfoFields = fields.extractPrefixed(this.asPrefix(Reference._createdBy));
FieldSet definitionFields = fields.extractPrefixed(this.asPrefix(Reference._definition));
FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Reference._dmpReferences));
Map<UUID, List<DmpReference>> dmpReferenceMap = this.collectDmpReferences(dmpReferencesFields, data);
@ -64,7 +70,10 @@ public class ReferenceBuilder extends BaseBuilder<Reference, ReferenceEntity>{
if (fields.hasField(this.asIndexer(Reference._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(Reference._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(Reference._isActive))) m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(Reference._definition))) m.setReference(d.getDefinition());
if (!definitionFields.isEmpty() && d.getDefinition() != null){
DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition());
m.setDefinition(this.builderFactory.builder(DefinitionBuilder.class).authorize(this.authorize).build(definitionFields, definition));
}
if (fields.hasField(this.asIndexer(Reference._reference))) m.setReference(d.getReference());
if (fields.hasField(this.asIndexer(Reference._abbreviation))) m.setAbbreviation(d.getAbbreviation());
if (fields.hasField(this.asIndexer(Reference._description))) m.setDescription(d.getDescription());

View File

@ -0,0 +1,59 @@
package eu.eudat.model.builder.referencedefinition;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.reference.DefinitionEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.referencedefinition.Definition;
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
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DefinitionBuilder extends BaseBuilder<Definition, DefinitionEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DefinitionBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DefinitionBuilder.class)));
this.builderFactory = builderFactory;
}
public DefinitionBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<Definition> build(FieldSet fields, List<DefinitionEntity> 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 definitionFields = fields.extractPrefixed(this.asPrefix(Definition._fields));
List<Definition> models = new ArrayList<>();
for (DefinitionEntity d : data) {
Definition m = new Definition();
if (!definitionFields.isEmpty() && d.getFields() != null) m.setFields(this.builderFactory.builder(FieldBuilder.class).authorize(this.authorize).build(definitionFields, d.getFields()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -0,0 +1,59 @@
package eu.eudat.model.builder.referencedefinition;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.reference.FieldEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.referencedefinition.Field;
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
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class FieldBuilder extends BaseBuilder<Field, FieldEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public FieldBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldBuilder.class)));
this.builderFactory = builderFactory;
}
public FieldBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
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<>();
List<Field> models = new ArrayList<>();
for (FieldEntity d : data) {
Field m = new Field();
if (fields.hasField(this.asIndexer(Field._code))) m.setCode(d.getCode());
if (fields.hasField(this.asIndexer(Field._dataType))) m.setDataType(d.getDataType());
if (fields.hasField(this.asIndexer(Field._value))) m.setValue(d.getValue());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -0,0 +1,123 @@
package eu.eudat.model.persist;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.enums.SourceType;
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
import eu.eudat.commons.validation.ValidEnum;
import eu.eudat.commons.validation.ValidId;
import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class ReferencePersist {
@ValidId(message = "{validation.invalidid}")
private UUID id;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = 250, message = "{validation.largerthanmax}")
private String label;
@ValidEnum(message = "{validation.empty}")
private ReferenceType type;
private String description;
@Valid
private DefinitionPersist definition;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = 1024, message = "{validation.largerthanmax}")
private String reference;
@Size(max = 50, message = "{validation.largerthanmax}")
private String abbreviation;
@Size(max = 1024, message = "{validation.largerthanmax}")
private String source;
@ValidEnum(message = "{validation.empty}")
private SourceType sourceType;
//private UserInfoPersist createdBy; ToDo
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public ReferenceType getType() {
return type;
}
public void setType(ReferenceType type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public DefinitionPersist getDefinition() {
return definition;
}
public void setDefinition(DefinitionPersist definition) {
this.definition = definition;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public SourceType getSourceType() {
return sourceType;
}
public void setSourceType(SourceType sourceType) {
this.sourceType = sourceType;
}
}

View File

@ -0,0 +1,21 @@
package eu.eudat.model.persist.referencedefinition;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.util.List;
public class DefinitionPersist {
@NotNull(message = "{validation.empty}")
@Valid
private List<FieldPersist> fields = null;
public List<FieldPersist> getFields() {
return fields;
}
public void setFields(List<FieldPersist> fields) {
this.fields = fields;
}
}

View File

@ -0,0 +1,47 @@
package eu.eudat.model.persist.referencedefinition;
import eu.eudat.commons.enums.ReferenceFieldDataType;
import eu.eudat.commons.validation.ValidEnum;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
public class FieldPersist {
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String code = null;
@ValidEnum(message = "{validation.empty}")
private ReferenceFieldDataType dataType;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String value = null;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public ReferenceFieldDataType getDataType() {
return dataType;
}
public void setDataType(ReferenceFieldDataType dataType) {
this.dataType = dataType;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -0,0 +1,17 @@
package eu.eudat.model.referencedefinition;
import java.util.List;
public class Definition {
public final static String _fields = "fields";
private List<Field> fields;
public List<Field> getFields() {
return fields;
}
public void setFields(List<Field> fields) {
this.fields = fields;
}
}

View File

@ -0,0 +1,39 @@
package eu.eudat.model.referencedefinition;
import eu.eudat.commons.enums.ReferenceFieldDataType;
public class Field {
public final static String _code = "code";
private String code;
public final static String _dataType = "dataType";
private ReferenceFieldDataType dataType;
public final static String _value = "value";
private String value;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public ReferenceFieldDataType getDataType() {
return dataType;
}
public void setDataType(ReferenceFieldDataType dataType) {
this.dataType = dataType;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -0,0 +1,17 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.ReferenceEntity;
import java.util.UUID;
public class ReferenceCriteria extends Criteria<ReferenceEntity>{
private UUID creationUserId;
public UUID getCreationUserId() {
return creationUserId;
}
public void setCreationUserId(UUID creationUserId) {
this.creationUserId = creationUserId;
}
}

View File

@ -1,5 +1,6 @@
package eu.eudat.controllers.v2;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
@ -13,6 +14,7 @@ import eu.eudat.logic.services.references.ReferenceService;
import eu.eudat.model.Reference;
import eu.eudat.model.builder.ReferenceBuilder;
import eu.eudat.model.censorship.ReferenceCensor;
import eu.eudat.model.persist.ReferencePersist;
import eu.eudat.model.result.QueryResult;
import eu.eudat.models.data.FetcherReference;
import eu.eudat.models.data.helpers.responses.ResponseItem;
@ -30,7 +32,9 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import jakarta.transaction.Transactional;
import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
@ -40,6 +44,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.management.InvalidApplicationException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
@ -88,7 +94,7 @@ public class ReferenceController extends BaseController {
List<Reference> models = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), datas);
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.External_Reference_Query, "lookup", lookup);
this.auditService.track(AuditableAction.Reference_Query, "lookup", lookup);
return new QueryResult(models, count);
}
@ -104,7 +110,7 @@ public class ReferenceController extends BaseController {
if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.auditService.track(AuditableAction.External_Reference_Lookup, Map.ofEntries(
this.auditService.track(AuditableAction.Reference_Lookup, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
@ -112,6 +118,22 @@ public class ReferenceController extends BaseController {
return model;
}
@PostMapping("persist")
@Transactional
public Reference persist(@MyValidate @RequestBody ReferencePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException {
logger.debug(new MapLogEntry("persisting" + Reference.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
this.censorFactory.censor(ReferenceCensor.class).censor(fieldSet, null);
Reference persisted = this.referenceService.persist(model, fieldSet);
this.auditService.track(AuditableAction.Reference_Persist, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return persisted;
}
@GetMapping(path = {"search/{externalType}"}, produces = "application/json")
public @ResponseBody ResponseEntity<ResponseItem<List<FetcherReference>>> searchReference(@PathVariable(value = "externalType") int externalType,
@RequestParam(value = "query", required = false) String query,
@ -131,7 +153,7 @@ public class ReferenceController extends BaseController {
this.referenceService.deleteAndSave(id);
this.auditService.track(AuditableAction.External_Reference_Delete, "id", id);
this.auditService.track(AuditableAction.Reference_Delete, "id", id);
}
@ -145,27 +167,4 @@ public class ReferenceController extends BaseController {
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
// }
// @GetMapping(path = {"{externalType}"}, produces = "application/json")
// public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference2>>> listExternalReferecnes2(@RequestParam(value = "externalType") String externalType, @RequestParam(value = "query", required = false) String query,
// @RequestParam(value = "type", required = false) String type
// ) throws HugeResultSet, NoURLFound, InvalidApplicationException {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// List<ExternalReference2> externalReferences = this.externalReferencesService.getExternalReference2(externalType, query, type);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference2>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences));
// }
//
// @Transactional
// @PostMapping(value = {"{externalType}/persist"}, consumes = "application/json", produces = "application/json")
// public @ResponseBody
// ResponseEntity<ResponseItem<ExternalReference2>> create(@RequestBody ExternalReference2 externalReference) throws Exception {
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
//
// ExternalReference2 newExternalReference = this.externalReferencesService.create(externalReference);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference2>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
// }
}

View File

@ -1,13 +1,18 @@
package eu.eudat.logic.services.references;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceType;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.reference.DefinitionEntity;
import eu.eudat.commons.types.reference.FieldEntity;
import eu.eudat.configurations.referencetype.ReferenceTypeProperties;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.dao.criteria.DataRepositoryCriteria;
import eu.eudat.data.dao.criteria.ExternalDatasetCriteria;
import eu.eudat.data.dao.criteria.RegistryCriteria;
import eu.eudat.data.dao.criteria.ServiceCriteria;
import eu.eudat.data.ReferenceEntity;
import eu.eudat.data.dao.criteria.*;
import eu.eudat.data.old.DataRepository;
import eu.eudat.data.old.ExternalDataset;
import eu.eudat.data.old.Registry;
@ -18,20 +23,37 @@ import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.model.Reference;
import eu.eudat.model.builder.ReferenceBuilder;
import eu.eudat.model.deleter.ReferenceDeleter;
import eu.eudat.model.persist.ReferencePersist;
import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
import eu.eudat.model.persist.referencedefinition.FieldPersist;
import eu.eudat.models.data.FetcherReference;
import eu.eudat.queryable.QueryableList;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import jakarta.persistence.EntityManager;
import jakarta.xml.bind.JAXBException;
import org.jetbrains.annotations.NotNull;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import javax.management.InvalidApplicationException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
@ -49,6 +71,8 @@ public class ReferenceService {
private final ConventionService conventionService;
private final MessageSource messageSource;
private final QueryFactory queryFactory;
private final XmlHandlingService xmlHandlingService;
private final ReferenceTypeProperties referenceTypeProperties;
public ReferenceService(ApiContext apiContext,
UserScope userScope,
@ -59,7 +83,9 @@ public class ReferenceService {
BuilderFactory builderFactory,
ConventionService conventionService,
MessageSource messageSource,
QueryFactory queryFactory) {
QueryFactory queryFactory,
XmlHandlingService xmlHandlingService,
ReferenceTypeProperties referenceTypeProperties) {
this.apiContext = apiContext;
this.userScope = userScope;
this.remoteFetcher = remoteFetcher;
@ -70,6 +96,68 @@ public class ReferenceService {
this.conventionService = conventionService;
this.messageSource = messageSource;
this.queryFactory = queryFactory;
this.xmlHandlingService = xmlHandlingService;
this.referenceTypeProperties = referenceTypeProperties;
}
public Reference persist(ReferencePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, TransformerException, ParserConfigurationException {
logger.debug(new MapLogEntry("persisting data").And("model", model).And("fields", fields));
this.authorizationService.authorizeForce(Permission.EditDmpBlueprint);
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
ReferenceEntity data;
if (isUpdate) {
data = this.entityManager.find(ReferenceEntity.class, model.getId());
if (data == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
} else {
data = new ReferenceEntity();
data.setId(UUID.randomUUID());
data.setIsActive(IsActive.Active);
data.setCreatedAt(Instant.now());
}
data.setLabel(model.getLabel());
data.setType(model.getType());
data.setDescription(model.getDescription());
data.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(model.getDefinition())));
data.setUpdatedAt(Instant.now());
data.setReference(model.getReference());
data.setAbbreviation(model.getAbbreviation());
data.setSource(model.getSource());
if (isUpdate) this.entityManager.merge(data);
else this.entityManager.persist(data);
this.entityManager.flush();
return this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(BaseFieldSet.build(fields, Reference._id), data);
}
private @NotNull DefinitionEntity buildDefinitionEntity(DefinitionPersist persist){
DefinitionEntity data = new DefinitionEntity();
if (persist == null) return data;
if (!this.conventionService.isListNullOrEmpty(persist.getFields())){
data.setFields(new ArrayList<>());
for (FieldPersist fieldPersist: persist.getFields()) {
data.getFields().add(this.buildFieldEntity(fieldPersist));
}
}
return data;
}
private @NotNull FieldEntity buildFieldEntity(FieldPersist persist){
FieldEntity data = new FieldEntity();
if (persist == null) return data;
data.setCode(persist.getCode());
data.setDataType(persist.getDataType());
data.setCode(persist.getCode());
return data;
}
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
@ -80,27 +168,13 @@ public class ReferenceService {
this.deleterFactory.deleter(ReferenceDeleter.class).deleteAndSaveByIds(List.of(id));
}
// external references:
// taxonomies,
// licenses,
// publications,
// journals,
// pubRepositories,
// dataRepositories
// registries,
// services
public List<FetcherReference> searchReference(ReferenceType externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
List<Map<String, String>> remoteRepos = null;
if (externalType.equals(ReferenceType.Datasets)){
remoteRepos = remoteFetcher.getDatasets(externalUrlCriteria, type);
}else {
remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type);
}
List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type);
List<FetcherReference> list = this.fetchFromDb(externalType, query, type, remoteRepos);
list.addAll(remoteRepos.stream().map(FetcherReference::fromRemoteModel).toList());
list = list.stream().filter(x -> x.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList());
list.sort(Comparator.comparing(FetcherReference::getName));
@ -136,7 +210,7 @@ public class ReferenceService {
if (!query.isEmpty()) criteria.setLike(query);
criteria.setCreationUserId(this.userScope.getUserId());
if (type.equals("")) {
List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList();
list = serviceList.stream().map(item -> new FetcherReference().fromService(item)).collect(Collectors.toList());
@ -156,7 +230,7 @@ public class ReferenceService {
case Licenses:
break;
}
return list;
}

View File

@ -18,4 +18,5 @@ spring:
optional:classpath:config/cors.yml[.yml], optional:classpath:config/cors-${spring.profiles.active}.yml[.yml], optional:file:../config/cors-${spring.profiles.active}.yml[.yml],
optional:classpath:config/swagger.yml[.yml], optional:classpath:config/swagger-${spring.profiles.active}.yml[.yml], optional:file:../config/swagger-${spring.profiles.active}.yml[.yml],
optional:classpath:config/deposit.yml[.yml], optional:classpath:config/deposit-${spring.profiles.active}.yml[.yml], optional:file:../config/deposit-${spring.profiles.active}.yml[.yml],
optional:classpath:config/errors.yml[.yml], optional:classpath:config/errors-${spring.profiles.active}.yml[.yml], optional:file:../config/errors-${spring.profiles.active}.yml[.yml]
optional:classpath:config/errors.yml[.yml], optional:classpath:config/errors-${spring.profiles.active}.yml[.yml], optional:file:../config/errors-${spring.profiles.active}.yml[.yml],
optional:classpath:config/reference-type.yml[.yml], optional:classpath:config/reference-type-${spring.profiles.active}.yml[.yml], optional:file:../config/reference-type-${spring.profiles.active}.yml[.yml]

View File

@ -0,0 +1,65 @@
reference-type:
grant:
fields:
- code: startDate
dataType: date
- code: endDate
dataType: date
funder:
fields:
- code: uri
dataType: text
researcher:
fields:
- code: firstName
dataType: text
- code: lastName
dataType: text
- code: uri
dataType: text
service:
fields:
- code: uri
dataType: text
registry:
fields:
- code: uri
dataType: text
project:
fields:
- code: startDate
dataType: date
- code: endDate
dataType: date
organisation:
fields:
- code: pid
dataType: text
- code: uri
dataType: text
- code: pidTypeField
dataType: text
dataset:
fields:
- code: pid
dataType: text
- code: pidTypeField
dataType: text
dataRepository:
fields:
pubRepository:
fields:
journal:
fields:
publication:
fields:
- code: pid
dataType: text
- code: pidTypeField
dataType: text
licence:
fields:
- code: uri
dataType: text
taxonomy:
fields:

View File

@ -0,0 +1,4 @@
export enum ReferenceFieldDataType {
Text = 0,
Date = 1
}

View File

@ -3,13 +3,14 @@ import { IsActive } from "@app/core/common/enum/is-active.enum";
import { SourceType } from "@app/core/common/enum/source-type";
import { UUID } from "crypto";
import { DmpModel } from "../dmp/dmp";
import { ReferenceFieldDataType } from "@app/core/common/enum/reference-field-data-type";
export interface Reference {
id: UUID;
label: string;
type: ReferenceType;
description: string;
definition: string;
definition: Definition;
reference: string;
abbreviation: string;
source: string;
@ -20,13 +21,26 @@ export interface Reference {
dmpReferences: DmpReference[];
}
export interface Definition {
fields: Field[];
}
export interface Field {
code: string;
dataType: ReferenceFieldDataType;
value: string;
}
export interface DmpReference {
id: UUID;
dmp: DmpModel;
reference: Reference;
data: string;
createdAt: Date;
updatedAt: Date;
}
// old fetcher
export interface FetcherReference {
id: string;
name: string;
@ -42,4 +56,29 @@ export interface FetcherReference {
firstName: string;
lastName: string;
tag: string;
}
// Persist
export interface ReferencePersist {
id: UUID;
label: string;
type: ReferenceType;
description: string;
definition: DefinitionPersist;
reference: string;
abbreviation: string;
source: string;
sourceType: SourceType;
}
export interface DefinitionPersist {
fields?: FieldPersist[];
}
export interface FieldPersist {
code: string;
dataType: ReferenceFieldDataType;
value: string;
}