Search in sources :

Example 6 with FilterSpec

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

the class TaskResourceRepositoryTest method checkEqualsName.

@Test
public void checkEqualsName() {
    QuerySpec querySpec = new QuerySpec(ApproveTask.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("id"), FilterOperator.EQ, task.getId()));
    Assert.assertEquals(1, taskRepository.findAll(querySpec).size());
    querySpec = new QuerySpec(TaskResource.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("id"), FilterOperator.EQ, "doesNotExists"));
    Assert.assertEquals(0, taskRepository.findAll(querySpec).size());
}
Also used : TaskResource(io.crnk.activiti.resource.TaskResource) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) Test(org.junit.Test)

Example 7 with FilterSpec

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

the class TaskResourceRepositoryTest method checkEqualsAssigneeList.

@Test
public void checkEqualsAssigneeList() {
    QuerySpec querySpec = new QuerySpec(ApproveTask.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("assignee"), FilterOperator.EQ, Arrays.asList("john", "jane")));
    Assert.assertEquals(1, taskRepository.findAll(querySpec).size());
    querySpec = new QuerySpec(TaskResource.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("assignee"), FilterOperator.EQ, Arrays.asList("jane", "other")));
    Assert.assertEquals(0, taskRepository.findAll(querySpec).size());
}
Also used : TaskResource(io.crnk.activiti.resource.TaskResource) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) Test(org.junit.Test)

Example 8 with FilterSpec

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

the class TaskRelationshipRepository method findOneTarget.

@Override
public T findOneTarget(Serializable sourceId, String fieldName, QuerySpec querySpec) {
    if (relationshipName.equals(fieldName)) {
        RegistryEntry taskEntry = resourceRegistry.getEntry(taskClass);
        ResourceRepositoryV2 taskRepository = (ResourceRepositoryV2) taskEntry.getResourceRepository(null).getResourceRepository();
        QuerySpec processQuerySpec = querySpec.duplicate();
        processQuerySpec.addFilter(new FilterSpec(Arrays.asList(PROCESS_INSTANCE_ID_FIELD), FilterOperator.EQ, sourceId.toString()));
        processQuerySpec.addFilter(new FilterSpec(Arrays.asList(TASK_DEFINITION_KEY_FIELD), FilterOperator.EQ, taskDefinitionId));
        ResourceList tasks = taskRepository.findAll(processQuerySpec);
        PreconditionUtil.assertTrue("unique result expected", tasks.size() <= 1);
        return tasks.isEmpty() ? null : (T) tasks.get(0);
    } else {
        throw new UnsupportedOperationException("unknown fieldName '" + fieldName + "'");
    }
}
Also used : ResourceList(io.crnk.core.resource.list.ResourceList) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 9 with FilterSpec

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

the class ActivitiQuerySpecMapper method applyFilterSpec.

private static void applyFilterSpec(Query activitiQuery, QuerySpec querySpec, List<FilterSpec> baseFilters) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
    List<FilterSpec> filters = new ArrayList<>();
    filters.addAll(baseFilters);
    filters.addAll(querySpec.getFilters());
    for (FilterSpec filterSpec : filters) {
        List<String> attributePath = filterSpec.getAttributePath();
        if (attributePath.size() == 2 && "id".equals(attributePath.get(1))) {
            attributePath = Arrays.asList(attributePath.get(0) + "Id");
        }
        PreconditionUtil.assertTrue("nested attribute paths not supported", attributePath.size() == 1);
        String attrName = attributePath.get(0);
        FilterOperator op = filterSpec.getOperator();
        Class valueClass = filterSpec.getValue().getClass();
        String attributeName = mapAttributeName(attrName, querySpec.getResourceClass(), op, valueClass);
        Object value = filterSpec.getValue();
        Method method = getMethod(activitiQuery.getClass(), attributeName);
        if (method.getParameterCount() == 0) {
            PreconditionUtil.assertEquals("only filtering by true supported for boolean values", Boolean.TRUE, value);
            method.invoke(activitiQuery);
        } else {
            Class<?> expectedType = method.getParameterTypes()[0];
            method.invoke(activitiQuery, unmapValue(value, expectedType));
        }
    }
}
Also used : FilterOperator(io.crnk.core.queryspec.FilterOperator) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) FilterSpec(io.crnk.core.queryspec.FilterSpec)

Example 10 with FilterSpec

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

the class ApprovalIntTest method verifyApprovalStarted.

private ApproveTask verifyApprovalStarted(Schedule schedule) {
    // check approval process started
    ResourceList<ScheduleApprovalProcessInstance> scheduleApprovals = approvalRepo.findAll(new QuerySpec(ScheduleApprovalProcessInstance.class));
    Assert.assertEquals(1, scheduleApprovals.size());
    checkOpenApproval(schedule, scheduleApprovals.get(0));
    // check relationship from resource to approval process
    ScheduleApprovalProcessInstance scheduleApproval = approvalRelRepo.findOneTarget(schedule.getId().toString(), "approval", new QuerySpec(ScheduleApprovalProcessInstance.class));
    checkOpenApproval(schedule, scheduleApproval);
    // check relationship from approval process to task
    ApproveTask approveTask = processTaskRepo.findOneTarget(scheduleApprovals.get(0).getId(), "approveTask", new QuerySpec(ApproveTask.class));
    Assert.assertNotNull(approveTask);
    // check task created
    QuerySpec taskQuery = new QuerySpec(ApproveTask.class);
    taskQuery.includeRelation(Arrays.asList("form"));
    ResourceList<ApproveTask> tasks = taskRepo.findAll(taskQuery);
    Assert.assertEquals(1, tasks.size());
    ApproveTask task = tasks.get(0);
    checkApproveTaskCreated(schedule, task);
    // check search for task by process
    QuerySpec querySpec = new QuerySpec(ApproveTask.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("processInstance", "id"), FilterOperator.EQ, scheduleApproval.getId()));
    ResourceList<ApproveTask> results = taskRepo.findAll(querySpec);
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(scheduleApproval.getId(), results.get(0).getProcessInstanceId());
    return task;
}
Also used : ScheduleApprovalProcessInstance(io.crnk.activiti.example.model.ScheduleApprovalProcessInstance) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) ApproveTask(io.crnk.activiti.example.model.ApproveTask)

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