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());
}
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());
}
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());
}
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);
}
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 + "'");
}
}
Aggregations