use of org.camunda.bpm.engine.impl.TaskQueryImpl in project camunda-bpm-platform by camunda.
the class TaskQueryExpressionTest method testQueryOverrideExpression.
public void testQueryOverrideExpression() {
String queryString = "query";
String expressionString = "expression";
String testStringExpression = "${'" + expressionString + "'}";
Date queryDate = new DateTime(now()).minusYears(1).toDate();
String testDateExpression = "${now()}";
TaskQueryImpl taskQuery = (TaskQueryImpl) taskQuery().taskAssigneeExpression(testStringExpression).taskAssignee(queryString).taskAssigneeLikeExpression(testStringExpression).taskAssigneeLike(queryString).taskOwnerExpression(expressionString).taskOwner(queryString).taskInvolvedUserExpression(expressionString).taskInvolvedUser(queryString).taskCreatedBeforeExpression(testDateExpression).taskCreatedBefore(queryDate).taskCreatedOnExpression(testDateExpression).taskCreatedOn(queryDate).taskCreatedAfterExpression(testDateExpression).taskCreatedAfter(queryDate).dueBeforeExpression(testDateExpression).dueBefore(queryDate).dueDateExpression(testDateExpression).dueDate(queryDate).dueAfterExpression(testDateExpression).dueAfter(queryDate).followUpBeforeExpression(testDateExpression).followUpBefore(queryDate).followUpDateExpression(testDateExpression).followUpDate(queryDate).followUpAfterExpression(testDateExpression).followUpAfter(queryDate);
// execute query so expression will be evaluated
taskQuery.count();
assertEquals(queryString, taskQuery.getAssignee());
assertEquals(queryString, taskQuery.getAssigneeLike());
assertEquals(queryString, taskQuery.getOwner());
assertEquals(queryString, taskQuery.getInvolvedUser());
assertTrue(taskQuery.getCreateTimeBefore().equals(queryDate));
assertTrue(taskQuery.getCreateTime().equals(queryDate));
assertTrue(taskQuery.getCreateTimeAfter().equals(queryDate));
assertTrue(taskQuery.getDueBefore().equals(queryDate));
assertTrue(taskQuery.getDueDate().equals(queryDate));
assertTrue(taskQuery.getDueAfter().equals(queryDate));
assertTrue(taskQuery.getFollowUpBefore().equals(queryDate));
assertTrue(taskQuery.getFollowUpDate().equals(queryDate));
assertTrue(taskQuery.getFollowUpAfter().equals(queryDate));
// candidates has to be tested separately cause they have to be set exclusively
taskQuery = (TaskQueryImpl) taskQuery().taskCandidateGroupExpression(testStringExpression).taskCandidateGroup(queryString);
// execute query so expression will be evaluated
taskQuery.count();
assertEquals(queryString, taskQuery.getCandidateGroup());
taskQuery = (TaskQueryImpl) taskQuery().taskCandidateUserExpression(testStringExpression).taskCandidateUser(queryString);
// execute query so expression will be evaluated
taskQuery.count();
assertEquals(queryString, taskQuery.getCandidateUser());
setCurrentUser(user);
List<String> queryList = Arrays.asList("query");
String testGroupsExpression = "${currentUserGroups()}";
taskQuery = (TaskQueryImpl) taskQuery().taskCandidateGroupInExpression(testGroupsExpression).taskCandidateGroupIn(queryList);
// execute query so expression will be evaluated
taskQuery.count();
assertEquals(1, taskQuery.getCandidateGroups().size());
}
use of org.camunda.bpm.engine.impl.TaskQueryImpl in project camunda-bpm-platform by camunda.
the class TaskQueryOrTest method shouldReturnTasksByExtendingQuery_OrInBothExtendedAndExtendingQuery.
@Test
public void shouldReturnTasksByExtendingQuery_OrInBothExtendedAndExtendingQuery() {
// given
TaskQuery extendedQuery = taskService.createTaskQuery().or().taskName("aTaskName").endOr().or().taskNameLike("anotherTaskName").endOr();
TaskQuery extendingQuery = taskService.createTaskQuery().or().taskCandidateGroup("aCandidateGroup").endOr().or().taskCandidateUser("aCandidateUser").endOr();
// when
TaskQueryImpl result = (TaskQueryImpl) ((TaskQueryImpl) extendedQuery).extend(extendingQuery);
// then
assertEquals("aTaskName", result.getQueries().get(1).getName());
assertEquals("anotherTaskName", result.getQueries().get(2).getNameLike());
assertEquals("aCandidateGroup", result.getQueries().get(3).getCandidateGroup());
assertEquals("aCandidateUser", result.getQueries().get(4).getCandidateUser());
}
use of org.camunda.bpm.engine.impl.TaskQueryImpl in project camunda-bpm-platform by camunda.
the class TaskQueryOrTest method shouldReturnTasksByExtendingQuery_OrInExtendedQuery.
@Test
public void shouldReturnTasksByExtendingQuery_OrInExtendedQuery() {
// given
TaskQuery extendedQuery = taskService.createTaskQuery().or().taskName("aTaskName").endOr().or().taskNameLike("anotherTaskName").endOr();
TaskQuery extendingQuery = taskService.createTaskQuery().taskCandidateGroup("aCandidateGroup");
// when
TaskQueryImpl result = (TaskQueryImpl) ((TaskQueryImpl) extendedQuery).extend(extendingQuery);
// then
assertEquals("aTaskName", result.getQueries().get(1).getName());
assertEquals("anotherTaskName", result.getQueries().get(2).getNameLike());
assertEquals("aCandidateGroup", result.getCandidateGroup());
}
use of org.camunda.bpm.engine.impl.TaskQueryImpl in project camunda-bpm-platform by camunda.
the class JsonTaskQueryConverter method toJsonObject.
public JSONObject toJsonObject(TaskQuery taskQuery, boolean isOrQueryActive) {
JSONObject json = new JSONObject();
TaskQueryImpl query = (TaskQueryImpl) taskQuery;
addField(json, TASK_ID, query.getTaskId());
addField(json, NAME, query.getName());
addField(json, NAME_NOT_EQUAL, query.getNameNotEqual());
addField(json, NAME_LIKE, query.getNameLike());
addField(json, NAME_NOT_LIKE, query.getNameNotLike());
addField(json, DESCRIPTION, query.getDescription());
addField(json, DESCRIPTION_LIKE, query.getDescriptionLike());
addField(json, PRIORITY, query.getPriority());
addField(json, MIN_PRIORITY, query.getMinPriority());
addField(json, MAX_PRIORITY, query.getMaxPriority());
addField(json, ASSIGNEE, query.getAssignee());
addField(json, ASSIGNEE_LIKE, query.getAssigneeLike());
addField(json, INVOLVED_USER, query.getInvolvedUser());
addField(json, OWNER, query.getOwner());
addDefaultField(json, UNASSIGNED, false, query.isUnassigned());
addDefaultField(json, ASSIGNED, false, query.isAssigned());
addField(json, DELEGATION_STATE, query.getDelegationStateString());
addField(json, CANDIDATE_USER, query.getCandidateUser());
addField(json, CANDIDATE_GROUP, query.getCandidateGroup());
addListField(json, CANDIDATE_GROUPS, query.getCandidateGroupsInternal());
addDefaultField(json, WITH_CANDIDATE_GROUPS, false, query.isWithCandidateGroups());
addDefaultField(json, WITHOUT_CANDIDATE_GROUPS, false, query.isWithoutCandidateGroups());
addDefaultField(json, WITH_CANDIDATE_USERS, false, query.isWithCandidateUsers());
addDefaultField(json, WITHOUT_CANDIDATE_USERS, false, query.isWithoutCandidateUsers());
addField(json, INCLUDE_ASSIGNED_TASKS, query.isIncludeAssignedTasksInternal());
addField(json, PROCESS_INSTANCE_ID, query.getProcessInstanceId());
addField(json, EXECUTION_ID, query.getExecutionId());
addArrayField(json, ACTIVITY_INSTANCE_ID_IN, query.getActivityInstanceIdIn());
addDateField(json, CREATED, query.getCreateTime());
addDateField(json, CREATED_BEFORE, query.getCreateTimeBefore());
addDateField(json, CREATED_AFTER, query.getCreateTimeAfter());
addField(json, KEY, query.getKey());
addArrayField(json, KEYS, query.getKeys());
addField(json, KEY_LIKE, query.getKeyLike());
addField(json, PARENT_TASK_ID, query.getParentTaskId());
addField(json, PROCESS_DEFINITION_KEY, query.getProcessDefinitionKey());
addArrayField(json, PROCESS_DEFINITION_KEYS, query.getProcessDefinitionKeys());
addField(json, PROCESS_DEFINITION_ID, query.getProcessDefinitionId());
addField(json, PROCESS_DEFINITION_NAME, query.getProcessDefinitionName());
addField(json, PROCESS_DEFINITION_NAME_LIKE, query.getProcessDefinitionNameLike());
addField(json, PROCESS_INSTANCE_BUSINESS_KEY, query.getProcessInstanceBusinessKey());
addArrayField(json, PROCESS_INSTANCE_BUSINESS_KEYS, query.getProcessInstanceBusinessKeys());
addField(json, PROCESS_INSTANCE_BUSINESS_KEY_LIKE, query.getProcessInstanceBusinessKeyLike());
addVariablesFields(json, query.getVariables());
addDateField(json, DUE, query.getDueDate());
addDateField(json, DUE_BEFORE, query.getDueBefore());
addDateField(json, DUE_AFTER, query.getDueAfter());
addDateField(json, FOLLOW_UP, query.getFollowUpDate());
addDateField(json, FOLLOW_UP_BEFORE, query.getFollowUpBefore());
addDefaultField(json, FOLLOW_UP_NULL_ACCEPTED, false, query.isFollowUpNullAccepted());
addDateField(json, FOLLOW_UP_AFTER, query.getFollowUpAfter());
addDefaultField(json, EXCLUDE_SUBTASKS, false, query.isExcludeSubtasks());
addSuspensionStateField(json, query.getSuspensionState());
addField(json, CASE_DEFINITION_KEY, query.getCaseDefinitionKey());
addField(json, CASE_DEFINITION_ID, query.getCaseDefinitionId());
addField(json, CASE_DEFINITION_NAME, query.getCaseDefinitionName());
addField(json, CASE_DEFINITION_NAME_LIKE, query.getCaseDefinitionNameLike());
addField(json, CASE_INSTANCE_ID, query.getCaseInstanceId());
addField(json, CASE_INSTANCE_BUSINESS_KEY, query.getCaseInstanceBusinessKey());
addField(json, CASE_INSTANCE_BUSINESS_KEY_LIKE, query.getCaseInstanceBusinessKeyLike());
addField(json, CASE_EXECUTION_ID, query.getCaseExecutionId());
addTenantIdFields(json, query);
if (query.getQueries().size() > 1 && !isOrQueryActive) {
JSONArray orQueries = new JSONArray();
for (TaskQueryImpl orQuery : query.getQueries()) {
if (orQuery != null && orQuery.isOrQueryActive()) {
orQueries.put(toJsonObject(orQuery, true));
}
}
addField(json, OR_QUERIES, orQueries);
}
if (query.getOrderingProperties() != null && !query.getOrderingProperties().isEmpty()) {
addField(json, ORDERING_PROPERTIES, JsonQueryOrderingPropertyConverter.ARRAY_CONVERTER.toJsonArray(query.getOrderingProperties()));
}
// expressions
for (Map.Entry<String, String> expressionEntry : query.getExpressions().entrySet()) {
json.put(expressionEntry.getKey() + "Expression", expressionEntry.getValue());
}
return json;
}
use of org.camunda.bpm.engine.impl.TaskQueryImpl in project camunda-bpm-platform by camunda.
the class FilterRestServiceInteractionTest method testGetFilterWithVariableValueTypeSorting.
@Test
public void testGetFilterWithVariableValueTypeSorting() {
TaskQuery query = new TaskQueryImpl().orderByExecutionVariable("foo", ValueType.STRING).asc().orderByExecutionVariable("foo", ValueType.INTEGER).asc().orderByExecutionVariable("foo", ValueType.SHORT).asc().orderByExecutionVariable("foo", ValueType.DATE).asc().orderByExecutionVariable("foo", ValueType.BOOLEAN).asc().orderByExecutionVariable("foo", ValueType.LONG).asc().orderByExecutionVariable("foo", ValueType.DOUBLE).asc();
Filter filter = new FilterEntity("Task").setName("test").setQuery(query);
when(filterServiceMock.getFilter(EXAMPLE_FILTER_ID)).thenReturn(filter);
Response response = given().pathParam("id", EXAMPLE_FILTER_ID).then().expect().statusCode(Status.OK.getStatusCode()).when().get(SINGLE_FILTER_URL);
// validate sorting content
String content = response.asString();
List<Map<String, Object>> sortings = from(content).getJsonObject("query.sorting");
assertThat(sortings).hasSize(7);
assertSorting(sortings.get(0), SORT_BY_EXECUTION_VARIABLE, SORT_ORDER_ASC_VALUE, "foo", ValueType.STRING);
assertSorting(sortings.get(1), SORT_BY_EXECUTION_VARIABLE, SORT_ORDER_ASC_VALUE, "foo", ValueType.INTEGER);
assertSorting(sortings.get(2), SORT_BY_EXECUTION_VARIABLE, SORT_ORDER_ASC_VALUE, "foo", ValueType.SHORT);
assertSorting(sortings.get(3), SORT_BY_EXECUTION_VARIABLE, SORT_ORDER_ASC_VALUE, "foo", ValueType.DATE);
assertSorting(sortings.get(4), SORT_BY_EXECUTION_VARIABLE, SORT_ORDER_ASC_VALUE, "foo", ValueType.BOOLEAN);
assertSorting(sortings.get(5), SORT_BY_EXECUTION_VARIABLE, SORT_ORDER_ASC_VALUE, "foo", ValueType.LONG);
assertSorting(sortings.get(6), SORT_BY_EXECUTION_VARIABLE, SORT_ORDER_ASC_VALUE, "foo", ValueType.DOUBLE);
}
Aggregations