Search in sources :

Example 1 with ValueFilter

use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.

the class JsonToFilterMapperTest method values_filter.

@Test
public void values_filter() throws Exception {
    Map<String, Object> value = new HashMap<>();
    List<String> values = List.of("fisk", "ost", "løk");
    final HashMap<String, Object> valueFilter = new HashMap<>();
    valueFilter.put("field", "myField");
    valueFilter.put("values", values);
    value.put("hasValue", valueFilter);
    final Filters filters = com.enonic.xp.lib.common.JsonToFilterMapper.create(value);
    assertTrue(filters.get(0) instanceof ValueFilter);
    assertEquals("myField", ((ValueFilter) filters.get(0)).getFieldName());
    assertEquals(3, ((ValueFilter) filters.get(0)).getValues().size());
}
Also used : Filters(com.enonic.xp.query.filter.Filters) HashMap(java.util.HashMap) ValueFilter(com.enonic.xp.query.filter.ValueFilter) Test(org.junit.jupiter.api.Test)

Example 2 with ValueFilter

use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.

the class FilterBuilderFactoryTest method createNumberValueFilter.

@Test
public void createNumberValueFilter() throws Exception {
    final ValueFilter queryFilter = ValueFilter.create().fieldName("myField").addValue(ValueFactory.newDouble(1.0)).addValue(ValueFactory.newDouble(2.0)).build();
    final String expected = load("filter_values_number.json");
    final QueryBuilder filterBuilder = new FilterBuilderFactory(new SearchQueryFieldNameResolver()).create(Filters.from(queryFilter));
    assertEquals(cleanString(expected), cleanString(filterBuilder.toString()));
}
Also used : ValueFilter(com.enonic.xp.query.filter.ValueFilter) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) Test(org.junit.jupiter.api.Test)

Example 3 with ValueFilter

use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.

the class FilterBuilderFactoryTest method createStringValueFilter.

@Test
public void createStringValueFilter() throws Exception {
    final ValueFilter queryFilter = ValueFilter.create().fieldName("myField").addValue(ValueFactory.newString("myValue1")).addValue(ValueFactory.newString("myValue2")).build();
    final String expected = load("filter_values_string.json");
    final QueryBuilder filterBuilder = new FilterBuilderFactory(new SearchQueryFieldNameResolver()).create(Filters.from(queryFilter));
    assertEquals(cleanString(expected), cleanString(filterBuilder.toString()));
}
Also used : ValueFilter(com.enonic.xp.query.filter.ValueFilter) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) Test(org.junit.jupiter.api.Test)

Example 4 with ValueFilter

use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.

the class AclFilterBuilderFactoryTest method anonymous.

@Test
public void anonymous() throws Exception {
    final Filter filter = AclFilterBuilderFactory.create(PrincipalKeys.empty());
    assertTrue(filter instanceof ValueFilter);
    ValueFilter valueFilter = (ValueFilter) filter;
    assertEquals(1, valueFilter.getValues().size());
}
Also used : ValueFilter(com.enonic.xp.query.filter.ValueFilter) Filter(com.enonic.xp.query.filter.Filter) ValueFilter(com.enonic.xp.query.filter.ValueFilter) Test(org.junit.jupiter.api.Test)

Example 5 with ValueFilter

use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.

the class AclFilterBuilderFactoryTest method testName.

@Test
public void testName() throws Exception {
    final Principals principals = Principals.from(User.create().email("rmy@enonic.com").login("rmy").displayName("Runar Myklebust").key(PrincipalKey.from("user:system:rmy")).build(), Group.create().key(PrincipalKey.from("group:system:mygroup")).displayName("My group").build());
    final Filter filter = AclFilterBuilderFactory.create(principals.getKeys());
    assertTrue(filter instanceof ValueFilter);
    ValueFilter valueFilter = (ValueFilter) filter;
    assertEquals(2, valueFilter.getValues().size());
}
Also used : Principals(com.enonic.xp.security.Principals) ValueFilter(com.enonic.xp.query.filter.ValueFilter) Filter(com.enonic.xp.query.filter.Filter) ValueFilter(com.enonic.xp.query.filter.ValueFilter) Test(org.junit.jupiter.api.Test)

Aggregations

ValueFilter (com.enonic.xp.query.filter.ValueFilter)10 Test (org.junit.jupiter.api.Test)6 NodeQuery (com.enonic.xp.node.NodeQuery)3 Filter (com.enonic.xp.query.filter.Filter)3 SearchQueryFieldNameResolver (com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver)3 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)2 ContentId (com.enonic.xp.content.ContentId)1 ContentIds (com.enonic.xp.content.ContentIds)1 MemoryBlobStore (com.enonic.xp.internal.blobstore.MemoryBlobStore)1 IssueStatus (com.enonic.xp.issue.IssueStatus)1 IssueType (com.enonic.xp.issue.IssueType)1 NodeService (com.enonic.xp.node.NodeService)1 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)1 QueryExpr (com.enonic.xp.query.expr.QueryExpr)1 BooleanFilter (com.enonic.xp.query.filter.BooleanFilter)1 ExistsFilter (com.enonic.xp.query.filter.ExistsFilter)1 Filters (com.enonic.xp.query.filter.Filters)1 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)1 Principals (com.enonic.xp.security.Principals)1