From f8251aaf43470eaab41a8606b7fe971a76a808c5 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Wed, 7 Feb 2024 17:23:47 +0200 Subject: [PATCH] bug fix --- .../java/eu/eudat/query/ReferenceQuery.java | 24 ++++++++++++++++++- .../description/DescriptionServiceImpl.java | 3 ++- .../eu/eudat/service/dmp/DmpServiceImpl.java | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java index 76d0110dd..91bce6f5d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java @@ -36,6 +36,7 @@ public class ReferenceQuery extends QueryBase { private Collection referenceTypes; private Collection references; + private Collection sources; private Collection excludedIds; @@ -111,6 +112,21 @@ public class ReferenceQuery extends QueryBase { return this; } + public ReferenceQuery sources(String value) { + this.sources = List.of(value); + return this; + } + + public ReferenceQuery sources(String... value) { + this.sources = Arrays.asList(value); + return this; + } + + public ReferenceQuery sources(Collection values) { + this.sources = values; + return this; + } + public ReferenceQuery excludedIds(Collection values) { this.excludedIds = values; return this; @@ -177,7 +193,7 @@ public class ReferenceQuery extends QueryBase { @Override protected Boolean isFalseQuery() { - return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.excludedIds) || this.isEmpty(this.referenceTypes) || this.isEmpty(this.referenceSourceTypes)|| this.isFalseQuery(this.dmpReferenceQuery); + return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.sources) ||this.isEmpty(this.excludedIds) || this.isEmpty(this.referenceTypes) || this.isEmpty(this.referenceSourceTypes)|| this.isFalseQuery(this.dmpReferenceQuery); } @Override @@ -219,6 +235,12 @@ public class ReferenceQuery extends QueryBase { inClause.value(item); predicates.add(inClause); } + if (this.sources != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._source)); + for (String item : this.sources) + inClause.value(item); + predicates.add(inClause); + } if (this.excludedIds != null) { CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id)); for (UUID item : this.excludedIds) 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 039e2d5e3..72c5c03bd 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 @@ -509,12 +509,13 @@ public class DescriptionServiceImpl implements DescriptionService { referenceEntity = this.entityManager.find(ReferenceEntity.class, referencePersist.getId()); if (referenceEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referencePersist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale())); } else { - referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).references(referencePersist.getReference()).first(); + referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).sources(referencePersist.getSource()).isActive(IsActive.Active).references(referencePersist.getReference()).first(); if (referenceEntity == null){ referenceEntity = new ReferenceEntity(); referenceEntity.setId(UUID.randomUUID()); referenceEntity.setIsActive(IsActive.Active); referenceEntity.setCreatedAt(Instant.now()); + referenceEntity.setType(referencePersist.getType()); referenceEntity.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(referencePersist.getDefinition()))); referenceEntity.setUpdatedAt(Instant.now()); 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 2970813b7..37fd26d96 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 @@ -647,12 +647,13 @@ public class DmpServiceImpl implements DmpService { referenceEntity = this.entityManager.find(ReferenceEntity.class, referencePersist.getId()); if (referenceEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referencePersist.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale())); } else { - referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).references(referencePersist.getReference()).first(); + referenceEntity = this.queryFactory.query(ReferenceQuery.class).sourceTypes(referencePersist.getSourceType()).sources(referencePersist.getSource()).isActive(IsActive.Active).references(referencePersist.getReference()).first(); if (referenceEntity == null){ referenceEntity = new ReferenceEntity(); referenceEntity.setId(UUID.randomUUID()); referenceEntity.setIsActive(IsActive.Active); referenceEntity.setCreatedAt(Instant.now()); + referenceEntity.setType(referencePersist.getType()); referenceEntity.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(referencePersist.getDefinition()))); referenceEntity.setUpdatedAt(Instant.now());