argos/dmp-backend/core/src/main/java/eu/eudat/elastic/query/NestedCollaboratorElasticQu...

95 lines
3.2 KiB
Java

package eu.eudat.elastic.query;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import eu.eudat.commons.enums.DmpUserRole;
import eu.eudat.elastic.data.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.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.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class NestedCollaboratorElasticQuery extends ElasticNestedQuery<NestedCollaboratorElasticQuery, NestedCollaboratorElasticEntity, UUID> {
private String nestedPath;
@Override
public NestedCollaboratorElasticQuery nestedPath(String value) {
this.nestedPath = value;
return this;
}
public NestedCollaboratorElasticQuery(
ElasticsearchTemplate elasticsearchRestTemplate,
ElasticProperties elasticProperties
) {
super(elasticsearchRestTemplate, elasticProperties);
}
@Override
protected Class<NestedCollaboratorElasticEntity> entityClass() {
return NestedCollaboratorElasticEntity.class;
}
@Override
protected Boolean isFalseQuery() {
return false;
}
@Override
protected Query applyAuthZ() {
return null;
}
@Override
protected Query applyFilters() {
return null;
}
@Override
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._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;
}
@Override
protected ElasticField fieldNameOf(FieldResolver item) {
if (item.match(NestedCollaboratorElasticEntity._id)) return this.elasticFieldOf(NestedCollaboratorElasticEntity._id).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;
}
@Override
protected String getNestedPath() {
return this.nestedPath;
}
@Override
protected UUID toKey(String key) {
return UUID.fromString(key);
}
@Override
protected ElasticField getKeyField() {
return this.elasticFieldOf(NestedCollaboratorElasticEntity._id);
}
@Override
protected ElasticNestedQuery<?, ?, ?> nestedQueryOf(FieldResolver item) {
return null;
}
}