From e698b198e720a133fd6ab0fcecaef7522f2a2413 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Fri, 24 Nov 2023 12:39:26 +0200 Subject: [PATCH] add description template to description --- .../java/eu/eudat/data/DescriptionEntity.java | 62 ++++---------- .../data/DmpDescriptionTemplateEntity.java | 14 +-- .../DescriptionElasticBuilder.java | 14 +-- .../elasticbuilder/DmpElasticBuilder.java | 4 +- .../main/java/eu/eudat/model/Description.java | 12 +++ .../eudat/model/DmpDescriptionTemplate.java | 37 ++++++-- .../eu/eudat/model/PublicDescription.java | 12 +++ .../model/PublicDmpDescriptionTemplate.java | 11 --- .../model/builder/DescriptionBuilder.java | 36 +++++++- .../DmpDescriptionTemplateBuilder.java | 85 ++++++++++++------- .../builder/PublicDescriptionBuilder.java | 38 ++++++++- .../PublicDmpDescriptionTemplateBuilder.java | 30 ------- .../model/censorship/DescriptionCensor.java | 3 + .../DmpDescriptionTemplateCensor.java | 6 +- .../censorship/PublicDescriptionCensor.java | 4 + .../PublicDmpDescriptionTemplateCensor.java | 2 - .../censorship/UserAdditionalInfoCensor.java | 9 +- .../deleter/DescriptionTemplateDeleter.java | 3 +- .../deposit/DmpEntityDepositMapper.java | 7 +- .../model/persist/DescriptionPersist.java | 12 +++ .../DmpDescriptionTemplatePersist.java | 31 ++----- .../java/eu/eudat/query/DescriptionQuery.java | 4 + .../eudat/query/DescriptionTemplateQuery.java | 4 +- .../query/DmpDescriptionTemplateQuery.java | 31 ++++--- .../description/DescriptionServiceImpl.java | 3 + .../eu/eudat/service/dmp/DmpServiceImpl.java | 58 +++++-------- .../managers/DataManagementPlanManager.java | 10 +-- .../eudat/logic/managers/DatasetManager.java | 10 +-- .../logic/managers/DatasetWizardManager.java | 2 +- .../eudat/logic/managers/MetricsManager.java | 2 +- .../models/rda/mapper/DatasetRDAMapper.java | 2 +- .../eudat/models/rda/mapper/DmpRDAMapper.java | 6 +- ...012_Add_Dmp_description_template_table.sql | 6 +- .../updates/00.01.014_sync_Description.sql | 10 +++ 34 files changed, 326 insertions(+), 254 deletions(-) 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 59ccd8c68..e8265d54a 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 @@ -80,6 +80,12 @@ public class DescriptionEntity implements DataEntity { @Column(name = "dmp", columnDefinition = "uuid", nullable = false) private UUID dmpId; + @Column(name = "description_template", columnDefinition = "uuid", nullable = false) + private UUID descriptionTemplateId; + + public static final String _descriptionTemplateId = "descriptionTemplateId"; + + public static final String _dmpId = "dmpId"; public UUID getId() { @@ -178,55 +184,17 @@ public class DescriptionEntity implements DataEntity { this.dmpId = dmpId; } + public UUID getDescriptionTemplateId() { + return descriptionTemplateId; + } + + public void setDescriptionTemplateId(UUID descriptionTemplateId) { + this.descriptionTemplateId = descriptionTemplateId; + } + @Override public void update(DescriptionEntity entity) { -// this.setUri(entity.getUri()); -// this.setDescription(entity.getDescription()); -// this.setLabel(entity.getLabel()); -// this.setProperties(entity.getProperties()); -// -// if (entity.getDatasetDataRepositories() == null || entity.getDatasetDataRepositories().size() < 1) { -// if (this.getDatasetDataRepositories() != null) this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories()); -// } else { -// if (this.getDatasetDataRepositories() != null) { -// this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories()); -// } else { -// this.setDatasetDataRepositories(new HashSet<>()); -// } -// this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList())); -// } -// -// if (entity.getDatasetExternalDatasets() == null || entity.getDatasetExternalDatasets().size() < 1) { -// if (this.getDatasetExternalDatasets() != null) this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets()); -// } else { -// if (this.getDatasetExternalDatasets() != null) { -// this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets()); -// } else { -// this.setDatasetExternalDatasets(new HashSet<>()); -// } -// this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList())); -// } -// -// if (entity.getServices() == null || entity.getServices().size() < 1) { -// if (this.getServices() != null) this.getServices().removeAll(this.getServices()); -// } else { -// if (this.getServices() != null) { -// this.getServices().removeAll(this.getServices()); -// } else { -// this.setServices(new HashSet<>()); -// } -// this.getServices().addAll(entity.getServices().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList())); -// } -// -// this.setRegistries(entity.getRegistries()); -// -// this.setDmp(entity.getDmp()); -// this.setDmpSectionIndex(entity.getDmpSectionIndex()); -// this.setStatus(entity.getStatus()); -// this.setProfile(entity.getProfile()); -// this.setModified(new Date()); -// if (entity.getStatus().equals(Status.FINALISED.getValue())) this.setFinalizedAt(new Date()); -// if (entity.getCreator() != null) this.creator = entity.getCreator(); + } @Override diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DmpDescriptionTemplateEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DmpDescriptionTemplateEntity.java index ee532bb7e..760a5bb78 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DmpDescriptionTemplateEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DmpDescriptionTemplateEntity.java @@ -24,10 +24,10 @@ public class DmpDescriptionTemplateEntity { public static final String _dmpId = "dmpId"; - @Column(name = "description_template", columnDefinition = "uuid", nullable = false) - private UUID descriptionTemplateId; + @Column(name = "description_template_group", columnDefinition = "uuid", nullable = false) + private UUID descriptionTemplateGroupId; - public static final String _descriptionTemplateId = "descriptionTemplateId"; + public static final String _descriptionTemplateGroupId = "descriptionTemplateGroupId"; @Column(name = "section_id") private UUID sectionId; @@ -66,12 +66,12 @@ public class DmpDescriptionTemplateEntity { this.dmpId = dmpId; } - public UUID getDescriptionTemplateId() { - return descriptionTemplateId; + public UUID getDescriptionTemplateGroupId() { + return descriptionTemplateGroupId; } - public void setDescriptionTemplateId(UUID descriptionTemplateId) { - this.descriptionTemplateId = descriptionTemplateId; + public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) { + this.descriptionTemplateGroupId = descriptionTemplateGroupId; } public UUID getSectionId() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DescriptionElasticBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DescriptionElasticBuilder.java index ef5ce69ed..82807d757 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DescriptionElasticBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DescriptionElasticBuilder.java @@ -127,23 +127,15 @@ public class DescriptionElasticBuilder extends BaseElasticBuilder collectDescriptionTemplates(List data) throws MyApplicationException { if (data.isEmpty()) return null; this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName()); - DmpDescriptionTemplateQuery associationQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(data.stream().map(DescriptionEntity::getDmpDescriptionTemplateId).collect(Collectors.toList())).isActive(IsActive.Active); - List associationEntities = associationQuery.collect(); + Map itemMap; + DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(q, NestedDescriptionTemplateElasticEntity::getId); - DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); - Map itemMapById = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(query, NestedDescriptionTemplateElasticEntity::getId); - - Map itemMap = new HashMap<>(); - for (DmpDescriptionTemplateEntity associationEntity : associationEntities){ - itemMap.put(associationEntity.getId(), itemMapById.getOrDefault(associationEntity.getDescriptionTemplateId(), null)); - } return itemMap; } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DmpElasticBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DmpElasticBuilder.java index f75f6acff..ee37e23ad 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DmpElasticBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DmpElasticBuilder.java @@ -99,13 +99,13 @@ public class DmpElasticBuilder extends BaseElasticBuilder associationEntities = associationQuery.collect(); - DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); + DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).groupIds(associationEntities.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList())); Map itemMapById = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(query, NestedDescriptionTemplateElasticEntity::getId); Map> itemMap = new HashMap<>(); for (DmpDescriptionTemplateEntity associationEntity : associationEntities){ if (!itemMap.containsKey(associationEntity.getDmpId())) itemMap.put(associationEntity.getDmpId(), new ArrayList<>()); - NestedDescriptionTemplateElasticEntity item = itemMapById.getOrDefault(associationEntity.getDescriptionTemplateId(), null); + NestedDescriptionTemplateElasticEntity item = itemMapById.getOrDefault(associationEntity.getDescriptionTemplateGroupId(), null); if (item != null) itemMap.get(associationEntity.getDmpId()).add(item); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/Description.java b/dmp-backend/core/src/main/java/eu/eudat/model/Description.java index e0d526396..40ae2681a 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/Description.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/Description.java @@ -67,6 +67,10 @@ public class Description { public static final String _dmpDescriptionTemplate = "dmpDescriptionTemplate"; + private DescriptionTemplate descriptionTemplate; + + public static final String _descriptionTemplate = "descriptionTemplate"; + private Dmp dmp; public static final String _dmp = "dmp"; @@ -191,4 +195,12 @@ public class Description { public void setDmp(Dmp dmp) { this.dmp = dmp; } + + public DescriptionTemplate getDescriptionTemplate() { + return descriptionTemplate; + } + + public void setDescriptionTemplate(DescriptionTemplate descriptionTemplate) { + this.descriptionTemplate = descriptionTemplate; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/DmpDescriptionTemplate.java b/dmp-backend/core/src/main/java/eu/eudat/model/DmpDescriptionTemplate.java index 11f5bf736..9d494af57 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/DmpDescriptionTemplate.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/DmpDescriptionTemplate.java @@ -17,14 +17,23 @@ public class DmpDescriptionTemplate{ public static final String _dmp = "dmp"; - private DescriptionTemplate descriptionTemplate; + private DescriptionTemplate currentDescriptionTemplate; - public static final String _descriptionTemplate = "descriptionTemplate"; + public static final String _currentDescriptionTemplate = "currentDescriptionTemplate"; + + + private List descriptionTemplates; + + public static final String _descriptionTemplates = "descriptionTemplates"; private UUID sectionId; public static final String _sectionId = "sectionId"; + private UUID descriptionTemplateGroupId; + + public static final String _descriptionTemplateGroupId = "descriptionTemplateGroupId"; + private Instant createdAt; public static final String _createdAt = "createdAt"; @@ -56,12 +65,28 @@ public class DmpDescriptionTemplate{ this.dmp = dmp; } - public DescriptionTemplate getDescriptionTemplate() { - return descriptionTemplate; + public DescriptionTemplate getCurrentDescriptionTemplate() { + return currentDescriptionTemplate; } - public void setDescriptionTemplate(DescriptionTemplate descriptionTemplate) { - this.descriptionTemplate = descriptionTemplate; + public void setCurrentDescriptionTemplate(DescriptionTemplate currentDescriptionTemplate) { + this.currentDescriptionTemplate = currentDescriptionTemplate; + } + + public List getDescriptionTemplates() { + return descriptionTemplates; + } + + public void setDescriptionTemplates(List descriptionTemplates) { + this.descriptionTemplates = descriptionTemplates; + } + + public UUID getDescriptionTemplateGroupId() { + return descriptionTemplateGroupId; + } + + public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) { + this.descriptionTemplateGroupId = descriptionTemplateGroupId; } public UUID getSectionId() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/PublicDescription.java b/dmp-backend/core/src/main/java/eu/eudat/model/PublicDescription.java index fb38337a2..ec332e564 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/PublicDescription.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/PublicDescription.java @@ -39,6 +39,11 @@ public class PublicDescription { public static final String _dmpDescriptionTemplate = "dmpDescriptionTemplate"; + private PublicDescriptionTemplate descriptionTemplate; + + public static final String _descriptionTemplate = "descriptionTemplate"; + + public UUID getId() { return id; } @@ -104,4 +109,11 @@ public class PublicDescription { this.dmpDescriptionTemplate = dmpDescriptionTemplate; } + public PublicDescriptionTemplate getDescriptionTemplate() { + return descriptionTemplate; + } + + public void setDescriptionTemplate(PublicDescriptionTemplate descriptionTemplate) { + this.descriptionTemplate = descriptionTemplate; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/PublicDmpDescriptionTemplate.java b/dmp-backend/core/src/main/java/eu/eudat/model/PublicDmpDescriptionTemplate.java index 0d1be79a9..0300241a6 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/PublicDmpDescriptionTemplate.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/PublicDmpDescriptionTemplate.java @@ -15,10 +15,6 @@ public class PublicDmpDescriptionTemplate { public static final String _dmp = "dmp"; - private PublicDescriptionTemplate descriptionTemplate; - - public static final String _descriptionTemplate = "descriptionTemplate"; - public UUID getId() { return id; } @@ -35,11 +31,4 @@ public class PublicDmpDescriptionTemplate { this.dmp = dmp; } - public PublicDescriptionTemplate getDescriptionTemplate() { - return descriptionTemplate; - } - - public void setDescriptionTemplate(PublicDescriptionTemplate descriptionTemplate) { - this.descriptionTemplate = descriptionTemplate; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionBuilder.java index e7d5d83bc..66629b89d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionBuilder.java @@ -62,9 +62,12 @@ public class DescriptionBuilder extends BaseBuilder dmpDescriptionTemplateItemsMap = this.collectDmpDescriptionTemplates(dmpDescriptionTemplateFields, data); - FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(Description._dmpDescriptionTemplate)); + FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(Description._dmp)); Map dmpItemsMap = this.collectDmps(dmpFields, data); + FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asPrefix(Description._descriptionTemplate)); + Map descriptionTemplateItemsMap = this.collectDescriptionTemplates(descriptionTemplateFields, data); + FieldSet descriptionReferencesFields = fields.extractPrefixed(this.asPrefix(Description._descriptionReferences)); Map> descriptionReferencesMap = this.collectDescriptionReferences(descriptionReferencesFields, data); @@ -89,6 +92,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 collectDmps(FieldSet fields, List data) throws MyApplicationException { if (fields.isEmpty() || data.isEmpty()) return null; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpDescriptionTemplateBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpDescriptionTemplateBuilder.java index 067ccdbf3..731be14fc 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpDescriptionTemplateBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpDescriptionTemplateBuilder.java @@ -1,11 +1,14 @@ package eu.eudat.model.builder; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.enums.DescriptionTemplateVersionStatus; import eu.eudat.convention.ConventionService; import eu.eudat.data.DmpDescriptionTemplateEntity; +import eu.eudat.data.DmpEntity; import eu.eudat.model.*; import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.DmpQuery; +import eu.eudat.query.DmpUserQuery; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; @@ -53,8 +56,11 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder(); - FieldSet templateFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._descriptionTemplate)); - Map templateItemsMap = this.collectTemplates(templateFields, data); + FieldSet templateFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._descriptionTemplates)); + Map> templateItemsMap = this.collectDescriptionTemplates(templateFields, data); + + FieldSet currentDescriptionTemplateFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._currentDescriptionTemplate)); + Map currentDescriptionTemplateItemsMap = this.collectCurrentDescriptionTemplates(currentDescriptionTemplateFields, data); FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._dmp)); Map dmpItemsMap = this.collectDmps(dmpFields, data); @@ -67,7 +73,8 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder collectTemplates(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(DmpDescriptionTemplateEntity::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(DmpDescriptionTemplateEntity::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.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList()); - } - - return itemMap; - } private Map collectDmps(FieldSet fields, List data) throws MyApplicationException { if (fields.isEmpty() || data.isEmpty()) @@ -129,4 +110,50 @@ public class DmpDescriptionTemplateBuilder 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; + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._groupId); + DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).groupIds(data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asMasterKey(query, clone, DescriptionTemplate::getGroupId); + + if (!fields.hasField(DescriptionTemplate._groupId)) { + itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getGroupId() != null).peek(x -> { + x.setGroupId(null); + }); + } + + return itemMap; + } + + private Map collectCurrentDescriptionTemplates(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._groupId))) { + itemMap = this.asEmpty( + data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList()), + x -> { + DescriptionTemplate item = new DescriptionTemplate(); + item.setGroupId(x); + return item; + }, + DescriptionTemplate::getGroupId); + } else { + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._id); + DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).versionStatuses(DescriptionTemplateVersionStatus.Current).groupIds(data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DescriptionTemplate::getGroupId); + } + if (!fields.hasField(DescriptionTemplate._groupId)) { + itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setGroupId(null)).collect(Collectors.toList()); + } + + return itemMap; + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDescriptionBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDescriptionBuilder.java index bbdf82cd3..1c9b33d22 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDescriptionBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDescriptionBuilder.java @@ -3,8 +3,8 @@ package eu.eudat.model.builder; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.convention.ConventionService; import eu.eudat.data.DescriptionEntity; -import eu.eudat.model.PublicDescription; -import eu.eudat.model.PublicDmpDescriptionTemplate; +import eu.eudat.model.*; +import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.DmpDescriptionTemplateQuery; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; @@ -56,6 +56,9 @@ public class PublicDescriptionBuilder extends BaseBuilder dmpDescriptionTemplateItemsMap = this.collectDmpDescriptionTemplates(dmpDescriptionTemplateFields, data); + FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asPrefix(Description._descriptionTemplate)); + Map descriptionTemplateItemsMap = this.collectDescriptionTemplates(descriptionTemplateFields, data); + List models = new ArrayList<>(); for (DescriptionEntity d : data) { PublicDescription m = new PublicDescription(); @@ -67,6 +70,7 @@ public class PublicDescriptionBuilder extends BaseBuilder collectDescriptionTemplates(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", PublicDescriptionTemplate.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(PublicDescriptionTemplate._id))) { + itemMap = this.asEmpty( + data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()), + x -> { + PublicDescriptionTemplate item = new PublicDescriptionTemplate(); + item.setId(x); + return item; + }, + PublicDescriptionTemplate::getId); + } else { + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(PublicDescriptionTemplate._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(PublicDescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicDescriptionTemplate::getId); + } + if (!fields.hasField(PublicDescriptionTemplate._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/PublicDmpDescriptionTemplateBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDmpDescriptionTemplateBuilder.java index 9294a639d..c44a5024c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDmpDescriptionTemplateBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDmpDescriptionTemplateBuilder.java @@ -55,8 +55,6 @@ public class PublicDmpDescriptionTemplateBuilder extends BaseBuilder(); - FieldSet templateFields = fields.extractPrefixed(this.asPrefix(PublicDmpDescriptionTemplate._descriptionTemplate)); - Map templateItemsMap = this.collectTemplates(templateFields, data); FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(PublicDmpDescriptionTemplate._dmp)); Map dmpItemsMap = this.collectDmps(dmpFields, data); @@ -65,7 +63,6 @@ public class PublicDmpDescriptionTemplateBuilder extends BaseBuilder collectTemplates(FieldSet fields, List data) throws MyApplicationException { - if (fields.isEmpty() || data.isEmpty()) - return null; - this.logger.debug("checking related - {}", PublicDescriptionTemplate.class.getSimpleName()); - - Map itemMap; - if (!fields.hasOtherField(this.asIndexer(PublicDescriptionTemplate._id))) { - itemMap = this.asEmpty( - data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()), - x -> { - PublicDescriptionTemplate item = new PublicDescriptionTemplate(); - item.setId(x); - return item; - }, - PublicDescriptionTemplate::getId); - } else { - FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(PublicDescriptionTemplate._id); - DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(PublicDescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicDescriptionTemplate::getId); - } - if (!fields.hasField(PublicDescriptionTemplate._id)) { - itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList()); - } - - return itemMap; - } - private Map collectDmps(FieldSet fields, List data) throws MyApplicationException { if (fields.isEmpty() || data.isEmpty()) return null; 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 31d6d6fa7..62adac6d8 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 @@ -48,6 +48,9 @@ public class DescriptionCensor extends BaseCensor { FieldSet dmpDescriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(Description._dmpDescriptionTemplate)); this.censorFactory.censor(DmpDescriptionTemplateCensor.class).censor(dmpDescriptionTemplateFields, userId); + FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(Description._descriptionTemplate)); + this.censorFactory.censor(DescriptionTemplateCensor.class).censor(descriptionTemplateFields, userId); + FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(Description._dmp)); this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpDescriptionTemplateCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpDescriptionTemplateCensor.java index 40236fa5b..a731055d5 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpDescriptionTemplateCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpDescriptionTemplateCensor.java @@ -42,8 +42,10 @@ public class DmpDescriptionTemplateCensor extends BaseCensor{ this.authService.authorizeForce(Permission.BrowseDescription); FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._dmp)); this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId); - FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._descriptionTemplate)); - this.censorFactory.censor(DescriptionTemplateCensor.class).censor(descriptionTemplateFields, userId); + FieldSet descriptionTemplatesFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._descriptionTemplates)); + this.censorFactory.censor(DescriptionTemplateCensor.class).censor(descriptionTemplatesFields, userId); + FieldSet currentDescriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._currentDescriptionTemplate)); + this.censorFactory.censor(DescriptionTemplateCensor.class).censor(currentDescriptionTemplateFields, userId); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDescriptionCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDescriptionCensor.java index 39a94f021..e655a871b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDescriptionCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDescriptionCensor.java @@ -2,6 +2,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.PublicDescription; import eu.eudat.model.censorship.descriptionproperties.PropertyDefinitionCensor; import gr.cite.commons.web.authz.service.AuthorizationService; @@ -42,6 +43,9 @@ public class PublicDescriptionCensor extends BaseCensor { FieldSet dmpDescriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDescription._dmpDescriptionTemplate)); this.censorFactory.censor(PublicDmpDescriptionTemplateCensor.class).censor(dmpDescriptionTemplateFields); + FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDescription._descriptionTemplate)); + this.censorFactory.censor(PublicDescriptionTemplateCensor.class).censor(descriptionTemplateFields); + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDmpDescriptionTemplateCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDmpDescriptionTemplateCensor.java index b3cdbe301..829bae0f9 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDmpDescriptionTemplateCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDmpDescriptionTemplateCensor.java @@ -43,8 +43,6 @@ public class PublicDmpDescriptionTemplateCensor extends BaseCensor{ this.authService.authorizeForce(Permission.PublicBrowseDescription); FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDmpDescriptionTemplate._dmp)); this.censorFactory.censor(PublicDmpCensor.class).censor(dmpFields); - FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDmpDescriptionTemplate._descriptionTemplate)); - this.censorFactory.censor(PublicDescriptionTemplateCensor.class).censor(descriptionTemplateFields); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserAdditionalInfoCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserAdditionalInfoCensor.java index 53bc93fac..6dc44e130 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserAdditionalInfoCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserAdditionalInfoCensor.java @@ -4,7 +4,6 @@ import eu.eudat.authorization.OwnedResource; import eu.eudat.authorization.Permission; import eu.eudat.convention.ConventionService; import eu.eudat.model.UserAdditionalInfo; -import eu.eudat.model.UserContactInfo; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.fieldset.FieldSet; @@ -26,10 +25,13 @@ public class UserAdditionalInfoCensor extends BaseCensor { protected final AuthorizationService authService; + protected final CensorFactory censorFactory; - public UserAdditionalInfoCensor(ConventionService conventionService, AuthorizationService authService) { + + public UserAdditionalInfoCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) { super(conventionService); this.authService = authService; + this.censorFactory = censorFactory; } public void censor(FieldSet fields, UUID userId) { @@ -37,6 +39,9 @@ public class UserAdditionalInfoCensor extends BaseCensor { if (fields == null || fields.isEmpty()) return; this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUser); + + FieldSet descriptionReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(UserAdditionalInfo._organization)); + this.censorFactory.censor(ReferenceCensor.class).censor(descriptionReferenceFields, userId); } } 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 85df578ed..efaccb06c 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 @@ -71,6 +71,7 @@ public class DescriptionTemplateDeleter implements Deleter { return; List ids = data.stream().map(DescriptionTemplateEntity::getId).distinct().collect(Collectors.toList()); + List groupIds = data.stream().map(DescriptionTemplateEntity::getGroupId).distinct().collect(Collectors.toList()); { logger.debug("checking related - {}", UserDescriptionTemplateEntity.class.getSimpleName()); List items = this.queryFactory.query(UserDescriptionTemplateQuery.class).descriptionTemplateIds(ids).collect(); @@ -79,7 +80,7 @@ public class DescriptionTemplateDeleter implements Deleter { } { logger.debug("checking related - {}", DmpDescriptionTemplateEntity.class.getSimpleName()); - List items = this.queryFactory.query(DmpDescriptionTemplateQuery.class).descriptionTemplateIds(ids).collect(); + List items = this.queryFactory.query(DmpDescriptionTemplateQuery.class).descriptionTemplateGroupIds(groupIds).collect(); DmpDescriptionTemplateDeleter deleter = this.deleterFactory.deleter(DmpDescriptionTemplateDeleter.class); deleter.delete(items); } 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 79a93eb8d..73a7c51e4 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 @@ -74,16 +74,15 @@ public class DmpEntityDepositMapper { model.setLabel(entity.getLabel()); model.setDescription(entity.getDescription()); model.setProperties(entity.getProperties()); - DescriptionTemplateEntity descriptionTemplateEntity = getDescriptionTemplate(entity.getDmpDescriptionTemplateId()); + DescriptionTemplateEntity descriptionTemplateEntity = getDescriptionTemplate(entity.getDescriptionTemplateId()); model.setProfileDefinition(descriptionTemplateEntity.getDefinition()); model.setFields(fromDefinitionAndProperties(descriptionTemplateEntity.getDefinition(), entity.getProperties())); return model; } - private DescriptionTemplateEntity getDescriptionTemplate(UUID dmpDescriptionTemplateId) { - DmpDescriptionTemplateEntity dmpDescriptionTemplate = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(dmpDescriptionTemplateId).isActive(IsActive.Active).first(); + private DescriptionTemplateEntity getDescriptionTemplate(UUID descriptionTemplateId) { DescriptionTemplateQuery descriptionTemplateQuery = this.queryFactory.query(DescriptionTemplateQuery.class); - return descriptionTemplateQuery.ids(dmpDescriptionTemplate.getDescriptionTemplateId()).isActive(IsActive.Active).first(); + return descriptionTemplateQuery.ids(descriptionTemplateId).isActive(IsActive.Active).first(); } private List fromDefinitionAndProperties(String definition, String properties){ diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java index 8addd1ab7..af6a8c9e8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java @@ -33,6 +33,10 @@ public class DescriptionPersist { @ValidId(message = "{validation.invalidid}") private UUID dmpDescriptionTemplateId; + @NotNull(message = "{validation.empty}") + @ValidId(message = "{validation.invalidid}") + private UUID descriptionTemplateId; + @ValidEnum(message = "{validation.empty}") private DescriptionStatus status; @@ -131,4 +135,12 @@ public class DescriptionPersist { public void setHash(String hash) { this.hash = hash; } + + public UUID getDescriptionTemplateId() { + return descriptionTemplateId; + } + + public void setDescriptionTemplateId(UUID descriptionTemplateId) { + this.descriptionTemplateId = descriptionTemplateId; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpDescriptionTemplatePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpDescriptionTemplatePersist.java index 8c753f8df..c34538289 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpDescriptionTemplatePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpDescriptionTemplatePersist.java @@ -9,33 +9,20 @@ import java.util.UUID; @FieldNotNullIfOtherSet(message = "{validation.hashempty}") public class DmpDescriptionTemplatePersist { - @ValidId(message = "{validation.invalidid}") - private UUID id; - @ValidId(message = "{validation.invalidid}") @NotNull(message = "{validation.empty}") - private UUID descriptionTemplate; + private UUID descriptionTemplateGroupId; @ValidId(message = "{validation.invalidid}") @NotNull(message = "{validation.empty}") private UUID sectionId; - private String hash; - - public UUID getId() { - return id; + public UUID getDescriptionTemplateGroupId() { + return descriptionTemplateGroupId; } - public void setId(UUID id) { - this.id = id; - } - - public UUID getDescriptionTemplate() { - return descriptionTemplate; - } - - public void setDescriptionTemplate(UUID descriptionTemplate) { - this.descriptionTemplate = descriptionTemplate; + public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) { + this.descriptionTemplateGroupId = descriptionTemplateGroupId; } public UUID getSectionId() { @@ -46,12 +33,4 @@ public class DmpDescriptionTemplatePersist { this.sectionId = sectionId; } - public String getHash() { - return hash; - } - - public void setHash(String hash) { - this.hash = hash; - } - } 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 552fc54a4..7966001e2 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 @@ -270,6 +270,9 @@ public class DescriptionQuery extends QueryBase { else if (item.match(Description._hash)) return DescriptionEntity._updatedAt; else if (item.match(Description._finalizedAt) || item.match(PublicDescription._finalizedAt)) return DescriptionEntity._finalizedAt; else if (item.prefix(Description._dmpDescriptionTemplate) || item.prefix(PublicDescription._dmpDescriptionTemplate)) return DescriptionEntity._dmpDescriptionTemplateId; + else if (item.match(Description._dmpDescriptionTemplate) || item.match(PublicDescription._dmpDescriptionTemplate)) return DescriptionEntity._dmpDescriptionTemplateId; + else if (item.prefix(Description._descriptionTemplate) || item.prefix(PublicDescription._descriptionTemplate)) return DescriptionEntity._descriptionTemplateId; + else if (item.match(Description._descriptionTemplate) || item.match(PublicDescription._descriptionTemplate)) return DescriptionEntity._descriptionTemplateId; else if (item.prefix(Description._dmp)) return DescriptionEntity._dmpId; else return null; } @@ -287,6 +290,7 @@ public class DescriptionQuery extends QueryBase { item.setIsActive(QueryBase.convertSafe(tuple, columns, DescriptionEntity._isActive, IsActive.class)); item.setFinalizedAt(QueryBase.convertSafe(tuple, columns, DescriptionEntity._finalizedAt, Instant.class)); item.setDmpDescriptionTemplateId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmpDescriptionTemplateId, UUID.class)); + item.setDescriptionTemplateId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._descriptionTemplateId, UUID.class)); item.setDmpId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmpId, UUID.class)); return item; } 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 8aeac222a..c623a0cf8 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 @@ -197,12 +197,12 @@ public class DescriptionTemplateQuery extends QueryBase dmpDescriptionTemplateSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>( new BuildSubQueryInput.Builder<>(DmpDescriptionTemplateEntity.class, UUID.class, queryContext) - .keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpDescriptionTemplateEntity._descriptionTemplateId)) + .keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId)) .filterFunc((subQueryRoot, cb) -> cb.in(subQueryRoot.get(DmpDescriptionTemplateEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic)) ) )); - predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._id)).value(dmpDescriptionTemplateSubquery)); + predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._groupId)).value(dmpDescriptionTemplateSubquery)); } if (!predicates.isEmpty()) { Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); 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 b45168275..eaf4c5ee4 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 @@ -36,7 +36,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase dmpIds; - private Collection descriptionTemplateIds; + private Collection descriptionTemplateGroupIds; private Collection isActives; @@ -105,18 +105,18 @@ public class DmpDescriptionTemplateQuery extends QueryBase values) { - this.descriptionTemplateIds = values; + public DmpDescriptionTemplateQuery descriptionTemplateGroupIds(Collection values) { + this.descriptionTemplateGroupIds = values; return this; } @@ -143,7 +143,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._descriptionTemplateId)); - for (UUID item : this.descriptionTemplateIds) + if (this.descriptionTemplateGroupIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId)); + for (UUID item : this.descriptionTemplateGroupIds) inClause.value(item); predicates.add(inClause); } @@ -212,7 +212,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase models, UUID dmpId) throws InvalidApplicationException { - if (models == null || models.isEmpty()) - return; - - List templates = this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(dmpId).collect(); - Map> templatesLookup = this.conventionService.toDictionaryOfList(templates, DmpDescriptionTemplateEntity::getDmpId); - - List existingTemplates; - if (templatesLookup.containsKey(dmpId)) - existingTemplates = this.queryFactory.query(DescriptionTemplateQuery.class).ids(templatesLookup.get(dmpId).stream().map(DmpDescriptionTemplateEntity::getId).toList()).collect(); - else existingTemplates = new ArrayList<>(); - - List updatedTemplatesIds = models.stream().map(DmpDescriptionTemplatePersist::getDescriptionTemplate).filter(this.conventionService::isValidGuid).distinct().toList(); - List toDelete = existingTemplates.stream().filter(x -> !updatedTemplatesIds.contains(x.getId())).toList(); - List dmpDescriptionTemplateRecordsToDelete = this.queryFactory.query(DmpDescriptionTemplateQuery.class).descriptionTemplateIds(toDelete.stream().map(DescriptionTemplateEntity::getId).toList()).collect(); - this.deleterFactory.deleter(DmpDescriptionTemplateDeleter.class).delete(dmpDescriptionTemplateRecordsToDelete); + private void patchAndSaveTemplates(UUID id, List models) throws InvalidApplicationException { + if (models == null) models = new ArrayList<>(); + List items = this.queryFactory.query(DmpDescriptionTemplateQuery.class).isActive(IsActive.Active).dmpIds(id).collect(); + List updatedCreatedIds = new ArrayList<>(); for (DmpDescriptionTemplatePersist model : models) { - boolean shouldAdd = existingTemplates.stream().noneMatch(x -> x.getId().equals(model.getDescriptionTemplate())); - - if (shouldAdd) { - DmpDescriptionTemplateEntity dmpTemplate = new DmpDescriptionTemplateEntity(); - dmpTemplate.setDescriptionTemplateId(model.getDescriptionTemplate()); - dmpTemplate.setDmpId(dmpId); - dmpTemplate.setSectionId(model.getSectionId()); - dmpTemplate.setCreatedAt(Instant.now()); - dmpTemplate.setUpdatedAt(Instant.now()); - dmpTemplate.setIsActive(IsActive.Active); - this.entityManager.persist(dmpTemplate); + DmpDescriptionTemplateEntity data = items.stream().filter(x -> x.getDescriptionTemplateGroupId().equals(model.getDescriptionTemplateGroupId()) && x.getSectionId().equals(model.getSectionId())).findFirst().orElse(null); + if (data == null){ + data = new DmpDescriptionTemplateEntity(); + data.setId(UUID.randomUUID()); + data.setIsActive(IsActive.Active); + data.setCreatedAt(Instant.now()); + data.setDmpId(id); + data.setSectionId(model.getSectionId()); + data.setDescriptionTemplateGroupId(model.getDescriptionTemplateGroupId()); + this.entityManager.persist(data); } - + updatedCreatedIds.add(data.getId()); } - this.entityManager.flush(); + List toDelete = items.stream().filter(x-> updatedCreatedIds.stream().noneMatch(y-> y.equals(x.getId()))).collect(Collectors.toList()); + + this.deleterFactory.deleter(DmpDescriptionTemplateDeleter.class).delete(toDelete); } private @NotNull DefinitionEntity buildDefinitionEntity(DefinitionPersist persist){ 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 a494b2858..4cb87126d 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 @@ -485,7 +485,7 @@ public class DataManagementPlanManager { List descriptionEntityList = this.databaseRepository.getDatasetDao().getWithCriteria(datasetCriteria).toList().stream().filter(dataset -> dataset.getIsActive() != IsActive.Inactive).collect(Collectors.toList()); for (DescriptionEntity descriptionEntity : descriptionEntityList) { - if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId().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() == DmpStatus.Finalized.getValue() && dmp1.getStatus().equals(DmpStatus.Finalized.getValue() )) @@ -1639,7 +1639,7 @@ public class DataManagementPlanManager { //runDatasetTemplate1.setBold(true); //runDatasetTemplate1.setFontSize(12); XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun(); - runDatasetTemplate.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(datasetEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getLabel()); + runDatasetTemplate.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(datasetEntity.getDescriptionTemplateId()).first().getLabel()); runDatasetTemplate.setColor("116a78"); //runDatasetTemplate.setBold(true); //runDatasetTemplate.setFontSize(12); @@ -1685,7 +1685,7 @@ public class DataManagementPlanManager { runDatasetDescription1.setText("Description: "); runDatasetDescription1.setColor("000000"); XWPFRun runDatasetDescription = datasetDescParagraph.createRun(); - runDatasetDescription.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(datasetEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).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); @@ -1981,11 +1981,11 @@ public class DataManagementPlanManager { Element datsetProfileElement = xmlDoc.createElement("profile-id"); datasetElement.appendChild(datsetProfileElement); - datsetProfileElement.setTextContent(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId().toString()); + datsetProfileElement.setTextContent(descriptionEntity.getDescriptionTemplateId().toString()); Element datsetProfileLabelElement = xmlDoc.createElement("profile-label"); datasetElement.appendChild(datsetProfileLabelElement); - datsetProfileLabelElement.setTextContent(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getLabel()); + datsetProfileLabelElement.setTextContent(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntity.getDescriptionTemplateId()).first().getLabel()); DatasetWizardModel datasetWizardModel = new DatasetWizardModel(); Map properties = new HashMap<>(); 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 9c466cad1..3ec4d2ef4 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 @@ -315,7 +315,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(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getGroupId(); + UUID profileId = this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplateId()).first().getGroupId(); List uuidList = new LinkedList<>(); uuidList.add(profileId); profileCriteria.setGroupIds(uuidList); @@ -346,7 +346,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(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).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; //TODO @@ -409,7 +409,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(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).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()); @@ -616,7 +616,7 @@ public class DatasetManager { PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, descriptionEntityEntity); visibilityRuleService.setProperties(properties); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); - File file = xmlBuilder.build(pagedDatasetProfile, this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId(), 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+ ]", ""); @@ -758,7 +758,7 @@ public class DatasetManager { public String checkDatasetValidation(DescriptionEntity descriptionEntity) throws Exception { List datasetProfileValidators = new LinkedList<>(); - DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()); + 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())); 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 a2b008280..f290235e6 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 @@ -57,7 +57,7 @@ public class DatasetWizardManager { public void unlock(ApiContext apiContext, QueryFactory queryFactory, UUID uuid) throws DatasetWizardCannotUnlockException, InvalidApplicationException { DescriptionEntity descriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid); - DmpEntity dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()); + DmpEntity dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(descriptionEntity.getDescriptionTemplateId()); if(dmp.getStatus().equals(DmpStatus.Finalized)) throw new DatasetWizardCannotUnlockException("To perform this action you will need to revert DMP's finalisation"); descriptionEntity.setStatus(DescriptionStatus.Draft); 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 8f1bc49c2..3d3e7d0be 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 @@ -414,7 +414,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 -> this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(root.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).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/models/rda/mapper/DatasetRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java index 71a7e8c24..d07762e76 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 @@ -55,7 +55,7 @@ public class DatasetRDAMapper { } rda.setTitle(descriptionEntity.getLabel()); rda.setDescription(descriptionEntity.getDescription()); - rda.setAdditionalProperty("template", this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()); //TODO + rda.setAdditionalProperty("template", this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDescriptionTemplateId())); //TODO try { JSONObject jObject = new JSONObject(descriptionEntity.getProperties()); Map templateIdsToValues = jObject.toMap(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DmpRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DmpRDAMapper.java index 88b19da0e..5198d453f 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DmpRDAMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DmpRDAMapper.java @@ -184,7 +184,7 @@ public class DmpRDAMapper { return entity; } - private DmpDescriptionTemplateEntity getProfile(String descriptionTemplateId, UUID dmpId) throws InvalidApplicationException { - return this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(dmpId).descriptionTemplateIds(UUID.fromString(descriptionTemplateId)).first(); - } +// private DmpDescriptionTemplateEntity getProfile(String descriptionTemplateId, UUID dmpId) throws InvalidApplicationException { +// return this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(dmpId).descriptionTemplateIds(UUID.fromString(descriptionTemplateId)).first(); +// } } diff --git a/dmp-db-scema/updates/00.01.012_Add_Dmp_description_template_table.sql b/dmp-db-scema/updates/00.01.012_Add_Dmp_description_template_table.sql index b771053d3..36477e12e 100644 --- a/dmp-db-scema/updates/00.01.012_Add_Dmp_description_template_table.sql +++ b/dmp-db-scema/updates/00.01.012_Add_Dmp_description_template_table.sql @@ -8,16 +8,14 @@ CREATE TABLE IF NOT EXISTS public."DmpDescriptionTemplate" ( "id" uuid NOT NULL, "dmp" uuid NOT NULL, - "description_template" uuid NOT NULL, + "description_template_group" uuid NOT NULL, "section_id" uuid NOT NULL, "created_at" timestamp without time zone NOT NULL DEFAULT now(), "updated_at" timestamp without time zone NOT NULL DEFAULT now(), "is_active" smallint NOT NULL DEFAULT 1, CONSTRAINT "DmpDescriptionTemplate_pkey" PRIMARY KEY (id), CONSTRAINT "DmpDescriptionTemplate_dmp_fkey" FOREIGN KEY (dmp) - REFERENCES public."Dmp" (id), - CONSTRAINT "DmpDescriptionTemplate_description_template_fkey" FOREIGN KEY (description_template) - REFERENCES public."DescriptionTemplate" (id) + REFERENCES public."Dmp" (id) ); INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.012', '2023-11-02 12:00:00.000000+02', now(), 'Add Dmp Description Template table (former DMPDatasetProfile).'); diff --git a/dmp-db-scema/updates/00.01.014_sync_Description.sql b/dmp-db-scema/updates/00.01.014_sync_Description.sql index 1a6519e2a..c1c1c6da5 100644 --- a/dmp-db-scema/updates/00.01.014_sync_Description.sql +++ b/dmp-db-scema/updates/00.01.014_sync_Description.sql @@ -14,6 +14,9 @@ BEGIN ALTER TABLE public."Description" DROP COLUMN dmp_section_index; + ALTER TABLE public."Description" ADD COLUMN description_template uuid NOT NULL; + + ALTER TABLE public."Description" ALTER COLUMN dmp SET NOT NULL; @@ -37,6 +40,13 @@ BEGIN ON DELETE NO ACTION NOT VALID; + ALTER TABLE public."Description" + ADD FOREIGN KEY (description_template) + REFERENCES public."DescriptionTemplate" (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID; + INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.014', '2023-11-20 12:00:00.000000+02', now(), 'Sync table Description.');