elastic changes
This commit is contained in:
parent
3aa6cdaf29
commit
5cfdc4be07
|
@ -37,6 +37,10 @@ public class DescriptionElasticEntity {
|
||||||
private Date finalizedAt;
|
private Date finalizedAt;
|
||||||
public final static String _finalizedAt = "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)
|
@Field(value = DescriptionElasticEntity._tags, type = FieldType.Nested)
|
||||||
private List<NestedTagElasticEntity> tags;
|
private List<NestedTagElasticEntity> tags;
|
||||||
public final static String _tags = "tags";
|
public final static String _tags = "tags";
|
||||||
|
@ -124,4 +128,12 @@ public class DescriptionElasticEntity {
|
||||||
public void setReferences(List<NestedReferenceElasticEntity> references) {
|
public void setReferences(List<NestedReferenceElasticEntity> references) {
|
||||||
this.references = references;
|
this.references = references;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getCreatedAt() {
|
||||||
|
return createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(Date createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@ public class DescriptionElasticBuilder extends BaseElasticBuilder<DescriptionEla
|
||||||
m.setLabel(d.getLabel());
|
m.setLabel(d.getLabel());
|
||||||
m.setDescription(d.getDescription());
|
m.setDescription(d.getDescription());
|
||||||
m.setStatus(d.getStatus());
|
m.setStatus(d.getStatus());
|
||||||
|
m.setCreatedAt(Date.from(d.getCreatedAt()));
|
||||||
m.setFinalizedAt(Date.from(d.getFinalizedAt()));
|
m.setFinalizedAt(Date.from(d.getFinalizedAt()));
|
||||||
if (referenceElasticEntityMap != null) m.setReferences(referenceElasticEntityMap.getOrDefault(d.getId(), null));
|
if (referenceElasticEntityMap != null) m.setReferences(referenceElasticEntityMap.getOrDefault(d.getId(), null));
|
||||||
if (tagElasticEntityMap != null) m.setTags(tagElasticEntityMap.getOrDefault(d.getId(), null));
|
if (tagElasticEntityMap != null) m.setTags(tagElasticEntityMap.getOrDefault(d.getId(), null));
|
||||||
|
|
|
@ -1,15 +1,28 @@
|
||||||
package eu.eudat.elastic.query;
|
package eu.eudat.elastic.query;
|
||||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||||
import eu.eudat.authorization.AuthorizationFlags;
|
import eu.eudat.authorization.AuthorizationFlags;
|
||||||
|
import eu.eudat.authorization.Permission;
|
||||||
import eu.eudat.commons.enums.DescriptionStatus;
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
|
import eu.eudat.commons.enums.DmpAccessType;
|
||||||
|
import eu.eudat.commons.enums.DmpStatus;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
import eu.eudat.configurations.elastic.AppElasticProperties;
|
import eu.eudat.configurations.elastic.AppElasticProperties;
|
||||||
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.elastic.data.DescriptionElasticEntity;
|
import eu.eudat.elastic.data.DescriptionElasticEntity;
|
||||||
|
import eu.eudat.elastic.data.DmpElasticEntity;
|
||||||
|
import eu.eudat.elastic.data.nested.NestedDmpElasticEntity;
|
||||||
|
import eu.eudat.query.DescriptionQuery;
|
||||||
|
import eu.eudat.query.DmpDescriptionTemplateQuery;
|
||||||
|
import eu.eudat.query.DmpQuery;
|
||||||
import eu.eudat.service.elastic.ElasticService;
|
import eu.eudat.service.elastic.ElasticService;
|
||||||
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||||
import gr.cite.tools.data.query.FieldResolver;
|
import gr.cite.tools.data.query.FieldResolver;
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||||
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
||||||
import gr.cite.tools.elastic.query.ElasticField;
|
import gr.cite.tools.elastic.query.ElasticField;
|
||||||
|
import gr.cite.tools.elastic.query.ElasticFields;
|
||||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
||||||
import gr.cite.tools.elastic.query.ElasticQuery;
|
import gr.cite.tools.elastic.query.ElasticQuery;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -19,6 +32,7 @@ import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -28,9 +42,21 @@ import java.util.stream.Collectors;
|
||||||
public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEntity, UUID> {
|
public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEntity, UUID> {
|
||||||
|
|
||||||
private Collection<UUID> ids;
|
private Collection<UUID> ids;
|
||||||
|
private String like;
|
||||||
|
private InnerObjectDmpElasticQuery dmpSubQuery;
|
||||||
|
private Instant createdAfter;
|
||||||
|
private Instant createdBefore;
|
||||||
|
private Instant finalizedAfter;
|
||||||
|
private Instant finalizedBefore;
|
||||||
|
private Collection<UUID> excludedIds;
|
||||||
private Collection<DescriptionStatus> statuses;
|
private Collection<DescriptionStatus> statuses;
|
||||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||||
|
|
||||||
|
public DescriptionElasticQuery like(String value) {
|
||||||
|
this.like = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public DescriptionElasticQuery ids(UUID value) {
|
public DescriptionElasticQuery ids(UUID value) {
|
||||||
this.ids = List.of(value);
|
this.ids = List.of(value);
|
||||||
return this;
|
return this;
|
||||||
|
@ -46,6 +72,48 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DescriptionElasticQuery dmpSubQuery(InnerObjectDmpElasticQuery subQuery) {
|
||||||
|
this.dmpSubQuery = subQuery;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public DescriptionElasticQuery createdAfter(Instant value) {
|
||||||
|
this.createdAfter = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptionElasticQuery createdBefore(Instant value) {
|
||||||
|
this.createdBefore = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptionElasticQuery finalizedAfter(Instant value) {
|
||||||
|
this.finalizedAfter = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptionElasticQuery finalizedBefore(Instant value) {
|
||||||
|
this.finalizedBefore = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public DescriptionElasticQuery excludedIds(Collection<UUID> 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) {
|
public DescriptionElasticQuery statuses(DescriptionStatus value) {
|
||||||
this.statuses = List.of(value);
|
this.statuses = List.of(value);
|
||||||
return this;
|
return this;
|
||||||
|
@ -69,17 +137,23 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
||||||
private final QueryFactory queryFactory;
|
private final QueryFactory queryFactory;
|
||||||
private final AppElasticProperties appElasticProperties;
|
private final AppElasticProperties appElasticProperties;
|
||||||
private final ElasticService elasticService;
|
private final ElasticService elasticService;
|
||||||
|
private final UserScope userScope;
|
||||||
|
private final AuthorizationService authService;
|
||||||
@Autowired()
|
@Autowired()
|
||||||
public DescriptionElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticProperties appElasticProperties, ElasticService elasticService) {
|
public DescriptionElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticProperties appElasticProperties, ElasticService elasticService, UserScope userScope, AuthorizationService authService) {
|
||||||
super(elasticsearchTemplate, elasticProperties);
|
super(elasticsearchTemplate, elasticProperties);
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
this.appElasticProperties = appElasticProperties;
|
this.appElasticProperties = appElasticProperties;
|
||||||
this.elasticService = elasticService;
|
this.elasticService = elasticService;
|
||||||
|
this.userScope = userScope;
|
||||||
|
this.authService = authService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean isFalseQuery() {
|
protected Boolean isFalseQuery() {
|
||||||
return this.isEmpty(this.ids) || this.isEmpty(this.statuses);
|
return this.isEmpty(this.ids) ||
|
||||||
|
this.isEmpty(this.excludedIds) ||
|
||||||
|
this.isEmpty(this.statuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -87,16 +161,69 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
||||||
return DescriptionElasticEntity.class;
|
return DescriptionElasticEntity.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Query applyAuthZ() {
|
||||||
|
if (this.authorize.contains(AuthorizationFlags.None)) return null;
|
||||||
|
//if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDescription)) return null;
|
||||||
|
UUID userId = null;
|
||||||
|
boolean usePublic = this.authorize.contains(AuthorizationFlags.Public);
|
||||||
|
if (this.authorize.contains(AuthorizationFlags.DmpAssociated)) userId = this.userScope.getUserIdSafe();
|
||||||
|
|
||||||
|
List<Query> 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
|
@Override
|
||||||
protected Query applyFilters() {
|
protected Query applyFilters() {
|
||||||
List<Query> predicates = new ArrayList<>();
|
List<Query> 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) {
|
if (ids != null) {
|
||||||
predicates.add(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._id), ids)._toQuery());
|
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) {
|
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());
|
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()) {
|
if (!predicates.isEmpty()) {
|
||||||
return this.and(predicates);
|
return this.and(predicates);
|
||||||
} else {
|
} else {
|
||||||
|
@ -112,6 +239,7 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
||||||
if (columns.contains(DescriptionElasticEntity._description)) mocDoc.setDescription(FieldBasedMapper.shallowSafeConversion(rawData.get(DescriptionElasticEntity._description), String.class));
|
if (columns.contains(DescriptionElasticEntity._description)) mocDoc.setDescription(FieldBasedMapper.shallowSafeConversion(rawData.get(DescriptionElasticEntity._description), String.class));
|
||||||
if (columns.contains(DescriptionElasticEntity._status)) mocDoc.setStatus(FieldBasedMapper.shallowSafeConversion(rawData.get(DescriptionElasticEntity._status), DescriptionStatus.class));
|
if (columns.contains(DescriptionElasticEntity._status)) mocDoc.setStatus(FieldBasedMapper.shallowSafeConversion(rawData.get(DescriptionElasticEntity._status), DescriptionStatus.class));
|
||||||
if (columns.contains(DescriptionElasticEntity._finalizedAt)) mocDoc.setFinalizedAt(FieldBasedMapper.shallowSafeConversion(rawData.get(DescriptionElasticEntity._finalizedAt), Date.class));
|
if (columns.contains(DescriptionElasticEntity._finalizedAt)) mocDoc.setFinalizedAt(FieldBasedMapper.shallowSafeConversion(rawData.get(DescriptionElasticEntity._finalizedAt), Date.class));
|
||||||
|
if (columns.contains(DescriptionElasticEntity._createdAt)) mocDoc.setFinalizedAt(FieldBasedMapper.shallowSafeConversion(rawData.get(DescriptionElasticEntity._createdAt), Date.class));
|
||||||
mocDoc.setTags(this.convertNested(rawData, columns, this.queryFactory.query(NestedTagElasticQuery.class), DescriptionElasticEntity._tags, null));
|
mocDoc.setTags(this.convertNested(rawData, columns, this.queryFactory.query(NestedTagElasticQuery.class), DescriptionElasticEntity._tags, null));
|
||||||
mocDoc.setReferences(this.convertNested(rawData, columns, this.queryFactory.query(NestedReferenceElasticQuery.class), DescriptionElasticEntity._references, null));
|
mocDoc.setReferences(this.convertNested(rawData, columns, this.queryFactory.query(NestedReferenceElasticQuery.class), DescriptionElasticEntity._references, null));
|
||||||
mocDoc.setDescriptionTemplate(this.convertInnerObject(rawData, columns, this.queryFactory.query(InnerObjectDescriptionTemplateElasticQuery.class), DescriptionElasticEntity._descriptionTemplate, null));
|
mocDoc.setDescriptionTemplate(this.convertInnerObject(rawData, columns, this.queryFactory.query(InnerObjectDescriptionTemplateElasticQuery.class), DescriptionElasticEntity._descriptionTemplate, null));
|
||||||
|
@ -126,6 +254,7 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
|
||||||
else if (item.match(DescriptionElasticEntity._description)) return this.elasticFieldOf(DescriptionElasticEntity._description);
|
else if (item.match(DescriptionElasticEntity._description)) return this.elasticFieldOf(DescriptionElasticEntity._description);
|
||||||
else if (item.match(DescriptionElasticEntity._status)) return this.elasticFieldOf(DescriptionElasticEntity._status);
|
else if (item.match(DescriptionElasticEntity._status)) return this.elasticFieldOf(DescriptionElasticEntity._status);
|
||||||
else if (item.match(DescriptionElasticEntity._finalizedAt)) return this.elasticFieldOf(DescriptionElasticEntity._finalizedAt);
|
else if (item.match(DescriptionElasticEntity._finalizedAt)) return this.elasticFieldOf(DescriptionElasticEntity._finalizedAt);
|
||||||
|
else if (item.match(DescriptionElasticEntity._createdAt)) return this.elasticFieldOf(DescriptionElasticEntity._createdAt);
|
||||||
else if (item.prefix(DescriptionElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(DescriptionElasticEntity._references).fieldNameOf(this.extractPrefixed(item, DescriptionElasticEntity._references));
|
else if (item.prefix(DescriptionElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(DescriptionElasticEntity._references).fieldNameOf(this.extractPrefixed(item, DescriptionElasticEntity._references));
|
||||||
else if (item.prefix(DescriptionElasticEntity._tags)) return this.queryFactory.query(NestedTagElasticQuery.class).nestedPath(DescriptionElasticEntity._tags).fieldNameOf(this.extractPrefixed(item, DescriptionElasticEntity._tags));
|
else if (item.prefix(DescriptionElasticEntity._tags)) return this.queryFactory.query(NestedTagElasticQuery.class).nestedPath(DescriptionElasticEntity._tags).fieldNameOf(this.extractPrefixed(item, DescriptionElasticEntity._tags));
|
||||||
else if (item.prefix(DescriptionElasticEntity._descriptionTemplate)) return this.queryFactory.query(InnerObjectDescriptionTemplateElasticQuery.class).innerPath(DescriptionElasticEntity._descriptionTemplate).fieldNameOf(this.extractPrefixed(item, DescriptionElasticEntity._description));
|
else if (item.prefix(DescriptionElasticEntity._descriptionTemplate)) return this.queryFactory.query(InnerObjectDescriptionTemplateElasticQuery.class).innerPath(DescriptionElasticEntity._descriptionTemplate).fieldNameOf(this.extractPrefixed(item, DescriptionElasticEntity._description));
|
||||||
|
|
|
@ -1,19 +1,26 @@
|
||||||
package eu.eudat.elastic.query;
|
package eu.eudat.elastic.query;
|
||||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||||
import eu.eudat.authorization.AuthorizationFlags;
|
import eu.eudat.authorization.AuthorizationFlags;
|
||||||
|
import eu.eudat.authorization.Permission;
|
||||||
import eu.eudat.commons.enums.DmpAccessType;
|
import eu.eudat.commons.enums.DmpAccessType;
|
||||||
import eu.eudat.commons.enums.DmpStatus;
|
import eu.eudat.commons.enums.DmpStatus;
|
||||||
import eu.eudat.commons.enums.DmpVersionStatus;
|
import eu.eudat.commons.enums.DmpVersionStatus;
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
import eu.eudat.configurations.elastic.AppElasticProperties;
|
import eu.eudat.configurations.elastic.AppElasticProperties;
|
||||||
|
import eu.eudat.data.DmpEntity;
|
||||||
import eu.eudat.elastic.data.DmpElasticEntity;
|
import eu.eudat.elastic.data.DmpElasticEntity;
|
||||||
|
import eu.eudat.query.DmpQuery;
|
||||||
|
import eu.eudat.query.utils.QueryUtilsService;
|
||||||
import eu.eudat.service.elastic.ElasticService;
|
import eu.eudat.service.elastic.ElasticService;
|
||||||
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||||
import gr.cite.tools.data.query.FieldResolver;
|
import gr.cite.tools.data.query.FieldResolver;
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||||
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
||||||
import gr.cite.tools.elastic.query.ElasticField;
|
import gr.cite.tools.elastic.query.*;
|
||||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
import jakarta.persistence.criteria.Predicate;
|
||||||
import gr.cite.tools.elastic.query.ElasticQuery;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
|
@ -29,10 +36,22 @@ import java.util.stream.Collectors;
|
||||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||||
public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
||||||
|
|
||||||
|
private String like;
|
||||||
private Collection<UUID> ids;
|
private Collection<UUID> ids;
|
||||||
|
private Collection<UUID> excludedIds;
|
||||||
private Collection<DmpStatus> statuses;
|
private Collection<DmpStatus> statuses;
|
||||||
|
private Collection<DmpVersionStatus> versionStatuses;
|
||||||
|
private Collection<DmpAccessType> accessTypes;
|
||||||
|
private Collection<Integer> versions;
|
||||||
|
private Collection<UUID> groupIds;
|
||||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||||
|
|
||||||
|
|
||||||
|
public DmpElasticQuery like(String value) {
|
||||||
|
this.like = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public DmpElasticQuery ids(UUID value) {
|
public DmpElasticQuery ids(UUID value) {
|
||||||
this.ids = List.of(value);
|
this.ids = List.of(value);
|
||||||
return this;
|
return this;
|
||||||
|
@ -48,6 +67,51 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DmpElasticQuery excludedIds(Collection<UUID> 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<DmpVersionStatus> 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<DmpAccessType> values) {
|
||||||
|
this.accessTypes = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public DmpElasticQuery statuses(DmpStatus value) {
|
public DmpElasticQuery statuses(DmpStatus value) {
|
||||||
this.statuses = List.of(value);
|
this.statuses = List.of(value);
|
||||||
return this;
|
return this;
|
||||||
|
@ -63,6 +127,36 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
||||||
return this;
|
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<Integer> 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<UUID> values) {
|
||||||
|
this.groupIds = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public DmpElasticQuery authorize(EnumSet<AuthorizationFlags> values) {
|
public DmpElasticQuery authorize(EnumSet<AuthorizationFlags> values) {
|
||||||
this.authorize = values;
|
this.authorize = values;
|
||||||
return this;
|
return this;
|
||||||
|
@ -71,17 +165,21 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
||||||
private final QueryFactory queryFactory;
|
private final QueryFactory queryFactory;
|
||||||
private final AppElasticProperties appElasticProperties;
|
private final AppElasticProperties appElasticProperties;
|
||||||
private final ElasticService elasticService;
|
private final ElasticService elasticService;
|
||||||
|
private final UserScope userScope;
|
||||||
|
private final AuthorizationService authService;
|
||||||
@Autowired()
|
@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);
|
super(elasticsearchTemplate, elasticProperties);
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
this.appElasticProperties = appElasticProperties;
|
this.appElasticProperties = appElasticProperties;
|
||||||
this.elasticService = elasticService;
|
this.elasticService = elasticService;
|
||||||
|
this.userScope = userScope;
|
||||||
|
this.authService = authService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean isFalseQuery() {
|
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
|
@Override
|
||||||
|
@ -89,15 +187,62 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
||||||
return DmpElasticEntity.class;
|
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<Query> 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
|
@Override
|
||||||
protected Query applyFilters() {
|
protected Query applyFilters() {
|
||||||
List<Query> predicates = new ArrayList<>();
|
List<Query> 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) {
|
if (ids != null) {
|
||||||
predicates.add(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._id), ids)._toQuery());
|
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) {
|
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());
|
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()) {
|
if (!predicates.isEmpty()) {
|
||||||
return this.and(predicates);
|
return this.and(predicates);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.elastic.query;
|
package eu.eudat.elastic.query;
|
||||||
import co.elastic.clients.elasticsearch._types.query_dsl.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.DmpAccessType;
|
||||||
import eu.eudat.commons.enums.DmpStatus;
|
import eu.eudat.commons.enums.DmpStatus;
|
||||||
import eu.eudat.commons.enums.DmpVersionStatus;
|
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.configuration.ElasticProperties;
|
||||||
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
import gr.cite.tools.elastic.mapper.FieldBasedMapper;
|
||||||
import gr.cite.tools.elastic.query.ElasticField;
|
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.ElasticInnerObjectQuery;
|
||||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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 org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
//Like in C# make it Transient
|
//Like in C# make it Transient
|
||||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||||
public class InnerObjectDmpElasticQuery extends ElasticInnerObjectQuery<InnerObjectDmpElasticQuery, NestedDmpElasticEntity, UUID> {
|
public class InnerObjectDmpElasticQuery extends ElasticInnerObjectQuery<InnerObjectDmpElasticQuery, NestedDmpElasticEntity, UUID> {
|
||||||
|
private String like;
|
||||||
|
private Collection<UUID> ids;
|
||||||
|
private Collection<UUID> excludedIds;
|
||||||
|
private Collection<DmpStatus> statuses;
|
||||||
|
private Collection<DmpVersionStatus> versionStatuses;
|
||||||
|
private Collection<DmpAccessType> accessTypes;
|
||||||
|
private Collection<Integer> versions;
|
||||||
|
private Collection<UUID> 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<UUID> values) {
|
||||||
|
this.ids = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InnerObjectDmpElasticQuery excludedIds(Collection<UUID> 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<DmpVersionStatus> 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<DmpAccessType> 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<DmpStatus> 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<Integer> 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<UUID> values) {
|
||||||
|
this.groupIds = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
private String innerPath;
|
private String innerPath;
|
||||||
|
|
||||||
|
@ -53,8 +177,44 @@ public class InnerObjectDmpElasticQuery extends ElasticInnerObjectQuery<InnerObj
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Query applyFilters() {
|
protected Query applyFilters() {
|
||||||
|
List<Query> 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NestedDmpElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
public NestedDmpElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package eu.eudat.elastic.query;
|
||||||
|
|
||||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||||
import eu.eudat.commons.enums.DmpUserRole;
|
import eu.eudat.commons.enums.DmpUserRole;
|
||||||
|
import eu.eudat.elastic.data.DmpElasticEntity;
|
||||||
import eu.eudat.elastic.data.nested.NestedCollaboratorElasticEntity;
|
import eu.eudat.elastic.data.nested.NestedCollaboratorElasticEntity;
|
||||||
import gr.cite.tools.data.query.FieldResolver;
|
import gr.cite.tools.data.query.FieldResolver;
|
||||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
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 org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCollaboratorElasticQuery, NestedCollaboratorElasticEntity, UUID> {
|
public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCollaboratorElasticQuery, NestedCollaboratorElasticEntity, UUID> {
|
||||||
|
private Collection<UUID> 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<UUID> values) {
|
||||||
|
this.ids = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
private String nestedPath;
|
private String nestedPath;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,7 +59,7 @@ public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCol
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean isFalseQuery() {
|
protected Boolean isFalseQuery() {
|
||||||
return false;
|
return this.isEmpty(this.ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,8 +69,17 @@ public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCol
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Query applyFilters() {
|
protected Query applyFilters() {
|
||||||
|
List<Query> 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NestedCollaboratorElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
public NestedCollaboratorElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
||||||
|
|
|
@ -35,8 +35,11 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
||||||
private Collection<UUID> ids;
|
private Collection<UUID> ids;
|
||||||
private DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery;
|
private DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery;
|
||||||
private DmpQuery dmpQuery;
|
private DmpQuery dmpQuery;
|
||||||
|
private Instant createdAfter;
|
||||||
|
private Instant createdBefore;
|
||||||
|
private Instant finalizedAfter;
|
||||||
|
private Instant finalizedBefore;
|
||||||
private Collection<UUID> excludedIds;
|
private Collection<UUID> excludedIds;
|
||||||
|
|
||||||
private Collection<IsActive> isActives;
|
private Collection<IsActive> isActives;
|
||||||
|
|
||||||
private Collection<DescriptionStatus> statuses;
|
private Collection<DescriptionStatus> statuses;
|
||||||
|
@ -77,6 +80,28 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
||||||
return this;
|
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) {
|
public DescriptionQuery dmpSubQuery(DmpQuery subQuery) {
|
||||||
this.dmpQuery = subQuery;
|
this.dmpQuery = subQuery;
|
||||||
return this;
|
return this;
|
||||||
|
@ -182,6 +207,18 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
||||||
inClause.value(item);
|
inClause.value(item);
|
||||||
predicates.add(inClause);
|
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) {
|
if (this.excludedIds != null) {
|
||||||
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._id));
|
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._id));
|
||||||
for (UUID item : this.excludedIds)
|
for (UUID item : this.excludedIds)
|
||||||
|
|
|
@ -33,7 +33,6 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
|
||||||
private Collection<UUID> ids;
|
private Collection<UUID> ids;
|
||||||
|
|
||||||
private Collection<UUID> dmpIds;
|
private Collection<UUID> dmpIds;
|
||||||
private DmpQuery dmpQuery;
|
|
||||||
|
|
||||||
private Collection<UUID> descriptionTemplateIds;
|
private Collection<UUID> descriptionTemplateIds;
|
||||||
|
|
||||||
|
@ -104,11 +103,6 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DmpDescriptionTemplateQuery dmpSubQuery(DmpQuery subQuery) {
|
|
||||||
this.dmpQuery = subQuery;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DmpDescriptionTemplateQuery descriptionTemplateIds(UUID value) {
|
public DmpDescriptionTemplateQuery descriptionTemplateIds(UUID value) {
|
||||||
this.descriptionTemplateIds = List.of(value);
|
this.descriptionTemplateIds = List.of(value);
|
||||||
return this;
|
return this;
|
||||||
|
@ -147,7 +141,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean isFalseQuery() {
|
protected Boolean isFalseQuery() {
|
||||||
return this.isEmpty(this.ids)|| this.isFalseQuery(this.dmpQuery) || this.isEmpty(this.excludedIds) || this.isEmpty(this.isActives) || this.isEmpty(this.dmpIds) || this.isEmpty(this.descriptionTemplateIds);
|
return this.isEmpty(this.ids) || this.isEmpty(this.excludedIds) || this.isEmpty(this.isActives) || this.isEmpty(this.dmpIds) || this.isEmpty(this.descriptionTemplateIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -185,11 +179,6 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
|
||||||
notInClause.value(item);
|
notInClause.value(item);
|
||||||
predicates.add(notInClause.not());
|
predicates.add(notInClause.not());
|
||||||
}
|
}
|
||||||
if (this.dmpQuery != null) {
|
|
||||||
Subquery<DmpEntity> 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) {
|
if (this.dmpIds != null) {
|
||||||
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._dmpId));
|
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._dmpId));
|
||||||
for (UUID item : this.dmpIds)
|
for (UUID item : this.dmpIds)
|
||||||
|
|
|
@ -2,10 +2,13 @@ package eu.eudat.query.lookup;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionStatus;
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
import eu.eudat.commons.enums.IsActive;
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.elastic.query.DescriptionElasticQuery;
|
||||||
|
import eu.eudat.elastic.query.InnerObjectDmpElasticQuery;
|
||||||
import eu.eudat.query.DescriptionQuery;
|
import eu.eudat.query.DescriptionQuery;
|
||||||
import gr.cite.tools.data.query.Lookup;
|
import gr.cite.tools.data.query.Lookup;
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -16,8 +19,11 @@ public class DescriptionLookup extends Lookup {
|
||||||
private List<UUID> ids;
|
private List<UUID> ids;
|
||||||
|
|
||||||
private List<UUID> excludedIds;
|
private List<UUID> excludedIds;
|
||||||
|
private Instant createdAfter;
|
||||||
|
private Instant createdBefore;
|
||||||
|
private Instant finalizedAfter;
|
||||||
|
private Instant finalizedBefore;
|
||||||
|
|
||||||
private DmpDescriptionTemplateLookup dmpDescriptionTemplateSubQuery;
|
|
||||||
private DmpLookup dmpSubQuery;
|
private DmpLookup dmpSubQuery;
|
||||||
|
|
||||||
private List<IsActive> isActive;
|
private List<IsActive> isActive;
|
||||||
|
@ -64,14 +70,6 @@ public class DescriptionLookup extends Lookup {
|
||||||
this.statuses = statuses;
|
this.statuses = statuses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DmpDescriptionTemplateLookup getDmpDescriptionTemplateSubQuery() {
|
|
||||||
return dmpDescriptionTemplateSubQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDmpDescriptionTemplateSubQuery(DmpDescriptionTemplateLookup dmpDescriptionTemplateSubQuery) {
|
|
||||||
this.dmpDescriptionTemplateSubQuery = dmpDescriptionTemplateSubQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DmpLookup getDmpSubQuery() {
|
public DmpLookup getDmpSubQuery() {
|
||||||
return dmpSubQuery;
|
return dmpSubQuery;
|
||||||
}
|
}
|
||||||
|
@ -80,19 +78,76 @@ public class DescriptionLookup extends Lookup {
|
||||||
this.dmpSubQuery = dmpSubQuery;
|
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) {
|
public DescriptionQuery enrich(QueryFactory queryFactory) {
|
||||||
DescriptionQuery query = queryFactory.query(DescriptionQuery.class);
|
DescriptionQuery query = queryFactory.query(DescriptionQuery.class);
|
||||||
if (this.like != null) query.like(this.like);
|
if (this.like != null) query.like(this.like);
|
||||||
if (this.ids != null) query.ids(this.ids);
|
if (this.ids != null) query.ids(this.ids);
|
||||||
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
|
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.dmpSubQuery != null) query.dmpSubQuery(this.dmpSubQuery.enrich(queryFactory));
|
||||||
if (this.isActive != null) query.isActive(this.isActive);
|
if (this.isActive != null) query.isActive(this.isActive);
|
||||||
if (this.statuses != null) query.statuses(this.statuses);
|
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);
|
this.enrichCommon(query);
|
||||||
|
|
||||||
return 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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ public class DmpDescriptionTemplateLookup extends Lookup {
|
||||||
private List<UUID> ids;
|
private List<UUID> ids;
|
||||||
private List<UUID> dmpIds;
|
private List<UUID> dmpIds;
|
||||||
private List<UUID> descriptionTemplateIds;
|
private List<UUID> descriptionTemplateIds;
|
||||||
private DmpLookup dmpSubQuery;
|
|
||||||
|
|
||||||
private List<UUID> excludedIds;
|
private List<UUID> excludedIds;
|
||||||
|
|
||||||
|
@ -61,14 +60,6 @@ public class DmpDescriptionTemplateLookup extends Lookup {
|
||||||
this.descriptionTemplateIds = descriptionTemplateIds;
|
this.descriptionTemplateIds = descriptionTemplateIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DmpLookup getDmpSubQuery() {
|
|
||||||
return dmpSubQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDmpSubQuery(DmpLookup dmpSubQuery) {
|
|
||||||
this.dmpSubQuery = dmpSubQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DmpDescriptionTemplateQuery enrich(QueryFactory queryFactory) {
|
public DmpDescriptionTemplateQuery enrich(QueryFactory queryFactory) {
|
||||||
DmpDescriptionTemplateQuery query = queryFactory.query(DmpDescriptionTemplateQuery.class);
|
DmpDescriptionTemplateQuery query = queryFactory.query(DmpDescriptionTemplateQuery.class);
|
||||||
if (this.ids != null) query.ids(this.ids);
|
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.descriptionTemplateIds != null) query.ids(this.descriptionTemplateIds);
|
||||||
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
|
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
|
||||||
if (this.isActive != null) query.isActive(this.isActive);
|
if (this.isActive != null) query.isActive(this.isActive);
|
||||||
if (this.dmpSubQuery != null) query.dmpSubQuery(this.dmpSubQuery.enrich(queryFactory));
|
|
||||||
|
|
||||||
this.enrichCommon(query);
|
this.enrichCommon(query);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ import eu.eudat.commons.enums.DmpAccessType;
|
||||||
import eu.eudat.commons.enums.DmpStatus;
|
import eu.eudat.commons.enums.DmpStatus;
|
||||||
import eu.eudat.commons.enums.DmpVersionStatus;
|
import eu.eudat.commons.enums.DmpVersionStatus;
|
||||||
import eu.eudat.commons.enums.IsActive;
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.elastic.query.DmpElasticQuery;
|
||||||
|
import eu.eudat.elastic.query.InnerObjectDmpElasticQuery;
|
||||||
import eu.eudat.query.DmpQuery;
|
import eu.eudat.query.DmpQuery;
|
||||||
import gr.cite.tools.data.query.Lookup;
|
import gr.cite.tools.data.query.Lookup;
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
|
@ -107,4 +109,36 @@ public class DmpLookup extends Lookup {
|
||||||
return query;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<Dmp> collect(DmpLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags, FieldSet fieldSet);
|
||||||
|
QueryResult<PublicDmp> collectPublic(DmpLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags, FieldSet fieldSet);
|
||||||
|
long count(DmpLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags);
|
||||||
|
QueryResult<Description> collect(DescriptionLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags, FieldSet fieldSet);
|
||||||
|
QueryResult<PublicDescription> collectPublic(DescriptionLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags, FieldSet fieldSet);
|
||||||
|
long count(DescriptionLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags);
|
||||||
|
}
|
|
@ -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<Dmp> collect(DmpLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags, FieldSet fieldSet) {
|
||||||
|
EnumSet<AuthorizationFlags> 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<PublicDmp> collectPublic(DmpLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags, FieldSet fieldSet) {
|
||||||
|
EnumSet<AuthorizationFlags> 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 <M> QueryResult<M> collect(DmpLookup lookup, Function<List<DmpEntity>, List<M>> buildFunc, EnumSet<AuthorizationFlags> flags) {
|
||||||
|
DmpQuery query = null;
|
||||||
|
QueryResult<M> result = new QueryResult<>();
|
||||||
|
if (lookup.useElastic() && this.elasticService.enabled()){
|
||||||
|
List<DmpElasticEntity> 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> authorizationFlags) {
|
||||||
|
EnumSet<AuthorizationFlags> 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<Description> collect(DescriptionLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags, FieldSet fieldSet) {
|
||||||
|
EnumSet<AuthorizationFlags> 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<PublicDescription> collectPublic(DescriptionLookup lookup, EnumSet<AuthorizationFlags> authorizationFlags, FieldSet fieldSet) {
|
||||||
|
EnumSet<AuthorizationFlags> 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 <M> QueryResult<M> collect(DescriptionLookup lookup, Function<List<DescriptionEntity>, List<M>> buildFunc, EnumSet<AuthorizationFlags> flags) {
|
||||||
|
DescriptionQuery query = null;
|
||||||
|
QueryResult<M> result = new QueryResult<>();
|
||||||
|
if (lookup.useElastic() && this.elasticService.enabled()){
|
||||||
|
List<DescriptionElasticEntity> 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> authorizationFlags) {
|
||||||
|
EnumSet<AuthorizationFlags> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -70,7 +70,7 @@ public class ElasticServiceImpl implements ElasticService {
|
||||||
@Override
|
@Override
|
||||||
public boolean existsDescriptionIndex() throws IOException {
|
public boolean existsDescriptionIndex() throws IOException {
|
||||||
if (!this.enabled()) return false;
|
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
|
//region ensure index
|
||||||
|
|
|
@ -19,6 +19,7 @@ import eu.eudat.query.DescriptionQuery;
|
||||||
import eu.eudat.query.DmpQuery;
|
import eu.eudat.query.DmpQuery;
|
||||||
import eu.eudat.query.lookup.DescriptionLookup;
|
import eu.eudat.query.lookup.DescriptionLookup;
|
||||||
import eu.eudat.service.description.DescriptionService;
|
import eu.eudat.service.description.DescriptionService;
|
||||||
|
import eu.eudat.service.elastic.ElasticQueryHelperService;
|
||||||
import gr.cite.tools.auditing.AuditService;
|
import gr.cite.tools.auditing.AuditService;
|
||||||
import gr.cite.tools.data.builder.BuilderFactory;
|
import gr.cite.tools.data.builder.BuilderFactory;
|
||||||
import gr.cite.tools.data.censor.CensorFactory;
|
import gr.cite.tools.data.censor.CensorFactory;
|
||||||
|
@ -59,20 +60,22 @@ public class DescriptionController {
|
||||||
private final QueryFactory queryFactory;
|
private final QueryFactory queryFactory;
|
||||||
|
|
||||||
private final MessageSource messageSource;
|
private final MessageSource messageSource;
|
||||||
|
private final ElasticQueryHelperService elasticQueryHelperService;
|
||||||
public DescriptionController(
|
public DescriptionController(
|
||||||
BuilderFactory builderFactory,
|
BuilderFactory builderFactory,
|
||||||
AuditService auditService,
|
AuditService auditService,
|
||||||
DescriptionService descriptionService,
|
DescriptionService descriptionService,
|
||||||
CensorFactory censorFactory,
|
CensorFactory censorFactory,
|
||||||
QueryFactory queryFactory,
|
QueryFactory queryFactory,
|
||||||
MessageSource messageSource) {
|
MessageSource messageSource,
|
||||||
|
ElasticQueryHelperService elasticQueryHelperService) {
|
||||||
this.builderFactory = builderFactory;
|
this.builderFactory = builderFactory;
|
||||||
this.auditService = auditService;
|
this.auditService = auditService;
|
||||||
this.descriptionService = descriptionService;
|
this.descriptionService = descriptionService;
|
||||||
this.censorFactory = censorFactory;
|
this.censorFactory = censorFactory;
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
this.messageSource = messageSource;
|
this.messageSource = messageSource;
|
||||||
|
this.elasticQueryHelperService = elasticQueryHelperService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("public/query")
|
@PostMapping("public/query")
|
||||||
|
@ -81,15 +84,12 @@ public class DescriptionController {
|
||||||
|
|
||||||
this.censorFactory.censor(PublicDescriptionCensor.class).censor(lookup.getProject());
|
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));
|
//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<PublicDescription> queryResult = this.elasticQueryHelperService.collectPublic(lookup, EnumSet.of(Public), null);
|
||||||
List<DescriptionEntity> data = query.collectAs(lookup.getProject());
|
|
||||||
List<PublicDescription> 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();
|
|
||||||
|
|
||||||
this.auditService.track(AuditableAction.Description_PublicQuery, "lookup", lookup);
|
this.auditService.track(AuditableAction.Description_PublicQuery, "lookup", lookup);
|
||||||
|
|
||||||
return new QueryResult<>(models, count);
|
return queryResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("public/{id}")
|
@GetMapping("public/{id}")
|
||||||
|
@ -117,15 +117,11 @@ public class DescriptionController {
|
||||||
|
|
||||||
this.censorFactory.censor(DescriptionCensor.class).censor(lookup.getProject(), null);
|
this.censorFactory.censor(DescriptionCensor.class).censor(lookup.getProject(), null);
|
||||||
|
|
||||||
DescriptionQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic);
|
QueryResult<Description> queryResult = this.elasticQueryHelperService.collect(lookup, AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic, null);
|
||||||
|
|
||||||
List<DescriptionEntity> data = query.collectAs(lookup.getProject());
|
|
||||||
List<Description> 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();
|
|
||||||
|
|
||||||
this.auditService.track(AuditableAction.Description_Query, "lookup", lookup);
|
this.auditService.track(AuditableAction.Description_Query, "lookup", lookup);
|
||||||
|
|
||||||
return new QueryResult<>(models, count);
|
return queryResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ package eu.eudat.controllers.v2;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import eu.eudat.audit.AuditableAction;
|
import eu.eudat.audit.AuditableAction;
|
||||||
import eu.eudat.authorization.AuthorizationFlags;
|
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.data.DmpBlueprintEntity;
|
||||||
import eu.eudat.model.DmpBlueprint;
|
import eu.eudat.model.DmpBlueprint;
|
||||||
import eu.eudat.model.builder.DmpBlueprintBuilder;
|
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.persist.DmpBlueprintPersist;
|
||||||
import eu.eudat.model.result.QueryResult;
|
import eu.eudat.model.result.QueryResult;
|
||||||
import eu.eudat.query.*;
|
import eu.eudat.query.*;
|
||||||
|
import eu.eudat.query.lookup.DescriptionLookup;
|
||||||
import eu.eudat.query.lookup.DmpBlueprintLookup;
|
import eu.eudat.query.lookup.DmpBlueprintLookup;
|
||||||
|
import eu.eudat.query.lookup.DmpLookup;
|
||||||
import eu.eudat.service.dmpblueprint.DmpBlueprintService;
|
import eu.eudat.service.dmpblueprint.DmpBlueprintService;
|
||||||
|
import eu.eudat.service.elastic.ElasticQueryHelperService;
|
||||||
import eu.eudat.service.elastic.ElasticService;
|
import eu.eudat.service.elastic.ElasticService;
|
||||||
import gr.cite.tools.auditing.AuditService;
|
import gr.cite.tools.auditing.AuditService;
|
||||||
import gr.cite.tools.data.builder.BuilderFactory;
|
import gr.cite.tools.data.builder.BuilderFactory;
|
||||||
import gr.cite.tools.data.censor.CensorFactory;
|
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.data.query.QueryFactory;
|
||||||
import gr.cite.tools.exception.MyApplicationException;
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
import gr.cite.tools.exception.MyForbiddenException;
|
import gr.cite.tools.exception.MyForbiddenException;
|
||||||
|
@ -61,37 +69,25 @@ public class DmpBlueprintController {
|
||||||
|
|
||||||
private final MessageSource messageSource;
|
private final MessageSource messageSource;
|
||||||
|
|
||||||
private final ElasticService elasticService;
|
|
||||||
|
|
||||||
public DmpBlueprintController(
|
public DmpBlueprintController(
|
||||||
BuilderFactory builderFactory,
|
BuilderFactory builderFactory,
|
||||||
AuditService auditService,
|
AuditService auditService,
|
||||||
DmpBlueprintService dmpBlueprintService,
|
DmpBlueprintService dmpBlueprintService,
|
||||||
CensorFactory censorFactory,
|
CensorFactory censorFactory,
|
||||||
QueryFactory queryFactory,
|
QueryFactory queryFactory,
|
||||||
MessageSource messageSource, ElasticService elasticService) {
|
MessageSource messageSource) {
|
||||||
this.builderFactory = builderFactory;
|
this.builderFactory = builderFactory;
|
||||||
this.auditService = auditService;
|
this.auditService = auditService;
|
||||||
this.dmpBlueprintService = dmpBlueprintService;
|
this.dmpBlueprintService = dmpBlueprintService;
|
||||||
this.censorFactory = censorFactory;
|
this.censorFactory = censorFactory;
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
this.messageSource = messageSource;
|
this.messageSource = messageSource;
|
||||||
this.elasticService = elasticService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("query")
|
@PostMapping("query")
|
||||||
public QueryResult<DmpBlueprint> query(@RequestBody DmpBlueprintLookup lookup) throws MyApplicationException, MyForbiddenException {
|
public QueryResult<DmpBlueprint> query(@RequestBody DmpBlueprintLookup lookup) throws MyApplicationException, MyForbiddenException {
|
||||||
logger.debug("querying {}", DmpBlueprint.class.getSimpleName());
|
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);
|
this.censorFactory.censor(DmpBlueprintCensor.class).censor(lookup.getProject(), null);
|
||||||
DmpBlueprintQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic);
|
DmpBlueprintQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermissionOrMemberOrPublic);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue