Search in sources :

Example 1 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class MetaDataServiceImpl method getEntityTypes.

@Override
public Stream<EntityType> getEntityTypes() {
    List<EntityType> entityTypeList = newArrayList();
    Fetch entityTypeFetch = getEntityTypeFetch();
    // Fetch the entitytypes page by page so that the results can be cached
    final int pageSize = 1000;
    for (int page = 0; entityTypeList.size() == page * pageSize; page++) {
        QueryImpl<EntityType> query = new QueryImpl<>();
        query.setFetch(entityTypeFetch);
        query.setPageSize(pageSize);
        query.setOffset(page * pageSize);
        dataService.findAll(ENTITY_TYPE_META_DATA, query, EntityType.class).forEach(entityTypeList::add);
    }
    return entityTypeList.stream();
}
Also used : MetaUtils.getEntityTypeFetch(org.molgenis.data.meta.MetaUtils.getEntityTypeFetch) QueryImpl(org.molgenis.data.support.QueryImpl)

Example 2 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsEnum.

@Test
public void generateOneQueryRuleNotEqualsEnum() {
    String value = "enum0";
    Query<Entity> q = new QueryImpl<>().not().eq(enumAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(termQuery(enumAttrName + '.' + FIELD_NOT_ANALYZED, value)));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryImpl(org.molgenis.data.support.QueryImpl) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 3 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsEnumNull.

@Test
public void generateOneQueryRuleNotEqualsEnumNull() {
    String value = null;
    Query<Entity> q = new QueryImpl<>().not().eq(enumAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(boolQuery().mustNot(existsQuery(enumAttrName))));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryImpl(org.molgenis.data.support.QueryImpl) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 4 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsCompoundPartString.

@Test
public void generateOneQueryRuleNotEqualsCompoundPartString() {
    String value = "value";
    Query<Entity> q = new QueryImpl<>().not().eq(compoundPart0AttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(termQuery(compoundPart0AttrName + '.' + FIELD_NOT_ANALYZED, value)));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryImpl(org.molgenis.data.support.QueryImpl) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 5 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsCategorical.

// FIXME add test for ref entity where id attribute is int
// FIXME add test where value is entity
@Test
public void generateOneQueryRuleNotEqualsCategorical() {
    String value = "id";
    Query<Entity> q = new QueryImpl<>().not().eq(categoricalAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(nestedQuery(categoricalAttrName, termQuery(categoricalAttrName + ".xid." + FIELD_NOT_ANALYZED, value), ScoreMode.Avg)));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryImpl(org.molgenis.data.support.QueryImpl) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Aggregations

QueryImpl (org.molgenis.data.support.QueryImpl)98 Test (org.testng.annotations.Test)70 DynamicEntity (org.molgenis.data.support.DynamicEntity)37 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)36 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)36 EntityType (org.molgenis.data.meta.model.EntityType)28 Attribute (org.molgenis.data.meta.model.Attribute)25 Entity (org.molgenis.data.Entity)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 Stream (java.util.stream.Stream)7 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)7 AggregateQueryImpl (org.molgenis.data.support.AggregateQueryImpl)7 Objects.requireNonNull (java.util.Objects.requireNonNull)6 QueryRule (org.molgenis.data.QueryRule)6 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)6 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 Instant (java.time.Instant)5 LocalDate (java.time.LocalDate)5 Operator (org.molgenis.data.QueryRule.Operator)5