diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/data/DescriptionElasticEntity.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/data/DescriptionElasticEntity.java index 4881d374b..df810740b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/elastic/data/DescriptionElasticEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/data/DescriptionElasticEntity.java @@ -37,6 +37,10 @@ public class DescriptionElasticEntity { private Date finalizedAt; public final static String _finalizedAt = "finalizedAt"; + @Field(value = DescriptionElasticEntity._createdAt, type = FieldType.Date) + private Date createdAt; + public final static String _createdAt = "createdAt"; + @Field(value = DescriptionElasticEntity._tags, type = FieldType.Nested) private List tags; public final static String _tags = "tags"; @@ -124,4 +128,12 @@ public class DescriptionElasticEntity { public void setReferences(List references) { this.references = references; } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DescriptionElasticBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DescriptionElasticBuilder.java index 327549108..ef5ce69ed 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DescriptionElasticBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DescriptionElasticBuilder.java @@ -63,6 +63,7 @@ public class DescriptionElasticBuilder extends BaseElasticBuilder { private Collection ids; + private String like; + private InnerObjectDmpElasticQuery dmpSubQuery; + private Instant createdAfter; + private Instant createdBefore; + private Instant finalizedAfter; + private Instant finalizedBefore; + private Collection excludedIds; private Collection statuses; private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + public DescriptionElasticQuery like(String value) { + this.like = value; + return this; + } + public DescriptionElasticQuery ids(UUID value) { this.ids = List.of(value); return this; @@ -45,7 +71,49 @@ public class DescriptionElasticQuery extends ElasticQuery values) { + this.excludedIds = values; + return this; + } + + public DescriptionElasticQuery excludedIds(UUID value) { + this.excludedIds = List.of(value); + return this; + } + + public DescriptionElasticQuery excludedIds(UUID... value) { + this.excludedIds = Arrays.asList(value); + return this; + } + public DescriptionElasticQuery statuses(DescriptionStatus value) { this.statuses = List.of(value); return this; @@ -69,17 +137,23 @@ public class DescriptionElasticQuery extends ElasticQuery predicates = new ArrayList<>(); + if (usePublic ) { + predicates.add(this.and( + this.equals(new ElasticField(DescriptionElasticEntity._dmp + "." + DmpElasticEntity._status, this.entityClass()).disableInfer(true), DmpStatus.Finalized.getValue()), + this.equals(new ElasticField(DescriptionElasticEntity._dmp + "." + DmpElasticEntity._accessType, this.entityClass()).disableInfer(true), DmpAccessType.Public.getValue()) + )); + } + if (userId != null) { + NestedCollaboratorElasticQuery query = this.queryFactory.query(NestedCollaboratorElasticQuery.class).nestedPath(DescriptionElasticEntity._dmp + "." + NestedDmpElasticEntity._collaborators); + query.ids(userId); + predicates.add(this.nestedQuery(query).build()._toQuery()); + } + + if (!predicates.isEmpty()) { + return this.or(predicates)._toQuery(); + } else { + return this.equals(this.elasticFieldOf(DescriptionElasticEntity._id), UUID.randomUUID()); + } + } + @Override protected Query applyFilters() { List predicates = new ArrayList<>(); + if (like != null && !like.isBlank()) { + if (!like.startsWith("*")) like = "*" + like; + if (!like.endsWith("*")) like = like + "*"; + ElasticFields elasticFields = this.elasticFieldsOf(); + elasticFields.add(DescriptionElasticEntity._label); + elasticFields.add(DescriptionElasticEntity._description); + predicates.add(this.like(elasticFields, List.of(like))._toQuery()); + } if (ids != null) { predicates.add(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._id), ids)._toQuery()); } + if (excludedIds != null) { + predicates.add(this.not(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._id), excludedIds)._toQuery())._toQuery()); + } if (statuses != null) { predicates.add(this.contains(this.elasticFieldOf(DescriptionElasticEntity._status), statuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[statuses.size()]))._toQuery()); } - + if (this.finalizedAfter != null) { + predicates.add(this.dateGreaterThanQuery(this.elasticFieldOf(DescriptionElasticEntity._finalizedAt), this.finalizedAfter)._toQuery()); + } + if (this.finalizedBefore != null) { + predicates.add(this.dateLessThanQuery(this.elasticFieldOf(DescriptionElasticEntity._finalizedAt), this.finalizedBefore)._toQuery()); + } + if (this.createdAfter != null) { + predicates.add(this.dateGreaterThanQuery(this.elasticFieldOf(DescriptionElasticEntity._createdAt), this.createdAfter)._toQuery()); + } + if (this.createdBefore != null) { + predicates.add(this.dateLessThanQuery(this.elasticFieldOf(DescriptionElasticEntity._createdAt), this.createdBefore)._toQuery()); + } + if (dmpSubQuery != null) { + predicates.add(dmpSubQuery.innerPath(DescriptionElasticEntity._dmp).applyFilters()); + } if (!predicates.isEmpty()) { return this.and(predicates); } else { @@ -112,6 +239,7 @@ public class DescriptionElasticQuery extends ElasticQuery { + private String like; private Collection ids; + private Collection excludedIds; private Collection statuses; + private Collection versionStatuses; + private Collection accessTypes; + private Collection versions; + private Collection groupIds; private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + public DmpElasticQuery like(String value) { + this.like = value; + return this; + } + public DmpElasticQuery ids(UUID value) { this.ids = List.of(value); return this; @@ -47,7 +66,52 @@ public class DmpElasticQuery extends ElasticQuery { this.ids = values; return this; } - + + public DmpElasticQuery excludedIds(Collection values) { + this.excludedIds = values; + return this; + } + + public DmpElasticQuery excludedIds(UUID value) { + this.excludedIds = List.of(value); + return this; + } + + public DmpElasticQuery excludedIds(UUID... value) { + this.excludedIds = Arrays.asList(value); + return this; + } + + public DmpElasticQuery versionStatuses(DmpVersionStatus value) { + this.versionStatuses = List.of(value); + return this; + } + + public DmpElasticQuery versionStatuses(DmpVersionStatus... value) { + this.versionStatuses = Arrays.asList(value); + return this; + } + + public DmpElasticQuery versionStatuses(Collection values) { + this.versionStatuses = values; + return this; + } + + public DmpElasticQuery accessTypes(DmpAccessType value) { + this.accessTypes = List.of(value); + return this; + } + + public DmpElasticQuery accessTypes(DmpAccessType... value) { + this.accessTypes = Arrays.asList(value); + return this; + } + + public DmpElasticQuery accessTypes(Collection values) { + this.accessTypes = values; + return this; + } + public DmpElasticQuery statuses(DmpStatus value) { this.statuses = List.of(value); return this; @@ -63,6 +127,36 @@ public class DmpElasticQuery extends ElasticQuery { return this; } + public DmpElasticQuery versions(Integer value) { + this.versions = List.of(value); + return this; + } + + public DmpElasticQuery versions(Integer... value) { + this.versions = Arrays.asList(value); + return this; + } + + public DmpElasticQuery versions(Collection values) { + this.versions = values; + return this; + } + + public DmpElasticQuery groupIds(UUID value) { + this.groupIds = List.of(value); + return this; + } + + public DmpElasticQuery groupIds(UUID... value) { + this.groupIds = Arrays.asList(value); + return this; + } + + public DmpElasticQuery groupIds(Collection values) { + this.groupIds = values; + return this; + } + public DmpElasticQuery authorize(EnumSet values) { this.authorize = values; return this; @@ -71,17 +165,21 @@ public class DmpElasticQuery extends ElasticQuery { private final QueryFactory queryFactory; private final AppElasticProperties appElasticProperties; private final ElasticService elasticService; + private final UserScope userScope; + private final AuthorizationService authService; @Autowired() - public DmpElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticProperties appElasticProperties, ElasticService elasticService) { + public DmpElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticProperties appElasticProperties, ElasticService elasticService, UserScope userScope, AuthorizationService authService) { super(elasticsearchTemplate, elasticProperties); this.queryFactory = queryFactory; this.appElasticProperties = appElasticProperties; this.elasticService = elasticService; + this.userScope = userScope; + this.authService = authService; } @Override protected Boolean isFalseQuery() { - return this.isEmpty(this.ids) || this.isEmpty(this.statuses); + return this.isEmpty(this.ids) || this.isEmpty(this.versionStatuses) || this.isEmpty(this.excludedIds) || this.isEmpty(this.accessTypes)|| this.isEmpty(this.statuses); } @Override @@ -89,15 +187,62 @@ public class DmpElasticQuery extends ElasticQuery { return DmpElasticEntity.class; } + @Override + protected Query applyAuthZ() { + if (this.authorize.contains(AuthorizationFlags.None)) return null; + if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDmp)) return null; + UUID userId = null; + boolean usePublic = this.authorize.contains(AuthorizationFlags.Public); + if (this.authorize.contains(AuthorizationFlags.DmpAssociated)) userId = this.userScope.getUserIdSafe(); + + List predicates = new ArrayList<>(); + if (usePublic) { + predicates.add(this.and( + this.equals(this.elasticFieldOf(DmpElasticEntity._status), DmpStatus.Finalized.getValue()), + this.equals(this.elasticFieldOf(DmpElasticEntity._accessType), DmpAccessType.Public.getValue()) + )); + } + if (userId != null) { + NestedCollaboratorElasticQuery query = this.queryFactory.query(NestedCollaboratorElasticQuery.class).nestedPath(DmpElasticEntity._collaborators); + query.ids(userId); + predicates.add(this.nestedQuery(query).build()._toQuery()); + } + return this.or(predicates)._toQuery(); + } + @Override protected Query applyFilters() { List predicates = new ArrayList<>(); + + if (like != null && !like.isBlank()) { + if (!like.startsWith("*")) like = "*" + like; + if (!like.endsWith("*")) like = like + "*"; + ElasticFields elasticFields = this.elasticFieldsOf(); + elasticFields.add(DmpElasticEntity._label); + elasticFields.add(DmpElasticEntity._descriptions); + predicates.add(this.like(elasticFields, List.of(like))._toQuery()); + } if (ids != null) { predicates.add(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._id), ids)._toQuery()); } + if (groupIds != null) { + predicates.add(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._groupId), groupIds)._toQuery()); + } + if (versions != null) { + predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._version), versions.toArray(new Integer[versions.size()]))._toQuery()); + } + if (excludedIds != null) { + predicates.add(this.not(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._id), excludedIds)._toQuery())._toQuery()); + } if (statuses != null) { predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._status), statuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[statuses.size()]))._toQuery()); } + if (versionStatuses != null) { + predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._versionStatus), versionStatuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[versionStatuses.size()]))._toQuery()); + } + if (accessTypes != null) { + predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._accessType), accessTypes.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[accessTypes.size()]))._toQuery()); + } if (!predicates.isEmpty()) { return this.and(predicates); diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/query/InnerObjectDmpElasticQuery.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/query/InnerObjectDmpElasticQuery.java index 0d66fc214..da2c272f5 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/elastic/query/InnerObjectDmpElasticQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/query/InnerObjectDmpElasticQuery.java @@ -1,5 +1,6 @@ package eu.eudat.elastic.query; import co.elastic.clients.elasticsearch._types.query_dsl.Query; +import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.commons.enums.DmpAccessType; import eu.eudat.commons.enums.DmpStatus; import eu.eudat.commons.enums.DmpVersionStatus; @@ -10,6 +11,7 @@ import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.elastic.configuration.ElasticProperties; import gr.cite.tools.elastic.mapper.FieldBasedMapper; import gr.cite.tools.elastic.query.ElasticField; +import gr.cite.tools.elastic.query.ElasticFields; import gr.cite.tools.elastic.query.ElasticInnerObjectQuery; import gr.cite.tools.elastic.query.ElasticNestedQuery; import org.springframework.beans.factory.annotation.Autowired; @@ -19,11 +21,133 @@ import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate; import org.springframework.stereotype.Component; import java.util.*; +import java.util.stream.Collectors; @Component //Like in C# make it Transient @Scope(BeanDefinition.SCOPE_PROTOTYPE) public class InnerObjectDmpElasticQuery extends ElasticInnerObjectQuery { + private String like; + private Collection ids; + private Collection excludedIds; + private Collection statuses; + private Collection versionStatuses; + private Collection accessTypes; + private Collection versions; + private Collection groupIds; + + + + + public InnerObjectDmpElasticQuery like(String value) { + this.like = value; + return this; + } + + public InnerObjectDmpElasticQuery ids(UUID value) { + this.ids = List.of(value); + return this; + } + + public InnerObjectDmpElasticQuery ids(UUID... value) { + this.ids = Arrays.asList(value); + return this; + } + + public InnerObjectDmpElasticQuery ids(Collection values) { + this.ids = values; + return this; + } + + public InnerObjectDmpElasticQuery excludedIds(Collection values) { + this.excludedIds = values; + return this; + } + + public InnerObjectDmpElasticQuery excludedIds(UUID value) { + this.excludedIds = List.of(value); + return this; + } + + public InnerObjectDmpElasticQuery excludedIds(UUID... value) { + this.excludedIds = Arrays.asList(value); + return this; + } + + public InnerObjectDmpElasticQuery versionStatuses(DmpVersionStatus value) { + this.versionStatuses = List.of(value); + return this; + } + + public InnerObjectDmpElasticQuery versionStatuses(DmpVersionStatus... value) { + this.versionStatuses = Arrays.asList(value); + return this; + } + + public InnerObjectDmpElasticQuery versionStatuses(Collection values) { + this.versionStatuses = values; + return this; + } + + public InnerObjectDmpElasticQuery accessTypes(DmpAccessType value) { + this.accessTypes = List.of(value); + return this; + } + + public InnerObjectDmpElasticQuery accessTypes(DmpAccessType... value) { + this.accessTypes = Arrays.asList(value); + return this; + } + + public InnerObjectDmpElasticQuery accessTypes(Collection values) { + this.accessTypes = values; + return this; + } + + public InnerObjectDmpElasticQuery statuses(DmpStatus value) { + this.statuses = List.of(value); + return this; + } + + public InnerObjectDmpElasticQuery statuses(DmpStatus... value) { + this.statuses = Arrays.asList(value); + return this; + } + + public InnerObjectDmpElasticQuery statuses(Collection values) { + this.statuses = values; + return this; + } + + public InnerObjectDmpElasticQuery versions(Integer value) { + this.versions = List.of(value); + return this; + } + + public InnerObjectDmpElasticQuery versions(Integer... value) { + this.versions = Arrays.asList(value); + return this; + } + + public InnerObjectDmpElasticQuery versions(Collection values) { + this.versions = values; + return this; + } + + public InnerObjectDmpElasticQuery groupIds(UUID value) { + this.groupIds = List.of(value); + return this; + } + + public InnerObjectDmpElasticQuery groupIds(UUID... value) { + this.groupIds = Arrays.asList(value); + return this; + } + + public InnerObjectDmpElasticQuery groupIds(Collection values) { + this.groupIds = values; + return this; + } private String innerPath; @@ -53,7 +177,43 @@ public class InnerObjectDmpElasticQuery extends ElasticInnerObjectQuery predicates = new ArrayList<>(); + + if (like != null && !like.isBlank()) { + if (!like.startsWith("*")) like = "*" + like; + if (!like.endsWith("*")) like = like + "*"; + ElasticFields elasticFields = new ElasticFields(this.entityClass(), List.of(this.getInnerPath())); + elasticFields.add(DmpElasticEntity._label, true); + elasticFields.add(DmpElasticEntity._descriptions, true); + predicates.add(this.like(elasticFields, List.of(like))._toQuery()); + } + if (ids != null) { + predicates.add(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._id).disableInfer(true), ids)._toQuery()); + } + if (groupIds != null) { + predicates.add(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._groupId).disableInfer(true), groupIds)._toQuery()); + } + if (versions != null) { + predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._version).disableInfer(true), versions.toArray(new Integer[versions.size()]))._toQuery()); + } + if (excludedIds != null) { + predicates.add(this.not(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._id).disableInfer(true), excludedIds)._toQuery())._toQuery()); + } + if (statuses != null) { + predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._status).disableInfer(true), statuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[statuses.size()]))._toQuery()); + } + if (versionStatuses != null) { + predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._versionStatus).disableInfer(true), versionStatuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[versionStatuses.size()]))._toQuery()); + } + if (accessTypes != null) { + predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._accessType).disableInfer(true), accessTypes.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[accessTypes.size()]))._toQuery()); + } + + if (!predicates.isEmpty()) { + return this.and(predicates); + } else { + return null; + } } @Override diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/query/NestedCollaboratorElasticQuery.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/query/NestedCollaboratorElasticQuery.java index ddc586f24..05b41f4fa 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/elastic/query/NestedCollaboratorElasticQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/query/NestedCollaboratorElasticQuery.java @@ -2,6 +2,7 @@ package eu.eudat.elastic.query; import co.elastic.clients.elasticsearch._types.query_dsl.Query; import eu.eudat.commons.enums.DmpUserRole; +import eu.eudat.elastic.data.DmpElasticEntity; import eu.eudat.elastic.data.nested.NestedCollaboratorElasticEntity; import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.elastic.configuration.ElasticProperties; @@ -14,11 +15,27 @@ import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate; import org.springframework.stereotype.Component; import java.util.*; +import java.util.stream.Collectors; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class NestedCollaboratorElasticQuery extends ElasticNestedQuery { + private Collection ids; + + public NestedCollaboratorElasticQuery ids(UUID value) { + this.ids = List.of(value); + return this; + } + public NestedCollaboratorElasticQuery ids(UUID... value) { + this.ids = Arrays.asList(value); + return this; + } + + public NestedCollaboratorElasticQuery ids(Collection values) { + this.ids = values; + return this; + } private String nestedPath; @Override @@ -42,7 +59,7 @@ public class NestedCollaboratorElasticQuery extends ElasticNestedQuery predicates = new ArrayList<>(); + if (ids != null) { + predicates.add(this.containsUUID(this.elasticFieldOf(NestedCollaboratorElasticEntity._id), ids)._toQuery()); + } + + if (!predicates.isEmpty()) { + return this.and(predicates); + } else { + return null; + } } @Override 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 5b7698481..36029acfd 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 @@ -35,8 +35,11 @@ public class DescriptionQuery extends QueryBase { private Collection ids; private DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery; private DmpQuery dmpQuery; + private Instant createdAfter; + private Instant createdBefore; + private Instant finalizedAfter; + private Instant finalizedBefore; private Collection excludedIds; - private Collection isActives; private Collection statuses; @@ -77,6 +80,28 @@ public class DescriptionQuery extends QueryBase { return this; } + public DescriptionQuery createdAfter(Instant value) { + this.createdAfter = value; + return this; + } + + public DescriptionQuery createdBefore(Instant value) { + this.createdBefore = value; + return this; + } + + + + public DescriptionQuery finalizedAfter(Instant value) { + this.finalizedAfter = value; + return this; + } + + public DescriptionQuery finalizedBefore(Instant value) { + this.finalizedBefore = value; + return this; + } + public DescriptionQuery dmpSubQuery(DmpQuery subQuery) { this.dmpQuery = subQuery; return this; @@ -182,6 +207,18 @@ public class DescriptionQuery extends QueryBase { inClause.value(item); predicates.add(inClause); } + if (this.createdAfter != null) { + predicates.add(queryContext.CriteriaBuilder.greaterThan(queryContext.Root.get(DescriptionEntity._createdAt), this.createdAfter)); + } + if (this.createdBefore != null) { + predicates.add(queryContext.CriteriaBuilder.lessThan(queryContext.Root.get(DescriptionEntity._createdAt), this.createdBefore)); + } + if (this.finalizedAfter != null) { + predicates.add(queryContext.CriteriaBuilder.greaterThan(queryContext.Root.get(DescriptionEntity._finalizedAt), this.finalizedAfter)); + } + if (this.finalizedBefore != null) { + predicates.add(queryContext.CriteriaBuilder.lessThan(queryContext.Root.get(DescriptionEntity._finalizedAt), this.finalizedAfter)); + } if (this.excludedIds != null) { CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._id)); for (UUID item : this.excludedIds) diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java index 9f93de0ac..5f6e6e171 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java @@ -33,7 +33,6 @@ public class DmpDescriptionTemplateQuery extends QueryBase ids; private Collection dmpIds; - private DmpQuery dmpQuery; private Collection descriptionTemplateIds; @@ -104,11 +103,6 @@ public class DmpDescriptionTemplateQuery extends QueryBase subQuery = queryContext.Query.subquery(this.dmpQuery.entityClass()); - this.applySubQuery(this.dmpQuery, queryContext.CriteriaBuilder, subQuery); - predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._dmpId)).value(subQuery)); - } if (this.dmpIds != null) { CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._dmpId)); for (UUID item : this.dmpIds) diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DescriptionLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DescriptionLookup.java index 95037acf1..203c6cebe 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DescriptionLookup.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DescriptionLookup.java @@ -2,10 +2,13 @@ package eu.eudat.query.lookup; import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.commons.enums.IsActive; +import eu.eudat.elastic.query.DescriptionElasticQuery; +import eu.eudat.elastic.query.InnerObjectDmpElasticQuery; import eu.eudat.query.DescriptionQuery; import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.QueryFactory; +import java.time.Instant; import java.util.List; import java.util.UUID; @@ -16,8 +19,11 @@ public class DescriptionLookup extends Lookup { private List ids; private List excludedIds; + private Instant createdAfter; + private Instant createdBefore; + private Instant finalizedAfter; + private Instant finalizedBefore; - private DmpDescriptionTemplateLookup dmpDescriptionTemplateSubQuery; private DmpLookup dmpSubQuery; private List isActive; @@ -64,14 +70,6 @@ public class DescriptionLookup extends Lookup { this.statuses = statuses; } - public DmpDescriptionTemplateLookup getDmpDescriptionTemplateSubQuery() { - return dmpDescriptionTemplateSubQuery; - } - - public void setDmpDescriptionTemplateSubQuery(DmpDescriptionTemplateLookup dmpDescriptionTemplateSubQuery) { - this.dmpDescriptionTemplateSubQuery = dmpDescriptionTemplateSubQuery; - } - public DmpLookup getDmpSubQuery() { return dmpSubQuery; } @@ -80,19 +78,76 @@ public class DescriptionLookup extends Lookup { this.dmpSubQuery = dmpSubQuery; } + public Instant getCreatedAfter() { + return createdAfter; + } + + public void setCreatedAfter(Instant createdAfter) { + this.createdAfter = createdAfter; + } + + public Instant getCreatedBefore() { + return createdBefore; + } + + public void setCreatedBefore(Instant createdBefore) { + this.createdBefore = createdBefore; + } + + public Instant getFinalizedAfter() { + return finalizedAfter; + } + + public void setFinalizedAfter(Instant finalizedAfter) { + this.finalizedAfter = finalizedAfter; + } + + public Instant getFinalizedBefore() { + return finalizedBefore; + } + + public void setFinalizedBefore(Instant finalizedBefore) { + this.finalizedBefore = finalizedBefore; + } + public DescriptionQuery enrich(QueryFactory queryFactory) { DescriptionQuery query = queryFactory.query(DescriptionQuery.class); if (this.like != null) query.like(this.like); if (this.ids != null) query.ids(this.ids); if (this.excludedIds != null) query.excludedIds(this.excludedIds); - if (this.dmpDescriptionTemplateSubQuery != null) query.dmpDescriptionTemplateSubQuery(this.dmpDescriptionTemplateSubQuery.enrich(queryFactory)); if (this.dmpSubQuery != null) query.dmpSubQuery(this.dmpSubQuery.enrich(queryFactory)); if (this.isActive != null) query.isActive(this.isActive); if (this.statuses != null) query.statuses(this.statuses); + if (this.createdAfter != null) query.createdAfter(this.createdAfter); + if (this.createdBefore != null) query.createdBefore(this.createdBefore); + if (this.finalizedAfter != null) query.finalizedAfter(this.finalizedAfter); + if (this.finalizedBefore != null) query.finalizedBefore(this.finalizedBefore); this.enrichCommon(query); return query; } + public DescriptionElasticQuery enrichElastic(QueryFactory queryFactory) { + DescriptionElasticQuery query = queryFactory.query(DescriptionElasticQuery.class); + InnerObjectDmpElasticQuery dmpElasticQuery = null; + if (this.like != null) query.like(this.like); + if (this.ids != null) query.ids(this.ids); + if (this.excludedIds != null) query.excludedIds(this.excludedIds); + if (this.statuses != null) query.statuses(this.statuses); + if (this.createdAfter != null) query.createdAfter(this.createdAfter); + if (this.createdBefore != null) query.createdBefore(this.createdBefore); + if (this.finalizedAfter != null) query.finalizedAfter(this.finalizedAfter); + if (this.finalizedBefore != null) query.finalizedBefore(this.finalizedBefore); + if (this.dmpSubQuery != null) query.dmpSubQuery(this.dmpSubQuery.enrichElasticInner(queryFactory)); + + this.enrichCommon(query); + + return query; + } + + public boolean useElastic() { + return this.like != null && !this.like.isBlank(); + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpDescriptionTemplateLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpDescriptionTemplateLookup.java index 23f85a022..637315f31 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpDescriptionTemplateLookup.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpDescriptionTemplateLookup.java @@ -15,7 +15,6 @@ public class DmpDescriptionTemplateLookup extends Lookup { private List ids; private List dmpIds; private List descriptionTemplateIds; - private DmpLookup dmpSubQuery; private List excludedIds; @@ -61,14 +60,6 @@ public class DmpDescriptionTemplateLookup extends Lookup { this.descriptionTemplateIds = descriptionTemplateIds; } - public DmpLookup getDmpSubQuery() { - return dmpSubQuery; - } - - public void setDmpSubQuery(DmpLookup dmpSubQuery) { - this.dmpSubQuery = dmpSubQuery; - } - public DmpDescriptionTemplateQuery enrich(QueryFactory queryFactory) { DmpDescriptionTemplateQuery query = queryFactory.query(DmpDescriptionTemplateQuery.class); if (this.ids != null) query.ids(this.ids); @@ -76,7 +67,6 @@ public class DmpDescriptionTemplateLookup extends Lookup { if (this.descriptionTemplateIds != null) query.ids(this.descriptionTemplateIds); if (this.excludedIds != null) query.excludedIds(this.excludedIds); if (this.isActive != null) query.isActive(this.isActive); - if (this.dmpSubQuery != null) query.dmpSubQuery(this.dmpSubQuery.enrich(queryFactory)); this.enrichCommon(query); 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 84742d2a7..6c11ed485 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 @@ -4,6 +4,8 @@ import eu.eudat.commons.enums.DmpAccessType; import eu.eudat.commons.enums.DmpStatus; 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.DmpQuery; import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.QueryFactory; @@ -107,4 +109,36 @@ public class DmpLookup extends Lookup { return query; } + public DmpElasticQuery enrichElastic(QueryFactory queryFactory) { + DmpElasticQuery query = queryFactory.query(DmpElasticQuery.class); + if (this.like != null) query.like(this.like); + if (this.ids != null) query.ids(this.ids); + if (this.excludedIds != null) query.excludedIds(this.excludedIds); + if (this.accessTypes != null) query.accessTypes(this.accessTypes); + if (this.statuses != null) query.statuses(this.statuses); + if (this.versions != null) query.versions(this.versions); + if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); + + this.enrichCommon(query); + + return query; + } + + public InnerObjectDmpElasticQuery enrichElasticInner(QueryFactory queryFactory) { + InnerObjectDmpElasticQuery query = queryFactory.query(InnerObjectDmpElasticQuery.class); + if (this.like != null) query.like(this.like); + if (this.ids != null) query.ids(this.ids); + if (this.excludedIds != null) query.excludedIds(this.excludedIds); + if (this.accessTypes != null) query.accessTypes(this.accessTypes); + if (this.statuses != null) query.statuses(this.statuses); + if (this.versions != null) query.versions(this.versions); + if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses); + + return query; + } + + public boolean useElastic() { + return this.like != null && !this.like.isBlank(); + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticQueryHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticQueryHelperService.java new file mode 100644 index 000000000..9ad285810 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticQueryHelperService.java @@ -0,0 +1,20 @@ +package eu.eudat.service.elastic; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.model.*; +import eu.eudat.model.result.QueryResult; +import eu.eudat.query.lookup.DescriptionLookup; +import eu.eudat.query.lookup.DmpLookup; +import gr.cite.tools.fieldset.FieldSet; + +import java.util.EnumSet; + + +public interface ElasticQueryHelperService { + QueryResult collect(DmpLookup lookup, EnumSet authorizationFlags, FieldSet fieldSet); + QueryResult collectPublic(DmpLookup lookup, EnumSet authorizationFlags, FieldSet fieldSet); + long count(DmpLookup lookup, EnumSet authorizationFlags); + QueryResult collect(DescriptionLookup lookup, EnumSet authorizationFlags, FieldSet fieldSet); + QueryResult collectPublic(DescriptionLookup lookup, EnumSet authorizationFlags, FieldSet fieldSet); + long count(DescriptionLookup lookup, EnumSet authorizationFlags); +} \ No newline at end of file diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticQueryHelperServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticQueryHelperServiceImpl.java new file mode 100644 index 000000000..63cb512c2 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticQueryHelperServiceImpl.java @@ -0,0 +1,123 @@ +package eu.eudat.service.elastic; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.data.DescriptionEntity; +import eu.eudat.data.DmpEntity; +import eu.eudat.elastic.data.DescriptionElasticEntity; +import eu.eudat.elastic.data.DmpElasticEntity; +import eu.eudat.model.Description; +import eu.eudat.model.Dmp; +import eu.eudat.model.PublicDescription; +import eu.eudat.model.PublicDmp; +import eu.eudat.model.builder.DescriptionBuilder; +import eu.eudat.model.builder.DmpBuilder; +import eu.eudat.model.builder.PublicDescriptionBuilder; +import eu.eudat.model.builder.PublicDmpBuilder; +import eu.eudat.model.result.QueryResult; +import eu.eudat.query.DescriptionQuery; +import eu.eudat.query.DmpQuery; +import eu.eudat.query.lookup.DescriptionLookup; +import eu.eudat.query.lookup.DmpLookup; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.fieldset.BaseFieldSet; +import gr.cite.tools.fieldset.FieldSet; +import org.springframework.stereotype.Service; + +import java.util.EnumSet; +import java.util.List; +import java.util.function.Function; + +@Service +public class ElasticQueryHelperServiceImpl implements ElasticQueryHelperService { + + private final QueryFactory queryFactory; + private final BuilderFactory builderFactory; + private final ElasticService elasticService; + + public ElasticQueryHelperServiceImpl(QueryFactory queryFactory, BuilderFactory builderFactory, ElasticService elasticService) { + this.queryFactory = queryFactory; + this.builderFactory = builderFactory; + this.elasticService = elasticService; + } + + @Override + public QueryResult collect(DmpLookup lookup, EnumSet authorizationFlags, FieldSet fieldSet) { + EnumSet flags = authorizationFlags == null ? EnumSet.of(AuthorizationFlags.None) : authorizationFlags; + return this.collect(lookup, (d) -> this.builderFactory.builder(DmpBuilder.class).authorize(flags).build(fieldSet != null ? fieldSet : lookup.getProject(), d), flags); + } + + @Override + public QueryResult collectPublic(DmpLookup lookup, EnumSet authorizationFlags, FieldSet fieldSet) { + EnumSet flags = authorizationFlags == null ? EnumSet.of(AuthorizationFlags.None) : authorizationFlags; + return this.collect(lookup, (d) -> this.builderFactory.builder(PublicDmpBuilder.class).authorize(flags).build(fieldSet != null ? fieldSet : lookup.getProject(), d), flags); + } + + private QueryResult collect(DmpLookup lookup, Function, List> buildFunc, EnumSet flags) { + DmpQuery query = null; + QueryResult result = new QueryResult<>(); + if (lookup.useElastic() && this.elasticService.enabled()){ + List elasticResponse = lookup.enrichElastic(this.queryFactory).authorize(flags).collectAs(new BaseFieldSet().ensure(DmpElasticEntity._id)); + query = this.queryFactory.query(DmpQuery.class).authorize(flags).ids(elasticResponse.stream().map(DmpElasticEntity::getId).toList()); + query.setOrder(lookup.enrich(this.queryFactory).getOrder()); + if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(lookup.enrichElastic(this.queryFactory).authorize(flags).count()); + } else { + query = lookup.enrich(this.queryFactory).authorize(flags); + if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(query.count()); + } + result.setItems(buildFunc.apply(query.collect())); + if (lookup.getMetadata() == null || !lookup.getMetadata().countAll) result.setCount(result.getItems() != null ? result.getItems().size() : 0); + + return result; + } + + @Override + public long count(DmpLookup lookup, EnumSet authorizationFlags) { + EnumSet flags = authorizationFlags == null ? EnumSet.of(AuthorizationFlags.None) : authorizationFlags; + if (lookup.useElastic() && this.elasticService.enabled()){ + return lookup.enrichElastic(this.queryFactory).authorize(flags).count(); + } else { + return lookup.enrich(this.queryFactory).authorize(flags).count(); + } + } + + @Override + public QueryResult collect(DescriptionLookup lookup, EnumSet authorizationFlags, FieldSet fieldSet) { + EnumSet flags = authorizationFlags == null ? EnumSet.of(AuthorizationFlags.None) : authorizationFlags; + return this.collect(lookup, (d) -> this.builderFactory.builder(DescriptionBuilder.class).authorize(flags).build(fieldSet != null ? fieldSet : lookup.getProject(), d), flags); + } + + @Override + public QueryResult collectPublic(DescriptionLookup lookup, EnumSet authorizationFlags, FieldSet fieldSet) { + EnumSet flags = authorizationFlags == null ? EnumSet.of(AuthorizationFlags.None) : authorizationFlags; + return this.collect(lookup, (d) -> this.builderFactory.builder(PublicDescriptionBuilder.class).authorize(flags).build(fieldSet != null ? fieldSet : lookup.getProject(), d), flags); + } + + private QueryResult collect(DescriptionLookup lookup, Function, List> buildFunc, EnumSet flags) { + DescriptionQuery query = null; + QueryResult result = new QueryResult<>(); + if (lookup.useElastic() && this.elasticService.enabled()){ + List elasticResponse = lookup.enrichElastic(this.queryFactory).authorize(flags).collectAs(new BaseFieldSet().ensure(DescriptionElasticEntity._id)); + query = this.queryFactory.query(DescriptionQuery.class).authorize(flags).ids(elasticResponse.stream().map(DescriptionElasticEntity::getId).toList()); + query.setOrder(lookup.enrich(this.queryFactory).getOrder()); + if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(lookup.enrichElastic(this.queryFactory).authorize(flags).count()); + } else { + query = lookup.enrich(this.queryFactory).authorize(flags); + if (lookup.getMetadata() != null && lookup.getMetadata().countAll) result.setCount(query.count()); + } + result.setItems(buildFunc.apply(query.collect())); + if (lookup.getMetadata() == null || !lookup.getMetadata().countAll) result.setCount(result.getItems() != null ? result.getItems().size() : 0); + + return result; + } + + @Override + public long count(DescriptionLookup lookup, EnumSet authorizationFlags) { + EnumSet flags = authorizationFlags == null ? EnumSet.of(AuthorizationFlags.None) : authorizationFlags; + if (lookup.useElastic() && this.elasticService.enabled()){ + return lookup.enrichElastic(this.queryFactory).authorize(flags).count(); + } else { + return lookup.enrich(this.queryFactory).authorize(flags).count(); + } + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticServiceImpl.java index c90dac6b5..85efb414e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/elastic/ElasticServiceImpl.java @@ -70,7 +70,7 @@ public class ElasticServiceImpl implements ElasticService { @Override public boolean existsDescriptionIndex() throws IOException { if (!this.enabled()) return false; - return restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticProperties.getDmpIndexName()).includeDefaults(true).build()).value(); + return restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticProperties.getDescriptionIndexName()).includeDefaults(true).build()).value(); } //region ensure index diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionController.java index 50fe8e6d9..d69de9de3 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionController.java @@ -19,6 +19,7 @@ import eu.eudat.query.DescriptionQuery; import eu.eudat.query.DmpQuery; import eu.eudat.query.lookup.DescriptionLookup; import eu.eudat.service.description.DescriptionService; +import eu.eudat.service.elastic.ElasticQueryHelperService; import gr.cite.tools.auditing.AuditService; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.censor.CensorFactory; @@ -59,20 +60,22 @@ public class DescriptionController { private final QueryFactory queryFactory; private final MessageSource messageSource; - + private final ElasticQueryHelperService elasticQueryHelperService; public DescriptionController( BuilderFactory builderFactory, AuditService auditService, DescriptionService descriptionService, CensorFactory censorFactory, QueryFactory queryFactory, - MessageSource messageSource) { + MessageSource messageSource, + ElasticQueryHelperService elasticQueryHelperService) { this.builderFactory = builderFactory; this.auditService = auditService; this.descriptionService = descriptionService; this.censorFactory = censorFactory; this.queryFactory = queryFactory; this.messageSource = messageSource; + this.elasticQueryHelperService = elasticQueryHelperService; } @PostMapping("public/query") @@ -81,15 +84,12 @@ public class DescriptionController { this.censorFactory.censor(PublicDescriptionCensor.class).censor(lookup.getProject()); - DescriptionQuery query = lookup.enrich(this.queryFactory).authorize(EnumSet.of(Public)).dmpSubQuery(this.queryFactory.query(DmpQuery.class).isActive(IsActive.Active).statuses(DmpStatus.Finalized).accessTypes(DmpAccessType.Public)); - - List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(PublicDescriptionBuilder.class).authorize(EnumSet.of(Public)).build(lookup.getProject(), data); - long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); - + //DescriptionQuery query = lookup.enrich(this.queryFactory).authorize(EnumSet.of(Public)).dmpSubQuery(this.queryFactory.query(DmpQuery.class).isActive(IsActive.Active).statuses(DmpStatus.Finalized).accessTypes(DmpAccessType.Public)); + QueryResult queryResult = this.elasticQueryHelperService.collectPublic(lookup, EnumSet.of(Public), null); + this.auditService.track(AuditableAction.Description_PublicQuery, "lookup", lookup); - return new QueryResult<>(models, count); + return queryResult; } @GetMapping("public/{id}") @@ -117,15 +117,11 @@ public class DescriptionController { this.censorFactory.censor(DescriptionCensor.class).censor(lookup.getProject(), null); - DescriptionQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic); - - List data = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic).build(lookup.getProject(), data); - long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); + QueryResult queryResult = this.elasticQueryHelperService.collect(lookup, AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic, null); this.auditService.track(AuditableAction.Description_Query, "lookup", lookup); - return new QueryResult<>(models, count); + return queryResult; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DmpBlueprintController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DmpBlueprintController.java index 795f80426..528033dbf 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DmpBlueprintController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DmpBlueprintController.java @@ -3,6 +3,8 @@ package eu.eudat.controllers.v2; import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.audit.AuditableAction; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.commons.enums.DmpStatus; import eu.eudat.data.DmpBlueprintEntity; import eu.eudat.model.DmpBlueprint; import eu.eudat.model.builder.DmpBlueprintBuilder; @@ -10,12 +12,18 @@ import eu.eudat.model.censorship.DmpBlueprintCensor; import eu.eudat.model.persist.DmpBlueprintPersist; import eu.eudat.model.result.QueryResult; import eu.eudat.query.*; +import eu.eudat.query.lookup.DescriptionLookup; import eu.eudat.query.lookup.DmpBlueprintLookup; +import eu.eudat.query.lookup.DmpLookup; import eu.eudat.service.dmpblueprint.DmpBlueprintService; +import eu.eudat.service.elastic.ElasticQueryHelperService; import eu.eudat.service.elastic.ElasticService; import gr.cite.tools.auditing.AuditService; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.censor.CensorFactory; +import gr.cite.tools.data.query.Lookup; +import gr.cite.tools.data.query.Ordering; +import gr.cite.tools.data.query.Paging; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyForbiddenException; @@ -61,37 +69,25 @@ public class DmpBlueprintController { private final MessageSource messageSource; - private final ElasticService elasticService; - public DmpBlueprintController( BuilderFactory builderFactory, AuditService auditService, DmpBlueprintService dmpBlueprintService, CensorFactory censorFactory, QueryFactory queryFactory, - MessageSource messageSource, ElasticService elasticService) { + MessageSource messageSource) { this.builderFactory = builderFactory; this.auditService = auditService; this.dmpBlueprintService = dmpBlueprintService; this.censorFactory = censorFactory; this.queryFactory = queryFactory; this.messageSource = messageSource; - this.elasticService = elasticService; } @PostMapping("query") public QueryResult query(@RequestBody DmpBlueprintLookup lookup) throws MyApplicationException, MyForbiddenException { logger.debug("querying {}", DmpBlueprint.class.getSimpleName()); - var a = elasticService.enabled(); - try { - var a1 = elasticService.existsDmpIndex(); - elasticService.ensureDmpIndex(); - elasticService.ensureDescriptionIndex(); - } catch (IOException e) { - throw new RuntimeException(e); - } - this.censorFactory.censor(DmpBlueprintCensor.class).censor(lookup.getProject(), null); DmpBlueprintQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic);