From a8c1736e83fdec1c663d89bd777801a595d55c76 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Tue, 30 Apr 2024 12:54:26 +0300 Subject: [PATCH] elastic fixes --- .../elastic/data/DmpElasticEntity.java | 43 +++++------ .../NestedCollaboratorElasticEntity.java | 29 ++++++-- .../NestedCollaboratorElasticBuilder.java | 13 ++-- .../query/DescriptionElasticQuery.java | 63 ++++++++-------- .../elastic/query/DmpElasticQuery.java | 73 ++++++++++--------- .../query/NestedCollaboratorElasticQuery.java | 41 ++++++++--- .../DmpUserCommonModelBuilder.java | 12 +-- .../java/org/opencdmp/query/UserQuery.java | 37 +++++----- .../query/lookup/DescriptionLookup.java | 29 ++++---- .../org/opencdmp/query/lookup/DmpLookup.java | 32 ++++---- .../opencdmp/query/lookup/DmpUserLookup.java | 22 +++--- .../service/elastic/ElasticServiceImpl.java | 61 ++++++++-------- .../controllers/DescriptionController.java | 50 ++++++------- 13 files changed, 271 insertions(+), 234 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/elastic/data/DmpElasticEntity.java b/backend/core/src/main/java/org/opencdmp/elastic/data/DmpElasticEntity.java index 8fa58eb12..38cc6133d 100644 --- a/backend/core/src/main/java/org/opencdmp/elastic/data/DmpElasticEntity.java +++ b/backend/core/src/main/java/org/opencdmp/elastic/data/DmpElasticEntity.java @@ -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 getReferences() { - return references; + return this.references; } public void setReferences(List references) { @@ -177,7 +178,7 @@ public class DmpElasticEntity { } public List getCollaborators() { - return collaborators; + return this.collaborators; } public void setCollaborators(List collaborators) { @@ -185,7 +186,7 @@ public class DmpElasticEntity { } public List getDescriptions() { - return descriptions; + return this.descriptions; } public void setDescriptions(List descriptions) { @@ -193,7 +194,7 @@ public class DmpElasticEntity { } public List getDois() { - return dois; + return this.dois; } public void setDois(List dois) { @@ -201,7 +202,7 @@ public class DmpElasticEntity { } public DmpVersionStatus getVersionStatus() { - return versionStatus; + return this.versionStatus; } public void setVersionStatus(DmpVersionStatus versionStatus) { diff --git a/backend/core/src/main/java/org/opencdmp/elastic/data/nested/NestedCollaboratorElasticEntity.java b/backend/core/src/main/java/org/opencdmp/elastic/data/nested/NestedCollaboratorElasticEntity.java index 6ca1d9ad0..228239eea 100644 --- a/backend/core/src/main/java/org/opencdmp/elastic/data/nested/NestedCollaboratorElasticEntity.java +++ b/backend/core/src/main/java/org/opencdmp/elastic/data/nested/NestedCollaboratorElasticEntity.java @@ -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; + } } diff --git a/backend/core/src/main/java/org/opencdmp/elastic/elasticbuilder/nested/NestedCollaboratorElasticBuilder.java b/backend/core/src/main/java/org/opencdmp/elastic/elasticbuilder/nested/NestedCollaboratorElasticBuilder.java index d11f38e38..f7f9a07e7 100644 --- a/backend/core/src/main/java/org/opencdmp/elastic/elasticbuilder/nested/NestedCollaboratorElasticBuilder.java +++ b/backend/core/src/main/java/org/opencdmp/elastic/elasticbuilder/nested/NestedCollaboratorElasticBuilder.java @@ -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 { private final QueryFactory queryFactory; @@ -46,6 +44,7 @@ public class NestedCollaboratorElasticBuilder extends BaseElasticBuilder 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 { 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 { } 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 { protected Query applyFilters() { List 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 { @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); diff --git a/backend/core/src/main/java/org/opencdmp/elastic/query/NestedCollaboratorElasticQuery.java b/backend/core/src/main/java/org/opencdmp/elastic/query/NestedCollaboratorElasticQuery.java index c0ec0404d..e2e1760d0 100644 --- a/backend/core/src/main/java/org/opencdmp/elastic/query/NestedCollaboratorElasticQuery.java +++ b/backend/core/src/main/java/org/opencdmp/elastic/query/NestedCollaboratorElasticQuery.java @@ -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 { private Collection ids; + private Collection userIds; private Collection userRoles; @@ -42,6 +39,21 @@ public class NestedCollaboratorElasticQuery extends ElasticNestedQuery 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 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 rawData, Set 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 { private final BuilderFactory builderFactory; @@ -61,6 +61,8 @@ public class DmpUserCommonModelBuilder extends BaseCommonModelBuilder 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())); diff --git a/backend/core/src/main/java/org/opencdmp/query/UserQuery.java b/backend/core/src/main/java/org/opencdmp/query/UserQuery.java index 8857ce5b1..b433c9af4 100644 --- a/backend/core/src/main/java/org/opencdmp/query/UserQuery.java +++ b/backend/core/src/main/java/org/opencdmp/query/UserQuery.java @@ -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 { private String like; private Boolean dmpAssociated; @@ -159,12 +160,12 @@ public class UserQuery extends QueryBase { 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 { protected Predicate applyFilters(QueryContext queryContext) { List 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 inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._id)); @@ -202,7 +203,7 @@ public class UserQuery extends QueryBase { predicates.add(inClause); } if (this.emails != null) { - Subquery userContactInfoSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>( + Subquery 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 { if (this.userScope.isSet()) userId = this.userScope.getUserIdSafe(); else throw new MyNotFoundException("Only user scoped allowed"); - Subquery dmpUserDmpQuery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>( + Subquery 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 { )) )); - Subquery dmpUserUserQuery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>( + Subquery 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( diff --git a/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionLookup.java b/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionLookup.java index b9b40815c..626db67ba 100644 --- a/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionLookup.java +++ b/backend/core/src/main/java/org/opencdmp/query/lookup/DescriptionLookup.java @@ -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 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 getIds() { - return ids; + return this.ids; } public void setIds(List ids) { @@ -47,7 +47,7 @@ public class DescriptionLookup extends Lookup { } public List getExcludedIds() { - return excludedIds; + return this.excludedIds; } public void setExcludedIds(List excludedIds) { @@ -55,7 +55,7 @@ public class DescriptionLookup extends Lookup { } public List getIsActive() { - return isActive; + return this.isActive; } public void setIsActive(List isActive) { @@ -63,7 +63,7 @@ public class DescriptionLookup extends Lookup { } public List getStatuses() { - return statuses; + return this.statuses; } public void setStatuses(List 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); diff --git a/backend/core/src/main/java/org/opencdmp/query/lookup/DmpLookup.java b/backend/core/src/main/java/org/opencdmp/query/lookup/DmpLookup.java index 024d4d030..b9b1d6b1e 100644 --- a/backend/core/src/main/java/org/opencdmp/query/lookup/DmpLookup.java +++ b/backend/core/src/main/java/org/opencdmp/query/lookup/DmpLookup.java @@ -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 getIds() { - return ids; + return this.ids; } public void setIds(List ids) { @@ -51,7 +51,7 @@ public class DmpLookup extends Lookup { } public List getExcludedIds() { - return excludedIds; + return this.excludedIds; } public void setExcludedIds(List excludedIds) { @@ -59,7 +59,7 @@ public class DmpLookup extends Lookup { } public List getIsActive() { - return isActive; + return this.isActive; } public void setIsActive(List isActive) { @@ -67,7 +67,7 @@ public class DmpLookup extends Lookup { } public List getStatuses() { - return statuses; + return this.statuses; } public void setStatuses(List statuses) { @@ -75,7 +75,7 @@ public class DmpLookup extends Lookup { } public List getVersions() { - return versions; + return this.versions; } public void setVersions(List versions) { @@ -83,7 +83,7 @@ public class DmpLookup extends Lookup { } public List getAccessTypes() { - return accessTypes; + return this.accessTypes; } public void setAccessTypes(List accessTypes) { @@ -91,7 +91,7 @@ public class DmpLookup extends Lookup { } public List getVersionStatuses() { - return versionStatuses; + return this.versionStatuses; } public void setVersionStatuses(List 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 getGroupIds() { - return groupIds; + return this.groupIds; } public void setGroupIds(List 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); diff --git a/backend/core/src/main/java/org/opencdmp/query/lookup/DmpUserLookup.java b/backend/core/src/main/java/org/opencdmp/query/lookup/DmpUserLookup.java index fd70e1712..7ecf651fc 100644 --- a/backend/core/src/main/java/org/opencdmp/query/lookup/DmpUserLookup.java +++ b/backend/core/src/main/java/org/opencdmp/query/lookup/DmpUserLookup.java @@ -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 userRoles; public List getIds() { - return ids; + return this.ids; } public void setIds(List ids) { @@ -32,7 +31,7 @@ public class DmpUserLookup extends Lookup { } public List getDmpIds() { - return dmpIds; + return this.dmpIds; } public void setDmpIds(List dmpIds) { @@ -40,7 +39,7 @@ public class DmpUserLookup extends Lookup { } public List getUserIds() { - return userIds; + return this.userIds; } public void setUserIds(List userIds) { @@ -48,7 +47,7 @@ public class DmpUserLookup extends Lookup { } public List getSectionIds() { - return sectionIds; + return this.sectionIds; } public void setSectionIds(List sectionIds) { @@ -56,7 +55,7 @@ public class DmpUserLookup extends Lookup { } public List getIsActive() { - return isActive; + return this.isActive; } public void setIsActive(List isActive) { @@ -64,7 +63,7 @@ public class DmpUserLookup extends Lookup { } public List getUserRoles() { - return userRoles; + return this.userRoles; } public void setUserRoles(List 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); diff --git a/backend/core/src/main/java/org/opencdmp/service/elastic/ElasticServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/elastic/ElasticServiceImpl.java index bbec8242a..d7ae9ae1c 100644 --- a/backend/core/src/main/java/org/opencdmp/service/elastic/ElasticServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/elastic/ElasticServiceImpl.java @@ -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 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 createNestedDescriptionTemplatePropertyMap(){ Map 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 createNestedCollaboratorTemplatePropertyMap(){ Map 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 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 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()); diff --git a/backend/web/src/main/java/org/opencdmp/controllers/DescriptionController.java b/backend/web/src/main/java/org/opencdmp/controllers/DescriptionController.java index 457ce85e4..405be58d4 100644 --- a/backend/web/src/main/java/org/opencdmp/controllers/DescriptionController.java +++ b/backend/web/src/main/java/org/opencdmp/controllers/DescriptionController.java @@ -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 getXml(@PathVariable UUID id) throws JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException { logger.debug(new MapLogEntry("export" + DmpBlueprint.class.getSimpleName()).And("id", id));