From 1cee5fb49f8de01c6648c02be61deb0c51fe206a Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Fri, 10 Nov 2023 19:11:15 +0200 Subject: [PATCH] Various fixes --- .../eu/eudat/model/deleter/DmpDeleter.java | 30 +++++++++++++++---- .../eu/eudat/model/deleter/TagDeleter.java | 1 - .../eu/eudat/model/persist/DmpPersist.java | 11 +++++++ .../description/DescriptionServiceImpl.java | 3 +- .../eu/eudat/service/dmp/DmpServiceImpl.java | 1 + 5 files changed, 39 insertions(+), 7 deletions(-) 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 19a6f168f..8889ce6c1 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,11 +1,10 @@ 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 eu.eudat.data.*; +import eu.eudat.model.DmpDescriptionTemplate; +import eu.eudat.model.DmpReference; +import eu.eudat.query.*; import gr.cite.tools.data.deleter.Deleter; import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.query.QueryFactory; @@ -23,6 +22,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) @@ -67,6 +67,26 @@ public class DmpDeleter implements Deleter { if (data == null || data.isEmpty()) return; + List ids = data.stream().map(DmpEntity::getId).distinct().toList(); + { + logger.debug("checking related - {}", DmpUserEntity.class.getSimpleName()); + List items = this.queryFactory.query(DmpUserQuery.class).dmpIds(ids).collect(); + DmpUserDeleter deleter = this.deleterFactory.deleter(DmpUserDeleter.class); + deleter.delete(items); + } + { + logger.debug("checking related - {}", DmpDescriptionTemplate.class.getSimpleName()); + List items = this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(ids).collect(); + DmpDescriptionTemplateDeleter deleter = this.deleterFactory.deleter(DmpDescriptionTemplateDeleter.class); + deleter.delete(items); + } + { + logger.debug("checking related - {}", DmpReference.class.getSimpleName()); + List items = this.queryFactory.query(DmpReferenceQuery.class).dmpIds(ids).collect(); + DmpReferenceDeleter deleter = this.deleterFactory.deleter(DmpReferenceDeleter.class); + deleter.delete(items); + } + Instant now = Instant.now(); for (DmpEntity item : data) { 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 index f96eb4ad8..ecfc79a86 100644 --- 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 @@ -1,7 +1,6 @@ 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; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpPersist.java index 05c38d8cf..cc11e713e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpPersist.java @@ -1,5 +1,6 @@ package eu.eudat.model.persist; +import eu.eudat.commons.enums.DmpAccessType; import eu.eudat.commons.enums.DmpStatus; import eu.eudat.commons.validation.ValidId; import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist; @@ -24,6 +25,8 @@ public class DmpPersist { private UUID blueprint; + private DmpAccessType accessType; + private List references; private List descriptionTemplates; @@ -94,6 +97,14 @@ public class DmpPersist { this.blueprint = blueprint; } + public DmpAccessType getAccessType() { + return accessType; + } + + public void setAccessType(DmpAccessType accessType) { + this.accessType = accessType; + } + public List getDescriptionTemplates() { return descriptionTemplates; } 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 7b317b3ae..5c7457c7b 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 @@ -153,7 +153,7 @@ public class DescriptionServiceImpl implements DescriptionService { newDescription.setId(UUID.randomUUID()); newDescription.setLabel(existing.getLabel()); newDescription.setDescription(existing.getDescription()); - newDescription.setStatus(DescriptionStatus.Finalized); + newDescription.setStatus(DescriptionStatus.Draft); newDescription.setProperties(existing.getProperties()); newDescription.setDmpId(dmpId); newDescription.setDmpDescriptionTemplateId(existing.getDmpDescriptionTemplateId()); @@ -198,6 +198,7 @@ public class DescriptionServiceImpl implements DescriptionService { this.entityManager.persist(newTag); } + this.entityManager.flush(); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java index 6340f88c7..c52ed7124 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java @@ -352,6 +352,7 @@ public class DmpServiceImpl implements DmpService { data.setLabel(model.getLabel()); data.setProperties(this.jsonHandlingService.toJson(model.getProperties())); data.setDescription(model.getDescription()); + data.setAccessType(model.getAccessType()); data.setUpdatedAt(Instant.now()); if (isUpdate) this.entityManager.merge(data);