Search in sources :

Example 51 with TaskQueryImpl

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());
}
Also used : TaskQueryImpl(org.camunda.bpm.engine.impl.TaskQueryImpl) Date(java.util.Date) DateTime(org.joda.time.DateTime)

Example 52 with TaskQueryImpl

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());
}
Also used : TaskQueryImpl(org.camunda.bpm.engine.impl.TaskQueryImpl) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) Test(org.junit.Test)

Example 53 with TaskQueryImpl

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());
}
Also used : TaskQueryImpl(org.camunda.bpm.engine.impl.TaskQueryImpl) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) Test(org.junit.Test)

Example 54 with TaskQueryImpl

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;
}
Also used : JSONObject(org.camunda.bpm.engine.impl.util.json.JSONObject) TaskQueryImpl(org.camunda.bpm.engine.impl.TaskQueryImpl) JSONArray(org.camunda.bpm.engine.impl.util.json.JSONArray) Map(java.util.Map)

Example 55 with TaskQueryImpl

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);
}
Also used : Response(com.jayway.restassured.response.Response) TaskQueryImpl(org.camunda.bpm.engine.impl.TaskQueryImpl) Filter(org.camunda.bpm.engine.filter.Filter) MockProvider.mockFilter(org.camunda.bpm.engine.rest.helper.MockProvider.mockFilter) FilterEntity(org.camunda.bpm.engine.impl.persistence.entity.FilterEntity) TaskQuery(org.camunda.bpm.engine.task.TaskQuery) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.anyString(org.mockito.Matchers.anyString) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

TaskQueryImpl (org.camunda.bpm.engine.impl.TaskQueryImpl)60 Filter (org.camunda.bpm.engine.filter.Filter)26 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)25 Test (org.junit.Test)17 FilterEntity (org.camunda.bpm.engine.impl.persistence.entity.FilterEntity)12 MockProvider.mockFilter (org.camunda.bpm.engine.rest.helper.MockProvider.mockFilter)12 QueryOrderingProperty (org.camunda.bpm.engine.impl.QueryOrderingProperty)8 Map (java.util.Map)7 Response (com.jayway.restassured.response.Response)6 HashMap (java.util.HashMap)6 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)6 Matchers.anyString (org.mockito.Matchers.anyString)6 JSONObject (org.camunda.bpm.engine.impl.util.json.JSONObject)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Date (java.util.Date)3 TaskQueryVariableValue (org.camunda.bpm.engine.impl.TaskQueryVariableValue)3 JsonTaskQueryConverter (org.camunda.bpm.engine.impl.json.JsonTaskQueryConverter)3 ArrayList (java.util.ArrayList)2 JSONArray (org.camunda.bpm.engine.impl.util.json.JSONArray)2 VariableQueryParameterDto (org.camunda.bpm.engine.rest.dto.VariableQueryParameterDto)2