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