From b34094f0613c723c556af069dd94e4a47384483c Mon Sep 17 00:00:00 2001 From: "CITE\\spapacharalampous" Date: Thu, 29 Aug 2024 17:40:42 +0300 Subject: [PATCH] added elastic filters for description --- .../query/DescriptionElasticQuery.java | 46 ++++++++ ...NestedDescriptionTemplateElasticQuery.java | 108 +++++++++++++++++- .../query/NestedReferenceElasticQuery.java | 2 +- .../elastic/query/NestedTagElasticQuery.java | 31 ++++- .../query/lookup/DescriptionLookup.java | 8 +- .../lookup/DescriptionReferenceLookup.java | 14 +++ .../query/lookup/DescriptionTagLookup.java | 13 +++ .../lookup/DescriptionTemplateLookup.java | 20 ++++ 8 files changed, 229 insertions(+), 13 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/elastic/query/DescriptionElasticQuery.java b/backend/core/src/main/java/org/opencdmp/elastic/query/DescriptionElasticQuery.java index 788106496..718dd697b 100644 --- a/backend/core/src/main/java/org/opencdmp/elastic/query/DescriptionElasticQuery.java +++ b/backend/core/src/main/java/org/opencdmp/elastic/query/DescriptionElasticQuery.java @@ -49,7 +49,11 @@ public class DescriptionElasticQuery extends ElasticQuery excludedIds; + private Collection tenantIds; private Collection statuses; + private NestedDescriptionTemplateElasticQuery descriptionTemplateSubQuery; + private NestedReferenceElasticQuery referenceSubQuery; + private NestedTagElasticQuery tagSubQuery; private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); public DescriptionElasticQuery like(String value) { @@ -114,6 +118,21 @@ public class DescriptionElasticQuery extends ElasticQuery values) { + this.tenantIds = values; + return this; + } + + public DescriptionElasticQuery tenantIds(UUID value) { + this.tenantIds = List.of(value); + return this; + } + + public DescriptionElasticQuery tenantIds(UUID... value) { + this.tenantIds = Arrays.asList(value); + return this; + } + public DescriptionElasticQuery statuses(DescriptionStatus value) { this.statuses = List.of(value); return this; @@ -129,6 +148,21 @@ public class DescriptionElasticQuery extends ElasticQuery values) { this.authorize = values; return this; @@ -247,6 +281,9 @@ public class DescriptionElasticQuery extends ElasticQuery { + private Collection ids; + private Collection groupIds; + private Collection versionStatuses; + private Collection excludedIds; + private Collection excludedGroupIds; + private String nestedPath; + public NestedDescriptionTemplateElasticQuery ids(UUID value) { + this.ids = List.of(value); + return this; + } + + public NestedDescriptionTemplateElasticQuery ids(UUID... value) { + this.ids = Arrays.asList(value); + return this; + } + + public NestedDescriptionTemplateElasticQuery ids(Collection value) { + this.ids = value; + return this; + } + + public NestedDescriptionTemplateElasticQuery groupIds(UUID value) { + this.groupIds = List.of(value); + return this; + } + + public NestedDescriptionTemplateElasticQuery groupIds(UUID... value) { + this.groupIds = Arrays.asList(value); + return this; + } + + public NestedDescriptionTemplateElasticQuery groupIds(Collection value) { + this.groupIds = value; + return this; + } + + public NestedDescriptionTemplateElasticQuery versionStatuses(DescriptionTemplateVersionStatus value) { + this.versionStatuses = List.of(value); + return this; + } + + public NestedDescriptionTemplateElasticQuery versionStatuses(DescriptionTemplateVersionStatus... value) { + this.versionStatuses = Arrays.asList(value); + return this; + } + + public NestedDescriptionTemplateElasticQuery versionStatuses(Collection value) { + this.versionStatuses = value; + return this; + } + + public NestedDescriptionTemplateElasticQuery excludedIds(UUID value) { + this.excludedIds = List.of(value); + return this; + } + + public NestedDescriptionTemplateElasticQuery excludedIds(UUID... value) { + this.excludedIds = Arrays.asList(value); + return this; + } + + public NestedDescriptionTemplateElasticQuery excludedIds(Collection value) { + this.excludedIds = value; + return this; + } + + public NestedDescriptionTemplateElasticQuery excludedGroupIds(UUID value) { + this.excludedGroupIds = List.of(value); + return this; + } + + public NestedDescriptionTemplateElasticQuery excludedGroupIds(UUID... value) { + this.excludedGroupIds = Arrays.asList(value); + return this; + } + + public NestedDescriptionTemplateElasticQuery excludedGroupIds(Collection value) { + this.excludedGroupIds = value; + return this; + } + @Override public NestedDescriptionTemplateElasticQuery nestedPath(String value) { this.nestedPath = value; @@ -54,7 +133,28 @@ public class NestedDescriptionTemplateElasticQuery extends ElasticNestedQuery predicates= new ArrayList<>(); + if (this.ids != null) { + predicates.add(this.containsUUID(this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._id), this.ids)._toQuery()); + } + if (this.groupIds != null) { + predicates.add(this.containsUUID(this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._groupId), this.groupIds)._toQuery()); + } + if (this.excludedIds != null) { + predicates.add(this.not(this.containsUUID(this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._id), this.ids)._toQuery())._toQuery()); + } + if (this.excludedGroupIds != null) { + predicates.add(this.not(this.containsUUID(this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._groupId), this.groupIds)._toQuery())._toQuery()); + } + if (this.versionStatuses != null) { + predicates.add(this.contains(this.elasticFieldOf(NestedDescriptionTemplateElasticEntity._versionStatus), this.versionStatuses.stream().map(DescriptionTemplateVersionStatus::getValue).toList().toArray(new Short[this.versionStatuses.size()]))._toQuery()); + } + + if (!predicates.isEmpty()) { + return this.and(predicates); + } else { + return null; + } } @Override diff --git a/backend/core/src/main/java/org/opencdmp/elastic/query/NestedReferenceElasticQuery.java b/backend/core/src/main/java/org/opencdmp/elastic/query/NestedReferenceElasticQuery.java index e4ad7a5b4..465fe8d9d 100644 --- a/backend/core/src/main/java/org/opencdmp/elastic/query/NestedReferenceElasticQuery.java +++ b/backend/core/src/main/java/org/opencdmp/elastic/query/NestedReferenceElasticQuery.java @@ -56,7 +56,7 @@ public class NestedReferenceElasticQuery extends ElasticNestedQuery { + private Collection ids; private String nestedPath; + public NestedTagElasticQuery ids(UUID value) { + this.ids = List.of(value); + return this; + } + + public NestedTagElasticQuery ids(UUID... value) { + this.ids = Arrays.asList(value); + return this; + } + + public NestedTagElasticQuery ids(Collection value) { + this.ids = value; + return this; + } + @Override public NestedTagElasticQuery nestedPath(String value) { this.nestedPath = value; @@ -40,9 +56,7 @@ public class NestedTagElasticQuery extends ElasticNestedQuery predicates = new ArrayList<>(); + if (ids != null) { + predicates.add(this.containsUUID(this.elasticFieldOf(NestedTagElasticEntity._id), this.ids)._toQuery()); + } + + if (!predicates.isEmpty()) { + return this.and(predicates); + } else { + return null; + } } @Override diff --git a/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionLookup.java b/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionLookup.java index d2ab224e2..94502c3b3 100644 --- a/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionLookup.java +++ b/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionLookup.java @@ -161,10 +161,10 @@ public class DescriptionLookup extends Lookup { if (this.finalizedBefore != null) query.finalizedBefore(this.finalizedBefore); if (this.planSubQuery != null) query.planSubQuery(this.planSubQuery.enrichElasticInner(queryFactory)); - if (this.tenantSubQuery != null) throw new UnsupportedOperationException(""); - if (this.descriptionTemplateSubQuery != null) throw new UnsupportedOperationException(""); - if (this.descriptionReferenceSubQuery != null) throw new UnsupportedOperationException(""); - if (this.descriptionTagSubQuery != null) throw new UnsupportedOperationException(""); + if (this.tenantSubQuery != null && this.tenantSubQuery.getIds() != null && !this.tenantSubQuery.getIds().isEmpty()) query.tenantIds(this.tenantSubQuery.getIds()); + if (this.descriptionTemplateSubQuery != null) query.descriptionTemplateSubQuery(this.descriptionTemplateSubQuery.enrichElasticInner(queryFactory)); + if (this.descriptionReferenceSubQuery != null) query.referenceSubQuery(this.descriptionReferenceSubQuery.enrichElasticInner(queryFactory)); + if (this.descriptionTagSubQuery != null) query.tagSubQuery(this.descriptionTagSubQuery.enrichElasticInner(queryFactory)); this.enrichCommon(query); diff --git a/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionReferenceLookup.java b/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionReferenceLookup.java index ef2ec553d..29d394a86 100644 --- a/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionReferenceLookup.java +++ b/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionReferenceLookup.java @@ -1,6 +1,7 @@ package org.opencdmp.query.lookup; import org.opencdmp.commons.enums.IsActive; +import org.opencdmp.elastic.query.NestedReferenceElasticQuery; import org.opencdmp.query.DescriptionReferenceQuery; import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.QueryFactory; @@ -73,4 +74,17 @@ public class DescriptionReferenceLookup extends Lookup { return query; } + public NestedReferenceElasticQuery enrichElasticInner(QueryFactory queryFactory) { + NestedReferenceElasticQuery query = queryFactory.query(NestedReferenceElasticQuery.class); + if (this.ids != null) throw new UnsupportedOperationException(""); + if (this.excludedIds != null) throw new UnsupportedOperationException(""); + if (this.isActives != null) throw new UnsupportedOperationException(""); + if (this.descriptionIds != null) throw new UnsupportedOperationException(""); + if (this.referenceIds != null) query.ids(this.referenceIds); + + this.enrichCommon(query); + + return query; + } + } diff --git a/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionTagLookup.java b/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionTagLookup.java index 9028e5309..bdf88fd9b 100644 --- a/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionTagLookup.java +++ b/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionTagLookup.java @@ -1,6 +1,7 @@ package org.opencdmp.query.lookup; import org.opencdmp.commons.enums.IsActive; +import org.opencdmp.elastic.query.NestedTagElasticQuery; import org.opencdmp.query.DescriptionTagQuery; import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.QueryFactory; @@ -73,4 +74,16 @@ public class DescriptionTagLookup extends Lookup { return query; } + public NestedTagElasticQuery enrichElasticInner(QueryFactory queryFactory) { + NestedTagElasticQuery query = queryFactory.query(NestedTagElasticQuery.class); + if (this.ids != null) throw new UnsupportedOperationException(""); + if (this.excludedIds != null) throw new UnsupportedOperationException(""); + if (this.isActives != null) throw new UnsupportedOperationException(""); + if (this.descriptionIds != null) throw new UnsupportedOperationException(""); + if (this.tagIds != null) query.ids(this.tagIds); + + this.enrichCommon(query); + + return query; + } } diff --git a/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionTemplateLookup.java b/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionTemplateLookup.java index 9f0037c5a..9f3c596b4 100644 --- a/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionTemplateLookup.java +++ b/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionTemplateLookup.java @@ -5,6 +5,7 @@ import gr.cite.tools.data.query.QueryFactory; import org.opencdmp.commons.enums.DescriptionTemplateStatus; import org.opencdmp.commons.enums.DescriptionTemplateVersionStatus; import org.opencdmp.commons.enums.IsActive; +import org.opencdmp.elastic.query.NestedDescriptionTemplateElasticQuery; import org.opencdmp.query.DescriptionTemplateQuery; import java.util.List; @@ -150,4 +151,23 @@ public class DescriptionTemplateLookup extends Lookup { return query; } + public NestedDescriptionTemplateElasticQuery enrichElasticInner(QueryFactory queryFactory) { + NestedDescriptionTemplateElasticQuery query = queryFactory.query(NestedDescriptionTemplateElasticQuery.class); + if (this.ids != null) query.ids(this.ids); + if (this.groupIds != null) query.groupIds(this.groupIds); + if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); + if (this.excludedIds != null) query.excludedIds(this.excludedIds); + if (this.excludedGroupIds != null) query.excludedGroupIds(this.excludedGroupIds); + + if (this.like != null) throw new UnsupportedOperationException(""); + if (this.isActive != null) throw new UnsupportedOperationException(""); + if (this.statuses != null) throw new UnsupportedOperationException(""); + if (this.typeIds != null) throw new UnsupportedOperationException(""); + if (this.versions != null) throw new UnsupportedOperationException(""); + if (this.onlyCanEdit != null) throw new UnsupportedOperationException(""); + + this.enrichCommon(query); + + return query; + } }