108 lines
5.6 KiB
Java
108 lines
5.6 KiB
Java
package eu.eudat.elastic.query;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
import eu.eudat.commons.enums.DmpAccessType;
|
|
import eu.eudat.commons.enums.DmpStatus;
|
|
import eu.eudat.elastic.data.nested.NestedDmpElasticEntity;
|
|
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.ElasticInnerObjectQuery;
|
|
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.config.BeanDefinition;
|
|
import org.springframework.context.annotation.Scope;
|
|
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.*;
|
|
|
|
@Component
|
|
//Like in C# make it Transient
|
|
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
|
public class InnerObjectDmpElasticQuery extends ElasticInnerObjectQuery<InnerObjectDmpElasticQuery, NestedDmpElasticEntity, UUID> {
|
|
|
|
private String innerPath;
|
|
|
|
@Override
|
|
public InnerObjectDmpElasticQuery innerPath(String value) {
|
|
this.innerPath = value;
|
|
return this;
|
|
}
|
|
|
|
|
|
private final QueryFactory queryFactory;
|
|
@Autowired()
|
|
public InnerObjectDmpElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory) {
|
|
super(elasticsearchTemplate, elasticProperties);
|
|
this.queryFactory = queryFactory;
|
|
}
|
|
|
|
@Override
|
|
protected Class<NestedDmpElasticEntity> entityClass() {
|
|
return NestedDmpElasticEntity.class;
|
|
}
|
|
|
|
@Override
|
|
protected Boolean isFalseQuery() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
protected Query applyFilters() {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public NestedDmpElasticEntity convert(Map<String, Object> rawData, Set<String> columns) {
|
|
NestedDmpElasticEntity mocDoc = new NestedDmpElasticEntity();
|
|
if (columns.contains(NestedDmpElasticEntity._id)) mocDoc.setId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._id), UUID.class));
|
|
if (columns.contains(NestedDmpElasticEntity._label)) mocDoc.setLabel(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._label), String.class));
|
|
if (columns.contains(NestedDmpElasticEntity._description)) mocDoc.setDescription(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._description), String.class));
|
|
if (columns.contains(NestedDmpElasticEntity._status)) mocDoc.setStatus(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._status), DmpStatus.class));
|
|
if (columns.contains(NestedDmpElasticEntity._groupId)) mocDoc.setGroupId(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._groupId), UUID.class));
|
|
if (columns.contains(NestedDmpElasticEntity._accessType)) mocDoc.setAccessType(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._accessType), DmpAccessType.class));
|
|
if (columns.contains(NestedDmpElasticEntity._finalizedAt)) mocDoc.setFinalizedAt(FieldBasedMapper.shallowSafeConversion(rawData.get(NestedDmpElasticEntity._finalizedAt), Date.class));
|
|
mocDoc.setCollaborators(this.convertNested(rawData, columns, this.queryFactory.query(NestedCollaboratorElasticQuery.class), NestedDmpElasticEntity._collaborators, null));
|
|
mocDoc.setReferences(this.convertNested(rawData, columns, this.queryFactory.query(NestedReferenceElasticQuery.class), NestedDmpElasticEntity._references, null));
|
|
return mocDoc;
|
|
}
|
|
|
|
@Override
|
|
protected ElasticField fieldNameOf(FieldResolver item) {
|
|
if (item.match(NestedDmpElasticEntity._id)) return this.elasticFieldOf(NestedDmpElasticEntity._id);
|
|
else if (item.match(NestedDmpElasticEntity._label)) return this.elasticFieldOf(NestedDmpElasticEntity._label);
|
|
else if (item.match(NestedDmpElasticEntity._description)) return this.elasticFieldOf(NestedDmpElasticEntity._description);
|
|
else if (item.match(NestedDmpElasticEntity._status)) return this.elasticFieldOf(NestedDmpElasticEntity._status);
|
|
else if (item.match(NestedDmpElasticEntity._groupId)) return this.elasticFieldOf(NestedDmpElasticEntity._groupId);
|
|
else if (item.match(NestedDmpElasticEntity._finalizedAt)) return this.elasticFieldOf(NestedDmpElasticEntity._finalizedAt);
|
|
else if (item.match(NestedDmpElasticEntity._accessType)) return this.elasticFieldOf(NestedDmpElasticEntity._accessType);
|
|
else if (item.prefix(NestedDmpElasticEntity._collaborators)) return this.queryFactory.query(NestedCollaboratorElasticQuery.class).nestedPath(NestedDmpElasticEntity._collaborators).fieldNameOf(this.extractPrefixed(item, NestedDmpElasticEntity._collaborators));
|
|
else if (item.prefix(NestedDmpElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(NestedDmpElasticEntity._references).fieldNameOf(this.extractPrefixed(item, NestedDmpElasticEntity._references));
|
|
else return null;
|
|
}
|
|
|
|
@Override
|
|
protected String getInnerPath() {
|
|
return this.innerPath;
|
|
}
|
|
|
|
@Override
|
|
protected UUID toKey(String key) {
|
|
return UUID.fromString(key);
|
|
}
|
|
|
|
@Override
|
|
protected ElasticField getKeyField() {
|
|
return this.elasticFieldOf(NestedDmpElasticEntity._id);
|
|
}
|
|
|
|
@Override
|
|
protected ElasticNestedQuery<?, ?, ?> nestedQueryOf(FieldResolver item) {
|
|
if (item.prefix(NestedDmpElasticEntity._collaborators)) return this.queryFactory.query(NestedCollaboratorElasticQuery.class).nestedPath(NestedDmpElasticEntity._collaborators);
|
|
else if (item.prefix(NestedDmpElasticEntity._references)) return this.queryFactory.query(NestedReferenceElasticQuery.class).nestedPath(NestedDmpElasticEntity._references);
|
|
else return null;
|
|
}
|
|
}
|