use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class QueryGeneratorTest method generateOneQueryRuleNotEqualsCompoundNull.
@Test(expectedExceptions = MolgenisQueryException.class)
public void generateOneQueryRuleNotEqualsCompoundNull() {
Object value = null;
Query<Entity> q = new QueryImpl<>().not().eq(compoundAttrName, value);
QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class L3Cache method createCacheLoader.
/**
* Create a cacheloader that loads entity ids from the repository and stores them together with their query
*
* @return the {@link CacheLoader}
*/
private CacheLoader<Query<Entity>, List<Object>> createCacheLoader(final Repository<Entity> repository) {
String repositoryName = repository.getName();
Fetch idAttributeFetch = new Fetch().field(repository.getEntityType().getIdAttribute().getName());
return new CacheLoader<Query<Entity>, List<Object>>() {
/**
* Loads {@link Entity} identifiers for a {@link Query}
* @param query the cache key to load
* @return {@link List} of identifier {@link Object}s
*/
@Override
public List<Object> load(@Nonnull Query<Entity> query) {
LOG.trace("Loading identifiers from repository {} for query {}", repositoryName, query);
return repository.findAll(new QueryImpl<>(query).fetch(idAttributeFetch)).map(Entity::getIdValue).collect(toList());
}
};
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class QueryGeneratorReferencesTest method generateOneQueryRuleNotEqualsEqualsBool.
@Test
public void generateOneQueryRuleNotEqualsEqualsBool() {
Boolean value = Boolean.TRUE;
Query<Entity> q = new QueryImpl<>().not().eq(PREFIX + refBoolAttributeName, value);
QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(nestedQuery(REF_ENTITY_ATT, termQuery(PREFIX + refBoolAttributeName, value), ScoreMode.Avg)));
assertQueryBuilderEquals(query, expectedQuery);
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class QueryGeneratorReferencesTest method generateOneQueryRuleGreaterEqualDate.
@Test
public void generateOneQueryRuleGreaterEqualDate() throws ParseException {
String date = "2015-05-22";
LocalDate value = LocalDate.parse(date);
Query<Entity> q;
q = new QueryImpl<>().ge(PREFIX + refDateAttributeName, value);
QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
QueryBuilder expectedQuery = constantScoreQuery(nestedQuery(REF_ENTITY_ATT, rangeQuery(PREFIX + refDateAttributeName).gte(date), ScoreMode.Avg));
assertQueryBuilderEquals(query, expectedQuery);
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class SearchAllServiceTest method testFindAll.
@Test
public void testFindAll() throws Exception {
when(dataService.findAll(PackageMetadata.PACKAGE, Package.class)).thenReturn(Stream.of(pack1, pack2, pack3, pack_sys));
when(dataService.findAll(EntityTypeMetadata.ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(Stream.of(entity1, entity2, entity3, entity4, abstractEntity));
when(dataService.count("entity id 1", new QueryImpl<>().search("test"))).thenReturn(2L);
when(dataService.count("entity id 3", new QueryImpl<>().search("test"))).thenReturn(6L);
when(dataService.count("entity id 4", new QueryImpl<>().search("test"))).thenReturn(11L);
PackageResult packageResult = PackageResult.create("package id 1", "package test nr 1", "package description 1");
AttributeResult attributeResult = AttributeResult.create("attr test nr 1", "attr description 1", "BOOL");
EntityTypeResult entityTypeResult1 = EntityTypeResult.builder().setId("entity id 1").setLabel("entity nr 1").setDescription("entity description 1").setPackageId("package id 2").setLabelMatch(false).setDescriptionMatch(false).setAttributes(singletonList(attributeResult)).setNrOfMatchingEntities(2).build();
EntityTypeResult entityTypeResult2 = EntityTypeResult.builder().setId("entity id 3").setLabel("entity test nr 3").setDescription("entity description 3").setPackageId("package id 3").setLabelMatch(true).setDescriptionMatch(false).setAttributes(Collections.emptyList()).setNrOfMatchingEntities(6).build();
EntityTypeResult entityTypeResult3 = EntityTypeResult.builder().setId("entity id 4").setLabel("entity nr 4").setDescription("entity test description 4").setPackageId(null).setLabelMatch(false).setDescriptionMatch(true).setAttributes(Collections.emptyList()).setNrOfMatchingEntities(11).build();
Result result = Result.builder().setEntityTypes(Arrays.asList(entityTypeResult1, entityTypeResult2, entityTypeResult3)).setPackages(singletonList(packageResult)).build();
assertEquals(searchAllService.searchAll("test"), result);
}
Aggregations