elastic fixes

This commit is contained in:
Efstratios Giannopoulos 2024-04-30 12:54:26 +03:00
parent 33196e28cd
commit a8c1736e83
13 changed files with 271 additions and 234 deletions

View File

@ -1,10 +1,13 @@
package org.opencdmp.elastic.data;
import gr.cite.tools.elastic.ElasticConstants;
import org.opencdmp.commons.enums.DmpAccessType;
import org.opencdmp.commons.enums.DmpStatus;
import org.opencdmp.commons.enums.DmpVersionStatus;
import org.opencdmp.elastic.data.nested.*;
import gr.cite.tools.elastic.ElasticConstants;
import org.opencdmp.elastic.data.nested.NestedCollaboratorElasticEntity;
import org.opencdmp.elastic.data.nested.NestedDescriptionElasticEntity;
import org.opencdmp.elastic.data.nested.NestedDoiElasticEntity;
import org.opencdmp.elastic.data.nested.NestedReferenceElasticEntity;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;
@ -23,9 +26,7 @@ public class DmpElasticEntity {
private UUID tenantId;
public final static String _tenantId = "tenantId";
@MultiField(mainField = @Field(value = DmpElasticEntity._label, type = FieldType.Text), otherFields = {
@InnerField(suffix = ElasticConstants.SubFields.keyword, type = FieldType.Keyword)
})
@MultiField(mainField = @Field(value = DmpElasticEntity._label, type = FieldType.Text), otherFields = @InnerField(suffix = ElasticConstants.SubFields.keyword, type = FieldType.Keyword))
private String label;
public final static String _label = "label";
@ -81,7 +82,7 @@ public class DmpElasticEntity {
public final static String _dois = "dois";
public UUID getId() {
return id;
return this.id;
}
public void setId(UUID id) {
@ -89,7 +90,7 @@ public class DmpElasticEntity {
}
public UUID getTenantId() {
return tenantId;
return this.tenantId;
}
public void setTenantId(UUID tenantId) {
@ -97,7 +98,7 @@ public class DmpElasticEntity {
}
public String getLabel() {
return label;
return this.label;
}
public void setLabel(String label) {
@ -105,7 +106,7 @@ public class DmpElasticEntity {
}
public String getDescription() {
return description;
return this.description;
}
public void setDescription(String description) {
@ -113,7 +114,7 @@ public class DmpElasticEntity {
}
public Short getVersion() {
return version;
return this.version;
}
public void setVersion(Short version) {
@ -121,7 +122,7 @@ public class DmpElasticEntity {
}
public DmpStatus getStatus() {
return status;
return this.status;
}
public void setStatus(DmpStatus status) {
@ -129,7 +130,7 @@ public class DmpElasticEntity {
}
public DmpAccessType getAccessType() {
return accessType;
return this.accessType;
}
public void setAccessType(DmpAccessType accessType) {
@ -137,7 +138,7 @@ public class DmpElasticEntity {
}
public String getLanguage() {
return language;
return this.language;
}
public void setLanguage(String language) {
@ -145,7 +146,7 @@ public class DmpElasticEntity {
}
public UUID getBlueprintId() {
return blueprintId;
return this.blueprintId;
}
public void setBlueprintId(UUID blueprintId) {
@ -153,7 +154,7 @@ public class DmpElasticEntity {
}
public UUID getGroupId() {
return groupId;
return this.groupId;
}
public void setGroupId(UUID groupId) {
@ -161,7 +162,7 @@ public class DmpElasticEntity {
}
public Date getFinalizedAt() {
return finalizedAt;
return this.finalizedAt;
}
public void setFinalizedAt(Date finalizedAt) {
@ -169,7 +170,7 @@ public class DmpElasticEntity {
}
public List<NestedReferenceElasticEntity> getReferences() {
return references;
return this.references;
}
public void setReferences(List<NestedReferenceElasticEntity> references) {
@ -177,7 +178,7 @@ public class DmpElasticEntity {
}
public List<NestedCollaboratorElasticEntity> getCollaborators() {
return collaborators;
return this.collaborators;
}
public void setCollaborators(List<NestedCollaboratorElasticEntity> collaborators) {
@ -185,7 +186,7 @@ public class DmpElasticEntity {
}
public List<NestedDescriptionElasticEntity> getDescriptions() {
return descriptions;
return this.descriptions;
}
public void setDescriptions(List<NestedDescriptionElasticEntity> descriptions) {
@ -193,7 +194,7 @@ public class DmpElasticEntity {
}
public List<NestedDoiElasticEntity> getDois() {
return dois;
return this.dois;
}
public void setDois(List<NestedDoiElasticEntity> dois) {
@ -201,7 +202,7 @@ public class DmpElasticEntity {
}
public DmpVersionStatus getVersionStatus() {
return versionStatus;
return this.versionStatus;
}
public void setVersionStatus(DmpVersionStatus versionStatus) {

View File

@ -1,9 +1,12 @@
package org.opencdmp.elastic.data.nested;
import org.opencdmp.commons.enums.DmpUserRole;
import gr.cite.tools.elastic.ElasticConstants;
import org.opencdmp.commons.enums.DmpUserRole;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.InnerField;
import org.springframework.data.elasticsearch.annotations.MultiField;
import java.util.UUID;
@ -12,10 +15,12 @@ public class NestedCollaboratorElasticEntity {
@Field(value = NestedCollaboratorElasticEntity._id, type = FieldType.Keyword)
private UUID id;
public final static String _id = "id";
@Field(value = NestedCollaboratorElasticEntity._userId, type = FieldType.Keyword)
private UUID userId;
public final static String _userId = "userId";
@MultiField(mainField = @Field(value = NestedCollaboratorElasticEntity._name, type = FieldType.Text), otherFields = {
@InnerField(suffix = ElasticConstants.SubFields.keyword, type = FieldType.Keyword)
})
@MultiField(mainField = @Field(value = NestedCollaboratorElasticEntity._name, type = FieldType.Text), otherFields = @InnerField(suffix = ElasticConstants.SubFields.keyword, type = FieldType.Keyword))
private String name;
public final static String _name = "name";
@ -24,7 +29,7 @@ public class NestedCollaboratorElasticEntity {
public final static String _role = "role";
public UUID getId() {
return id;
return this.id;
}
public void setId(UUID id) {
@ -32,7 +37,7 @@ public class NestedCollaboratorElasticEntity {
}
public String getName() {
return name;
return this.name;
}
public void setName(String name) {
@ -40,10 +45,18 @@ public class NestedCollaboratorElasticEntity {
}
public DmpUserRole getRole() {
return role;
return this.role;
}
public void setRole(DmpUserRole role) {
this.role = role;
}
public UUID getUserId() {
return this.userId;
}
public void setUserId(UUID userId) {
this.userId = userId;
}
}

View File

@ -1,19 +1,17 @@
package org.opencdmp.elastic.elasticbuilder.nested;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.DescriptionEntity;
import org.opencdmp.data.DmpUserEntity;
import org.opencdmp.data.UserEntity;
import org.opencdmp.elastic.data.nested.NestedCollaboratorElasticEntity;
import org.opencdmp.elastic.elasticbuilder.BaseElasticBuilder;
import org.opencdmp.model.User;
import org.opencdmp.query.DescriptionTemplateQuery;
import org.opencdmp.query.UserQuery;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -24,7 +22,7 @@ import java.util.*;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class NestedCollaboratorElasticBuilder extends BaseElasticBuilder<NestedCollaboratorElasticEntity, DmpUserEntity> {
private final QueryFactory queryFactory;
@ -46,6 +44,7 @@ public class NestedCollaboratorElasticBuilder extends BaseElasticBuilder<NestedC
for (DmpUserEntity d : data) {
NestedCollaboratorElasticEntity m = new NestedCollaboratorElasticEntity();
m.setId(d.getId());
m.setUserId(d.getUserId());
m.setRole(d.getRole());
m.setName(userNameMap.getOrDefault(d.getUserId(), d.getUserId().toString()));
models.add(m);

View File

@ -1,6 +1,18 @@
package org.opencdmp.elastic.query;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.OrderingFieldResolver;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.elastic.ElasticConstants;
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.ElasticNestedQuery;
import gr.cite.tools.elastic.query.ElasticQuery;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.enums.DescriptionStatus;
@ -8,20 +20,11 @@ import org.opencdmp.commons.enums.DmpAccessType;
import org.opencdmp.commons.enums.DmpStatus;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.service.elastic.AppElasticProperties;
import org.opencdmp.elastic.data.DescriptionElasticEntity;
import org.opencdmp.elastic.data.DmpElasticEntity;
import org.opencdmp.elastic.data.nested.NestedDmpElasticEntity;
import org.opencdmp.service.elastic.AppElasticProperties;
import org.opencdmp.service.elastic.ElasticService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;
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.ElasticNestedQuery;
import gr.cite.tools.elastic.query.ElasticQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
@ -137,7 +140,7 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
private final UserScope userScope;
private final TenantScope tenantScope;
private final AuthorizationService authService;
@Autowired()
@Autowired
public DescriptionElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticProperties appElasticProperties, ElasticService elasticService, UserScope userScope, TenantScope tenantScope, AuthorizationService authService) {
super(elasticsearchTemplate, elasticProperties);
this.queryFactory = queryFactory;
@ -199,7 +202,7 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
}
if (userId != null) {
NestedCollaboratorElasticQuery query = this.queryFactory.query(NestedCollaboratorElasticQuery.class).nestedPath(DescriptionElasticEntity._dmp + "." + NestedDmpElasticEntity._collaborators);
query.ids(userId);
query.userIds(userId);
predicates.add(this.nestedQuery(query).build()._toQuery());
}
@ -213,39 +216,39 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
@Override
protected Query applyFilters() {
List<Query> predicates = new ArrayList<>();
if (like != null && !like.isBlank()) {
if (!like.startsWith("*")) like = "*" + like;
if (!like.endsWith("*")) like = like + "*";
if (this.like != null && !this.like.isBlank()) {
if (!this.like.startsWith("*")) this.like = "*" + this.like;
if (!this.like.endsWith("*")) this.like = this.like + "*";
ElasticFields elasticFields = this.elasticFieldsOf();
elasticFields.add("*", null, true);
predicates.add(this.or(
this.like(elasticFields, List.of(like))._toQuery(),
this.like(elasticFields, List.of(this.like))._toQuery(),
QueryBuilders.nested().path(DescriptionElasticEntity._tags).query(
this.like(elasticFields, List.of(like))._toQuery()
this.like(elasticFields, List.of(this.like))._toQuery()
).build()._toQuery(),
QueryBuilders.nested().path(DescriptionElasticEntity._references).query(
this.like(elasticFields, List.of(like))._toQuery()
this.like(elasticFields, List.of(this.like))._toQuery()
).build()._toQuery(),
QueryBuilders.nested().path(DescriptionElasticEntity._dmp + "." + NestedDmpElasticEntity._references).query(
this.like(elasticFields, List.of(like))._toQuery()
this.like(elasticFields, List.of(this.like))._toQuery()
).build()._toQuery(),
QueryBuilders.nested().path(DescriptionElasticEntity._dmp + "." + NestedDmpElasticEntity._collaborators).query(
this.like(elasticFields, List.of(like))._toQuery()
this.like(elasticFields, List.of(this.like))._toQuery()
).build()._toQuery(),
QueryBuilders.nested().path(DescriptionElasticEntity._dmp + "." + NestedDmpElasticEntity._dois).query(
this.like(elasticFields, List.of(like))._toQuery()
this.like(elasticFields, List.of(this.like))._toQuery()
).build()._toQuery()
)._toQuery());
}
if (ids != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._id), ids)._toQuery());
if (this.ids != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._id), this.ids)._toQuery());
}
if (excludedIds != null) {
predicates.add(this.not(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._id), excludedIds)._toQuery())._toQuery());
if (this.excludedIds != null) {
predicates.add(this.not(this.containsUUID(this.elasticFieldOf(DescriptionElasticEntity._id), this.excludedIds)._toQuery())._toQuery());
}
if (statuses != null) {
predicates.add(this.contains(this.elasticFieldOf(DescriptionElasticEntity._status), statuses.stream().map(DescriptionStatus::getValue).toList().toArray(new Short[statuses.size()]))._toQuery());
if (this.statuses != null) {
predicates.add(this.contains(this.elasticFieldOf(DescriptionElasticEntity._status), this.statuses.stream().map(DescriptionStatus::getValue).toList().toArray(new Short[this.statuses.size()]))._toQuery());
}
if (this.finalizedAfter != null) {
predicates.add(this.dateGreaterThanQuery(this.elasticFieldOf(DescriptionElasticEntity._finalizedAt), this.finalizedAfter)._toQuery());
@ -259,8 +262,8 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
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 (this.dmpSubQuery != null) {
predicates.add(this.dmpSubQuery.innerPath(DescriptionElasticEntity._dmp).applyFilters());
}
if (!predicates.isEmpty()) {
return this.and(predicates);
@ -288,7 +291,7 @@ public class DescriptionElasticQuery extends ElasticQuery<DescriptionElasticEnti
@Override
protected ElasticField fieldNameOf(FieldResolver item) {
if (item.match(DescriptionElasticEntity._id)) return this.elasticFieldOf(DescriptionElasticEntity._id);
else if (item.match(DescriptionElasticEntity._label)) return this.elasticFieldOf(DescriptionElasticEntity._label);
else if (item.match(DescriptionElasticEntity._label)) return item instanceof OrderingFieldResolver ? this.elasticFieldOf(DescriptionElasticEntity._label).subfield(ElasticConstants.SubFields.keyword) : this.elasticFieldOf(DescriptionElasticEntity._label);
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._finalizedAt)) return this.elasticFieldOf(DescriptionElasticEntity._finalizedAt);

View File

@ -1,6 +1,18 @@
package org.opencdmp.elastic.query;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.OrderingFieldResolver;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.elastic.ElasticConstants;
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.ElasticNestedQuery;
import gr.cite.tools.elastic.query.ElasticQuery;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.enums.DmpAccessType;
@ -9,16 +21,10 @@ import org.opencdmp.commons.enums.DmpVersionStatus;
import org.opencdmp.commons.scope.tenant.TenantScope;
import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.elastic.data.DescriptionElasticEntity;
import org.opencdmp.service.elastic.AppElasticProperties;
import org.opencdmp.elastic.data.DmpElasticEntity;
import org.opencdmp.elastic.data.nested.NestedDescriptionElasticEntity;
import org.opencdmp.service.elastic.AppElasticProperties;
import org.opencdmp.service.elastic.ElasticService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;
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.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
@ -167,7 +173,7 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
private final UserScope userScope;
private final TenantScope tenantScope;
private final AuthorizationService authService;
@Autowired()
@Autowired
public DmpElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory, AppElasticProperties appElasticProperties, ElasticService elasticService, UserScope userScope, TenantScope tenantScope, AuthorizationService authService) {
super(elasticsearchTemplate, elasticProperties);
this.queryFactory = queryFactory;
@ -227,7 +233,7 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
}
if (userId != null) {
NestedCollaboratorElasticQuery query = this.queryFactory.query(NestedCollaboratorElasticQuery.class).nestedPath(DmpElasticEntity._collaborators);
query.ids(userId);
query.userIds(userId);
predicates.add(this.nestedQuery(query).build()._toQuery());
}
if (!predicates.isEmpty()) {
@ -241,53 +247,54 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
protected Query applyFilters() {
List<Query> predicates = new ArrayList<>();
if (like != null && !like.isBlank()) {
if (this.like != null && !this.like.isBlank()) {
if (!like.startsWith("*")) like = "*" + like;
if (!like.endsWith("*")) like = like + "*";
if (!this.like.startsWith("*")) this.like = "*" + this.like;
if (!this.like.endsWith("*")) this.like = this.like + "*";
ElasticFields elasticFields = this.elasticFieldsOf();
elasticFields.add("*", null, true);
predicates.add(this.or(
this.like(elasticFields, List.of(like))._toQuery(),
this.like(elasticFields, List.of(this.like))._toQuery()
,
QueryBuilders.nested().path(DmpElasticEntity._collaborators).query(
this.like(elasticFields, List.of(like))._toQuery()
this.like(elasticFields, List.of(this.like))._toQuery()
).build()._toQuery(),
QueryBuilders.nested().path(DmpElasticEntity._references).query(
this.like(elasticFields, List.of(like))._toQuery()
this.like(elasticFields, List.of(this.like))._toQuery()
).build()._toQuery(),
QueryBuilders.nested().path(DmpElasticEntity._descriptions + "." + NestedDescriptionElasticEntity._references).query(
this.like(elasticFields, List.of(like))._toQuery()
this.like(elasticFields, List.of(this.like))._toQuery()
).build()._toQuery(),
QueryBuilders.nested().path(DmpElasticEntity._descriptions + "." + NestedDescriptionElasticEntity._tags).query(
this.like(elasticFields, List.of(like))._toQuery()
this.like(elasticFields, List.of(this.like))._toQuery()
).build()._toQuery(),
QueryBuilders.nested().path(DmpElasticEntity._descriptions).query(
this.like(elasticFields, List.of(like))._toQuery()
this.like(elasticFields, List.of(this.like))._toQuery()
).build()._toQuery()
)._toQuery());
}
if (ids != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._id), ids)._toQuery());
if (this.ids != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._id), this.ids)._toQuery());
}
if (groupIds != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._groupId), groupIds)._toQuery());
if (this.groupIds != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._groupId), this.groupIds)._toQuery());
}
if (versions != null) {
predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._version), versions.toArray(new Integer[versions.size()]))._toQuery());
if (this.versions != null) {
predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._version), this.versions.toArray(new Integer[this.versions.size()]))._toQuery());
}
if (excludedIds != null) {
predicates.add(this.not(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._id), excludedIds)._toQuery())._toQuery());
if (this.excludedIds != null) {
predicates.add(this.not(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._id), this.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 (this.statuses != null) {
predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._status), this.statuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[this.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 (this.versionStatuses != null) {
predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._versionStatus), this.versionStatuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[this.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 (this.accessTypes != null) {
predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._accessType), this.accessTypes.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[this.accessTypes.size()]))._toQuery());
}
if (!predicates.isEmpty()) {
@ -318,7 +325,7 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
@Override
protected ElasticField fieldNameOf(FieldResolver item) {
if (item.match(DmpElasticEntity._id)) return this.elasticFieldOf(DmpElasticEntity._id);
else if (item.match(DmpElasticEntity._label)) return this.elasticFieldOf(DmpElasticEntity._label);
else if (item.match(DmpElasticEntity._label)) return item instanceof OrderingFieldResolver ? this.elasticFieldOf(DmpElasticEntity._label).subfield(ElasticConstants.SubFields.keyword) : this.elasticFieldOf(DmpElasticEntity._label);
else if (item.match(DmpElasticEntity._description)) return this.elasticFieldOf(DmpElasticEntity._description);
else if (item.match(DmpElasticEntity._status)) return this.elasticFieldOf(DmpElasticEntity._status);
else if (item.match(DmpElasticEntity._version)) return this.elasticFieldOf(DmpElasticEntity._version);

View File

@ -1,28 +1,25 @@
package org.opencdmp.elastic.query;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import org.opencdmp.commons.enums.DescriptionStatus;
import org.opencdmp.commons.enums.DmpUserRole;
import org.opencdmp.elastic.data.DescriptionElasticEntity;
import org.opencdmp.elastic.data.DmpElasticEntity;
import org.opencdmp.elastic.data.nested.NestedCollaboratorElasticEntity;
import gr.cite.tools.data.query.FieldResolver;
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.ElasticNestedQuery;
import org.opencdmp.commons.enums.DmpUserRole;
import org.opencdmp.elastic.data.nested.NestedCollaboratorElasticEntity;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
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)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCollaboratorElasticQuery, NestedCollaboratorElasticEntity, UUID> {
private Collection<UUID> ids;
private Collection<UUID> userIds;
private Collection<DmpUserRole> userRoles;
@ -42,6 +39,21 @@ public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCol
return this;
}
public NestedCollaboratorElasticQuery userIds(UUID value) {
this.userIds = List.of(value);
return this;
}
public NestedCollaboratorElasticQuery userIds(UUID... value) {
this.userIds = Arrays.asList(value);
return this;
}
public NestedCollaboratorElasticQuery userIds(Collection<UUID> values) {
this.userIds = values;
return this;
}
public NestedCollaboratorElasticQuery userRoles(DmpUserRole value) {
this.userRoles = List.of(value);
return this;
@ -79,7 +91,7 @@ public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCol
@Override
protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.userRoles);
return this.isEmpty(this.ids) || this.isEmpty(this.userIds) ||this.isEmpty(this.userRoles);
}
@Override
@ -90,12 +102,15 @@ public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCol
@Override
protected Query applyFilters() {
List<Query> predicates = new ArrayList<>();
if (ids != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(NestedCollaboratorElasticEntity._id), ids)._toQuery());
if (this.ids != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(NestedCollaboratorElasticEntity._id), this.ids)._toQuery());
}
if (this.userIds != null) {
predicates.add(this.containsUUID(this.elasticFieldOf(NestedCollaboratorElasticEntity._userId), this.userIds)._toQuery());
}
if (userRoles != null) {
predicates.add(this.contains(this.elasticFieldOf(NestedCollaboratorElasticEntity._role), userRoles.stream().map(DmpUserRole::getValue).toList().toArray(new Short[userRoles.size()]))._toQuery());
if (this.userRoles != null) {
predicates.add(this.contains(this.elasticFieldOf(NestedCollaboratorElasticEntity._role), this.userRoles.stream().map(DmpUserRole::getValue).toList().toArray(new Short[this.userRoles.size()]))._toQuery());
}
if (!predicates.isEmpty()) {
@ -109,6 +124,7 @@ public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCol
public NestedCollaboratorElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
NestedCollaboratorElasticEntity mocDoc = new NestedCollaboratorElasticEntity();
if (columns.contains(NestedCollaboratorElasticEntity._id)) mocDoc.setId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedCollaboratorElasticEntity._id), UUID.class));
if (columns.contains(NestedCollaboratorElasticEntity._userId)) mocDoc.setUserId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedCollaboratorElasticEntity._userId), UUID.class));
if (columns.contains(NestedCollaboratorElasticEntity._name)) mocDoc.setName(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedCollaboratorElasticEntity._name), String.class));
if (columns.contains(NestedCollaboratorElasticEntity._role)) mocDoc.setRole(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedCollaboratorElasticEntity._role), DmpUserRole.class));
return mocDoc;
@ -117,6 +133,7 @@ public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCol
@Override
protected ElasticField fieldNameOf(FieldResolver item) {
if (item.match(NestedCollaboratorElasticEntity._id)) return this.elasticFieldOf(NestedCollaboratorElasticEntity._id).disableInfer(true);
else if (item.match(NestedCollaboratorElasticEntity._userId)) return this.elasticFieldOf(NestedCollaboratorElasticEntity._userId).disableInfer(true);
else if (item.match(NestedCollaboratorElasticEntity._name)) return this.elasticFieldOf(NestedCollaboratorElasticEntity._name).disableInfer(true);
else if (item.match(NestedCollaboratorElasticEntity._role)) return this.elasticFieldOf(NestedCollaboratorElasticEntity._role).disableInfer(true);
else return null;

View File

@ -1,5 +1,9 @@
package org.opencdmp.model.builder.commonmodels;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commonmodels.enums.DmpUserRole;
import org.opencdmp.commonmodels.models.DmpUserModel;
@ -9,10 +13,6 @@ import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.DmpUserEntity;
import org.opencdmp.data.UserEntity;
import org.opencdmp.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -23,7 +23,7 @@ import java.util.*;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DmpUserCommonModelBuilder extends BaseCommonModelBuilder<DmpUserModel, DmpUserEntity> {
private final BuilderFactory builderFactory;
@ -61,6 +61,8 @@ public class DmpUserCommonModelBuilder extends BaseCommonModelBuilder<DmpUserMod
switch (d.getRole()){
case User -> m.setRole(DmpUserRole.User);
case Owner -> m.setRole(DmpUserRole.Owner);
case DescriptionContributor -> m.setRole(DmpUserRole.DescriptionContributor);
case Reviewer -> m.setRole(DmpUserRole.Reviewer);
default -> throw new MyApplicationException("unrecognized type " + d.getRole().getValue());
}
if (userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));

View File

@ -1,15 +1,5 @@
package org.opencdmp.query;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.data.*;
import org.opencdmp.model.Language;
import org.opencdmp.model.User;
import org.opencdmp.model.PublicUser;
import org.opencdmp.query.utils.BuildSubQueryInput;
import org.opencdmp.query.utils.QueryUtilsService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
@ -19,16 +9,27 @@ import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Subquery;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.commons.scope.user.UserScope;
import org.opencdmp.data.DmpUserEntity;
import org.opencdmp.data.UserContactInfoEntity;
import org.opencdmp.data.UserEntity;
import org.opencdmp.data.UserRoleEntity;
import org.opencdmp.model.PublicUser;
import org.opencdmp.model.User;
import org.opencdmp.query.utils.BuildSubQueryInput;
import org.opencdmp.query.utils.QueryUtilsService;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class UserQuery extends QueryBase<UserEntity> {
private String like;
private Boolean dmpAssociated;
@ -159,12 +160,12 @@ public class UserQuery extends QueryBase<UserEntity> {
UUID finalUserId = userId;
predicates.add(queryContext.CriteriaBuilder.or(
userId != null ? queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._id)).value(userId) : queryContext.CriteriaBuilder.or(), //Creates a false query
queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._id)).value(queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(new BuildSubQueryInput.Builder<>(DmpUserEntity.class, UUID.class)
queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._id)).value(this.queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(new BuildSubQueryInput.Builder<>(DmpUserEntity.class, UUID.class)
.query(queryContext.Query)
.criteriaBuilder(queryContext.CriteriaBuilder)
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpUserEntity._userId))
.filterFunc((subQueryRoot, cb) ->
cb.in(subQueryRoot.get(DmpUserEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, finalUserId, usePublic))
cb.in(subQueryRoot.get(DmpUserEntity._dmpId)).value(this.queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, finalUserId, usePublic))
)
)))
));
@ -181,7 +182,7 @@ public class UserQuery extends QueryBase<UserEntity> {
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
List<Predicate> predicates = new ArrayList<>();
if (this.like != null && !this.like.isEmpty()) {
predicates.add(queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(UserEntity._name), this.like));
predicates.add(this.queryUtilsService.ilike(queryContext.CriteriaBuilder, queryContext.Root.get(UserEntity._name), this.like));
}
if (this.ids != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._id));
@ -202,7 +203,7 @@ public class UserQuery extends QueryBase<UserEntity> {
predicates.add(inClause);
}
if (this.emails != null) {
Subquery<UUID> userContactInfoSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
Subquery<UUID> userContactInfoSubquery = this.queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
new BuildSubQueryInput.Builder<>(UserContactInfoQuery.class, UUID.class, queryContext)
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(UserContactInfoEntity._id))
.filterFunc((subQueryRoot, cb) -> {
@ -224,7 +225,7 @@ public class UserQuery extends QueryBase<UserEntity> {
if (this.userScope.isSet()) userId = this.userScope.getUserIdSafe();
else throw new MyNotFoundException("Only user scoped allowed");
Subquery<UUID> dmpUserDmpQuery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
Subquery<UUID> dmpUserDmpQuery = this.queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
new BuildSubQueryInput.Builder<>(DmpUserEntity.class, UUID.class, queryContext)
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpUserEntity._dmpId))
.filterFunc((subQueryRoot, cb) -> cb.and(
@ -233,7 +234,7 @@ public class UserQuery extends QueryBase<UserEntity> {
))
));
Subquery<UUID> dmpUserUserQuery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
Subquery<UUID> dmpUserUserQuery = this.queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
new BuildSubQueryInput.Builder<>(DmpUserEntity.class, UUID.class, queryContext)
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpUserEntity._userId))
.filterFunc((subQueryRoot, cb) -> cb.and(

View File

@ -1,12 +1,12 @@
package org.opencdmp.query.lookup;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import org.apache.commons.lang3.StringUtils;
import org.opencdmp.commons.enums.DescriptionStatus;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.elastic.query.DescriptionElasticQuery;
import org.opencdmp.elastic.query.InnerObjectDmpElasticQuery;
import org.opencdmp.query.DescriptionQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import java.time.Instant;
import java.util.List;
@ -31,7 +31,7 @@ public class DescriptionLookup extends Lookup {
private List<DescriptionStatus> statuses;
public String getLike() {
return like;
return this.like;
}
public void setLike(String like) {
@ -39,7 +39,7 @@ public class DescriptionLookup extends Lookup {
}
public List<UUID> getIds() {
return ids;
return this.ids;
}
public void setIds(List<UUID> ids) {
@ -47,7 +47,7 @@ public class DescriptionLookup extends Lookup {
}
public List<UUID> getExcludedIds() {
return excludedIds;
return this.excludedIds;
}
public void setExcludedIds(List<UUID> excludedIds) {
@ -55,7 +55,7 @@ public class DescriptionLookup extends Lookup {
}
public List<IsActive> getIsActive() {
return isActive;
return this.isActive;
}
public void setIsActive(List<IsActive> isActive) {
@ -63,7 +63,7 @@ public class DescriptionLookup extends Lookup {
}
public List<DescriptionStatus> getStatuses() {
return statuses;
return this.statuses;
}
public void setStatuses(List<DescriptionStatus> statuses) {
@ -71,7 +71,7 @@ public class DescriptionLookup extends Lookup {
}
public DmpLookup getDmpSubQuery() {
return dmpSubQuery;
return this.dmpSubQuery;
}
public void setDmpSubQuery(DmpLookup dmpSubQuery) {
@ -79,7 +79,7 @@ public class DescriptionLookup extends Lookup {
}
public Instant getCreatedAfter() {
return createdAfter;
return this.createdAfter;
}
public void setCreatedAfter(Instant createdAfter) {
@ -87,7 +87,7 @@ public class DescriptionLookup extends Lookup {
}
public Instant getCreatedBefore() {
return createdBefore;
return this.createdBefore;
}
public void setCreatedBefore(Instant createdBefore) {
@ -95,7 +95,7 @@ public class DescriptionLookup extends Lookup {
}
public Instant getFinalizedAfter() {
return finalizedAfter;
return this.finalizedAfter;
}
public void setFinalizedAfter(Instant finalizedAfter) {
@ -103,7 +103,7 @@ public class DescriptionLookup extends Lookup {
}
public Instant getFinalizedBefore() {
return finalizedBefore;
return this.finalizedBefore;
}
public void setFinalizedBefore(Instant finalizedBefore) {
@ -130,8 +130,7 @@ public class DescriptionLookup extends Lookup {
public DescriptionElasticQuery enrichElastic(QueryFactory queryFactory) {
DescriptionElasticQuery query = queryFactory.query(DescriptionElasticQuery.class);
InnerObjectDmpElasticQuery dmpElasticQuery = null;
if (this.like != null) query.like(this.like);
if (this.like != null) query.like(StringUtils.strip(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);

View File

@ -1,15 +1,15 @@
package org.opencdmp.query.lookup;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import org.apache.commons.lang3.StringUtils;
import org.opencdmp.commons.enums.DmpAccessType;
import org.opencdmp.commons.enums.DmpStatus;
import org.opencdmp.commons.enums.DmpVersionStatus;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.elastic.query.DmpElasticQuery;
import org.opencdmp.elastic.query.InnerObjectDmpElasticQuery;
import org.opencdmp.query.DmpDescriptionTemplateQuery;
import org.opencdmp.query.DmpQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import java.util.List;
import java.util.UUID;
@ -35,7 +35,7 @@ public class DmpLookup extends Lookup {
private DmpUserLookup dmpUserSubQuery;
public String getLike() {
return like;
return this.like;
}
public void setLike(String like) {
@ -43,7 +43,7 @@ public class DmpLookup extends Lookup {
}
public List<UUID> getIds() {
return ids;
return this.ids;
}
public void setIds(List<UUID> ids) {
@ -51,7 +51,7 @@ public class DmpLookup extends Lookup {
}
public List<UUID> getExcludedIds() {
return excludedIds;
return this.excludedIds;
}
public void setExcludedIds(List<UUID> excludedIds) {
@ -59,7 +59,7 @@ public class DmpLookup extends Lookup {
}
public List<IsActive> getIsActive() {
return isActive;
return this.isActive;
}
public void setIsActive(List<IsActive> isActive) {
@ -67,7 +67,7 @@ public class DmpLookup extends Lookup {
}
public List<DmpStatus> getStatuses() {
return statuses;
return this.statuses;
}
public void setStatuses(List<DmpStatus> statuses) {
@ -75,7 +75,7 @@ public class DmpLookup extends Lookup {
}
public List<Integer> getVersions() {
return versions;
return this.versions;
}
public void setVersions(List<Integer> versions) {
@ -83,7 +83,7 @@ public class DmpLookup extends Lookup {
}
public List<DmpAccessType> getAccessTypes() {
return accessTypes;
return this.accessTypes;
}
public void setAccessTypes(List<DmpAccessType> accessTypes) {
@ -91,7 +91,7 @@ public class DmpLookup extends Lookup {
}
public List<DmpVersionStatus> getVersionStatuses() {
return versionStatuses;
return this.versionStatuses;
}
public void setVersionStatuses(List<DmpVersionStatus> versionStatuses) {
@ -99,7 +99,7 @@ public class DmpLookup extends Lookup {
}
public DmpDescriptionTemplateLookup getDmpDescriptionTemplateSubQuery() {
return dmpDescriptionTemplateSubQuery;
return this.dmpDescriptionTemplateSubQuery;
}
public void setDmpDescriptionTemplateSubQuery(DmpDescriptionTemplateLookup dmpDescriptionTemplateSubQuery) {
@ -107,7 +107,7 @@ public class DmpLookup extends Lookup {
}
public List<UUID> getGroupIds() {
return groupIds;
return this.groupIds;
}
public void setGroupIds(List<UUID> groupIds) {
@ -115,7 +115,7 @@ public class DmpLookup extends Lookup {
}
public DmpUserLookup getDmpUserSubQuery() {
return dmpUserSubQuery;
return this.dmpUserSubQuery;
}
public void setDmpUserSubQuery(DmpUserLookup dmpUserSubQuery) {
@ -143,7 +143,7 @@ public class DmpLookup extends Lookup {
public DmpElasticQuery enrichElastic(QueryFactory queryFactory) {
DmpElasticQuery query = queryFactory.query(DmpElasticQuery.class);
if (this.like != null) query.like(this.like);
if (this.like != null) query.like(StringUtils.strip(this.like, "%"));
if (this.ids != null) query.ids(this.ids);
if (this.groupIds != null) query.groupIds(this.groupIds);
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
@ -161,7 +161,7 @@ public class DmpLookup extends Lookup {
public InnerObjectDmpElasticQuery enrichElasticInner(QueryFactory queryFactory) {
InnerObjectDmpElasticQuery query = queryFactory.query(InnerObjectDmpElasticQuery.class);
if (this.like != null) query.like(this.like);
if (this.like != null) query.like(StringUtils.strip(this.like, "%"));
if (this.ids != null) query.ids(this.ids);
if (this.groupIds != null) query.groupIds(this.groupIds);
if (this.excludedIds != null) query.excludedIds(this.excludedIds);

View File

@ -1,12 +1,11 @@
package org.opencdmp.query.lookup;
import org.opencdmp.commons.enums.*;
import org.opencdmp.elastic.query.DmpElasticQuery;
import org.opencdmp.elastic.query.InnerObjectDmpElasticQuery;
import org.opencdmp.elastic.query.NestedCollaboratorElasticQuery;
import org.opencdmp.query.DmpUserQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import org.opencdmp.commons.enums.DmpUserRole;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.elastic.query.NestedCollaboratorElasticQuery;
import org.opencdmp.query.DmpUserQuery;
import java.util.List;
import java.util.UUID;
@ -24,7 +23,7 @@ public class DmpUserLookup extends Lookup {
private List<DmpUserRole> userRoles;
public List<UUID> getIds() {
return ids;
return this.ids;
}
public void setIds(List<UUID> ids) {
@ -32,7 +31,7 @@ public class DmpUserLookup extends Lookup {
}
public List<UUID> getDmpIds() {
return dmpIds;
return this.dmpIds;
}
public void setDmpIds(List<UUID> dmpIds) {
@ -40,7 +39,7 @@ public class DmpUserLookup extends Lookup {
}
public List<UUID> getUserIds() {
return userIds;
return this.userIds;
}
public void setUserIds(List<UUID> userIds) {
@ -48,7 +47,7 @@ public class DmpUserLookup extends Lookup {
}
public List<UUID> getSectionIds() {
return sectionIds;
return this.sectionIds;
}
public void setSectionIds(List<UUID> sectionIds) {
@ -56,7 +55,7 @@ public class DmpUserLookup extends Lookup {
}
public List<IsActive> getIsActive() {
return isActive;
return this.isActive;
}
public void setIsActive(List<IsActive> isActive) {
@ -64,7 +63,7 @@ public class DmpUserLookup extends Lookup {
}
public List<DmpUserRole> getUserRoles() {
return userRoles;
return this.userRoles;
}
public void setUserRoles(List<DmpUserRole> userRoles) {
@ -88,6 +87,7 @@ public class DmpUserLookup extends Lookup {
public NestedCollaboratorElasticQuery enrichElastic(QueryFactory queryFactory) {
NestedCollaboratorElasticQuery query = queryFactory.query(NestedCollaboratorElasticQuery.class);
if (this.ids != null) query.ids(this.ids);
if (this.userIds != null) query.userIds(this.userIds);
if (this.userRoles != null) query.userRoles(this.userRoles);
this.enrichCommon(query);

View File

@ -4,22 +4,6 @@ import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.mapping.Property;
import co.elastic.clients.elasticsearch._types.mapping.TypeMapping;
import co.elastic.clients.elasticsearch.indices.*;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.data.DescriptionEntity;
import org.opencdmp.data.DmpEntity;
import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.data.tenant.TenantScopedBaseEntity;
import org.opencdmp.elastic.data.DescriptionElasticEntity;
import org.opencdmp.elastic.data.DmpElasticEntity;
import org.opencdmp.elastic.data.nested.*;
import org.opencdmp.elastic.elasticbuilder.DescriptionElasticBuilder;
import org.opencdmp.elastic.elasticbuilder.DmpElasticBuilder;
import org.opencdmp.model.Description;
import org.opencdmp.model.Dmp;
import org.opencdmp.query.DescriptionQuery;
import org.opencdmp.query.DmpQuery;
import org.opencdmp.service.dmpblueprint.DmpBlueprintServiceImpl;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.Ordering;
@ -30,20 +14,34 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import org.hibernate.Session;
import org.opencdmp.authorization.Permission;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.data.DescriptionEntity;
import org.opencdmp.data.DmpEntity;
import org.opencdmp.data.TenantEntityManager;
import org.opencdmp.elastic.data.DescriptionElasticEntity;
import org.opencdmp.elastic.data.DmpElasticEntity;
import org.opencdmp.elastic.data.nested.*;
import org.opencdmp.elastic.elasticbuilder.DescriptionElasticBuilder;
import org.opencdmp.elastic.elasticbuilder.DmpElasticBuilder;
import org.opencdmp.model.Description;
import org.opencdmp.model.Dmp;
import org.opencdmp.query.DescriptionQuery;
import org.opencdmp.query.DmpQuery;
import org.opencdmp.service.dmpblueprint.DmpBlueprintServiceImpl;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.elasticsearch.annotations.FieldType;
import java.io.IOException;
import java.util.*;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.stereotype.Service;
import javax.management.InvalidApplicationException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ElasticServiceImpl implements ElasticService {
@ -70,20 +68,20 @@ public class ElasticServiceImpl implements ElasticService {
@Override
public boolean enabled() {
return appElasticProperties.isEnabled();
return this.appElasticProperties.isEnabled();
}
@Override
public boolean existsDmpIndex() throws IOException {
if (!this.enabled()) return false;
return restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticProperties.getDmpIndexName()).includeDefaults(true).build()).value();
return this.restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticProperties.getDmpIndexName()).includeDefaults(true).build()).value();
}
@Override
public boolean existsDescriptionIndex() throws IOException {
if (!this.enabled()) return false;
return restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticProperties.getDescriptionIndexName()).includeDefaults(true).build()).value();
return this.restHighLevelClient.indices().exists(new ExistsRequest.Builder().index(this.appElasticProperties.getDescriptionIndexName()).includeDefaults(true).build()).value();
}
//region ensure index
@ -128,7 +126,7 @@ public class ElasticServiceImpl implements ElasticService {
indexSettingsAnalysis.analyzer("icu_analyzer_text", ab -> ab.custom(x-> x.filter("icu_folding", "english_stop", "english_stemmer").tokenizer("standard")));
}
indexSettings.analysis(indexSettingsAnalysis.build());
restHighLevelClient.indices().create(new CreateIndexRequest.Builder().index(indexName).mappings(typeMapping.build()).settings(indexSettings.build()).build());
this.restHighLevelClient.indices().create(new CreateIndexRequest.Builder().index(indexName).mappings(typeMapping.build()).settings(indexSettings.build()).build());
}
@ -136,7 +134,7 @@ public class ElasticServiceImpl implements ElasticService {
Map<String, Property> propertyMap = new HashMap<>();
propertyMap.put(DescriptionElasticEntity._id, this.createElastic(FieldType.Keyword, false));
propertyMap.put(DescriptionElasticEntity._tenantId, this.createElastic(FieldType.Keyword, false));
propertyMap.put(DescriptionElasticEntity._label, this.createElastic(FieldType.Keyword, false));
propertyMap.put(DescriptionElasticEntity._label, this.createElastic(FieldType.Text, true));
propertyMap.put(DescriptionElasticEntity._description, this.createElastic(FieldType.Text, true));
propertyMap.put(DescriptionElasticEntity._status, this.createElastic(FieldType.Short, false));
propertyMap.put(DescriptionElasticEntity._finalizedAt, this.createElastic(FieldType.Date, false));
@ -174,7 +172,7 @@ public class ElasticServiceImpl implements ElasticService {
private Map<String, Property> createNestedDescriptionTemplatePropertyMap(){
Map<String, Property> propertyMap = new HashMap<>();
propertyMap.put(NestedDescriptionElasticEntity._id, this.createElastic(FieldType.Keyword, false));
propertyMap.put(NestedDescriptionElasticEntity._label, this.createElastic(FieldType.Keyword, false));
propertyMap.put(NestedDescriptionElasticEntity._label, this.createElastic(FieldType.Text, true));
propertyMap.put(NestedDescriptionElasticEntity._dmpId, this.createElastic(FieldType.Keyword, false));
propertyMap.put(NestedDescriptionElasticEntity._description, this.createElastic(FieldType.Text, true));
propertyMap.put(NestedDescriptionElasticEntity._status, this.createElastic(FieldType.Short, false));
@ -235,6 +233,7 @@ public class ElasticServiceImpl implements ElasticService {
private Map<String, Property> createNestedCollaboratorTemplatePropertyMap(){
Map<String, Property> propertyMap = new HashMap<>();
propertyMap.put(NestedCollaboratorElasticEntity._id, this.createElastic(FieldType.Keyword, false));
propertyMap.put(NestedCollaboratorElasticEntity._userId, this.createElastic(FieldType.Keyword, false));
propertyMap.put(NestedCollaboratorElasticEntity._name, this.createElastic(FieldType.Text, true));
propertyMap.put(NestedCollaboratorElasticEntity._role, this.createElastic(FieldType.Short, false));
@ -308,7 +307,7 @@ public class ElasticServiceImpl implements ElasticService {
DescriptionElasticEntity descriptionElasticEntity = this.builderFactory.builder(DescriptionElasticBuilder.class).build(description);
this.elasticsearchTemplate.save(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, description.getDmpId());
if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{description.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{description.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpEntity.getIsActive().equals(IsActive.Active)) {
DmpElasticEntity dmpElasticEntity = this.builderFactory.builder(DmpElasticBuilder.class).build(dmpEntity);
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
@ -325,7 +324,7 @@ public class ElasticServiceImpl implements ElasticService {
this.elasticsearchTemplate.delete(descriptionElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
DmpEntity dmpEntity = this.entityManager.find(DmpEntity.class, description.getDmpId());
if (dmpEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{description.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{description.getDmpId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (dmpEntity.getIsActive().equals(IsActive.Active)) {
DmpElasticEntity dmpElasticEntity = this.builderFactory.builder(DmpElasticBuilder.class).build(dmpEntity);
this.elasticsearchTemplate.save(dmpElasticEntity, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
@ -381,7 +380,7 @@ public class ElasticServiceImpl implements ElasticService {
items = query.collect();
if (items != null && !items.isEmpty()) {
List<DmpElasticEntity> elasticEntities = this.builderFactory.builder(DmpElasticBuilder.class).build(items);
elasticsearchTemplate.save(elasticEntities, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
this.elasticsearchTemplate.save(elasticEntities, IndexCoordinates.of(this.appElasticProperties.getDmpIndexName()));
page++;
}
} while (items != null && !items.isEmpty());
@ -413,7 +412,7 @@ public class ElasticServiceImpl implements ElasticService {
items = query.collect();
if (items != null && !items.isEmpty()) {
List<DescriptionElasticEntity> elasticEntities = this.builderFactory.builder(DescriptionElasticBuilder.class).build(items);
elasticsearchTemplate.save(elasticEntities, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
this.elasticsearchTemplate.save(elasticEntities, IndexCoordinates.of(this.appElasticProperties.getDescriptionIndexName()));
page++;
}
} while (items != null && !items.isEmpty());

View File

@ -1,30 +1,5 @@
package org.opencdmp.controllers;
import org.opencdmp.audit.AuditableAction;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.enums.DmpAccessType;
import org.opencdmp.commons.enums.DmpStatus;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.StorageFileEntity;
import org.opencdmp.model.*;
import org.opencdmp.model.builder.PublicDescriptionBuilder;
import org.opencdmp.model.persist.DescriptionFieldFilePersist;
import org.opencdmp.model.persist.DescriptionSectionPermissionResolver;
import org.opencdmp.service.storage.StorageFileService;
import gr.cite.tools.validation.ValidationFilterAnnotation;
import org.opencdmp.model.builder.DescriptionBuilder;
import org.opencdmp.model.censorship.DescriptionCensor;
import org.opencdmp.model.censorship.PublicDescriptionCensor;
import org.opencdmp.model.persist.DescriptionPersist;
import org.opencdmp.model.persist.DescriptionStatusPersist;
import org.opencdmp.model.persist.UpdateDescriptionTemplatePersist;
import org.opencdmp.model.result.QueryResult;
import org.opencdmp.query.DescriptionQuery;
import org.opencdmp.query.DmpQuery;
import org.opencdmp.query.lookup.DescriptionLookup;
import org.opencdmp.service.description.DescriptionService;
import org.opencdmp.service.elastic.ElasticQueryHelperService;
import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.censor.CensorFactory;
@ -35,7 +10,28 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.ValidationFilterAnnotation;
import jakarta.xml.bind.JAXBException;
import org.opencdmp.audit.AuditableAction;
import org.opencdmp.authorization.AuthorizationFlags;
import org.opencdmp.commons.enums.DmpAccessType;
import org.opencdmp.commons.enums.DmpStatus;
import org.opencdmp.commons.enums.IsActive;
import org.opencdmp.convention.ConventionService;
import org.opencdmp.data.StorageFileEntity;
import org.opencdmp.model.*;
import org.opencdmp.model.builder.DescriptionBuilder;
import org.opencdmp.model.builder.PublicDescriptionBuilder;
import org.opencdmp.model.censorship.DescriptionCensor;
import org.opencdmp.model.censorship.PublicDescriptionCensor;
import org.opencdmp.model.persist.*;
import org.opencdmp.model.result.QueryResult;
import org.opencdmp.query.DescriptionQuery;
import org.opencdmp.query.DmpQuery;
import org.opencdmp.query.lookup.DescriptionLookup;
import org.opencdmp.service.description.DescriptionService;
import org.opencdmp.service.elastic.ElasticQueryHelperService;
import org.opencdmp.service.storage.StorageFileService;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
@ -153,7 +149,7 @@ public class DescriptionController {
this.censorFactory.censor(DescriptionCensor.class).censor(fieldSet, null);
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).ids(id);
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).isActive(IsActive.Active).ids(id);
Description model = this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet));
if (model == null)
throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
@ -292,7 +288,7 @@ public class DescriptionController {
return true;
}
@RequestMapping(method = RequestMethod.GET, value = {"/xml/export/{id}"}, produces = "application/xml")
@RequestMapping(method = RequestMethod.GET, value = "/xml/export/{id}", produces = "application/xml")
public @ResponseBody ResponseEntity<byte[]> getXml(@PathVariable UUID id) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException {
logger.debug(new MapLogEntry("export" + DmpBlueprint.class.getSimpleName()).And("id", id));