elastic changes

This commit is contained in:
Efstratios Giannopoulos 2024-01-08 13:25:56 +02:00
parent 614fa9314a
commit 371dcd5a61
6 changed files with 35 additions and 44 deletions

View File

@ -68,10 +68,6 @@ public class DmpElasticEntity {
private List<NestedCollaboratorElasticEntity> collaborators;
public final static String _collaborators = "collaborators";
@Field(value = DmpElasticEntity._descriptionTemplates, type = FieldType.Nested)
private List<NestedDescriptionTemplateElasticEntity> descriptionTemplates;
public final static String _descriptionTemplates = "descriptionTemplates";
@Field(value = DmpElasticEntity._descriptions, type = FieldType.Nested)
private List<NestedDescriptionElasticEntity> descriptions;
public final static String _descriptions = "descriptions";
@ -176,14 +172,6 @@ public class DmpElasticEntity {
this.collaborators = collaborators;
}
public List<NestedDescriptionTemplateElasticEntity> getDescriptionTemplates() {
return descriptionTemplates;
}
public void setDescriptionTemplates(List<NestedDescriptionTemplateElasticEntity> descriptionTemplates) {
this.descriptionTemplates = descriptionTemplates;
}
public List<NestedDescriptionElasticEntity> getDescriptions() {
return descriptions;
}

View File

@ -1,6 +1,7 @@
package eu.eudat.elastic.data.nested;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.elastic.data.DescriptionElasticEntity;
import gr.cite.tools.elastic.ElasticConstants;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;
@ -46,6 +47,10 @@ public class NestedDescriptionElasticEntity {
private List<NestedReferenceElasticEntity> references;
public final static String _references = "references";
@Field(value = DescriptionElasticEntity._descriptionTemplate, type = FieldType.Object)
private NestedDescriptionTemplateElasticEntity descriptionTemplate;
public final static String _descriptionTemplate = "descriptionTemplate";
public UUID getId() {
return id;
}
@ -109,4 +114,12 @@ public class NestedDescriptionElasticEntity {
public void setReferences(List<NestedReferenceElasticEntity> references) {
this.references = references;
}
public NestedDescriptionTemplateElasticEntity getDescriptionTemplate() {
return descriptionTemplate;
}
public void setDescriptionTemplate(NestedDescriptionTemplateElasticEntity descriptionTemplate) {
this.descriptionTemplate = descriptionTemplate;
}
}

View File

@ -42,10 +42,9 @@ public class DmpElasticBuilder extends BaseElasticBuilder<DmpElasticEntity, DmpE
return new ArrayList<>();
Map<UUID, List<NestedReferenceElasticEntity>> referenceElasticEntityMap = this.collectDmpReferences(data);
Map<UUID, List<NestedDescriptionElasticEntity>> dmpElasticEntityMap = this.collectDescriptions(data);
Map<UUID, List<NestedDescriptionElasticEntity>> descriptionElasticEntityMap = this.collectDescriptions(data);
Map<UUID, List<NestedCollaboratorElasticEntity>> collaboratorElasticEntityMap = this.collectCollaborators(data);
Map<UUID, List<NestedDoiElasticEntity>> doiElasticEntityMap = this.collectDois(data);
Map<UUID, List<NestedDescriptionTemplateElasticEntity>> descriptionTemplateElasticEntityMap = this.collectDescriptionTemplates(data);
List<DmpElasticEntity> models = new ArrayList<>();
for (DmpEntity d : data) {
@ -64,10 +63,9 @@ public class DmpElasticBuilder extends BaseElasticBuilder<DmpElasticEntity, DmpE
m.setFinalizedAt(Date.from(d.getFinalizedAt()));
}
if (referenceElasticEntityMap != null) m.setReferences(referenceElasticEntityMap.getOrDefault(d.getId(), null));
if (dmpElasticEntityMap != null) m.setDescriptions(dmpElasticEntityMap.getOrDefault(d.getId(), null));
if (descriptionElasticEntityMap != null) m.setDescriptions(descriptionElasticEntityMap.getOrDefault(d.getId(), null));
if (collaboratorElasticEntityMap != null) m.setCollaborators(collaboratorElasticEntityMap.getOrDefault(d.getId(), null));
if (doiElasticEntityMap != null) m.setDois(doiElasticEntityMap.getOrDefault(d.getId(), null));
if (descriptionTemplateElasticEntityMap != null) m.setDescriptionTemplates(descriptionTemplateElasticEntityMap.getOrDefault(d.getId(), null));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
@ -94,26 +92,6 @@ public class DmpElasticBuilder extends BaseElasticBuilder<DmpElasticEntity, DmpE
return itemMap;
}
private Map<UUID, List<NestedDescriptionTemplateElasticEntity>> collectDescriptionTemplates(List<DmpEntity> data) throws MyApplicationException {
if (data.isEmpty()) return null;
this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
DmpDescriptionTemplateQuery associationQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(data.stream().map(DmpEntity::getId).collect(Collectors.toList())).isActive(IsActive.Active);
List<DmpDescriptionTemplateEntity> associationEntities = associationQuery.collect();
DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).groupIds(associationEntities.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList()));
Map<UUID, NestedDescriptionTemplateElasticEntity> itemMapById = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(query, NestedDescriptionTemplateElasticEntity::getId);
Map<UUID, List<NestedDescriptionTemplateElasticEntity>> itemMap = new HashMap<>();
for (DmpDescriptionTemplateEntity associationEntity : associationEntities){
if (!itemMap.containsKey(associationEntity.getDmpId())) itemMap.put(associationEntity.getDmpId(), new ArrayList<>());
NestedDescriptionTemplateElasticEntity item = itemMapById.getOrDefault(associationEntity.getDescriptionTemplateGroupId(), null);
if (item != null) itemMap.get(associationEntity.getDmpId()).add(item);
}
return itemMap;
}
private Map<UUID, List<NestedDescriptionElasticEntity>> collectDescriptions(List<DmpEntity> data) throws MyApplicationException {
if (data.isEmpty())
return null;

View File

@ -6,15 +6,14 @@ import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionReferenceEntity;
import eu.eudat.data.DescriptionTagEntity;
import eu.eudat.elastic.data.nested.NestedDescriptionElasticEntity;
import eu.eudat.elastic.data.nested.NestedDescriptionTemplateElasticEntity;
import eu.eudat.elastic.data.nested.NestedReferenceElasticEntity;
import eu.eudat.elastic.data.nested.NestedTagElasticEntity;
import eu.eudat.elastic.elasticbuilder.BaseElasticBuilder;
import eu.eudat.model.DescriptionReference;
import eu.eudat.model.DescriptionTag;
import eu.eudat.query.DescriptionReferenceQuery;
import eu.eudat.query.DescriptionTagQuery;
import eu.eudat.query.ReferenceQuery;
import eu.eudat.query.TagQuery;
import eu.eudat.model.DescriptionTemplate;
import eu.eudat.query.*;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
@ -33,7 +32,7 @@ import java.util.stream.Collectors;
public class NestedDescriptionElasticBuilder extends BaseElasticBuilder<NestedDescriptionElasticEntity, DescriptionEntity> {
private final QueryFactory queryFactory;
private final BuilderFactory builderFactory;
private final BuilderFactory builderFactory;
@Autowired
public NestedDescriptionElasticBuilder(
@ -50,6 +49,7 @@ public class NestedDescriptionElasticBuilder extends BaseElasticBuilder<NestedDe
Map<UUID, List<NestedReferenceElasticEntity>> referenceElasticEntityMap = this.collectDescriptionReferences(data);
Map<UUID, List<NestedTagElasticEntity>> tagElasticEntityMap = this.collectDescriptionTags(data);
Map<UUID, NestedDescriptionTemplateElasticEntity> descriptionTemplateElasticEntityMap = this.collectDescriptionTemplates(data);
List<NestedDescriptionElasticEntity> models = new ArrayList<>();
for (DescriptionEntity d : data) {
@ -109,4 +109,16 @@ public class NestedDescriptionElasticBuilder extends BaseElasticBuilder<NestedDe
return itemMap;
}
private Map<UUID, NestedDescriptionTemplateElasticEntity> collectDescriptionTemplates(List<DescriptionEntity> data) throws MyApplicationException {
if (data.isEmpty())
return null;
this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName());
Map<UUID, NestedDescriptionTemplateElasticEntity> itemMap;
DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(q, NestedDescriptionTemplateElasticEntity::getId);
return itemMap;
}
}

View File

@ -265,7 +265,6 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
if (columns.contains(DmpElasticEntity._finalizedAt)) mocDoc.setFinalizedAt(FieldBasedMapper.shallowSafeConversion(rawData.get(DmpElasticEntity._finalizedAt), Date.class));
mocDoc.setCollaborators(this.convertNested(rawData, columns, this.queryFactory.query(NestedCollaboratorElasticQuery.class), DmpElasticEntity._collaborators, null));
mocDoc.setReferences(this.convertNested(rawData, columns, this.queryFactory.query(NestedReferenceElasticQuery.class), DmpElasticEntity._references, null));
mocDoc.setDescriptionTemplates(this.convertNested(rawData, columns, this.queryFactory.query(NestedDescriptionTemplateElasticQuery.class), DmpElasticEntity._descriptionTemplates, null));
mocDoc.setDescriptions(this.convertNested(rawData, columns, this.queryFactory.query(NestedDescriptionElasticQuery.class), DmpElasticEntity._descriptions, null));
return mocDoc;
}
@ -283,7 +282,6 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
else if (item.match(DmpElasticEntity._accessType)) return this.elasticFieldOf(DmpElasticEntity._accessType);
else if (item.prefix(DmpElasticEntity._collaborators)) return this.queryFactory.query(NestedCollaboratorElasticQuery.class).nestedPath(DmpElasticEntity._collaborators).fieldNameOf(this.extractPrefixed(item, DmpElasticEntity._collaborators));
else if (item.prefix(DmpElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(DmpElasticEntity._references).fieldNameOf(this.extractPrefixed(item, DmpElasticEntity._references));
else if (item.prefix(DmpElasticEntity._descriptionTemplates)) return this.queryFactory.query(NestedDescriptionTemplateElasticQuery.class).nestedPath(DmpElasticEntity._descriptionTemplates).fieldNameOf(this.extractPrefixed(item, DmpElasticEntity._descriptionTemplates));
else if (item.prefix(DmpElasticEntity._descriptions)) return this.queryFactory.query(NestedDescriptionElasticQuery.class).nestedPath(DmpElasticEntity._descriptions).fieldNameOf(this.extractPrefixed(item, DmpElasticEntity._descriptions));
else return null;
}
@ -314,7 +312,6 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
protected ElasticNestedQuery<?, ?, ?> nestedQueryOf(FieldResolver item) {
if (item.prefix(DmpElasticEntity._collaborators)) return this.queryFactory.query(NestedCollaboratorElasticQuery.class).nestedPath(DmpElasticEntity._collaborators);
else if (item.prefix(DmpElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(DmpElasticEntity._references);
else if (item.prefix(DmpElasticEntity._descriptionTemplates)) return this.queryFactory.query(NestedDescriptionTemplateElasticQuery.class).nestedPath(DmpElasticEntity._descriptionTemplates);
else if (item.prefix(DmpElasticEntity._descriptions)) return this.queryFactory.query(NestedDescriptionElasticQuery.class).nestedPath(DmpElasticEntity._descriptions);
else return null;
}

View File

@ -3,6 +3,7 @@ package eu.eudat.elastic.query;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.convention.ConventionService;
import eu.eudat.elastic.data.DescriptionElasticEntity;
import eu.eudat.elastic.data.nested.NestedDescriptionElasticEntity;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryFactory;
@ -74,6 +75,7 @@ public class NestedDescriptionElasticQuery extends ElasticNestedQuery<NestedDesc
if (columns.contains(NestedDescriptionElasticEntity._finalizedAt)) mocDoc.setFinalizedAt(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDescriptionElasticEntity._finalizedAt), Date.class));
mocDoc.setReferences(this.convertNested(rawData, columns, this.queryFactory.query(NestedReferenceElasticQuery.class), NestedDescriptionElasticEntity._references, this.getNestedPath()));
mocDoc.setTags(this.convertNested(rawData, columns, this.queryFactory.query(NestedTagElasticQuery.class), NestedDescriptionElasticEntity._tags, this.getNestedPath()));
mocDoc.setDescriptionTemplate(this.convertInnerObject(rawData, columns, this.queryFactory.query(InnerObjectDescriptionTemplateElasticQuery.class), NestedDescriptionElasticEntity._descriptionTemplate, null));
return mocDoc;
}
@ -87,6 +89,7 @@ public class NestedDescriptionElasticQuery extends ElasticNestedQuery<NestedDesc
else if (item.match(NestedDescriptionElasticEntity._finalizedAt)) return this.elasticFieldOf(NestedDescriptionElasticEntity._finalizedAt);
else if (item.prefix(NestedDescriptionElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(this.conventionService.asIndexer(this.getNestedPath(), NestedDescriptionElasticEntity._references)).fieldNameOf(this.extractPrefixed(item, NestedDescriptionElasticEntity._references));
else if (item.prefix(NestedDescriptionElasticEntity._tags)) return this.queryFactory.query(NestedTagElasticQuery.class).nestedPath(this.conventionService.asIndexer(this.getNestedPath(), NestedDescriptionElasticEntity._tags)).fieldNameOf(this.extractPrefixed(item, NestedDescriptionElasticEntity._tags));
else if (item.prefix(NestedDescriptionElasticEntity._descriptionTemplate)) return this.queryFactory.query(InnerObjectDescriptionTemplateElasticQuery.class).innerPath(this.conventionService.asIndexer(this.getNestedPath(), NestedDescriptionElasticEntity._descriptionTemplate)).fieldNameOf(this.extractPrefixed(item, NestedDescriptionElasticEntity._description));
else return null;
}