From bf8edfad921fa3709e2b7c1e5da734107f6daa3c Mon Sep 17 00:00:00 2001 From: amentis Date: Tue, 24 Oct 2023 18:47:13 +0300 Subject: [PATCH] add ExternalReference, DmpExternalReference entities --- .../eu/eudat/authorization/Permission.java | 11 + .../eu/eudat/commons/enums/SourceType.java | 28 +++ .../data/DmpExternalReferenceEntity.java | 62 +++++ .../eudat/data/ExternalReferenceEntity.java | 177 ++++++++++++++ .../ExternalReferencesTypeConverter.java | 11 + .../converters/enums/SourceTypeConverter.java | 11 + .../eu/eudat/model/DmpExternalReference.java | 50 ++++ .../eu/eudat/model/ExternalReference.java | 147 +++++++++++ .../builder/DmpExternalReferenceBuilder.java | 130 ++++++++++ .../builder/ExternalReferenceBuilder.java | 72 ++++++ .../DmpExternalReferenceCensor.java | 47 ++++ .../censorship/ExternalReferenceCensor.java | 48 ++++ .../deleter/DmpExternalReferenceDeleter.java | 72 ++++++ .../deleter/ExternalReferenceDeleter.java | 78 ++++++ .../query/DmpExternalReferenceQuery.java | 152 ++++++++++++ .../eudat/query/ExternalReferenceQuery.java | 230 ++++++++++++++++++ .../lookup/DmpExternalReferenceLookup.java | 30 +++ .../query/lookup/ExternalReferenceLookup.java | 90 +++++++ .../src/main/resources/config/permissions.yml | 42 ++++ 19 files changed, 1488 insertions(+) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/enums/SourceType.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/DmpExternalReferenceEntity.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/ExternalReferenceEntity.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/ExternalReferencesTypeConverter.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/SourceTypeConverter.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/DmpExternalReference.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/ExternalReference.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpExternalReferenceBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/ExternalReferenceBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpExternalReferenceCensor.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/censorship/ExternalReferenceCensor.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpExternalReferenceDeleter.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/deleter/ExternalReferenceDeleter.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/query/DmpExternalReferenceQuery.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/query/ExternalReferenceQuery.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpExternalReferenceLookup.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/query/lookup/ExternalReferenceLookup.java diff --git a/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java b/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java index 5937257bf..4a06422bd 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java +++ b/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java @@ -62,4 +62,15 @@ public final class Permission { public static String ViewDescriptionTemplateTypePage = "ViewDescriptionTemplateTypePage"; public static String ViewDmpBlueprintPage = "ViewDmpBlueprintPage"; + //ExternalReference + public static String BrowseExternalReference = "BrowseExternalReference"; + public static String EditExternalReference = "EditExternalReference"; + public static String DeleteExternalReference = "DeleteExternalReference"; + + //DmpExternalReference + public static String BrowseDmpExternalReference = "BrowseDmpExternalReference"; + public static String EditDmpExternalReference = "EditDmpExternalReference"; + public static String DeleteDmpExternalReference = "DeleteDmpExternalReference"; + + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/SourceType.java b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/SourceType.java new file mode 100644 index 000000000..3a9fd28ca --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/SourceType.java @@ -0,0 +1,28 @@ +package eu.eudat.commons.enums; + +import eu.eudat.data.converters.enums.DatabaseEnum; + +import java.util.Map; + +public enum SourceType implements DatabaseEnum { + + Internal((short) 0), + External((short) 1); + + private final Short value; + + SourceType(Short value) { + this.value = value; + } + + @Override + public Short getValue() { + return value; + } + + private static final Map map = EnumUtils.getEnumValueMap(SourceType.class); + + public static SourceType of(Short i) { + return map.get(i); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DmpExternalReferenceEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DmpExternalReferenceEntity.java new file mode 100644 index 000000000..c10468523 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DmpExternalReferenceEntity.java @@ -0,0 +1,62 @@ +package eu.eudat.data; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +import java.util.UUID; + +@Entity +@Table(name = "\"ExternalReference\"") +public class DmpExternalReferenceEntity { + + @Id + @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false) + private UUID id; + public static final String _id = "id"; + + @Column(name = "dmp_id", columnDefinition = "uuid", nullable = false) + private UUID dmpId; + public static final String _dmpId = "dmpId"; + + @Column(name = "reference_id", columnDefinition = "uuid", nullable = false) + private UUID referenceId; + public static final String _referenceId = "referenceId"; + + @Column(name = "data") + private String data; + public static final String _data = "data"; + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + public UUID getDmpId() { + return dmpId; + } + + public void setDmpId(UUID dmpId) { + this.dmpId = dmpId; + } + + public UUID getReferenceId() { + return referenceId; + } + + public void setReferenceId(UUID referenceId) { + this.referenceId = referenceId; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/ExternalReferenceEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/ExternalReferenceEntity.java new file mode 100644 index 000000000..8cb605ae1 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/data/ExternalReferenceEntity.java @@ -0,0 +1,177 @@ +package eu.eudat.data; + +import eu.eudat.commons.enums.ExternalReferencesType; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.SourceType; +import eu.eudat.data.converters.enums.ExternalReferencesTypeConverter; +import eu.eudat.data.converters.enums.IsActiveConverter; +import jakarta.persistence.*; +import org.hibernate.annotations.Type; + +import java.time.Instant; +import java.util.UUID; + +@Entity +@Table(name = "\"ExternalReference\"") +public class ExternalReferenceEntity { + + @Id + @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false) + private UUID id; + public static final String _id = "id"; + + @Column(name = "label", length = 500, nullable = false) + private String label; + public static final String _label = "label"; + + @Column(name = "type", nullable = false) + @Convert(converter = ExternalReferencesTypeConverter.class) + private ExternalReferencesType type; + public static final String _type = "type"; + + @Column(name = "description") + private String description; + public static final String _description = "description"; + + @Type(eu.eudat.configurations.typedefinition.XMLType.class) + @Column(name = "definition", columnDefinition = "xml") + private String definition; + public static final String _definition = "definition"; + + @Column(name = "reference", length = 1024, nullable = false) + private String reference; + public static final String _reference = "reference"; + + @Column(name = "abbreviation", length = 50) + private String abbreviation; + public static final String _abbreviation = "abbreviation"; + + @Column(name = "source", length = 1024) + private String source; + public static final String _source = "source"; + + @Column(name = "source_type", nullable = false) + private SourceType sourceType; + public static final String _sourceType = "sourceType"; + + @Column(name = "is_active", nullable = false) + @Convert(converter = IsActiveConverter.class) + private IsActive isActive; + public static final String _isActive = "isActive"; + + @Column(name = "created_at", nullable = false) + private Instant createdAt; + public static final String _createdAt = "createdAt"; + + @Column(name = "updated_at", nullable = false) + private Instant updatedAt; + public static final String _updatedAt = "updatedAt"; + + @Column(name = "created_by", columnDefinition = "uuid") + private UUID createdBy; + public static final String _createdBy = "createdBy"; + + 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 ExternalReferencesType getType() { + return type; + } + + public void setType(ExternalReferencesType type) { + this.type = type; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDefinition() { + return definition; + } + + public void setDefinition(String 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; + } + + public IsActive getIsActive() { + return isActive; + } + + public void setIsActive(IsActive isActive) { + this.isActive = isActive; + } + + public Instant getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Instant createdAt) { + this.createdAt = createdAt; + } + + public Instant getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Instant updatedAt) { + this.updatedAt = updatedAt; + } + + public UUID getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(UUID createdBy) { + this.createdBy = createdBy; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/ExternalReferencesTypeConverter.java b/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/ExternalReferencesTypeConverter.java new file mode 100644 index 000000000..a15b2a130 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/ExternalReferencesTypeConverter.java @@ -0,0 +1,11 @@ +package eu.eudat.data.converters.enums; + +import eu.eudat.commons.enums.ExternalReferencesType; +import jakarta.persistence.Converter; + +@Converter +public class ExternalReferencesTypeConverter extends DatabaseEnumConverter { + public ExternalReferencesType of(Short i) { + return ExternalReferencesType.of(i); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/SourceTypeConverter.java b/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/SourceTypeConverter.java new file mode 100644 index 000000000..573921637 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/SourceTypeConverter.java @@ -0,0 +1,11 @@ +package eu.eudat.data.converters.enums; + +import eu.eudat.commons.enums.SourceType; +import jakarta.persistence.Converter; + +@Converter +public class SourceTypeConverter extends DatabaseEnumConverter{ + public SourceType of(Short i) { + return SourceType.of(i); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/DmpExternalReference.java b/dmp-backend/core/src/main/java/eu/eudat/model/DmpExternalReference.java new file mode 100644 index 000000000..67deac0a8 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/DmpExternalReference.java @@ -0,0 +1,50 @@ +package eu.eudat.model; + +import java.util.UUID; + +public class DmpExternalReference { + + private UUID id; + public static final String _id = "id"; + + private DmpBlueprint dmp; + public static final String _dmp = "dmp"; + + private ExternalReference externalReference; + public static final String _externalReference = "externalReference"; + + private String data; + public static final String _data = "data"; + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + public DmpBlueprint getDmp() { + return dmp; + } + + public void setDmp(DmpBlueprint dmp) { + this.dmp = dmp; + } + + public ExternalReference getExternalReference() { + return externalReference; + } + + public void setExternalReference(ExternalReference externalReference) { + this.externalReference = externalReference; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/ExternalReference.java b/dmp-backend/core/src/main/java/eu/eudat/model/ExternalReference.java new file mode 100644 index 000000000..7f4f7c583 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/ExternalReference.java @@ -0,0 +1,147 @@ +package eu.eudat.model; + +import eu.eudat.commons.enums.ExternalReferencesType; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.SourceType; + +import java.time.Instant; +import java.util.UUID; + +public class ExternalReference { + + private UUID id; + public static final String _id = "id"; + + private String label; + public static final String _label = "label"; + + private ExternalReferencesType type; + public static final String _type = "type"; + + private String description; + public static final String _description = "description"; + + private String definition; + public static final String _definition = "definition"; + + private String reference; + public static final String _reference = "reference"; + + private String abbreviation; + public static final String _abbreviation = "abbreviation"; + + private String source; + public static final String _source = "source"; + + private SourceType sourceType; + public static final String _sourceType = "sourceType"; + + private IsActive isActive; + public static final String _isActive = "isActive"; + + private Instant createdAt; + public static final String _createdAt = "createdAt"; + + private Instant updatedAt; + public static final String _updatedAt = "updatedAt"; + + //private UserInfo createdBy; ToDo + //public static final String _createdBy = "createdBy"; + + 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 ExternalReferencesType getType() { + return type; + } + + public void setType(ExternalReferencesType type) { + this.type = type; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDefinition() { + return definition; + } + + public void setDefinition(String 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; + } + + public IsActive getIsActive() { + return isActive; + } + + public void setIsActive(IsActive isActive) { + this.isActive = isActive; + } + + public Instant getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Instant createdAt) { + this.createdAt = createdAt; + } + + public Instant getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Instant updatedAt) { + this.updatedAt = updatedAt; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpExternalReferenceBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpExternalReferenceBuilder.java new file mode 100644 index 000000000..25c7400ab --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpExternalReferenceBuilder.java @@ -0,0 +1,130 @@ +package eu.eudat.model.builder; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.DmpExternalReferenceEntity; +import eu.eudat.model.DmpBlueprint; +import eu.eudat.model.DmpExternalReference; +import eu.eudat.model.ExternalReference; +import eu.eudat.query.DmpBlueprintQuery; +import eu.eudat.query.ExternalReferenceQuery; +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; +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.*; +import java.util.stream.Collectors; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DmpExternalReferenceBuilder extends BaseBuilder{ + + private final BuilderFactory builderFactory; + private final QueryFactory queryFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public DmpExternalReferenceBuilder( + ConventionService conventionService, + BuilderFactory builderFactory, QueryFactory queryFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpExternalReferenceBuilder.class))); + this.builderFactory = builderFactory; + this.queryFactory = queryFactory; + } + + public DmpExternalReferenceBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (fields == null || data == null || fields.isEmpty()) + return new ArrayList<>(); + FieldSet externalReferenceFields = fields.extractPrefixed(this.asPrefix(DmpExternalReference._externalReference)); + Map externalReferenceItemsMap = this.collectExternalReferences(externalReferenceFields, data); + + FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(DmpExternalReference._dmp)); + Map dmpBlueprintItemsMap = this.collectDmps(dmpFields, data); + + List models = new ArrayList<>(); + for (DmpExternalReferenceEntity d : data) { + DmpExternalReference m = new DmpExternalReference(); + if (fields.hasField(this.asIndexer(DmpExternalReference._id))) m.setId(d.getId()); + if (fields.hasField(this.asIndexer(DmpExternalReference._data))) m.setData(d.getData()); + if(!externalReferenceFields.isEmpty() && externalReferenceItemsMap != null && externalReferenceItemsMap.containsKey(d.getReferenceId())){ + m.setExternalReference(externalReferenceItemsMap.get(d.getReferenceId())); + } + if(!dmpFields.isEmpty() && dmpBlueprintItemsMap != null && dmpBlueprintItemsMap.containsKey(d.getDmpId())){ + m.setDmp(dmpBlueprintItemsMap.get(d.getDmpId())); + } + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } + + private Map collectExternalReferences(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) return null; + this.logger.debug("checking related - {}", ExternalReference.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(ExternalReference._id))) { + itemMap = this.asEmpty( + data.stream().map(x -> x.getReferenceId()).distinct().collect(Collectors.toList()), + x -> { + ExternalReference item = new ExternalReference(); + item.setId(x); + return item; + }, + ExternalReference::getId); + } else { + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(ExternalReference._id); + ExternalReferenceQuery q = this.queryFactory.query(ExternalReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(x -> x.getReferenceId()).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(ExternalReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, ExternalReference::getId); + } + if (!fields.hasField(ExternalReference._id)) { + itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList()); + } + + return itemMap; + } + + private Map collectDmps(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) return null; + this.logger.debug("checking related - {}", DmpBlueprint.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(DmpBlueprint._id))) { + itemMap = this.asEmpty( + data.stream().map(x -> x.getDmpId()).distinct().collect(Collectors.toList()), + x -> { + DmpBlueprint item = new DmpBlueprint(); + item.setId(x); + return item; + }, + DmpBlueprint::getId); + } else { + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DmpBlueprint._id); + DmpBlueprintQuery q = this.queryFactory.query(DmpBlueprintQuery.class).authorize(this.authorize).ids(data.stream().map(x -> x.getDmpId()).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DmpBlueprint::getId); + } + if (!fields.hasField(DmpBlueprint._id)) { + itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList()); + } + + return itemMap; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/ExternalReferenceBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/ExternalReferenceBuilder.java new file mode 100644 index 000000000..57e10ec57 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/ExternalReferenceBuilder.java @@ -0,0 +1,72 @@ +package eu.eudat.model.builder; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.ExternalReferenceEntity; +import eu.eudat.model.ExternalReference; +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 ExternalReferenceBuilder extends BaseBuilder{ + + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public ExternalReferenceBuilder( + ConventionService conventionService, + BuilderFactory builderFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(ExternalReferenceBuilder.class))); + this.builderFactory = builderFactory; + } + + public ExternalReferenceBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (fields == null || data == null || fields.isEmpty()) + return new ArrayList<>(); + // FieldSet userInfoFields = fields.extractPrefixed(this.asPrefix(ExternalReference._createdBy)); + + List models = new ArrayList<>(); + for (ExternalReferenceEntity d : data) { + ExternalReference m = new ExternalReference(); + if (fields.hasField(this.asIndexer(ExternalReference._id))) m.setId(d.getId()); + if (fields.hasField(this.asIndexer(ExternalReference._label))) m.setLabel(d.getLabel()); + if (fields.hasField(this.asIndexer(ExternalReference._createdAt))) m.setCreatedAt(d.getCreatedAt()); + if (fields.hasField(this.asIndexer(ExternalReference._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); + if (fields.hasField(this.asIndexer(ExternalReference._isActive))) m.setIsActive(d.getIsActive()); + if (fields.hasField(this.asIndexer(ExternalReference._definition))) m.setReference(d.getDefinition()); + if (fields.hasField(this.asIndexer(ExternalReference._reference))) m.setReference(d.getReference()); + if (fields.hasField(this.asIndexer(ExternalReference._abbreviation))) m.setAbbreviation(d.getAbbreviation()); + if (fields.hasField(this.asIndexer(ExternalReference._description))) m.setDescription(d.getDescription()); + if (fields.hasField(this.asIndexer(ExternalReference._source))) m.setSource(d.getSource()); + if (fields.hasField(this.asIndexer(ExternalReference._sourceType))) m.setSourceType(d.getSourceType()); + if (fields.hasField(this.asIndexer(ExternalReference._type))) m.setType(d.getType()); + +// if (!userInfoFields.isEmpty() && d.getCreatedBy() != null){ +// //Todo +// } + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpExternalReferenceCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpExternalReferenceCensor.java new file mode 100644 index 000000000..bd372a41e --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpExternalReferenceCensor.java @@ -0,0 +1,47 @@ +package eu.eudat.model.censorship; + +import eu.eudat.authorization.Permission; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.DmpExternalReference; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.data.censor.CensorFactory; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DmpExternalReferenceCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpExternalReferenceCensor.class)); + + protected final AuthorizationService authService; + protected final CensorFactory censorFactory; + + public DmpExternalReferenceCensor(ConventionService conventionService, + AuthorizationService authService, + CensorFactory censorFactory) { + super(conventionService); + this.authService = authService; + this.censorFactory = censorFactory; + } + + public void censor(FieldSet fields, UUID userId) { + logger.debug(new DataLogEntry("censoring fields", fields)); + if (fields == null || fields.isEmpty()) + return; + + this.authService.authorizeForce(Permission.BrowseDmpExternalReference); + FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpExternalReference._dmp)); + this.censorFactory.censor(DmpBlueprintCensor.class).censor(dmpFields, userId); + FieldSet externalReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(DmpExternalReference._externalReference)); + this.censorFactory.censor(ExternalReferenceCensor.class).censor(externalReferenceFields, userId); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/ExternalReferenceCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/ExternalReferenceCensor.java new file mode 100644 index 000000000..fe2dfe760 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/ExternalReferenceCensor.java @@ -0,0 +1,48 @@ +package eu.eudat.model.censorship; + +import eu.eudat.authorization.Permission; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.DmpBlueprint; +import eu.eudat.model.ExternalReference; +import eu.eudat.model.censorship.dmpblueprintdefinition.DefinitionCensor; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.data.censor.CensorFactory; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ExternalReferenceCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceCensor.class)); + + protected final AuthorizationService authService; + protected final CensorFactory censorFactory; + + public ExternalReferenceCensor(ConventionService conventionService, + AuthorizationService authService, + CensorFactory censorFactory) { + super(conventionService); + this.authService = authService; + this.censorFactory = censorFactory; + } + + public void censor(FieldSet fields, UUID userId) { + logger.debug(new DataLogEntry("censoring fields", fields)); + if (fields == null || fields.isEmpty()) + return; + + this.authService.authorizeForce(Permission.BrowseExternalReference); + //ToDo + //FieldSet definitionFields = fields.extractPrefixed(this.asIndexerPrefix(ExternalReference._createdBy)); + //this.censorFactory.censor(UserInfo.class).censor(definitionFields, userId); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpExternalReferenceDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpExternalReferenceDeleter.java new file mode 100644 index 000000000..41f063322 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpExternalReferenceDeleter.java @@ -0,0 +1,72 @@ +package eu.eudat.model.deleter; + +import eu.eudat.data.DmpExternalReferenceEntity; +import eu.eudat.query.DmpExternalReferenceQuery; +import gr.cite.tools.data.deleter.Deleter; +import gr.cite.tools.data.deleter.DeleterFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.logging.LoggerService; +import gr.cite.tools.logging.MapLogEntry; +import jakarta.persistence.EntityManager; +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 javax.management.InvalidApplicationException; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DmpExternalReferenceDeleter implements Deleter { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpExternalReferenceDeleter.class)); + private final EntityManager entityManager; + + protected final QueryFactory queryFactory; + + protected final DeleterFactory deleterFactory; + + @Autowired + public DmpExternalReferenceDeleter( + EntityManager entityManager, + QueryFactory queryFactory, + DeleterFactory deleterFactory + ) { + this.entityManager = entityManager; + this.queryFactory = queryFactory; + this.deleterFactory = deleterFactory; + } + + public void deleteAndSaveByIds(List ids) throws InvalidApplicationException { + logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids)); + List data = this.queryFactory.query(DmpExternalReferenceQuery.class).ids(ids).collect(); + logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0)); + this.deleteAndSave(data); + } + + public void deleteAndSave(List data) throws InvalidApplicationException { + logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0)); + this.delete(data); + logger.trace("saving changes"); + this.entityManager.flush(); + logger.trace("changes saved"); + } + + public void delete(List data) throws InvalidApplicationException { + logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null || data.isEmpty()) + return; + + for (DmpExternalReferenceEntity item : data) { + logger.trace("deleting item {}", item.getId()); + logger.trace("updating item"); + this.entityManager.merge(item); + logger.trace("updated item"); + } + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/ExternalReferenceDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/ExternalReferenceDeleter.java new file mode 100644 index 000000000..4711da890 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/ExternalReferenceDeleter.java @@ -0,0 +1,78 @@ +package eu.eudat.model.deleter; + +import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.ExternalReferenceEntity; +import eu.eudat.query.ExternalReferenceQuery; +import gr.cite.tools.data.deleter.Deleter; +import gr.cite.tools.data.deleter.DeleterFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.logging.LoggerService; +import gr.cite.tools.logging.MapLogEntry; +import jakarta.persistence.EntityManager; +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 javax.management.InvalidApplicationException; +import java.time.Instant; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ExternalReferenceDeleter implements Deleter { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceDeleter.class)); + private final EntityManager entityManager; + + protected final QueryFactory queryFactory; + + protected final DeleterFactory deleterFactory; + + @Autowired + public ExternalReferenceDeleter( + EntityManager entityManager, + QueryFactory queryFactory, + DeleterFactory deleterFactory + ) { + this.entityManager = entityManager; + this.queryFactory = queryFactory; + this.deleterFactory = deleterFactory; + } + + public void deleteAndSaveByIds(List ids) throws InvalidApplicationException { + logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids)); + List data = this.queryFactory.query(ExternalReferenceQuery.class).ids(ids).collect(); + logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0)); + this.deleteAndSave(data); + } + + public void deleteAndSave(List data) throws InvalidApplicationException { + logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0)); + this.delete(data); + logger.trace("saving changes"); + this.entityManager.flush(); + logger.trace("changes saved"); + } + + public void delete(List data) throws InvalidApplicationException { + logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null || data.isEmpty()) + return; + + Instant now = Instant.now(); + + for (ExternalReferenceEntity item : data) { + logger.trace("deleting item {}", item.getId()); + item.setIsActive(IsActive.Inactive); + item.setUpdatedAt(now); + logger.trace("updating item"); + this.entityManager.merge(item); + logger.trace("updated item"); + } + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DmpExternalReferenceQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DmpExternalReferenceQuery.java new file mode 100644 index 000000000..a2a8ba61c --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DmpExternalReferenceQuery.java @@ -0,0 +1,152 @@ +package eu.eudat.query; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.data.DmpExternalReferenceEntity; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.data.query.FieldResolver; +import gr.cite.tools.data.query.QueryBase; +import gr.cite.tools.data.query.QueryContext; +import jakarta.persistence.Tuple; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.Predicate; +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 DmpExternalReferenceQuery extends QueryBase { + + private Collection ids; + + private Collection dmpIds; + + private Collection referenceIds; + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + + public DmpExternalReferenceQuery ids(UUID value) { + this.ids = List.of(value); + return this; + } + + public DmpExternalReferenceQuery ids(UUID... value) { + this.ids = Arrays.asList(value); + return this; + } + + public DmpExternalReferenceQuery ids(Collection values) { + this.ids = values; + return this; + } + + public DmpExternalReferenceQuery dmpIds(UUID value) { + this.dmpIds = List.of(value); + return this; + } + + public DmpExternalReferenceQuery dmpIds(UUID... value) { + this.dmpIds = Arrays.asList(value); + return this; + } + + public DmpExternalReferenceQuery dmpIds(Collection values) { + this.dmpIds = values; + return this; + } + + public DmpExternalReferenceQuery referenceIds(UUID value) { + this.referenceIds = List.of(value); + return this; + } + + public DmpExternalReferenceQuery referenceIds(UUID... value) { + this.referenceIds = Arrays.asList(value); + return this; + } + + public DmpExternalReferenceQuery referenceIds(Collection values) { + this.referenceIds = values; + return this; + } + + public DmpExternalReferenceQuery authorize(EnumSet values) { + this.authorize = values; + return this; + } + + private final UserScope userScope; + + private final AuthorizationService authService; + + public DmpExternalReferenceQuery( + UserScope userScope, + AuthorizationService authService + ) { + this.userScope = userScope; + this.authService = authService; + } + + @Override + protected Class entityClass() { + return DmpExternalReferenceEntity.class; + } + + @Override + protected Boolean isFalseQuery() { + return this.isEmpty(this.ids) || this.isEmpty(this.dmpIds) || this.isEmpty(this.referenceIds); + } + + @Override + protected Predicate applyFilters(QueryContext queryContext) { + List predicates = new ArrayList<>(); + if (this.ids != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpExternalReferenceEntity._id)); + for (UUID item : this.ids) + inClause.value(item); + predicates.add(inClause); + } + if (this.dmpIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpExternalReferenceEntity._dmpId)); + for (UUID item : this.ids) + inClause.value(item); + predicates.add(inClause); + } + if (this.referenceIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpExternalReferenceEntity._referenceId)); + for (UUID item : this.ids) + inClause.value(item); + predicates.add(inClause); + } + if (!predicates.isEmpty()) { + Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); + return queryContext.CriteriaBuilder.and(predicatesArray); + } else { + return null; + } + } + + @Override + protected DmpExternalReferenceEntity convert(Tuple tuple, Set columns) { + DmpExternalReferenceEntity item = new DmpExternalReferenceEntity(); + item.setId(QueryBase.convertSafe(tuple, columns, DmpExternalReferenceEntity._id, UUID.class)); + item.setReferenceId(QueryBase.convertSafe(tuple, columns, DmpExternalReferenceEntity._dmpId, UUID.class)); + item.setReferenceId(QueryBase.convertSafe(tuple, columns, DmpExternalReferenceEntity._referenceId, UUID.class)); + item.setData(QueryBase.convertSafe(tuple, columns, DmpExternalReferenceEntity._data, String.class)); + return item; + } + + @Override + protected String fieldNameOf(FieldResolver item) { + if (item.match(DmpExternalReferenceEntity._id)) return DmpExternalReferenceEntity._id; + else if (item.prefix(DmpExternalReferenceEntity._dmpId)) return DmpExternalReferenceEntity._dmpId; + else if (item.prefix(DmpExternalReferenceEntity._referenceId)) return DmpExternalReferenceEntity._referenceId; + else if (item.match(DmpExternalReferenceEntity._data)) return DmpExternalReferenceEntity._data; + else return null; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/ExternalReferenceQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/ExternalReferenceQuery.java new file mode 100644 index 000000000..a39a2f0d1 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/query/ExternalReferenceQuery.java @@ -0,0 +1,230 @@ +package eu.eudat.query; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.enums.ExternalReferencesType; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.SourceType; +import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.data.DmpBlueprintEntity; +import eu.eudat.data.ExternalReferenceEntity; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.data.query.FieldResolver; +import gr.cite.tools.data.query.QueryBase; +import gr.cite.tools.data.query.QueryContext; +import jakarta.persistence.Tuple; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.Predicate; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.time.Instant; +import java.util.*; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ExternalReferenceQuery extends QueryBase { + + private String like; + + private Collection ids; + + private Collection isActives; + + private Collection sourceTypes; + + private Collection externalReferenceTypes; + + private Collection excludedIds; + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + public ExternalReferenceQuery like(String value) { + this.like = value; + return this; + } + + public ExternalReferenceQuery ids(UUID value) { + this.ids = List.of(value); + return this; + } + + public ExternalReferenceQuery ids(UUID... value) { + this.ids = Arrays.asList(value); + return this; + } + + public ExternalReferenceQuery ids(Collection values) { + this.ids = values; + return this; + } + + public ExternalReferenceQuery isActive(IsActive value) { + this.isActives = List.of(value); + return this; + } + + public ExternalReferenceQuery isActive(IsActive... value) { + this.isActives = Arrays.asList(value); + return this; + } + + public ExternalReferenceQuery isActive(Collection values) { + this.isActives = values; + return this; + } + + public ExternalReferenceQuery externalReferenceTypes(ExternalReferencesType value) { + this.externalReferenceTypes = List.of(value); + return this; + } + + public ExternalReferenceQuery externalReferenceTypes(ExternalReferencesType... value) { + this.externalReferenceTypes = Arrays.asList(value); + return this; + } + + public ExternalReferenceQuery externalReferenceTypes(Collection values) { + this.externalReferenceTypes = values; + return this; + } + + public ExternalReferenceQuery excludedIds(Collection values) { + this.excludedIds = values; + return this; + } + + public ExternalReferenceQuery excludedIds(UUID value) { + this.excludedIds = List.of(value); + return this; + } + + public ExternalReferenceQuery excludedIds(UUID... value) { + this.excludedIds = Arrays.asList(value); + return this; + } + + public ExternalReferenceQuery sourceTypes(SourceType value) { + this.sourceTypes = List.of(value); + return this; + } + + public ExternalReferenceQuery sourceTypes(SourceType... value) { + this.sourceTypes = Arrays.asList(value); + return this; + } + + public ExternalReferenceQuery sourceTypes(Collection values) { + this.sourceTypes = values; + return this; + } + + public ExternalReferenceQuery authorize(EnumSet values) { + this.authorize = values; + return this; + } + + private final UserScope userScope; + + private final AuthorizationService authService; + + public ExternalReferenceQuery( + UserScope userScope, + AuthorizationService authService + ) { + this.userScope = userScope; + this.authService = authService; + } + + @Override + protected Class entityClass() { + return ExternalReferenceEntity.class; + } + + @Override + protected Boolean isFalseQuery() { + return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds) || this.isEmpty(this.externalReferenceTypes) || this.isEmpty(this.sourceTypes); + } + + @Override + protected Predicate applyFilters(QueryContext queryContext) { + List predicates = new ArrayList<>(); + if (this.ids != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._id)); + for (UUID item : this.ids) + inClause.value(item); + predicates.add(inClause); + } + if (this.like != null && !this.like.isEmpty()) { + predicates.add(queryContext.CriteriaBuilder.like(queryContext.Root.get(ExternalReferenceEntity._label), this.like)); + } + if (this.isActives != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._isActive)); + for (IsActive item : this.isActives) + inClause.value(item); + predicates.add(inClause); + } + if (this.sourceTypes != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._sourceType)); + for (SourceType item : this.sourceTypes) + inClause.value(item); + predicates.add(inClause); + } + if (this.externalReferenceTypes != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._type)); + for (ExternalReferencesType item : this.externalReferenceTypes) + inClause.value(item); + predicates.add(inClause); + } + if (this.excludedIds != null) { + CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpBlueprintEntity._id)); + for (UUID item : this.excludedIds) + notInClause.value(item); + predicates.add(notInClause.not()); + } + if (!predicates.isEmpty()) { + Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); + return queryContext.CriteriaBuilder.and(predicatesArray); + } else { + return null; + } + } + + @Override + protected ExternalReferenceEntity convert(Tuple tuple, Set columns) { + ExternalReferenceEntity item = new ExternalReferenceEntity(); + item.setId(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._id, UUID.class)); + item.setLabel(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._label, String.class)); + item.setDescription(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._description, String.class)); + item.setCreatedAt(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._createdAt, Instant.class)); + item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._updatedAt, Instant.class)); + item.setIsActive(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._isActive, IsActive.class)); + item.setDefinition(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._definition, String.class)); + item.setAbbreviation(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._abbreviation, String.class)); + item.setReference(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._reference, String.class)); + item.setSource(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._source, String.class)); + item.setSourceType(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._sourceType, SourceType.class)); + item.setType(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._type, ExternalReferencesType.class)); + //item.setCreatedBy(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._createdBy, UUID.class)); + return item; + } + + @Override + protected String fieldNameOf(FieldResolver item) { + if (item.match(ExternalReferenceEntity._id)) return ExternalReferenceEntity._id; + else if (item.match(ExternalReferenceEntity._label)) return ExternalReferenceEntity._label; + else if (item.match(ExternalReferenceEntity._description)) return ExternalReferenceEntity._description; + else if (item.match(ExternalReferenceEntity._createdAt)) return ExternalReferenceEntity._createdAt; + else if (item.match(ExternalReferenceEntity._updatedAt)) return ExternalReferenceEntity._updatedAt; + else if (item.match(ExternalReferenceEntity._isActive)) return ExternalReferenceEntity._isActive; + else if (item.match(ExternalReferenceEntity._definition)) return ExternalReferenceEntity._definition; + else if (item.match(ExternalReferenceEntity._abbreviation)) return ExternalReferenceEntity._abbreviation; + else if (item.match(ExternalReferenceEntity._reference)) return ExternalReferenceEntity._reference; + else if (item.match(ExternalReferenceEntity._source)) return ExternalReferenceEntity._source; + else if (item.match(ExternalReferenceEntity._sourceType)) return ExternalReferenceEntity._sourceType; + else if (item.match(ExternalReferenceEntity._type)) return ExternalReferenceEntity._type; + //else if (item.prefix(ExternalReferenceEntity._createdBy)) return ExternalReferenceEntity._createdBy; + else return null; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpExternalReferenceLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpExternalReferenceLookup.java new file mode 100644 index 000000000..affe22396 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpExternalReferenceLookup.java @@ -0,0 +1,30 @@ +package eu.eudat.query.lookup; + +import eu.eudat.query.DmpExternalReferenceQuery; +import gr.cite.tools.data.query.Lookup; +import gr.cite.tools.data.query.QueryFactory; + +import java.util.Collection; +import java.util.UUID; + +public class DmpExternalReferenceLookup extends Lookup { + + private Collection ids; + + private Collection dmpIds; + + private Collection referenceIds; + + + public DmpExternalReferenceQuery enrich(QueryFactory queryFactory) { + DmpExternalReferenceQuery query = queryFactory.query(DmpExternalReferenceQuery.class); + if (this.ids != null) query.ids(this.ids); + if (this.dmpIds != null) query.dmpIds(this.dmpIds); + if (this.referenceIds != null) query.referenceIds(this.referenceIds); + + this.enrichCommon(query); + + return query; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/ExternalReferenceLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/ExternalReferenceLookup.java new file mode 100644 index 000000000..3e991f483 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/ExternalReferenceLookup.java @@ -0,0 +1,90 @@ +package eu.eudat.query.lookup; + +import eu.eudat.commons.enums.ExternalReferencesType; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.SourceType; +import eu.eudat.query.ExternalReferenceQuery; +import gr.cite.tools.data.query.Lookup; +import gr.cite.tools.data.query.QueryFactory; + +import java.util.Collection; +import java.util.List; +import java.util.UUID; + +public class ExternalReferenceLookup extends Lookup { + + private String like; + + private List isActive; + + private Collection sourceTypes; + + private Collection externalReferenceTypes; + + private List ids; + + private List excludedIds; + + public String getLike() { + return like; + } + + public void setLike(String like) { + this.like = like; + } + + public List getIsActive() { + return isActive; + } + + public void setIsActive(List isActive) { + this.isActive = isActive; + } + + public List getIds() { + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } + + public List getExcludedIds() { + return excludedIds; + } + + public void setExcludedIds(List excludeIds) { + this.excludedIds = excludeIds; + } + + public Collection getSourceTypes() { + return sourceTypes; + } + + public void setSourceTypes(Collection sourceTypes) { + this.sourceTypes = sourceTypes; + } + + public Collection getExternalReferenceTypes() { + return externalReferenceTypes; + } + + public void setExternalReferenceTypes(Collection externalReferenceTypes) { + this.externalReferenceTypes = externalReferenceTypes; + } + + public ExternalReferenceQuery enrich(QueryFactory queryFactory) { + ExternalReferenceQuery query = queryFactory.query(ExternalReferenceQuery.class); + if (this.like != null) query.like(this.like); + if (this.isActive != null) query.isActive(this.isActive); + if (this.externalReferenceTypes != null) query.externalReferenceTypes(this.externalReferenceTypes); + if (this.sourceTypes != null) query.sourceTypes(this.sourceTypes); + if (this.ids != null) query.ids(this.ids); + if (this.excludedIds != null) query.excludedIds(this.excludedIds); + + this.enrichCommon(query); + + return query; + } + +} diff --git a/dmp-backend/web/src/main/resources/config/permissions.yml b/dmp-backend/web/src/main/resources/config/permissions.yml index 271d7dc52..5d5428d03 100644 --- a/dmp-backend/web/src/main/resources/config/permissions.yml +++ b/dmp-backend/web/src/main/resources/config/permissions.yml @@ -135,3 +135,45 @@ permissions: clients: [ ] allowAnonymous: false allowAuthenticated: false + + # ExternalReference Permissions + BrowseExternalReference: + roles: + - Admin + clients: [ ] + allowAnonymous: false + allowAuthenticated: false + EditExternalReference: + roles: + - Admin + clients: [ ] + allowAnonymous: false + allowAuthenticated: false + DeleteExternalReference: + roles: + - Admin + claims: [ ] + clients: [ ] + allowAnonymous: false + allowAuthenticated: false + + # DmpExternalReference Permissions + BrowseDmpExternalReference: + roles: + - Admin + clients: [ ] + allowAnonymous: false + allowAuthenticated: false + EditDmpExternalReference: + roles: + - Admin + clients: [ ] + allowAnonymous: false + allowAuthenticated: false + DeleteDmpExternalReference: + roles: + - Admin + claims: [ ] + clients: [ ] + allowAnonymous: false + allowAuthenticated: false