Search in sources :

Example 86 with QueryImpl

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

the class OntologyImportService method validateImport.

@Override
public EntitiesValidationReport validateImport(File file, RepositoryCollection source) {
    EntitiesValidationReport report = new EntitiesValidationReportImpl();
    if (source.getRepository(ONTOLOGY) == null)
        throw new MolgenisDataException("Exception Repository [" + ONTOLOGY + "] is missing");
    boolean ontologyExists = false;
    for (Entity ontologyEntity : source.getRepository(ONTOLOGY)) {
        String ontologyIRI = ontologyEntity.getString(OntologyMetaData.ONTOLOGY_IRI);
        String ontologyName = ontologyEntity.getString(OntologyMetaData.ONTOLOGY_NAME);
        Entity ontologyQueryEntity = dataService.findOne(ONTOLOGY, new QueryImpl<>().eq(OntologyMetaData.ONTOLOGY_IRI, ontologyIRI).or().eq(OntologyMetaData.ONTOLOGY_NAME, ontologyName));
        ontologyExists = ontologyQueryEntity != null;
    }
    if (ontologyExists)
        throw new MolgenisDataException("The ontology you are trying to import already exists");
    for (String entityTypeId : source.getEntityTypeIds()) {
        report.getSheetsImportable().put(entityTypeId, !ontologyExists);
    }
    return report;
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) EntitiesValidationReport(org.molgenis.data.importer.EntitiesValidationReport) EntitiesValidationReportImpl(org.molgenis.data.importer.EntitiesValidationReportImpl)

Example 87 with QueryImpl

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

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsDateTimeNull.

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

Example 88 with QueryImpl

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

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsDateNull.

@Test
public void generateOneQueryRuleNotEqualsDateNull() throws ParseException {
    LocalDate value = null;
    Query<Entity> q = new QueryImpl<>().not().eq(dateAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(boolQuery().mustNot(existsQuery(dateAttrName))));
    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) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 89 with QueryImpl

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

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsScript.

// TODO enable when implemented in QueryGenerator (see note in QueryGenerator)
// @Test
// public void generateOneQueryRuleNotEqualsMref()
// {
// }
@Test
public void generateOneQueryRuleNotEqualsScript() {
    String value = "int a = 1;";
    Query<Entity> q = new QueryImpl<>().not().eq(scriptAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(termQuery(scriptAttrName + '.' + 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 90 with QueryImpl

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

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsString.

@Test
public void generateOneQueryRuleNotEqualsString() {
    String value = "value";
    Query<Entity> q = new QueryImpl<>().not().eq(stringAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(termQuery(stringAttrName + '.' + 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)

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