added elastic filters for description
This commit is contained in:
parent
fd4be758c0
commit
b34094f061
|
@ -49,7 +49,11 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
|||
private Instant finalizedAfter;
|
||||
private Instant finalizedBefore;
|
||||
private Collection<UUID> excludedIds;
|
||||
private Collection<UUID> tenantIds;
|
||||
private Collection<DescriptionStatus> statuses;
|
||||
private NestedDescriptionTemplateElasticQuery descriptionTemplateSubQuery;
|
||||
private NestedReferenceElasticQuery referenceSubQuery;
|
||||
private NestedTagElasticQuery tagSubQuery;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
public DescriptionElasticQuery like(String value) {
|
||||
|
@ -114,6 +118,21 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
|||
return this;
|
||||
}
|
||||
|
||||
public DescriptionElasticQuery tenantIds(Collection<UUID> 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<DescriptionElasticEnti
|
|||
return this;
|
||||
}
|
||||
|
||||
public DescriptionElasticQuery descriptionTemplateSubQuery(NestedDescriptionTemplateElasticQuery subQuery) {
|
||||
this.descriptionTemplateSubQuery = subQuery;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionElasticQuery referenceSubQuery(NestedReferenceElasticQuery subQuery) {
|
||||
this.referenceSubQuery = subQuery;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionElasticQuery tagSubQuery(NestedTagElasticQuery subQuery) {
|
||||
this.tagSubQuery = subQuery;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionElasticQuery authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
|
@ -247,6 +281,9 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
|||
if (this.excludedIds != null) {
|
||||
predicates.add(this.not(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._id), this.excludedIds)._toQuery())._toQuery());
|
||||
}
|
||||
if (this.tenantIds != null) {
|
||||
predicates.add(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._tenantId), this.tenantIds)._toQuery());
|
||||
}
|
||||
if (this.statuses != null) {
|
||||
predicates.add(this.contains(this.elasticFieldOf(DescriptionElasticEntity._status), this.statuses.stream().map(DescriptionStatus::getValue).toList().toArray(new Short[this.statuses.size()]))._toQuery());
|
||||
}
|
||||
|
@ -265,6 +302,15 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
|||
if (this.planSubQuery != null) {
|
||||
predicates.add(this.planSubQuery.innerPath(DescriptionElasticEntity._plan).applyFilters());
|
||||
}
|
||||
if (this.descriptionTemplateSubQuery != null) {
|
||||
predicates.add(this.nestedQuery( this.descriptionTemplateSubQuery.nestedPath(DescriptionElasticEntity._descriptionTemplate)).build()._toQuery());
|
||||
}
|
||||
if (this.referenceSubQuery != null) {
|
||||
predicates.add(this.nestedQuery( this.referenceSubQuery.nestedPath(DescriptionElasticEntity._references)).build()._toQuery());
|
||||
}
|
||||
if (this.tagSubQuery != null) {
|
||||
predicates.add(this.nestedQuery( this.tagSubQuery.nestedPath(DescriptionElasticEntity._tags)).build()._toQuery());
|
||||
}
|
||||
if (!predicates.isEmpty()) {
|
||||
return this.and(predicates);
|
||||
} else {
|
||||
|
|
|
@ -13,16 +13,95 @@ import org.springframework.context.annotation.Scope;
|
|||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedDescriptionTemplateElasticQuery extends ElasticNestedQuery<NestedDescriptionTemplateElasticQuery, NestedDescriptionTemplateElasticEntity, UUID> {
|
||||
|
||||
private Collection<UUID> ids;
|
||||
private Collection<UUID> groupIds;
|
||||
private Collection<DescriptionTemplateVersionStatus> versionStatuses;
|
||||
private Collection<UUID> excludedIds;
|
||||
private Collection<UUID> 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<UUID> 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<UUID> 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<DescriptionTemplateVersionStatus> 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<UUID> 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<UUID> value) {
|
||||
this.excludedGroupIds = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NestedDescriptionTemplateElasticQuery nestedPath(String value) {
|
||||
this.nestedPath = value;
|
||||
|
@ -54,7 +133,28 @@ public class NestedDescriptionTemplateElasticQuery extends ElasticNestedQuery<Ne
|
|||
|
||||
@Override
|
||||
protected Query applyFilters() {
|
||||
return null;
|
||||
List<Query> 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
|
||||
|
|
|
@ -56,7 +56,7 @@ public class NestedReferenceElasticQuery extends ElasticNestedQuery<NestedRefere
|
|||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return false;
|
||||
return this.isEmpty(this.ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,8 +18,24 @@ import java.util.*;
|
|||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class NestedTagElasticQuery extends ElasticNestedQuery<NestedTagElasticQuery, NestedTagElasticEntity, UUID> {
|
||||
|
||||
private Collection<UUID> 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<UUID> value) {
|
||||
this.ids = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NestedTagElasticQuery nestedPath(String value) {
|
||||
this.nestedPath = value;
|
||||
|
@ -40,9 +56,7 @@ public class NestedTagElasticQuery extends ElasticNestedQuery<NestedTagElasticQu
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Boolean isFalseQuery() {
|
||||
return false;
|
||||
}
|
||||
protected Boolean isFalseQuery() { return this.isEmpty(this.ids); }
|
||||
|
||||
@Override
|
||||
protected Query applyAuthZ() {
|
||||
|
@ -51,7 +65,16 @@ public class NestedTagElasticQuery extends ElasticNestedQuery<NestedTagElasticQu
|
|||
|
||||
@Override
|
||||
protected Query applyFilters() {
|
||||
return null;
|
||||
List<Query> 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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue