Search in sources :

Example 11 with QuerySpec

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

the class TaskResourceRepositoryTest method checkOrderByPriorityAsc.

@Test
public void checkOrderByPriorityAsc() {
    addTask("otherTask", 14);
    QuerySpec querySpec = new QuerySpec(ApproveTask.class);
    querySpec.addSort(new SortSpec(Arrays.asList("priority"), Direction.ASC));
    ResourceList<ApproveTask> resources = taskRepository.findAll(querySpec);
    Assert.assertEquals(2, resources.size());
    Assert.assertEquals("testTask", resources.get(0).getName());
    Assert.assertEquals("otherTask", resources.get(1).getName());
}
Also used : QuerySpec(io.crnk.core.queryspec.QuerySpec) ApproveTask(io.crnk.activiti.example.model.ApproveTask) SortSpec(io.crnk.core.queryspec.SortSpec) Test(org.junit.Test)

Example 12 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec 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 13 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec 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 14 with QuerySpec

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

the class TaskResourceRepositoryTest method createTask.

@Test
public void createTask() {
    QuerySpec querySpec = new QuerySpec(ApproveTask.class);
    ApproveTask resource = new ApproveTask();
    resource.setName("testTask");
    resource.setDescription(ENFORCED_DESCRIPTION);
    ApproveTask createdTask = taskRepository.create(resource);
    Assert.assertEquals("testTask", createdTask.getName());
    createdTask = taskRepository.findOne(task.getId(), querySpec);
    Assert.assertNotNull(createdTask);
}
Also used : QuerySpec(io.crnk.core.queryspec.QuerySpec) ApproveTask(io.crnk.activiti.example.model.ApproveTask) Test(org.junit.Test)

Example 15 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec 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)

Aggregations

QuerySpec (io.crnk.core.queryspec.QuerySpec)306 Test (org.junit.Test)233 FilterSpec (io.crnk.core.queryspec.FilterSpec)51 Document (io.crnk.core.engine.document.Document)45 Resource (io.crnk.core.engine.document.Resource)43 Set (java.util.Set)39 HashMap (java.util.HashMap)37 HashSet (java.util.HashSet)36 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)34 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)32 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)32 Task (io.crnk.test.mock.models.Task)32 Project (io.crnk.core.mock.models.Project)28 Relationship (io.crnk.core.engine.document.Relationship)26 Task (io.crnk.core.mock.models.Task)26 TestEntity (io.crnk.jpa.model.TestEntity)26 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)25 Serializable (java.io.Serializable)24 RelatedEntity (io.crnk.jpa.model.RelatedEntity)21 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)20