From df87dbf76cd6ef7331abacdf907dea325f123eb3 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Mon, 4 Dec 2023 17:27:47 +0200 Subject: [PATCH] use new subquery --- .../java/eu/eudat/query/DescriptionQuery.java | 8 +++---- .../main/java/eu/eudat/query/DmpQuery.java | 21 ++++++++++++++++--- .../java/eu/eudat/query/lookup/DmpLookup.java | 14 +++++++++++++ dmp-backend/pom.xml | 2 +- 4 files changed, 37 insertions(+), 8 deletions(-) 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 7966001e2..8766064ba 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 @@ -10,6 +10,8 @@ import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DmpDescriptionTemplateEntity; import eu.eudat.data.DmpEntity; import eu.eudat.model.Description; +import eu.eudat.model.Dmp; +import eu.eudat.model.DmpDescriptionTemplate; import eu.eudat.model.PublicDescription; import eu.eudat.query.utils.BuildSubQueryInput; import eu.eudat.query.utils.QueryUtilsService; @@ -238,13 +240,11 @@ public class DescriptionQuery extends QueryBase { predicates.add(inClause); } if (this.dmpDescriptionTemplateQuery != null) { - Subquery subQuery = queryContext.Query.subquery(this.dmpDescriptionTemplateQuery.entityClass()); - this.applySubQuery(this.dmpDescriptionTemplateQuery, queryContext.CriteriaBuilder, subQuery); + QueryContext subQuery = this.applySubQuery(this.dmpDescriptionTemplateQuery, queryContext, UUID.class, DmpDescriptionTemplate._id); predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpDescriptionTemplateId)).value(subQuery)); } if (this.dmpQuery != null) { - Subquery subQuery = queryContext.Query.subquery(this.dmpQuery.entityClass()); - this.applySubQuery(this.dmpQuery, queryContext.CriteriaBuilder, subQuery); + QueryContext subQuery = this.applySubQuery(this.dmpQuery, queryContext, UUID.class, Dmp._id); predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpId)).value(subQuery)); } if (!predicates.isEmpty()) { diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DmpQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DmpQuery.java index a356e5729..49f741676 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DmpQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DmpQuery.java @@ -7,21 +7,24 @@ import eu.eudat.commons.enums.DmpStatus; import eu.eudat.commons.enums.DmpVersionStatus; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.data.DescriptionEntity; +import eu.eudat.data.DmpDescriptionTemplateEntity; import eu.eudat.data.DmpEntity; import eu.eudat.model.Dmp; +import eu.eudat.model.DmpDescriptionTemplate; import eu.eudat.model.PublicDmp; import eu.eudat.query.utils.QueryUtilsService; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.query.*; import jakarta.persistence.Tuple; -import jakarta.persistence.criteria.CriteriaBuilder; -import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.*; 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.*; +import java.util.function.Function; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @@ -43,6 +46,8 @@ public class DmpQuery extends QueryBase { private Collection groupIds; + private DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); private final UserScope userScope; @@ -180,6 +185,11 @@ public class DmpQuery extends QueryBase { return this; } + public DmpQuery dmpDescriptionTemplateSubQuery(DmpDescriptionTemplateQuery subQuery) { + this.dmpDescriptionTemplateQuery = subQuery; + return this; + } + public DmpQuery authorize(EnumSet values) { this.authorize = values; return this; @@ -187,7 +197,7 @@ public class DmpQuery extends QueryBase { @Override protected Boolean isFalseQuery() { - return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.excludedIds) || this.isEmpty(this.accessTypes)|| this.isEmpty(this.statuses); + return this.isEmpty(this.ids) || this.isEmpty(this.isActives) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.excludedIds) || this.isEmpty(this.accessTypes)|| this.isEmpty(this.statuses)|| this.isFalseQuery(this.dmpDescriptionTemplateQuery); } @Override @@ -276,6 +286,11 @@ public class DmpQuery extends QueryBase { inClause.value(item); predicates.add(inClause); } + + if (this.dmpDescriptionTemplateQuery != null) { + QueryContext subQuery = this.applySubQuery(this.dmpDescriptionTemplateQuery, queryContext, UUID.class, DmpDescriptionTemplate._dmp); + predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpDescriptionTemplateId)).value(subQuery)); + } if (!predicates.isEmpty()) { Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); return queryContext.CriteriaBuilder.and(predicatesArray); diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpLookup.java index 6c11ed485..fc727026e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpLookup.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpLookup.java @@ -6,6 +6,7 @@ import eu.eudat.commons.enums.DmpVersionStatus; import eu.eudat.commons.enums.IsActive; import eu.eudat.elastic.query.DmpElasticQuery; import eu.eudat.elastic.query.InnerObjectDmpElasticQuery; +import eu.eudat.query.DmpDescriptionTemplateQuery; import eu.eudat.query.DmpQuery; import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.QueryFactory; @@ -29,6 +30,8 @@ public class DmpLookup extends Lookup { private List versions; + private DmpDescriptionTemplateQuery dmpDescriptionTemplateSubQuery; + public String getLike() { return like; } @@ -93,6 +96,14 @@ public class DmpLookup extends Lookup { this.versionStatuses = versionStatuses; } + public DmpDescriptionTemplateQuery getDmpDescriptionTemplateSubQuery() { + return dmpDescriptionTemplateSubQuery; + } + + public void setDmpDescriptionTemplateSubQuery(DmpDescriptionTemplateQuery dmpDescriptionTemplateSubQuery) { + this.dmpDescriptionTemplateSubQuery = dmpDescriptionTemplateSubQuery; + } + public DmpQuery enrich(QueryFactory queryFactory) { DmpQuery query = queryFactory.query(DmpQuery.class); if (this.like != null) query.like(this.like); @@ -103,6 +114,7 @@ public class DmpLookup extends Lookup { if (this.statuses != null) query.statuses(this.statuses); if (this.versions != null) query.versions(this.versions); if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); + if (this.dmpDescriptionTemplateSubQuery != null) query.dmpDescriptionTemplateSubQuery(this.dmpDescriptionTemplateSubQuery); this.enrichCommon(query); @@ -118,6 +130,7 @@ public class DmpLookup extends Lookup { if (this.statuses != null) query.statuses(this.statuses); if (this.versions != null) query.versions(this.versions); if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); + if (this.dmpDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException(""); this.enrichCommon(query); @@ -133,6 +146,7 @@ public class DmpLookup extends Lookup { if (this.statuses != null) query.statuses(this.statuses); if (this.versions != null) query.versions(this.versions); if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); + if (this.dmpDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException(""); return query; } diff --git a/dmp-backend/pom.xml b/dmp-backend/pom.xml index 6467e3d88..ec9675e3a 100644 --- a/dmp-backend/pom.xml +++ b/dmp-backend/pom.xml @@ -315,7 +315,7 @@ gr.cite data-tools - 2.1.0 + 2.1.1 gr.cite