From 1469e2218518a500c13b3f8c2d73572e6fe75268 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Tue, 7 Nov 2023 12:36:36 +0200 Subject: [PATCH] description refactor --- .../eu/eudat/authorization/Permission.java | 5 + .../java/eu/eudat/data/DescriptionEntity.java | 48 ++--- .../eu/eudat/data/DescriptionTagEntity.java | 24 +-- .../eudat/data/DescriptionTemplateEntity.java | 12 +- .../main/java/eu/eudat/model/Description.java | 6 +- .../model/builder/DescriptionBuilder.java | 160 ++++++++++---- .../model/builder/DescriptionTagBuilder.java | 143 +++++++++++++ .../builder/DescriptionTemplateBuilder.java | 6 +- .../eu/eudat/model/builder/TagBuilder.java | 57 +++++ .../FieldBuilder.java | 62 ++++++ .../PropertyDefinitionBuilder.java | 61 ++++++ .../model/censorship/DescriptionCensor.java | 20 ++ .../censorship/DescriptionTagCensor.java | 51 +++++ .../eu/eudat/model/censorship/TagCensor.java | 48 +++++ .../descriptionproperties/FieldCensor.java | 39 ++++ .../PropertyDefinitionCensor.java | 49 +++++ .../model/deleter/DescriptionDeleter.java | 29 ++- .../model/deleter/DescriptionTagDeleter.java | 79 +++++++ .../deleter/DescriptionTemplateDeleter.java | 3 +- .../DescriptionTemplateTypeDeleter.java | 22 +- .../eu/eudat/model/deleter/DmpDeleter.java | 3 + .../eudat/model/deleter/ReferenceDeleter.java | 27 ++- .../eu/eudat/model/deleter/TagDeleter.java | 88 ++++++++ .../model/descriptionproperties/Field.java | 12 +- .../PropertyDefinition.java | 7 + .../deposit/DmpEntityDepositMapper.java | 2 +- .../java/eu/eudat/query/DescriptionQuery.java | 63 ++---- .../query/DescriptionReferenceQuery.java | 35 +--- .../eu/eudat/query/DescriptionTagQuery.java | 196 ++++++++++++++++++ .../eudat/query/DescriptionTemplateQuery.java | 12 +- .../query/DescriptionTemplateTypeQuery.java | 8 - .../eu/eudat/query/DmpBlueprintQuery.java | 6 - .../query/DmpDescriptionTemplateQuery.java | 8 - .../java/eu/eudat/query/ReferenceQuery.java | 8 - .../main/java/eu/eudat/query/TagQuery.java | 188 +++++++++++++++++ .../query/UserDescriptionTemplateQuery.java | 4 - .../query/lookup/DescriptionTagLookup.java | 76 +++++++ .../java/eu/eudat/query/lookup/TagLookup.java | 76 +++++++ .../description/DescriptionServiceImpl.java | 4 +- .../DescriptionTemplateServiceImpl.java | 6 +- .../eu/eudat/controllers/FileController.java | 2 +- .../entity/DatasetProfileBuilder.java | 2 +- .../managers/DataManagementPlanManager.java | 34 +-- .../eudat/logic/managers/DatasetManager.java | 50 ++--- .../logic/managers/DatasetWizardManager.java | 2 +- .../eudat/logic/managers/MetricsManager.java | 5 +- .../logic/mapper/elastic/DatasetMapper.java | 2 +- .../eudat/logic/mapper/elastic/DmpMapper.java | 2 +- .../mapper/prefilling/PrefillingMapper.java | 2 +- .../models/rda/mapper/DatasetRDAMapper.java | 6 +- .../src/main/resources/config/permissions.yml | 21 ++ 51 files changed, 1601 insertions(+), 280 deletions(-) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionTagBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/TagBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/FieldBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionTagCensor.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/censorship/TagCensor.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/FieldCensor.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionCensor.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTagDeleter.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/deleter/TagDeleter.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTagQuery.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/query/TagQuery.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/query/lookup/DescriptionTagLookup.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/query/lookup/TagLookup.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 1f67d0a30..adf839d65 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 @@ -81,6 +81,11 @@ public final class Permission { public static String EditReference = "EditReference"; public static String DeleteReference = "DeleteReference"; + //Tag + public static String BrowseTag = "BrowseTag"; + public static String EditTag = "EditTag"; + public static String DeleteTag = "DeleteTag"; + //DmpReference public static String BrowseDmpReference = "BrowseDmpReference"; public static String EditDmpReference = "EditDmpReference"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java index 91005ea23..5f295a9ad 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java @@ -32,9 +32,9 @@ public class DescriptionEntity implements DataEntity { public static final String _label = "label"; @Column(name = "dmp", columnDefinition = "uuid", nullable = false) - private UUID dmp; + private UUID dmpId; - public static final String _dmp = "dmp"; + public static final String _dmpId = "dmpId"; @Column(name = "properties") private String properties; @@ -42,9 +42,9 @@ public class DescriptionEntity implements DataEntity { public static final String _properties = "properties"; @Column(name = "description_template", columnDefinition = "uuid", nullable = false) - private UUID descriptionTemplate; + private UUID descriptionTemplateId; - public static final String _descriptionTemplate = "descriptionTemplate"; + public static final String _descriptionTemplateId = "descriptionTemplateId"; @Column(name = "status", nullable = false) @Convert(converter = DescriptionStatusConverter.class) @@ -80,14 +80,14 @@ public class DescriptionEntity implements DataEntity { public static final String _finalizedAt = "finalizedAt"; @Column(name = "created_by", columnDefinition = "uuid", nullable = false) - private UUID createdBy; + private UUID createdById; - public static final String _createdBy = "createdBy"; + public static final String _createdById = "createdById"; @Column(name = "dmp_description_template", columnDefinition = "uuid", nullable = false) - private UUID dmpDescriptionTemplate; + private UUID dmpDescriptionTemplateId; - public static final String _dmpDescriptionTemplate = "dmpDescriptionTemplate"; + public static final String _dmpDescriptionTemplateId = "dmpDescriptionTemplateId"; public UUID getId() { return id; @@ -105,12 +105,12 @@ public class DescriptionEntity implements DataEntity { this.label = label; } - public UUID getDmp() { - return dmp; + public UUID getDmpId() { + return dmpId; } - public void setDmp(UUID dmp) { - this.dmp = dmp; + public void setDmpId(UUID dmpId) { + this.dmpId = dmpId; } public String getProperties() { @@ -121,12 +121,12 @@ public class DescriptionEntity implements DataEntity { this.properties = properties; } - public UUID getDescriptionTemplate() { - return descriptionTemplate; + public UUID getDescriptionTemplateId() { + return descriptionTemplateId; } - public void setDescriptionTemplate(UUID descriptionTemplate) { - this.descriptionTemplate = descriptionTemplate; + public void setDescriptionTemplateId(UUID descriptionTemplateId) { + this.descriptionTemplateId = descriptionTemplateId; } public DescriptionStatus getStatus() { @@ -177,20 +177,20 @@ public class DescriptionEntity implements DataEntity { this.finalizedAt = finalizedAt; } - public UUID getCreatedBy() { - return createdBy; + public UUID getCreatedById() { + return createdById; } - public void setCreatedBy(UUID createdBy) { - this.createdBy = createdBy; + public void setCreatedById(UUID createdById) { + this.createdById = createdById; } - public UUID getDmpDescriptionTemplate() { - return dmpDescriptionTemplate; + public UUID getDmpDescriptionTemplateId() { + return dmpDescriptionTemplateId; } - public void setDmpDescriptionTemplate(UUID dmpDescriptionTemplate) { - this.dmpDescriptionTemplate = dmpDescriptionTemplate; + public void setDmpDescriptionTemplateId(UUID dmpDescriptionTemplateId) { + this.dmpDescriptionTemplateId = dmpDescriptionTemplateId; } @Override diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTagEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTagEntity.java index cbb24f5d2..fdc88bb78 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTagEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTagEntity.java @@ -19,14 +19,14 @@ public class DescriptionTagEntity { public static final String _id = "id"; @Column(name = "description", columnDefinition = "uuid", nullable = false) - private UUID description; + private UUID descriptionId; - public static final String _description = "description"; + public static final String _descriptionId = "descriptionId"; @Column(name = "tag", columnDefinition = "uuid", nullable = false) - private UUID tag; + private UUID tagId; - public static final String _tag = "tag"; + public static final String _tagId = "tagId"; @Column(name = "created_at") @Convert(converter = DateToUTCConverter.class) @@ -54,20 +54,20 @@ public class DescriptionTagEntity { this.id = id; } - public UUID getDescription() { - return description; + public UUID getDescriptionId() { + return descriptionId; } - public void setDescription(UUID description) { - this.description = description; + public void setDescriptionId(UUID descriptionId) { + this.descriptionId = descriptionId; } - public UUID getTag() { - return tag; + public UUID getTagId() { + return tagId; } - public void setTag(UUID tag) { - this.tag = tag; + public void setTagId(UUID tagId) { + this.tagId = tagId; } public Instant getCreatedAt() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java index a485dbd04..d3cc5145c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionTemplateEntity.java @@ -67,8 +67,8 @@ public class DescriptionTemplateEntity implements DataEntity authorize = EnumSet.of(AuthorizationFlags.None); @@ -39,10 +40,11 @@ public class DescriptionBuilder extends BaseBuilder values) { @@ -60,43 +62,41 @@ public class DescriptionBuilder extends BaseBuilder dmpItemsMap = this.collectDmps(dmpFields, data); + FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asPrefix(Description._descriptionTemplate)); + Map descriptionTemplateItemsMap = this.collectDescriptionTemplates(descriptionTemplateFields, data); + + FieldSet dmpDescriptionTemplateFields = fields.extractPrefixed(this.asPrefix(Description._dmpDescriptionTemplate)); + Map dmpDescriptionTemplateItemsMap = this.collectDmpDescriptionTemplates(dmpDescriptionTemplateFields, data); + FieldSet descriptionReferencesFields = fields.extractPrefixed(this.asPrefix(Description._descriptionReferences)); Map> descriptionReferencesMap = this.collectDescriptionReferences(descriptionReferencesFields, data); + FieldSet descriptionTagsFields = fields.extractPrefixed(this.asPrefix(Description._descriptionTags)); + Map> descriptionTagsMap = this.collectDescriptionTags(descriptionTagsFields, data); + + FieldSet definitionPropertiesFields = fields.extractPrefixed(this.asPrefix(Description._properties)); List models = new ArrayList<>(); for (DescriptionEntity d : data) { Description m = new Description(); - if (fields.hasField(this.asIndexer(Description._id))) - m.setId(d.getId()); - if (fields.hasField(this.asIndexer(Description._label))) - m.setLabel(d.getLabel()); -// if (fields.hasField(this.asIndexer(Description._properties))) -// m.setProperties(d.getProperties()); -// if (fields.hasField(this.asIndexer(Description._profile))) -// m.setProfile(d.getDescriptionTemplate()); - if (fields.hasField(this.asIndexer(Description._status))) - m.setStatus(d.getStatus()); - if (fields.hasField(this.asIndexer(Description._description))) - m.setDescription(d.getDescription()); -// if (fields.hasField(this.asIndexer(Description._creator))) -// m.setCreatedBy(d.getDmpDescriptionTemplate()); -// if (fields.hasField(this.asIndexer(Description._createdAt))) -// m.setCreatedAt(d.getCreatedAt()); - if (fields.hasField(this.asIndexer(Description._updatedAt))) - m.setUpdatedAt(d.getUpdatedAt()); - if (fields.hasField(this.asIndexer(Description._isActive))) - m.setIsActive(d.getIsActive()); - if (fields.hasField(this.asIndexer(Description._finalizedAt))) - m.setFinalizedAt(d.getFinalizedAt()); - if (fields.hasField(this.asIndexer(Description._hash))) - m.setHash(this.hashValue(d.getUpdatedAt())); - - if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmp())) - m.setDmp(dmpItemsMap.get(d.getDmp())); - - if (!descriptionReferencesFields.isEmpty() && descriptionReferencesMap != null && descriptionReferencesMap.containsKey(d.getId())) - m.setDescriptionReferences(descriptionReferencesMap.get(d.getId())); - + if (fields.hasField(this.asIndexer(Description._id))) m.setId(d.getId()); + if (fields.hasField(this.asIndexer(Description._label))) m.setLabel(d.getLabel()); + if (fields.hasField(this.asIndexer(Description._status))) m.setStatus(d.getStatus()); + if (fields.hasField(this.asIndexer(Description._description))) m.setDescription(d.getDescription()); + if (fields.hasField(this.asIndexer(Description._createdBy))) m.setCreatedBy(d.getCreatedById()); + if (fields.hasField(this.asIndexer(Description._createdAt))) m.setCreatedAt(d.getCreatedAt()); + if (fields.hasField(this.asIndexer(Description._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); + if (fields.hasField(this.asIndexer(Description._isActive))) m.setIsActive(d.getIsActive()); + if (fields.hasField(this.asIndexer(Description._finalizedAt))) m.setFinalizedAt(d.getFinalizedAt()); + if (fields.hasField(this.asIndexer(Description._hash))) m.setHash(this.hashValue(d.getUpdatedAt())); + if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())) m.setDmp(dmpItemsMap.get(d.getDmpId())); + if (!descriptionTemplateFields.isEmpty() && descriptionTemplateItemsMap != null && descriptionTemplateItemsMap.containsKey(d.getDmpId())) m.setDescriptionTemplate(descriptionTemplateItemsMap.get(d.getDescriptionTemplateId())); + if (!dmpDescriptionTemplateFields.isEmpty() && dmpDescriptionTemplateItemsMap != null && dmpDescriptionTemplateItemsMap.containsKey(d.getDmpId())) m.setDmpDescriptionTemplate(dmpDescriptionTemplateItemsMap.get(d.getDmpDescriptionTemplateId())); + if (!descriptionReferencesFields.isEmpty() && descriptionReferencesMap != null && descriptionReferencesMap.containsKey(d.getId())) m.setDescriptionReferences(descriptionReferencesMap.get(d.getId())); + if (!descriptionTagsFields.isEmpty() && descriptionTagsMap != null && descriptionTagsMap.containsKey(d.getId())) m.setDescriptionTags(descriptionTagsMap.get(d.getId())); + if (!definitionPropertiesFields.isEmpty() && d.getProperties() != null){ + PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties()); + m.setProperties(this.builderFactory.builder(PropertyDefinitionBuilder.class).authorize(this.authorize).build(definitionPropertiesFields, propertyDefinition)); + } models.add(m); } @@ -113,7 +113,7 @@ public class DescriptionBuilder extends BaseBuilder itemMap; if (!fields.hasOtherField(this.asIndexer(Dmp._id))) { itemMap = this.asEmpty( - data.stream().map(DescriptionEntity::getDmp).distinct().collect(Collectors.toList()), + data.stream().map(DescriptionEntity::getDmpId).distinct().collect(Collectors.toList()), x -> { Dmp item = new Dmp(); item.setId(x); @@ -122,7 +122,7 @@ public class DescriptionBuilder extends BaseBuilder collectDescriptionTemplates(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(DescriptionTemplate._id))) { + itemMap = this.asEmpty( + data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()), + x -> { + DescriptionTemplate item = new DescriptionTemplate(); + item.setId(x); + return item; + }, + DescriptionTemplate::getId); + } else { + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._id); + DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DescriptionTemplate::getId); + } + if (!fields.hasField(DescriptionTemplate._id)) { + itemMap.forEach((id, item) -> { + if (item != null) + item.setId(null); + }); + } + + return itemMap; + } + + private Map collectDmpDescriptionTemplates(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", DmpDescriptionTemplate.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(DmpDescriptionTemplate._id))) { + itemMap = this.asEmpty( + data.stream().map(DescriptionEntity::getDmpDescriptionTemplateId).distinct().collect(Collectors.toList()), + x -> { + DmpDescriptionTemplate item = new DmpDescriptionTemplate(); + item.setId(x); + return item; + }, + DmpDescriptionTemplate::getId); + } else { + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DmpDescriptionTemplate._id); + DmpDescriptionTemplateQuery q = this.queryFactory.query(DmpDescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDmpDescriptionTemplateId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DmpDescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DmpDescriptionTemplate::getId); + } + if (!fields.hasField(DmpDescriptionTemplate._id)) { + itemMap.forEach((id, item) -> { + if (item != null) + item.setId(null); + }); + } + + return itemMap; + } + private Map> collectDescriptionReferences(FieldSet fields, List data) throws MyApplicationException { if (fields.isEmpty() || data.isEmpty()) return null; this.logger.debug("checking related - {}", DescriptionReference.class.getSimpleName()); @@ -144,7 +204,25 @@ public class DescriptionBuilder extends BaseBuilder x.getDescription().getId()); - if (!fields.hasField(this.asIndexer(DmpReference._dmp, Dmp._id))) { + if (!fields.hasField(this.asIndexer(DescriptionReference._description, Description._id))) { + itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDescription() != null).peek(x -> { + x.getDescription().setId(null); + }); + } + + return itemMap; + } + + private Map> collectDescriptionTags(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) return null; + this.logger.debug("checking related - {}", DescriptionTag.class.getSimpleName()); + + Map> itemMap; + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DescriptionTag._description, Description._id)); + DescriptionTagQuery query = this.queryFactory.query(DescriptionTagQuery.class).authorize(this.authorize).descriptionIds(data.stream().map(DescriptionEntity::getId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DescriptionTagBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDescription().getId()); + + if (!fields.hasField(this.asIndexer(DescriptionTag._description, Description._id))) { itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDescription() != null).peek(x -> { x.getDescription().setId(null); }); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionTagBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionTagBuilder.java new file mode 100644 index 000000000..5b36794a2 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionTagBuilder.java @@ -0,0 +1,143 @@ +package eu.eudat.model.builder; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.DescriptionTagEntity; +import eu.eudat.model.Description; +import eu.eudat.model.DescriptionTag; +import eu.eudat.model.Tag; +import eu.eudat.query.DescriptionQuery; +import eu.eudat.query.TagQuery; +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 DescriptionTagBuilder extends BaseBuilder { + + private final BuilderFactory builderFactory; + + private final QueryFactory queryFactory; + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public DescriptionTagBuilder( + ConventionService conventionService, + BuilderFactory builderFactory, QueryFactory queryFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTagBuilder.class))); + this.builderFactory = builderFactory; + this.queryFactory = queryFactory; + } + + public DescriptionTagBuilder 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 referenceFields = fields.extractPrefixed(this.asPrefix(DescriptionTag._tag)); + Map referenceItemsMap = this.collectTags(referenceFields, data); + + FieldSet descriptionFields = fields.extractPrefixed(this.asPrefix(DescriptionTag._description)); + Map descriptionItemsMap = this.collectDescriptions(descriptionFields, data); + + List models = new ArrayList<>(); + + for (DescriptionTagEntity d : data) { + DescriptionTag m = new DescriptionTag(); + if (fields.hasField(this.asIndexer(DescriptionTag._id))) m.setId(d.getId()); + if (fields.hasField(this.asIndexer(DescriptionTag._createdAt))) m.setCreatedAt(d.getCreatedAt()); + if (fields.hasField(this.asIndexer(DescriptionTag._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); + if (fields.hasField(this.asIndexer(DescriptionTag._isActive))) m.setIsActive(d.getIsActive()); + if (!referenceFields.isEmpty() && referenceItemsMap != null && referenceItemsMap.containsKey(d.getTagId())) m.setTag(referenceItemsMap.get(d.getTagId())); + if (!descriptionFields.isEmpty() && descriptionItemsMap != null && descriptionItemsMap.containsKey(d.getDescriptionId())) m.setDescription(descriptionItemsMap.get(d.getDescriptionId())); + + models.add(m); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } + + private Map collectDescriptions(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", Description.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(Tag._id))) { + itemMap = this.asEmpty( + data.stream().map(DescriptionTagEntity::getDescriptionId).distinct().collect(Collectors.toList()), + x -> { + Description item = new Description(); + item.setId(x); + return item; + }, + Description::getId); + } else { + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Tag._id); + DescriptionQuery q = this.queryFactory.query(DescriptionQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionTagEntity::getDescriptionId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DescriptionBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Description::getId); + } + if (!fields.hasField(Description._id)) { + itemMap.forEach((id, item) -> { + if (item != null) + item.setId(null); + }); + } + + return itemMap; + } + + private Map collectTags(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", Tag.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(Tag._id))) { + itemMap = this.asEmpty( + data.stream().map(DescriptionTagEntity::getTagId).distinct().collect(Collectors.toList()), + x -> { + Tag item = new Tag(); + item.setId(x); + return item; + }, + Tag::getId); + } else { + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Tag._id); + TagQuery q = this.queryFactory.query(TagQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionTagEntity::getTagId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(TagBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Tag::getId); + } + if (!fields.hasField(Tag._id)) { + itemMap.forEach((id, item) -> { + if (item != null) + item.setId(null); + }); + } + + return itemMap; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionTemplateBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionTemplateBuilder.java index 602d11ab5..978dabe86 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionTemplateBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionTemplateBuilder.java @@ -85,7 +85,7 @@ public class DescriptionTemplateBuilder extends BaseBuilder itemMap = null; if (!fields.hasOtherField(this.asIndexer(DescriptionTemplateType._id))) { itemMap = this.asEmpty( - datas.stream().map(DescriptionTemplateEntity::getType).distinct().collect(Collectors.toList()), + datas.stream().map(DescriptionTemplateEntity::getTypeId).distinct().collect(Collectors.toList()), x -> { DescriptionTemplateType item = new DescriptionTemplateType(); item.setId(x); @@ -108,7 +108,7 @@ public class DescriptionTemplateBuilder extends BaseBuilder x.getId()); } else { FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplateType._id); - DescriptionTemplateTypeQuery q = this.queryFactory.query(DescriptionTemplateTypeQuery.class).ids(datas.stream().map(DescriptionTemplateEntity::getType).distinct().collect(Collectors.toList())); + DescriptionTemplateTypeQuery q = this.queryFactory.query(DescriptionTemplateTypeQuery.class).ids(datas.stream().map(DescriptionTemplateEntity::getTypeId).distinct().collect(Collectors.toList())); itemMap = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).asForeignKey(q, clone, DescriptionTemplateType::getId); } if (!fields.hasField(DescriptionTemplateType._id)) { diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/TagBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/TagBuilder.java new file mode 100644 index 000000000..8b8fb5a11 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/TagBuilder.java @@ -0,0 +1,57 @@ +package eu.eudat.model.builder; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.TagEntity; +import eu.eudat.model.Tag; +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 TagBuilder extends BaseBuilder{ + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public TagBuilder( + ConventionService conventionService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(TagBuilder.class))); + } + + public TagBuilder 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<>(); + + List models = new ArrayList<>(); + for (TagEntity d : data) { + Tag m = new Tag(); + if (fields.hasField(this.asIndexer(Tag._id))) m.setId(d.getId()); + if (fields.hasField(this.asIndexer(Tag._label))) m.setLabel(d.getLabel()); + if (fields.hasField(this.asIndexer(Tag._createdAt))) m.setCreatedAt(d.getCreatedAt()); + if (fields.hasField(this.asIndexer(Tag._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); + if (fields.hasField(this.asIndexer(Tag._isActive))) m.setIsActive(d.getIsActive()); + if (fields.hasField(this.asIndexer(Tag._createdBy))) m.setCreatedBy(d.getCreatedBy()); + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/FieldBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/FieldBuilder.java new file mode 100644 index 000000000..aaa506ecd --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/FieldBuilder.java @@ -0,0 +1,62 @@ +package eu.eudat.model.builder.descriptionpropertiesdefinition; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.types.description.FieldEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.BaseBuilder; +import eu.eudat.model.descriptionproperties.Field; +import eu.eudat.service.fielddatahelper.FieldDataHelperServiceProvider; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component("descriptionpropertiesdefinitionFieldbuilder") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class FieldBuilder extends BaseBuilder { + + private final BuilderFactory builderFactory; + private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public FieldBuilder( + ConventionService conventionService, BuilderFactory builderFactory, FieldDataHelperServiceProvider fieldDataHelperServiceProvider) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldBuilder.class))); + this.builderFactory = builderFactory; + this.fieldDataHelperServiceProvider = fieldDataHelperServiceProvider; + } + + public FieldBuilder authorize(EnumSet values) { + 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<>(); + + + List models = new ArrayList<>(); + for (FieldEntity d : data) { + Field m = new Field(); + if (fields.hasField(this.asIndexer(Field._key))) m.setKey(d.getKey()); + if (fields.hasField(this.asIndexer(Field._value))) m.setValue(d.getValue()); + + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionBuilder.java new file mode 100644 index 000000000..6346f306c --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptionpropertiesdefinition/PropertyDefinitionBuilder.java @@ -0,0 +1,61 @@ +package eu.eudat.model.builder.descriptionpropertiesdefinition; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.types.description.PropertyDefinitionEntity; +import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.BaseBuilder; +import eu.eudat.model.descriptiontemplatedefinition.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 eu.eudat.model.descriptionproperties.PropertyDefinition; + +import java.util.*; + +@Component("descriptionpropertiesdefinitionbuilder") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class PropertyDefinitionBuilder extends BaseBuilder { + + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public PropertyDefinitionBuilder( + ConventionService conventionService, BuilderFactory builderFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(PropertyDefinitionBuilder.class))); + this.builderFactory = builderFactory; + } + + public PropertyDefinitionBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (fields == null || data == null || fields.isEmpty()) + return new ArrayList<>(); + + //Not Bulk Build because is XML no interaction with db + FieldSet fieldsFields = fields.extractPrefixed(this.asPrefix(PropertyDefinition._fields)); + + List models = new ArrayList<>(); + for (PropertyDefinitionEntity d : data) { + PropertyDefinition m = new PropertyDefinition(); + if (!fieldsFields.isEmpty() && d.getFields() != null) m.setFields(this.builderFactory.builder(FieldBuilder.class).authorize(this.authorize).build(fieldsFields, d.getFields())); + 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/DescriptionCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionCensor.java index 15ee3aae7..97128818c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionCensor.java @@ -3,6 +3,7 @@ package eu.eudat.model.censorship; import eu.eudat.authorization.Permission; import eu.eudat.convention.ConventionService; import eu.eudat.model.Description; +import eu.eudat.model.censorship.descriptionproperties.PropertyDefinitionCensor; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.fieldset.FieldSet; @@ -40,6 +41,25 @@ public class DescriptionCensor extends BaseCensor { FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(Description._dmp)); this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId); + + FieldSet descriptionReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(Description._descriptionReferences)); + this.censorFactory.censor(DescriptionReferenceCensor.class).censor(descriptionReferenceFields, userId); + + FieldSet descriptionTagsFields = fields.extractPrefixed(this.asIndexerPrefix(Description._descriptionTags)); + this.censorFactory.censor(DescriptionTagCensor.class).censor(descriptionTagsFields, userId); + + FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(Description._descriptionTemplate)); + this.censorFactory.censor(DescriptionTemplateCensor.class).censor(descriptionTemplateFields, userId); + + FieldSet dmpDescriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(Description._dmpDescriptionTemplate)); + this.censorFactory.censor(DmpDescriptionTemplateCensor.class).censor(dmpDescriptionTemplateFields, userId); + + FieldSet propertiesFields = fields.extractPrefixed(this.asIndexerPrefix(Description._properties)); + this.censorFactory.censor(PropertyDefinitionCensor.class).censor(propertiesFields, userId); + + //ToDo +// FieldSet createdByFields = fields.extractPrefixed(this.asIndexerPrefix(Description._createdBy)); +// this.censorFactory.censor(UserInfo.class).censor(createdByFields, userId); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionTagCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionTagCensor.java new file mode 100644 index 000000000..5babfb353 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionTagCensor.java @@ -0,0 +1,51 @@ +package eu.eudat.model.censorship; + +import eu.eudat.authorization.Permission; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.DescriptionReference; +import eu.eudat.model.DescriptionTag; +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.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DescriptionTagCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTagCensor.class)); + + protected final AuthorizationService authService; + + protected final CensorFactory censorFactory; + + @Autowired + public DescriptionTagCensor(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.BrowseDescriptionReference); + FieldSet descriptionFields = fields.extractPrefixed(this.asIndexerPrefix(DescriptionTag._description)); + this.censorFactory.censor(DescriptionCensor.class).censor(descriptionFields, userId); + FieldSet tagFields = fields.extractPrefixed(this.asIndexerPrefix(DescriptionTag._tag)); + this.censorFactory.censor(TagCensor.class).censor(tagFields, userId); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/TagCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/TagCensor.java new file mode 100644 index 000000000..43e60de25 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/TagCensor.java @@ -0,0 +1,48 @@ +package eu.eudat.model.censorship; + +import eu.eudat.authorization.Permission; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.Reference; +import eu.eudat.model.Tag; +import eu.eudat.model.censorship.referencedefinition.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 TagCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TagCensor.class)); + + protected final AuthorizationService authService; + protected final CensorFactory censorFactory; + + public TagCensor(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.BrowseTag); + //ToDo +// FieldSet createdByFields = fields.extractPrefixed(this.asIndexerPrefix(Tag._createdBy)); +// this.censorFactory.censor(UserInfo.class).censor(createdByFields, userId); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/FieldCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/FieldCensor.java new file mode 100644 index 000000000..1e3e9eef0 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/FieldCensor.java @@ -0,0 +1,39 @@ +package eu.eudat.model.censorship.descriptionproperties; + +import eu.eudat.authorization.Permission; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.censorship.BaseCensor; +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component("descriptionpropertiesfieldcensor") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class FieldCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(FieldCensor.class)); + + protected final AuthorizationService authService; + + public FieldCensor(ConventionService conventionService, + AuthorizationService authService) { + super(conventionService); + this.authService = authService; + } + + public void censor(FieldSet fields, UUID userId) { + logger.debug(new DataLogEntry("censoring fields", fields)); + if (fields == null || fields.isEmpty()) + return; + + this.authService.authorizeForce(Permission.BrowseDescription); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionCensor.java new file mode 100644 index 000000000..2436ebf5e --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/descriptionproperties/PropertyDefinitionCensor.java @@ -0,0 +1,49 @@ +package eu.eudat.model.censorship.descriptionproperties; + +import eu.eudat.authorization.Permission; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.Description; +import eu.eudat.model.censorship.BaseCensor; +import eu.eudat.model.censorship.dmpblueprintdefinition.SectionCensor; +import eu.eudat.model.descriptionproperties.PropertyDefinition; +import eu.eudat.model.dmpblueprintdefinition.Definition; +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("descriptionpropertiescensor") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class PropertyDefinitionCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(PropertyDefinitionCensor.class)); + + protected final AuthorizationService authService; + protected final CensorFactory censorFactory; + + public PropertyDefinitionCensor(ConventionService conventionService, + AuthorizationService authService, + CensorFactory censorFactory) { + super(conventionService); + this.authService = authService; + this.censorFactory = censorFactory; + } + + public void censor(FieldSet fields, UUID userId) { + logger.debug(new DataLogEntry("censoring fields", fields)); + if (fields == null || fields.isEmpty()) + return; + + this.authService.authorizeForce(Permission.BrowseDescription); + FieldSet fieldFields = fields.extractPrefixed(this.asIndexerPrefix(PropertyDefinition._fields)); + this.censorFactory.censor(FieldCensor.class).censor(fieldFields, userId); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionDeleter.java index fc98bd167..c02f33d5e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionDeleter.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionDeleter.java @@ -2,7 +2,13 @@ package eu.eudat.model.deleter; import eu.eudat.commons.enums.IsActive; import eu.eudat.data.DescriptionEntity; +import eu.eudat.data.DescriptionReferenceEntity; +import eu.eudat.data.DescriptionTagEntity; +import eu.eudat.data.UserDescriptionTemplateEntity; import eu.eudat.query.DescriptionQuery; +import eu.eudat.query.DescriptionReferenceQuery; +import eu.eudat.query.DescriptionTagQuery; +import eu.eudat.query.UserDescriptionTemplateQuery; import gr.cite.tools.data.deleter.Deleter; import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.query.QueryFactory; @@ -20,6 +26,7 @@ import java.time.Instant; import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @@ -59,14 +66,28 @@ public class DescriptionDeleter implements Deleter { 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()) + public void delete(List datas) throws InvalidApplicationException { + logger.debug("will delete {} items", Optional.ofNullable(datas).map(List::size).orElse(0)); + if (datas == null || datas.isEmpty()) return; Instant now = Instant.now(); - for (DescriptionEntity item : data) { + List ids = datas.stream().map(DescriptionEntity::getId).distinct().collect(Collectors.toList()); + { + logger.debug("checking related - {}", DescriptionReferenceEntity.class.getSimpleName()); + List items = this.queryFactory.query(DescriptionReferenceQuery.class).descriptionIds(ids).collect(); + DescriptionReferenceDeleter deleter = this.deleterFactory.deleter(DescriptionReferenceDeleter.class); + deleter.delete(items); + } + { + logger.debug("checking related - {}", DescriptionTagEntity.class.getSimpleName()); + List items = this.queryFactory.query(DescriptionTagQuery.class).descriptionIds(ids).collect(); + DescriptionTagDeleter deleter = this.deleterFactory.deleter(DescriptionTagDeleter.class); + deleter.delete(items); + } + + for (DescriptionEntity item : datas) { logger.trace("deleting item {}", item.getId()); item.setIsActive(IsActive.Inactive); item.setUpdatedAt(now); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTagDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTagDeleter.java new file mode 100644 index 000000000..887b4a85d --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTagDeleter.java @@ -0,0 +1,79 @@ +package eu.eudat.model.deleter; + +import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DescriptionTagEntity; +import eu.eudat.query.DescriptionTagQuery; +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 DescriptionTagDeleter implements Deleter { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTagDeleter.class)); + + private final EntityManager entityManager; + + protected final QueryFactory queryFactory; + + protected final DeleterFactory deleterFactory; + + @Autowired + public DescriptionTagDeleter( + 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(DescriptionTagQuery.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 (DescriptionTagEntity 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/model/deleter/DescriptionTemplateDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateDeleter.java index e54be0757..62b8960a3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateDeleter.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateDeleter.java @@ -3,6 +3,7 @@ package eu.eudat.model.deleter; import eu.eudat.commons.enums.IsActive; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.UserDescriptionTemplateEntity; +import eu.eudat.query.DescriptionQuery; import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.UserDescriptionTemplateQuery; import gr.cite.tools.data.deleter.Deleter; @@ -67,7 +68,7 @@ public class DescriptionTemplateDeleter implements Deleter { if (datas == null || datas.isEmpty()) return; - List ids = datas.stream().map(x -> x.getId()).distinct().collect(Collectors.toList()); + List ids = datas.stream().map(DescriptionTemplateEntity::getId).distinct().collect(Collectors.toList()); { logger.debug("checking related - {}", UserDescriptionTemplateEntity.class.getSimpleName()); List items = this.queryFactory.query(UserDescriptionTemplateQuery.class).descriptionTemplateIds(ids).collect(); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateTypeDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateTypeDeleter.java index c27f4e7a8..e9b562018 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateTypeDeleter.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateTypeDeleter.java @@ -1,7 +1,12 @@ package eu.eudat.model.deleter; import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DescriptionTagEntity; +import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.DescriptionTemplateTypeEntity; +import eu.eudat.data.ReferenceEntity; +import eu.eudat.query.DescriptionTagQuery; +import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.DescriptionTemplateTypeQuery; import gr.cite.tools.data.deleter.Deleter; import gr.cite.tools.data.deleter.DeleterFactory; @@ -20,6 +25,7 @@ import java.time.Instant; import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @@ -59,14 +65,22 @@ public class DescriptionTemplateTypeDeleter implements Deleter { 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()) + public void delete(List datas) throws InvalidApplicationException { + logger.debug("will delete {} items", Optional.ofNullable(datas).map(List::size).orElse(0)); + if (datas == null || datas.isEmpty()) return; + List ids = datas.stream().map(DescriptionTemplateTypeEntity::getId).distinct().collect(Collectors.toList()); + { + logger.debug("checking related - {}", DescriptionTemplateEntity.class.getSimpleName()); + List items = this.queryFactory.query(DescriptionTemplateQuery.class).typeIds(ids).collect(); + DescriptionTemplateDeleter deleter = this.deleterFactory.deleter(DescriptionTemplateDeleter.class); + deleter.delete(items); + } + Instant now = Instant.now(); - for (DescriptionTemplateTypeEntity item : data) { + for (DescriptionTemplateTypeEntity item : datas) { logger.trace("deleting item {}", item.getId()); item.setIsActive(IsActive.Inactive); item.setUpdatedAt(now); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpDeleter.java index a58368434..19a6f168f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpDeleter.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpDeleter.java @@ -1,8 +1,11 @@ package eu.eudat.model.deleter; import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DescriptionReferenceEntity; import eu.eudat.data.DmpEntity; +import eu.eudat.query.DescriptionReferenceQuery; import eu.eudat.query.DmpQuery; +import eu.eudat.query.DmpReferenceQuery; import gr.cite.tools.data.deleter.Deleter; import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.query.QueryFactory; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/ReferenceDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/ReferenceDeleter.java index f2bb69945..7e3f76a67 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/ReferenceDeleter.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/ReferenceDeleter.java @@ -1,7 +1,12 @@ package eu.eudat.model.deleter; import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DescriptionReferenceEntity; +import eu.eudat.data.DmpReferenceEntity; import eu.eudat.data.ReferenceEntity; +import eu.eudat.data.TagEntity; +import eu.eudat.query.DescriptionReferenceQuery; +import eu.eudat.query.DmpReferenceQuery; import eu.eudat.query.ReferenceQuery; import gr.cite.tools.data.deleter.Deleter; import gr.cite.tools.data.deleter.DeleterFactory; @@ -20,6 +25,7 @@ import java.time.Instant; import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @@ -58,14 +64,27 @@ public class ReferenceDeleter implements Deleter { 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()) + public void delete(List datas) throws InvalidApplicationException { + logger.debug("will delete {} items", Optional.ofNullable(datas).map(List::size).orElse(0)); + if (datas == null || datas.isEmpty()) return; + List ids = datas.stream().map(ReferenceEntity::getId).distinct().collect(Collectors.toList()); + { + logger.debug("checking related - {}", DescriptionReferenceEntity.class.getSimpleName()); + List items = this.queryFactory.query(DescriptionReferenceQuery.class).referenceIds(ids).collect(); + DescriptionReferenceDeleter deleter = this.deleterFactory.deleter(DescriptionReferenceDeleter.class); + deleter.delete(items); + } + { + logger.debug("checking related - {}", DmpReferenceEntity.class.getSimpleName()); + List items = this.queryFactory.query(DmpReferenceQuery.class).referenceIds(ids).collect(); + DmpReferenceDeleter deleter = this.deleterFactory.deleter(DmpReferenceDeleter.class); + deleter.delete(items); + } Instant now = Instant.now(); - for (ReferenceEntity item : data) { + for (ReferenceEntity item : datas) { logger.trace("deleting item {}", item.getId()); item.setIsActive(IsActive.Inactive); item.setUpdatedAt(now); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/TagDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/TagDeleter.java new file mode 100644 index 000000000..f96eb4ad8 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/TagDeleter.java @@ -0,0 +1,88 @@ +package eu.eudat.model.deleter; + +import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DescriptionEntity; +import eu.eudat.data.DescriptionTagEntity; +import eu.eudat.data.TagEntity; +import eu.eudat.query.DescriptionTagQuery; +import eu.eudat.query.TagQuery; +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; +import java.util.stream.Collectors; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class TagDeleter implements Deleter { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TagDeleter.class)); + private final EntityManager entityManager; + + protected final QueryFactory queryFactory; + + protected final DeleterFactory deleterFactory; + + @Autowired + public TagDeleter( + 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(TagQuery.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 datas) throws InvalidApplicationException { + logger.debug("will delete {} items", Optional.ofNullable(datas).map(List::size).orElse(0)); + if (datas == null || datas.isEmpty()) + return; + List ids = datas.stream().map(TagEntity::getId).distinct().collect(Collectors.toList()); + { + logger.debug("checking related - {}", DescriptionTagEntity.class.getSimpleName()); + List items = this.queryFactory.query(DescriptionTagQuery.class).tagIds(ids).collect(); + DescriptionTagDeleter deleter = this.deleterFactory.deleter(DescriptionTagDeleter.class); + deleter.delete(items); + } + Instant now = Instant.now(); + + for (TagEntity item : datas) { + 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/model/descriptionproperties/Field.java b/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/Field.java index 2ddbb93fb..d12151353 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/Field.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/Field.java @@ -3,18 +3,18 @@ package eu.eudat.model.descriptionproperties; public class Field { - public final static String _id = "id"; - private String id; + public final static String _key = "key"; + private String key; public final static String _value = "value"; private String value; - public String getId() { - return id; + public String getKey() { + return key; } - public void setId(String id) { - this.id = id; + public void setKey(String key) { + this.key = key; } public String getValue() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinition.java b/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinition.java index d3f1b4c8e..853a8f1c3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinition.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/descriptionproperties/PropertyDefinition.java @@ -7,4 +7,11 @@ public class PropertyDefinition { public final static String _fields = "fields"; private List fields; + public List getFields() { + return fields; + } + + public void setFields(List fields) { + this.fields = fields; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DmpEntityDepositMapper.java b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DmpEntityDepositMapper.java index 061330e3d..d86217090 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DmpEntityDepositMapper.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DmpEntityDepositMapper.java @@ -72,7 +72,7 @@ public class DmpEntityDepositMapper { model.setLabel(entity.getLabel()); model.setDescription(entity.getDescription()); model.setProperties(entity.getProperties()); - DescriptionTemplateEntity descriptionTemplateEntity = getDescriptionTemplate(entity.getDescriptionTemplate()); + DescriptionTemplateEntity descriptionTemplateEntity = getDescriptionTemplate(entity.getDescriptionTemplateId()); model.setProfileDefinition(descriptionTemplateEntity.getDefinition()); model.setFields(fromDefinitionAndProperties(descriptionTemplateEntity.getDefinition(), entity.getProperties())); return model; diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java index 1f2e16933..0fceba7e6 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java @@ -3,10 +3,8 @@ package eu.eudat.query; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.commons.enums.IsActive; -import eu.eudat.commons.scope.user.UserScope; import eu.eudat.data.DescriptionEntity; import eu.eudat.model.Description; -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; @@ -38,13 +36,8 @@ public class DescriptionQuery extends QueryBase { private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - private final UserScope userScope; - private final AuthorizationService authService; - - public DescriptionQuery(UserScope userScope, AuthorizationService authService) { - this.userScope = userScope; - this.authService = authService; + public DescriptionQuery() { } public DescriptionQuery like(String value) { @@ -178,7 +171,7 @@ public class DescriptionQuery extends QueryBase { predicates.add(inClause); } if (this.dmpIds != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmp)); + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpId)); for (UUID item : this.dmpIds) inClause.value(item); predicates.add(inClause); @@ -193,36 +186,21 @@ public class DescriptionQuery extends QueryBase { @Override protected String fieldNameOf(FieldResolver item) { - if (item.match(Description._id)) - return DescriptionEntity._id; - else if (item.match(Description._label)) - return DescriptionEntity._label; - else if (item.prefix(Description._dmp)) - return DescriptionEntity._dmp; - else if (item.match(Description._dmp)) - return DescriptionEntity._dmp; - else if (item.prefix(Description._properties)) - return DescriptionEntity._properties; - else if (item.prefix(Description._descriptionTemplate)) - return DescriptionEntity._descriptionTemplate; - else if (item.match(Description._status)) - return DescriptionEntity._status; - else if (item.match(Description._description)) - return DescriptionEntity._description; - else if (item.match(Description._createdBy)) - return DescriptionEntity._createdBy; - else if (item.match(Description._createdAt)) - return DescriptionEntity._createdAt; - else if (item.match(Description._updatedAt)) - return DescriptionEntity._updatedAt; - else if (item.match(Description._isActive)) - return DescriptionEntity._isActive; - else if (item.match(Description._finalizedAt)) - return DescriptionEntity._finalizedAt; - else if (item.match(Description._dmpDescriptionTemplate)) - return DescriptionEntity._dmpDescriptionTemplate; - else - return null; + if (item.match(Description._id)) return DescriptionEntity._id; + else if (item.match(Description._label)) return DescriptionEntity._label; + else if (item.prefix(Description._dmp)) return DescriptionEntity._dmpId; + else if (item.match(Description._dmp)) return DescriptionEntity._dmpId; + else if (item.prefix(Description._properties)) return DescriptionEntity._properties; + else if (item.prefix(Description._descriptionTemplate)) return DescriptionEntity._descriptionTemplateId; + else if (item.match(Description._status)) return DescriptionEntity._status; + else if (item.match(Description._description)) return DescriptionEntity._description; + else if (item.match(Description._createdBy)) return DescriptionEntity._createdById; + else if (item.match(Description._createdAt)) return DescriptionEntity._createdAt; + else if (item.match(Description._updatedAt)) return DescriptionEntity._updatedAt; + else if (item.match(Description._isActive)) return DescriptionEntity._isActive; + else if (item.match(Description._finalizedAt)) return DescriptionEntity._finalizedAt; + else if (item.match(Description._dmpDescriptionTemplate)) return DescriptionEntity._dmpDescriptionTemplateId; + else return null; } @Override @@ -230,17 +208,16 @@ public class DescriptionQuery extends QueryBase { DescriptionEntity item = new DescriptionEntity(); item.setId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._id, UUID.class)); item.setLabel(QueryBase.convertSafe(tuple, columns, DescriptionEntity._label, String.class)); - item.setDmp(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmp, UUID.class)); + item.setDmpId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmpId, UUID.class)); item.setProperties(QueryBase.convertSafe(tuple, columns, DescriptionEntity._properties, String.class)); - item.setDescriptionTemplate(QueryBase.convertSafe(tuple, columns, DescriptionEntity._descriptionTemplate, UUID.class)); + item.setDescriptionTemplateId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._descriptionTemplateId, UUID.class)); item.setStatus(QueryBase.convertSafe(tuple, columns, DescriptionEntity._status, DescriptionStatus.class)); item.setDescription(QueryBase.convertSafe(tuple, columns, DescriptionEntity._description, String.class)); - item.setDmpDescriptionTemplate(QueryBase.convertSafe(tuple, columns, DescriptionEntity._createdBy, UUID.class)); item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DescriptionEntity._createdAt, Instant.class)); item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, DescriptionEntity._updatedAt, Instant.class)); item.setIsActive(QueryBase.convertSafe(tuple, columns, DescriptionEntity._isActive, IsActive.class)); item.setFinalizedAt(QueryBase.convertSafe(tuple, columns, DescriptionEntity._finalizedAt, Instant.class)); - item.setDmpDescriptionTemplate(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmpDescriptionTemplate, UUID.class)); + item.setDmpDescriptionTemplateId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmpDescriptionTemplateId, UUID.class)); return item; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionReferenceQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionReferenceQuery.java index 3141f5b2b..0251b4b39 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionReferenceQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionReferenceQuery.java @@ -35,13 +35,7 @@ public class DescriptionReferenceQuery extends QueryBase authorize = EnumSet.of(AuthorizationFlags.None); - private final UserScope userScope; - - private final AuthorizationService authService; - - public DescriptionReferenceQuery(UserScope userScope, AuthorizationService authService) { - this.userScope = userScope; - this.authService = authService; + public DescriptionReferenceQuery() { } public DescriptionReferenceQuery ids(UUID value) { @@ -182,24 +176,15 @@ public class DescriptionReferenceQuery extends QueryBase { + + private Collection ids; + + private Collection tagIds; + + private Collection excludedIds; + + private Collection descriptionIds; + + private Collection isActives; + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + + public DescriptionTagQuery ids(UUID value) { + this.ids = List.of(value); + return this; + } + + public DescriptionTagQuery ids(UUID... value) { + this.ids = Arrays.asList(value); + return this; + } + + public DescriptionTagQuery ids(Collection values) { + this.ids = values; + return this; + } + + public DescriptionTagQuery excludedIds(Collection values) { + this.excludedIds = values; + return this; + } + + public DescriptionTagQuery excludedIds(UUID value) { + this.excludedIds = List.of(value); + return this; + } + + public DescriptionTagQuery excludedIds(UUID... value) { + this.excludedIds = Arrays.asList(value); + return this; + } + + public DescriptionTagQuery isActive(IsActive value) { + this.isActives = List.of(value); + return this; + } + + public DescriptionTagQuery isActive(IsActive... value) { + this.isActives = Arrays.asList(value); + return this; + } + + public DescriptionTagQuery isActive(Collection values) { + this.isActives = values; + return this; + } + + public DescriptionTagQuery tagIds(UUID value) { + this.tagIds = List.of(value); + return this; + } + + public DescriptionTagQuery tagIds(UUID... value) { + this.tagIds = Arrays.asList(value); + return this; + } + + public DescriptionTagQuery tagIds(Collection values) { + this.tagIds = values; + return this; + } + + public DescriptionTagQuery descriptionIds(UUID value) { + this.descriptionIds = List.of(value); + return this; + } + + public DescriptionTagQuery descriptionIds(UUID... value) { + this.descriptionIds = Arrays.asList(value); + return this; + } + + public DescriptionTagQuery descriptionIds(Collection values) { + this.descriptionIds = values; + return this; + } + + public DescriptionTagQuery authorize(EnumSet values) { + this.authorize = values; + return this; + } + + public DescriptionTagQuery( + ) { + } + + @Override + protected Class entityClass() { + return DescriptionTagEntity.class; + } + + @Override + protected Boolean isFalseQuery() { + return this.isEmpty(this.ids) || this.isEmpty(this.excludedIds) || this.isEmpty(this.isActives) ||this.isEmpty(this.tagIds) || this.isEmpty(this.descriptionIds); + } + + @Override + protected Predicate applyFilters(QueryContext queryContext) { + List predicates = new ArrayList<>(); + if (this.ids != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTagEntity._id)); + for (UUID item : this.ids) + inClause.value(item); + predicates.add(inClause); + } + if (this.excludedIds != null) { + CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._id)); + for (UUID item : this.excludedIds) + notInClause.value(item); + predicates.add(notInClause.not()); + } + if (this.tagIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTagEntity._tagId)); + for (UUID item : this.tagIds) + inClause.value(item); + predicates.add(inClause); + } + if (this.descriptionIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTagEntity._descriptionId)); + for (UUID item : this.descriptionIds) + inClause.value(item); + predicates.add(inClause); + } + if (this.isActives != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTagEntity._isActive)); + for (IsActive item : this.isActives) + 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 DescriptionTagEntity convert(Tuple tuple, Set columns) { + DescriptionTagEntity item = new DescriptionTagEntity(); + item.setId(QueryBase.convertSafe(tuple, columns, DescriptionTagEntity._id, UUID.class)); + item.setTagId(QueryBase.convertSafe(tuple, columns, DescriptionTagEntity._tagId, UUID.class)); + item.setDescriptionId(QueryBase.convertSafe(tuple, columns, DescriptionTagEntity._descriptionId, UUID.class)); + item.setIsActive(QueryBase.convertSafe(tuple, columns, DescriptionTagEntity._isActive, IsActive.class)); + item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DescriptionTagEntity._createdAt, Instant.class)); + item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, DescriptionTagEntity._updatedAt, Instant.class)); + return item; + } + + @Override + protected String fieldNameOf(FieldResolver item) { + if (item.match(DescriptionTag._id)) return DescriptionTagEntity._id; + else if (item.prefix(DescriptionTag._tag)) return DescriptionTagEntity._tagId; + else if (item.prefix(DescriptionTag._description)) return DescriptionTagEntity._descriptionId; + else if (item.match(DescriptionTag._isActive)) return DescriptionTagEntity._isActive; + else if (item.match(DescriptionTag._createdAt)) return DescriptionTagEntity._createdAt; + else if (item.match(DescriptionTag._updatedAt)) return DescriptionTagEntity._updatedAt; + else return null; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateQuery.java index ff102c5ad..37922fdda 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateQuery.java @@ -3,10 +3,8 @@ package eu.eudat.query; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.commons.enums.DescriptionTemplateStatus; import eu.eudat.commons.enums.IsActive; -import eu.eudat.commons.scope.user.UserScope; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.model.DescriptionTemplate; -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; @@ -140,13 +138,9 @@ public class DescriptionTemplateQuery extends QueryBase inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._type)); + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._typeId)); for (UUID item : this.typeIds) inClause.value(item); predicates.add(inClause); @@ -222,7 +216,7 @@ public class DescriptionTemplateQuery extends QueryBase { return this; } - private final UserScope userScope; - - private final AuthorizationService authService; - public DmpBlueprintQuery( UserScope userScope, AuthorizationService authService ) { - this.userScope = userScope; - this.authService = authService; } @Override diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java index fef4167e0..52ee85aed 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java @@ -83,16 +83,8 @@ public class DmpDescriptionTemplateQuery extends QueryBase { return this; } - private final UserScope userScope; - - private final AuthorizationService authService; - public ReferenceQuery( - UserScope userScope, - AuthorizationService authService ) { - this.userScope = userScope; - this.authService = authService; } @Override diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/TagQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/TagQuery.java new file mode 100644 index 000000000..9ad575aed --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/query/TagQuery.java @@ -0,0 +1,188 @@ +package eu.eudat.query; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.data.TagEntity; +import eu.eudat.model.Tag; +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 TagQuery extends QueryBase { + + private String like; + + private Collection ids; + + private Collection excludedIds; + + private Collection isActives; + + private Collection createdByIds; + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + public TagQuery() { + } + + public TagQuery like(String value) { + this.like = value; + return this; + } + + public TagQuery ids(UUID value) { + this.ids = List.of(value); + return this; + } + + public TagQuery ids(UUID... value) { + this.ids = Arrays.asList(value); + return this; + } + + public TagQuery ids(Collection values) { + this.ids = values; + return this; + } + + public TagQuery excludedIds(Collection values) { + this.excludedIds = values; + return this; + } + + public TagQuery excludedIds(UUID value) { + this.excludedIds = List.of(value); + return this; + } + + public TagQuery excludedIds(UUID... value) { + this.excludedIds = Arrays.asList(value); + return this; + } + + public TagQuery isActive(IsActive value) { + this.isActives = List.of(value); + return this; + } + + public TagQuery isActive(IsActive... value) { + this.isActives = Arrays.asList(value); + return this; + } + + public TagQuery isActive(Collection values) { + this.isActives = values; + return this; + } + + public TagQuery createdByIds(UUID value) { + this.createdByIds = List.of(value); + return this; + } + + public TagQuery createdByIds(UUID... value) { + this.createdByIds = Arrays.asList(value); + return this; + } + + public TagQuery createdByIds(Collection values) { + this.createdByIds = values; + return this; + } + + public TagQuery authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected Boolean isFalseQuery() { + return + this.isEmpty(this.ids) || + this.isEmpty(this.isActives) || + this.isEmpty(this.excludedIds) || + this.isEmpty(this.createdByIds); + } + + @Override + protected Class entityClass() { + return TagEntity.class; + } + + @Override + protected Predicate applyFilters(QueryContext queryContext) { + List predicates = new ArrayList<>(); + if (this.like != null && !this.like.isEmpty()) { + predicates.add(queryContext.CriteriaBuilder.like(queryContext.Root.get(TagEntity._label), this.like)); + } + if (this.ids != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TagEntity._id)); + for (UUID item : this.ids) + inClause.value(item); + predicates.add(inClause); + } + if (this.excludedIds != null) { + CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TagEntity._id)); + for (UUID item : this.excludedIds) + notInClause.value(item); + predicates.add(notInClause.not()); + } + if (this.isActives != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TagEntity._isActive)); + for (IsActive item : this.isActives) + inClause.value(item); + predicates.add(inClause); + } + if (this.createdByIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TagEntity._createdBy)); + for (UUID item : this.createdByIds) + 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 String fieldNameOf(FieldResolver item) { + if (item.match(Tag._id)) return TagEntity._id; + else if (item.match(Tag._label)) return TagEntity._label; + else if (item.prefix(Tag._createdBy)) return TagEntity._createdBy; + else if (item.match(Tag._createdBy)) return TagEntity._createdBy; + else if (item.match(Tag._createdBy)) return TagEntity._createdBy; + else if (item.match(Tag._createdAt)) return TagEntity._createdAt; + else if (item.match(Tag._updatedAt)) return TagEntity._updatedAt; + else if (item.match(Tag._isActive)) return TagEntity._isActive; + else return null; + } + + @Override + protected TagEntity convert(Tuple tuple, Set columns) { + TagEntity item = new TagEntity(); + item.setId(QueryBase.convertSafe(tuple, columns, TagEntity._id, UUID.class)); + item.setLabel(QueryBase.convertSafe(tuple, columns, TagEntity._label, String.class)); + item.setCreatedBy(QueryBase.convertSafe(tuple, columns, TagEntity._createdBy, UUID.class)); + item.setCreatedAt(QueryBase.convertSafe(tuple, columns, TagEntity._createdAt, Instant.class)); + item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, TagEntity._updatedAt, Instant.class)); + item.setIsActive(QueryBase.convertSafe(tuple, columns, TagEntity._isActive, IsActive.class)); + return item; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/UserDescriptionTemplateQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/UserDescriptionTemplateQuery.java index 90ae164e2..06ead5ae1 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/UserDescriptionTemplateQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/UserDescriptionTemplateQuery.java @@ -127,13 +127,9 @@ public class UserDescriptionTemplateQuery extends QueryBase ids; + + private Collection excludedIds; + + private Collection isActives; + + private Collection descriptionIds; + + private Collection tagIds; + + public Collection getIds() { + return ids; + } + + public void setIds(Collection ids) { + this.ids = ids; + } + + public Collection getExcludedIds() { + return excludedIds; + } + + public void setExcludedIds(Collection excludedIds) { + this.excludedIds = excludedIds; + } + + public Collection getIsActives() { + return isActives; + } + + public void setIsActives(Collection isActives) { + this.isActives = isActives; + } + + public Collection getDescriptionIds() { + return descriptionIds; + } + + public void setDescriptionIds(Collection descriptionIds) { + this.descriptionIds = descriptionIds; + } + + public Collection getTagIds() { + return tagIds; + } + + public void setTagIds(Collection referenceIds) { + this.tagIds = referenceIds; + } + + public DescriptionTagQuery enrich(QueryFactory queryFactory) { + DescriptionTagQuery query = queryFactory.query(DescriptionTagQuery.class); + if (this.ids != null) query.ids(this.ids); + if (this.excludedIds != null) query.excludedIds(this.excludedIds); + if (this.isActives != null) query.isActive(this.isActives); + if (this.descriptionIds != null) query.descriptionIds(this.descriptionIds); + if (this.tagIds != null) query.tagIds(this.tagIds); + + this.enrichCommon(query); + + return query; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/TagLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/TagLookup.java new file mode 100644 index 000000000..0d592e0e7 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/TagLookup.java @@ -0,0 +1,76 @@ +package eu.eudat.query.lookup; + +import eu.eudat.commons.enums.IsActive; +import eu.eudat.query.TagQuery; +import gr.cite.tools.data.query.Lookup; +import gr.cite.tools.data.query.QueryFactory; + +import java.util.List; +import java.util.UUID; + +public class TagLookup extends Lookup { + + private String like; + + private List ids; + + private List excludedIds; + + private List isActive; + + private List createdByIds; + + public String getLike() { + return like; + } + + public void setLike(String like) { + this.like = like; + } + + public List getIds() { + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } + + public List getExcludedIds() { + return excludedIds; + } + + public void setExcludedIds(List excludedIds) { + this.excludedIds = excludedIds; + } + + public List getIsActive() { + return isActive; + } + + public void setIsActive(List isActive) { + this.isActive = isActive; + } + + public List getCreatedByIds() { + return createdByIds; + } + + public void setCreatedByIds(List createdByIds) { + this.createdByIds = createdByIds; + } + + public TagQuery enrich(QueryFactory queryFactory) { + TagQuery query = queryFactory.query(TagQuery.class); + if (this.like != null) query.like(this.like); + if (this.ids != null) query.ids(this.ids); + if (this.excludedIds != null) query.excludedIds(this.excludedIds); + if (this.isActive != null) query.isActive(this.isActive); + if (this.createdByIds != null) query.createdByIds(this.createdByIds); + + this.enrichCommon(query); + + return query; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java index 22d89c4a8..89c6ef6c4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java @@ -107,9 +107,9 @@ public class DescriptionServiceImpl implements DescriptionService { } data.setLabel(model.getLabel()); - data.setDmp(model.getDmp()); + data.setDmpId(model.getDmp()); data.setProperties(model.getProperties()); - data.setDescriptionTemplate(model.getProfile()); + data.setDescriptionTemplateId(model.getProfile()); data.setStatus(model.getStatus()); data.setDescription(model.getDescription()); data.setUpdatedAt(Instant.now()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java index 0432ba8aa..3cf3e4805 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java @@ -162,7 +162,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic data.setDescription(model.getDescription()); data.setLabel(model.getLabel()); - data.setType(model.getType()); + data.setTypeId(model.getType()); data.setLanguage(model.getLanguage()); data.setStatus(model.getStatus()); data.setUpdatedAt(Instant.now()); @@ -478,7 +478,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic data.setVersion((short)(oldDescriptionTemplateEntity.getVersion() + 1)); data.setDescription(model.getDescription()); data.setLabel(model.getLabel()); - data.setType(model.getType()); + data.setTypeId(model.getType()); data.setLanguage(model.getLanguage()); data.setStatus(model.getStatus()); data.setDefinition(this.xmlHandlingService.toXml(this.buildDefinitionEntity(model.getDefinition()))); @@ -671,7 +671,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic private DescriptionTemplateImportExport definitionXmlToExport(DescriptionTemplateEntity data, DefinitionEntity entity){ DescriptionTemplateImportExport xml = new DescriptionTemplateImportExport(); - xml.setType(data.getType()); + xml.setType(data.getTypeId()); xml.setLanguage(data.getLanguage()); xml.setDescription(data.getDescription()); List pagesDatasetEntity = new LinkedList<>(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java index 0b6075808..61a3e7f4d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java @@ -143,7 +143,7 @@ public class FileController { throw new NoSuchElementException("No dataset with id " + fileUpload.getEntityId() + " found. This dataset was related to the file with id " + id); } - DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); + DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmpId()); if (!dmp.isPublic() && dmp.getUsers() .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/builders/entity/DatasetProfileBuilder.java b/dmp-backend/web/src/main/java/eu/eudat/logic/builders/entity/DatasetProfileBuilder.java index d49f6df32..1c148c99f 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/builders/entity/DatasetProfileBuilder.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/builders/entity/DatasetProfileBuilder.java @@ -94,7 +94,7 @@ public class DatasetProfileBuilder extends Builder { descriptionTemplateEntity.setUpdatedAt(modified); descriptionTemplateEntity.setLabel(label); descriptionTemplateEntity.setLanguage(language); - descriptionTemplateEntity.setType(type); + descriptionTemplateEntity.setTypeId(type); return descriptionTemplateEntity; } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index 276770177..3c52d92ec 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -494,7 +494,7 @@ public class DataManagementPlanManager { } List descriptionEntityList = dmp1.getDataset().stream().filter(dataset -> dataset.getIsActive() != IsActive.Inactive).collect(Collectors.toList()); for (DescriptionEntity descriptionEntity : descriptionEntityList) { - if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> descriptionEntity.getDescriptionTemplate().equals(associatedProfile.getDescriptionTemplateId())).findAny().orElse(null) == null) + if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> descriptionEntity.getDescriptionTemplateId().equals(associatedProfile.getDescriptionTemplateId())).findAny().orElse(null) == null) throw new Exception("Dataset Template for Dataset Description is missing from the DMP."); } if (dataManagementPlan.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue() && dmp1.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) @@ -917,7 +917,7 @@ public class DataManagementPlanManager { if (elastic != null) { tags = elastic.getTags(); } - descriptionEntity.setDmp(dmp.getId()); + descriptionEntity.setDmpId(dmp.getId()); this.datasetManager.updateTags(descriptionEntity, tags); } catch (Exception e) { logger.error(e.getMessage(), e); @@ -1049,7 +1049,7 @@ public class DataManagementPlanManager { if (elastic != null) { tags = elastic.getTags(); } - UUID dmpId = tempDescriptionEntity.getDmp(); + UUID dmpId = tempDescriptionEntity.getDmpId(); //TODO //tempDescriptionEntity.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); this.datasetManager.updateTags(tempDescriptionEntity, tags); @@ -1060,7 +1060,7 @@ public class DataManagementPlanManager { .thenApplyAsync(entityDataset -> { DescriptionEntity newDescriptionEntity = new DescriptionEntity(); newDescriptionEntity.update(entityDataset); - newDescriptionEntity.setDmp(newDmp.getId()); + newDescriptionEntity.setDmpId(newDmp.getId()); newDescriptionEntity.setStatus(DescriptionStatus.Saved); //TODO // if (newDescriptionEntity.getDatasetDataRepositories() != null) { @@ -1113,7 +1113,7 @@ public class DataManagementPlanManager { futures.add(datasetDao.createOrUpdateAsync(item).whenComplete(((dataset1, throwable) -> { DMP dmp = null; try { - dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataset1.getDmp()); + dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataset1.getDmpId()); } catch (InvalidApplicationException e) { throw new RuntimeException(e); } @@ -1122,9 +1122,9 @@ public class DataManagementPlanManager { datasetElastic.setId(dataset1.getId().toString()); datasetElastic.setLabel(dataset1.getLabel()); datasetElastic.setDescription(dataset1.getDescription()); - datasetElastic.setTemplate(dataset1.getDescriptionTemplate()); + datasetElastic.setTemplate(dataset1.getDescriptionTemplateId()); datasetElastic.setStatus(dataset1.getStatus().getValue()); - datasetElastic.setDmp(dataset1.getDmp()); + datasetElastic.setDmp(dataset1.getDmpId()); datasetElastic.setGroup(dmp.getGroupId()); if(this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { datasetElastic.setGrant(dmp.getGrant().getId()); @@ -1194,7 +1194,7 @@ public class DataManagementPlanManager { if (elastic != null) { tags = elastic.getTags(); } - UUID tmdmpId = dataset.getDmp(); + UUID tmdmpId = dataset.getDmpId(); //TODO //dataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), tmdmpId)).toList())); this.datasetManager.updateTags(dataset, tags); @@ -1600,7 +1600,7 @@ public class DataManagementPlanManager { //runDatasetTemplate1.setBold(true); //runDatasetTemplate1.setFontSize(12); XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun(); - runDatasetTemplate.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(datasetEntity.getDescriptionTemplate()).first().getLabel()); + runDatasetTemplate.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(datasetEntity.getDescriptionTemplateId()).first().getLabel()); runDatasetTemplate.setColor("116a78"); //runDatasetTemplate.setBold(true); //runDatasetTemplate.setFontSize(12); @@ -1646,7 +1646,7 @@ public class DataManagementPlanManager { runDatasetDescription1.setText("Description: "); runDatasetDescription1.setColor("000000"); XWPFRun runDatasetDescription = datasetDescParagraph.createRun(); - runDatasetDescription.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(datasetEntity.getDescriptionTemplate()).first().getLabel()); + runDatasetDescription.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(datasetEntity.getDescriptionTemplateId()).first().getLabel()); runDatasetDescription.setColor("116a78"); //wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0); @@ -1928,11 +1928,11 @@ public class DataManagementPlanManager { Element datsetProfileElement = xmlDoc.createElement("profile-id"); datasetElement.appendChild(datsetProfileElement); - datsetProfileElement.setTextContent(descriptionEntity.getDescriptionTemplate().toString()); + datsetProfileElement.setTextContent(descriptionEntity.getDescriptionTemplateId().toString()); Element datsetProfileLabelElement = xmlDoc.createElement("profile-label"); datasetElement.appendChild(datsetProfileLabelElement); - datsetProfileLabelElement.setTextContent(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntity.getDescriptionTemplate()).first().getLabel()); + datsetProfileLabelElement.setTextContent(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntity.getDescriptionTemplateId()).first().getLabel()); DatasetWizardModel datasetWizardModel = new DatasetWizardModel(); Map properties = new HashMap<>(); @@ -2235,9 +2235,9 @@ public class DataManagementPlanManager { //TODO // descriptionEntity.setDmpSectionIndex(das.getDmpSectionIndex()); try { - descriptionEntity.setDescriptionTemplate(das.getProfile()); + descriptionEntity.setDescriptionTemplateId(das.getProfile()); } catch (Exception ignored) { - descriptionEntity.setDescriptionTemplate(associatedProfiles.get(0).getDescriptionTemplateId()); + descriptionEntity.setDescriptionTemplateId(associatedProfiles.get(0).getDescriptionTemplateId()); } descriptionEntity.setProperties(objectMapper.writeValueAsString(das.getFieldImportModels())); descriptionEntity.setStatus(DescriptionStatus.Saved); @@ -2245,7 +2245,7 @@ public class DataManagementPlanManager { // descriptionEntity.setDatasetDataRepositories(new HashSet<>()); // descriptionEntity.setServices(new HashSet<>()); // descriptionEntity.setDatasetExternalDatasets(new HashSet<>()); - descriptionEntity.setDmp(dmp.getId()); + descriptionEntity.setDmpId(dmp.getId()); DatasetWizardModel datasetWizard = new DatasetWizardModel(); datasetWizard.setDatasetProfileDefinition(this.datasetManager.getPagedProfile(datasetWizard, descriptionEntity)); datasetWizard.fromDataModel(descriptionEntity); @@ -2294,7 +2294,7 @@ public class DataManagementPlanManager { dataset.setStatus(DescriptionStatus.Saved); dataset.setCreatedAt(Instant.now()); dataset.setUpdatedAt(Instant.now()); - dataset.setDmp(dmp.getId()); + dataset.setDmpId(dmp.getId()); dataset = databaseRepository.getDatasetDao().createOrUpdate(dataset); // dataset.setRegistries(new HashSet<>()); // dataset.setDatasetDataRepositories(new HashSet<>()); @@ -2401,7 +2401,7 @@ public class DataManagementPlanManager { if (elastic != null) { tags = elastic.getTags(); } - UUID dmpId = dataset.getDmp(); + UUID dmpId = dataset.getDmpId(); //TODO //dataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); this.datasetManager.updateTags(dataset, tags); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index a3b48c152..a862f55d0 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -299,7 +299,7 @@ public class DatasetManager { public DatasetWizardModel getSingle(String id) throws InvalidApplicationException { DatasetWizardModel dataset = new DatasetWizardModel(); DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); - DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); + DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmpId()); if (dmp.getUsers() .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) .collect(Collectors.toList()).size() == 0 && !dmp.isPublic()) @@ -309,7 +309,7 @@ public class DatasetManager { // Creates the Criteria to get all version of DescriptionTemplate in question. DatasetProfileCriteria profileCriteria = new DatasetProfileCriteria(); - UUID profileId = this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplate()).first().getGroupId(); + UUID profileId = this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplateId()).first().getGroupId(); List uuidList = new LinkedList<>(); uuidList.add(profileId); profileCriteria.setGroupIds(uuidList); @@ -340,7 +340,7 @@ public class DatasetManager { DescriptionTemplateEntity profile = profiles.get(0); // Check if the dataset is on the latest Version. - boolean latestVersion = profile.getVersion().toString().equals(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplate()).first().getVersion()); + boolean latestVersion = profile.getVersion().toString().equals(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplateId()).first().getVersion()); dataset.setIsProfileLatestVersion(latestVersion); eu.eudat.elastic.entities.Dataset datasetElastic; @@ -364,7 +364,7 @@ public class DatasetManager { public DatasetWizardModel getSinglePublic(String id) throws Exception { DatasetWizardModel dataset = new DatasetWizardModel(); DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().isPublicDataset(UUID.fromString(id)); - DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); + DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmpId()); if (descriptionEntityEntity != null && descriptionEntityEntity.getStatus() == DescriptionStatus.Finalized && dmp.getStatus() == 1) { dataset.setDatasetProfileDefinition(getPagedProfile(dataset, descriptionEntityEntity)); dataset.fromDataModel(descriptionEntityEntity); @@ -379,7 +379,7 @@ public class DatasetManager { if (descriptionEntityEntity.getIsActive() == IsActive.Inactive) { throw new Exception("Dataset is deleted."); } - DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); + DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmpId()); if (!isPublic && !this.userScope.isSet()) { throw new UnauthorisedException(); } else @@ -400,7 +400,7 @@ public class DatasetManager { } public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, DescriptionEntity descriptionEntityEntity) { - eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplate()).first()); + eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplateId()).first()); datasetprofile.setStatus(dataset.getStatus().getValue()); if (descriptionEntityEntity.getProperties() != null) { JSONObject jObject = new JSONObject(descriptionEntityEntity.getProperties()); @@ -417,7 +417,7 @@ public class DatasetManager { DatasetWizardModel dataset = new DatasetWizardModel(); XWPFDocument document = configLoader.getDatasetDocument(); - DMP dmpEntity = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); + DMP dmpEntity = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmpId()); if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())).collect(Collectors.toList()).size() == 0) throw new UnauthorisedException(); @@ -555,7 +555,7 @@ public class DatasetManager { public FileEnvelope getWordDocumentFile(ConfigLoader configLoader, String id, VisibilityRuleService visibilityRuleService) throws IOException, InvalidApplicationException { DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); - DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); + DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmpId()); if (!dmp.isPublic() && dmp.getUsers() .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) .collect(Collectors.toList()).size() == 0) @@ -585,7 +585,7 @@ public class DatasetManager { ExportXmlBuilder xmlBuilder = new ExportXmlBuilder(); DatasetWizardModel dataset = new DatasetWizardModel(); DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); - DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); + DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmpId()); if (!dmp.isPublic() && dmp.getUsers() .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) .collect(Collectors.toList()).size() == 0) @@ -598,7 +598,7 @@ public class DatasetManager { PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, descriptionEntityEntity); visibilityRuleService.setProperties(properties); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); - File file = xmlBuilder.build(pagedDatasetProfile, descriptionEntityEntity.getDescriptionTemplate(), visibilityRuleService, environment); + File file = xmlBuilder.build(pagedDatasetProfile, descriptionEntityEntity.getDescriptionTemplateId(), visibilityRuleService, environment); FileEnvelope fileEnvelope = new FileEnvelope(); fileEnvelope.setFile(file); String label = descriptionEntityEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", ""); @@ -627,7 +627,7 @@ public class DatasetManager { if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()) && datasetWizardModel.getId() != null) throw new Exception("DMP is finalized, therefore Dataset cannot be edited."); DescriptionEntity descriptionEntity = datasetWizardModel.toDataModel(); - descriptionEntity.setDmp(dmp.getId()); + descriptionEntity.setDmpId(dmp.getId()); descriptionEntity.setProperties(propertiesModelToString(datasetWizardModel.getDatasetProfileDefinition())); if (this.apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().getClient() != null) { this.getTagsFromProfile(datasetWizardModel, descriptionEntity); @@ -639,7 +639,7 @@ public class DatasetManager { } } UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(this.userScope.getUserId()).build(); - descriptionEntity.setDmpDescriptionTemplate(userInfo.getId()); + descriptionEntity.setDmpDescriptionTemplateId(userInfo.getId()); createDataRepositoriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao(), descriptionEntity); createExternalDatasetsIfTheyDontExist(descriptionEntity); @@ -648,14 +648,14 @@ public class DatasetManager { DescriptionEntity descriptionEntity1 = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(descriptionEntity); datasetWizardModel.setId(descriptionEntity1.getId()); if (datasetWizardModel.getDmp().getGrant() == null) { - DMP dmp1 = databaseRepository.getDmpDao().find(descriptionEntity1.getDmp()); + DMP dmp1 = databaseRepository.getDmpDao().find(descriptionEntity1.getDmpId()); datasetWizardModel.setDmp(new DataManagementPlan().fromDataModelNoDatasets(dmp1)); } - descriptionEntity1.setDescriptionTemplate(datasetWizardModel.getProfile().getId()); + descriptionEntity1.setDescriptionTemplateId(datasetWizardModel.getProfile().getId()); // datasetWizardModel.setDatasetProfileDefinition(getPagedProfile(datasetWizardModel, dataset1)); - UUID dmpId = descriptionEntity1.getDmp(); - DMP dmp1 = databaseRepository.getDmpDao().find(descriptionEntity1.getDmp()); + UUID dmpId = descriptionEntity1.getDmpId(); + DMP dmp1 = databaseRepository.getDmpDao().find(descriptionEntity1.getDmpId()); dmp1.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); updateTags(descriptionEntity1, datasetWizardModel.getTags()); if (sendNotification) { @@ -737,7 +737,7 @@ public class DatasetManager { public String checkDatasetValidation(DescriptionEntity descriptionEntity) throws Exception { List datasetProfileValidators = new LinkedList<>(); - DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(descriptionEntity.getDescriptionTemplate()); + DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(descriptionEntity.getDescriptionTemplateId()); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document xmlDocument = builder.parse(new ByteArrayInputStream(profile.getDefinition().getBytes())); @@ -759,7 +759,7 @@ public class DatasetManager { VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl(); visibilityRuleService.setProperties(obj.toMap()); - descriptionEntity.setDescriptionTemplate(profile.getId()); + descriptionEntity.setDescriptionTemplateId(profile.getId()); PagedDatasetProfile pagedDatasetProfile = this.getPagedProfile(new DatasetWizardModel(), descriptionEntity); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); @@ -1030,16 +1030,16 @@ public class DatasetManager { entity.setLabel(importFile.getOriginalFilename()); DMP dmp = new DMP(); dmp.setId(UUID.fromString(dmpId)); - entity.setDmp(dmp.getId()); + entity.setDmpId(dmp.getId()); entity.setStatus(DescriptionStatus.Saved); entity.setCreatedAt(Instant.now()); entity.setUpdatedAt(Instant.now()); DescriptionTemplateEntity profile = new DescriptionTemplateEntity(); profile.setId(UUID.fromString(datasetProfileId)); - entity.setDescriptionTemplate(profile.getId()); + entity.setDescriptionTemplateId(profile.getId()); UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(this.userScope.getUserId()).build(); - entity.setDmpDescriptionTemplate(userInfo.getId()); + entity.setDmpDescriptionTemplateId(userInfo.getId()); updateTagsXmlImportDataset(apiContext.getOperationsContext().getElasticRepository().getDatasetRepository(), entity); createRegistriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao(), entity); @@ -1064,7 +1064,7 @@ public class DatasetManager { // Creates the Criteria to get all version of DescriptionTemplate in question. DatasetProfileCriteria profileCriteria = new DatasetProfileCriteria(); - UUID profileId = this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplate()).first().getGroupId(); + UUID profileId = this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplateId()).first().getGroupId(); List uuidList = new LinkedList<>(); uuidList.add(profileId); profileCriteria.setGroupIds(uuidList); @@ -1130,8 +1130,8 @@ public class DatasetManager { descriptionEntityEntities.forEach(datasetEntity -> { try { eu.eudat.elastic.entities.Dataset dataset = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(datasetEntity.getId().toString()); - UUID dmpId = datasetEntity.getDmp(); - DMP dmp = databaseRepository.getDmpDao().find(datasetEntity.getDmp()); + UUID dmpId = datasetEntity.getDmpId(); + DMP dmp = databaseRepository.getDmpDao().find(datasetEntity.getDmpId()); dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); updateTags(datasetEntity, dataset != null ? dataset.getTags() : null); } catch (Exception e) { @@ -1152,7 +1152,7 @@ public class DatasetManager { } public void getTagsFromProfile(DatasetWizardModel wizardModel, DescriptionEntity descriptionEntity) throws IOException, InvalidApplicationException { - descriptionEntity.setDescriptionTemplate(descriptionEntity.getDescriptionTemplate()); + descriptionEntity.setDescriptionTemplateId(descriptionEntity.getDescriptionTemplateId()); wizardModel.setDatasetProfileDefinition(this.getPagedProfile(wizardModel, descriptionEntity)); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(wizardModel.getDatasetProfileDefinition()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetWizardManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetWizardManager.java index f1eb4c86f..eae5daf6a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetWizardManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetWizardManager.java @@ -54,7 +54,7 @@ public class DatasetWizardManager { public void unlock(ApiContext apiContext, UUID uuid) throws DatasetWizardCannotUnlockException, InvalidApplicationException { DescriptionEntity descriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid); - DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(descriptionEntity.getDmp()); + DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(descriptionEntity.getDmpId()); if(dmp.getStatus() == DMP.DMPStatus.FINALISED.getValue()) throw new DatasetWizardCannotUnlockException("To perform this action you will need to revert DMP's finalisation"); descriptionEntity.setStatus(DescriptionStatus.Saved); apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(descriptionEntity); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java index 0b73e7269..8b8b8bd0d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java @@ -19,9 +19,6 @@ import jakarta.transaction.Transactional; import javax.management.InvalidApplicationException; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; @@ -412,7 +409,7 @@ public class MetricsManager { List descriptionTemplateEntities = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(criteria).withFields(Collections.singletonList("id")).toList(); DatasetCriteria datasetCriteria = new DatasetCriteria(); datasetCriteria.setDatasetTemplates(descriptionTemplateEntities.stream().map(DescriptionTemplateEntity::getId).collect(Collectors.toList())); - return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria).select(root -> root.getDescriptionTemplate()).stream().distinct().count(); + return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria).select(root -> root.getDescriptionTemplateId()).stream().distinct().count(); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DatasetMapper.java b/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DatasetMapper.java index 8278b2b05..ddb148676 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DatasetMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DatasetMapper.java @@ -19,7 +19,7 @@ public class DatasetMapper { } public Dataset toElastic(DescriptionEntity descriptionEntity, List tags) throws Exception { - if (descriptionEntity.getDescriptionTemplate() == null) { + if (descriptionEntity.getDescriptionTemplateId() == null) { return null; } //TODO diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DmpMapper.java b/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DmpMapper.java index 5ec02a294..fecc8f16f 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DmpMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DmpMapper.java @@ -70,7 +70,7 @@ public class DmpMapper { if (dataset1 != null) { tags = dataset1.getTags(); } - dataset.setDmp(dmp.getId()); + dataset.setDmpId(dmp.getId()); return datasetMapper.toElastic(dataset, tags); } catch (Exception e) { logger.error(e.getMessage(), e); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/prefilling/PrefillingMapper.java b/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/prefilling/PrefillingMapper.java index 6e675d5f2..5170a024e 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/prefilling/PrefillingMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/prefilling/PrefillingMapper.java @@ -53,7 +53,7 @@ public class PrefillingMapper { DatasetWizardModel datasetWizardModel = new DatasetWizardModel(); datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(profile)); DescriptionEntity descriptionEntity = new DescriptionEntity(); - descriptionEntity.setDescriptionTemplate(profile.getId()); + descriptionEntity.setDescriptionTemplateId(profile.getId()); Map properties = new HashMap<>(); JsonNode parentNode = mapper.readTree(mapper.writeValueAsString(datasetManager.getPagedProfile(datasetWizardModel, descriptionEntity))); for (DefaultPrefillingMapping prefillingMapping: prefillingGet.getMappings()) { diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java index 9cc27739a..0714da5ad 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java @@ -51,7 +51,7 @@ public class DatasetRDAMapper { } rda.setTitle(descriptionEntity.getLabel()); rda.setDescription(descriptionEntity.getDescription()); - rda.setAdditionalProperty("template", descriptionEntity.getDescriptionTemplate()); + rda.setAdditionalProperty("template", descriptionEntity.getDescriptionTemplateId()); try { JSONObject jObject = new JSONObject(descriptionEntity.getProperties()); Map templateIdsToValues = jObject.toMap(); @@ -288,10 +288,10 @@ public class DatasetRDAMapper { entity.setDescription(rda.getDescription()); try { DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(rda.getAdditionalProperties().get("template").toString())); - entity.setDescriptionTemplate(profile.getId()); + entity.setDescriptionTemplateId(profile.getId()); }catch(Exception e) { logger.warn(e.getMessage(), e); - entity.setDescriptionTemplate(defaultProfile.getId()); + entity.setDescriptionTemplateId(defaultProfile.getId()); } try { Map properties = new HashMap<>(); diff --git a/dmp-backend/web/src/main/resources/config/permissions.yml b/dmp-backend/web/src/main/resources/config/permissions.yml index 1d2f618c9..d56002665 100644 --- a/dmp-backend/web/src/main/resources/config/permissions.yml +++ b/dmp-backend/web/src/main/resources/config/permissions.yml @@ -88,6 +88,27 @@ permissions: clients: [ ] allowAnonymous: false allowAuthenticated: false + + # Tag + BrowseTag: + roles: + - Admin + clients: [ ] + allowAnonymous: false + allowAuthenticated: false + EditTag: + roles: + - Admin + clients: [ ] + allowAnonymous: false + allowAuthenticated: false + DeleteTag: + roles: + - Admin + claims: [ ] + clients: [ ] + allowAnonymous: false + allowAuthenticated: false # DescriptionTemplateType BrowseDescriptionTemplateType: roles: