Search in sources :

Example 36 with FilterSpec

use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.

the class DefaultQuerySpecDeserializerTestBase method testFilterWithDotNotation.

@Test
public void testFilterWithDotNotation() {
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.addFilter(new FilterSpec(Arrays.asList("project", "name"), FilterOperator.EQ, "value"));
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "filter[project.name]", "value");
    QuerySpec actualSpec = deserializer.deserialize(taskInformation, params);
    Assert.assertEquals(expectedSpec, actualSpec);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 37 with FilterSpec

use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.

the class DefaultQuerySpecDeserializerTestBase method checkIgnoreParseExceptions.

@Test
public void checkIgnoreParseExceptions() {
    Assert.assertFalse(deserializer.isIgnoreParseExceptions());
    deserializer.setIgnoreParseExceptions(true);
    Assert.assertTrue(deserializer.isIgnoreParseExceptions());
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "filter[id]", "notAnInteger");
    QuerySpec actualSpec = deserializer.deserialize(taskInformation, params);
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.addFilter(new FilterSpec(Arrays.asList("id"), FilterOperator.EQ, "notAnInteger"));
    Assert.assertEquals(expectedSpec, actualSpec);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 38 with FilterSpec

use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.

the class DefaultQuerySpecDeserializerTestBase method testFilterWithDefaultOp.

@Test
public void testFilterWithDefaultOp() {
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.addFilter(new FilterSpec(Arrays.asList("name"), FilterOperator.EQ, "value"));
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "filter[tasks][name]", "value");
    QuerySpec actualSpec = deserializer.deserialize(taskInformation, params);
    Assert.assertEquals(expectedSpec, actualSpec);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 39 with FilterSpec

use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.

the class DtoMappingTest method testSubQueryComputation.

@Test
public void testSubQueryComputation() {
    ResourceRepositoryV2<TestDTO, Serializable> dtoRepo = client.getQuerySpecRepository(TestDTO.class);
    int n = 5;
    for (long i = 0; i < n; i++) {
        TestDTO dto = new TestDTO();
        dto.setId(i + 100);
        dto.setStringValue(Long.toString(i));
        dtoRepo.create(dto);
    }
    // select, sort, filter by complex subquery
    QuerySpec querySpec = new QuerySpec(TestDTO.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList(TestDTO.ATTR_COMPUTED_NUMBER_OF_SMALLER_IDS), FilterOperator.LT, 4));
    // TODO enable querySpec parser
    // querySpec.addSort(new SortSpec(Arrays.asList(TestDTO.ATTR_COMPUTED_NUMBER_OF_SMALLER_IDS), Direction.DESC));
    ResourceList<TestDTO> dtos = dtoRepo.findAll(querySpec);
    Assert.assertEquals(4, dtos.size());
    for (int i = 0; i < dtos.size(); i++) {
        TestDTO dto = dtos.get(i);
        // 4 - i;
        int j = i;
        Assert.assertEquals(100 + j, dto.getId().longValue());
        Assert.assertEquals(j, dto.getComputedNumberOfSmallerIds());
    }
}
Also used : TestDTO(io.crnk.jpa.model.dto.TestDTO) Serializable(java.io.Serializable) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest) Test(org.junit.Test)

Example 40 with FilterSpec

use of io.crnk.core.queryspec.FilterSpec in project crnk-framework by crnk-project.

the class QueryFilterBuilder method filterLargeValueSets.

private P filterLargeValueSets(FilterSpec filterSpec, MetaDataObject rootMeta, F root, JoinType defaultPredicateJoinType) {
    // Split filter values with two many elements. Oracle is limited to 1000.
    ArrayList<FilterSpec> filterSpecs = new ArrayList<>();
    List<?> list = new ArrayList<>((Collection<?>) filterSpec.getValue());
    for (int i = 0; i < list.size(); i += PARAM_LIMIT_FOR_ORACLE) {
        int nextOffset = i + Math.min(list.size() - i, PARAM_LIMIT_FOR_ORACLE);
        List<?> batchList = list.subList(i, nextOffset);
        filterSpecs.add(new FilterSpec(filterSpec.getAttributePath(), filterSpec.getOperator(), batchList));
    }
    FilterSpec orSpec = FilterSpec.or(filterSpecs);
    return filterSpecListToPredicate(rootMeta, root, orSpec, defaultPredicateJoinType);
}
Also used : ArrayList(java.util.ArrayList) FilterSpec(io.crnk.core.queryspec.FilterSpec)

Aggregations

FilterSpec (io.crnk.core.queryspec.FilterSpec)56 QuerySpec (io.crnk.core.queryspec.QuerySpec)51 Test (org.junit.Test)40 HashSet (java.util.HashSet)14 Set (java.util.Set)13 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)12 HashMap (java.util.HashMap)12 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)9 TaskResource (io.crnk.activiti.resource.TaskResource)8 MetaResource (io.crnk.meta.model.resource.MetaResource)8 ScheduleApprovalProcessInstance (io.crnk.activiti.example.model.ScheduleApprovalProcessInstance)5 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)5 MetaAttribute (io.crnk.meta.model.MetaAttribute)5 ResourceField (io.crnk.core.engine.information.resource.ResourceField)4 ResourceList (io.crnk.core.resource.list.ResourceList)3 RelatedEntity (io.crnk.jpa.model.RelatedEntity)3 ArrayList (java.util.ArrayList)3 MultivaluedMap (io.crnk.core.engine.internal.utils.MultivaluedMap)2 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)2 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)2