Search in sources :

Example 21 with TaskQueryImpl

use of org.camunda.bpm.engine.impl.TaskQueryImpl in project camunda-bpm-platform by camunda.

the class FilterTaskQueryTest method testTaskQueryByBusinessKeyExpression.

public void testTaskQueryByBusinessKeyExpression() {
    // given
    String aBusinessKey = "business key";
    Mocks.register("aBusinessKey", aBusinessKey);
    createDeploymentWithBusinessKey(aBusinessKey);
    // when
    TaskQueryImpl extendedQuery = (TaskQueryImpl) taskService.createTaskQuery().processInstanceBusinessKeyExpression("${ " + Mocks.getMocks().keySet().toArray()[0] + " }");
    Filter filter = filterService.newTaskFilter("aFilterName");
    filter.setQuery(extendedQuery);
    filterService.saveFilter(filter);
    TaskQueryImpl filterQuery = filterService.getFilter(filter.getId()).getQuery();
    // then
    assertEquals(extendedQuery.getExpressions().get("processInstanceBusinessKey"), filterQuery.getExpressions().get("processInstanceBusinessKey"));
    assertEquals(1, filterService.list(filter.getId()).size());
}
Also used : TaskQueryImpl(org.camunda.bpm.engine.impl.TaskQueryImpl) Filter(org.camunda.bpm.engine.filter.Filter)

Example 22 with TaskQueryImpl

use of org.camunda.bpm.engine.impl.TaskQueryImpl in project camunda-bpm-platform by camunda.

the class FilterTaskQueryTest method testTaskQueryByBusinessKeyExpressionInAdhocQuery.

public void testTaskQueryByBusinessKeyExpressionInAdhocQuery() {
    // given
    processEngineConfiguration.setEnableExpressionsInAdhocQueries(true);
    String aBusinessKey = "business key";
    Mocks.register("aBusinessKey", aBusinessKey);
    createDeploymentWithBusinessKey(aBusinessKey);
    // when
    Filter filter = filterService.newTaskFilter("aFilterName");
    filter.setQuery(taskService.createTaskQuery());
    filterService.saveFilter(filter);
    TaskQueryImpl extendingQuery = (TaskQueryImpl) taskService.createTaskQuery().processInstanceBusinessKeyExpression("${ " + Mocks.getMocks().keySet().toArray()[0] + " }");
    // then
    assertEquals(extendingQuery.getExpressions().get("processInstanceBusinessKey"), "${ " + Mocks.getMocks().keySet().toArray()[0] + " }");
    assertEquals(1, filterService.list(filter.getId(), extendingQuery).size());
}
Also used : Filter(org.camunda.bpm.engine.filter.Filter) TaskQueryImpl(org.camunda.bpm.engine.impl.TaskQueryImpl)

Example 23 with TaskQueryImpl

use of org.camunda.bpm.engine.impl.TaskQueryImpl in project camunda-bpm-platform by camunda.

the class FilterTaskQueryTest method testTaskQueryCandidateUser.

public void testTaskQueryCandidateUser() {
    TaskQueryImpl query = new TaskQueryImpl();
    query.taskCandidateUser(testUser.getId());
    query.taskCandidateUserExpression(testUser.getId());
    filter.setQuery(query);
    query = filter.getQuery();
    assertEquals(testUser.getId(), query.getCandidateUser());
    assertEquals(testUser.getId(), query.getExpressions().get("taskCandidateUser"));
}
Also used : TaskQueryImpl(org.camunda.bpm.engine.impl.TaskQueryImpl)

Example 24 with TaskQueryImpl

use of org.camunda.bpm.engine.impl.TaskQueryImpl in project camunda-bpm-platform by camunda.

the class JsonTaskQueryConverter method toObject.

@Override
public TaskQuery toObject(JSONObject json) {
    TaskQueryImpl query = new TaskQueryImpl();
    if (json.has(OR_QUERIES)) {
        for (int i = 0; i < json.getJSONArray(OR_QUERIES).length(); i++) {
            query.addOrQuery((TaskQueryImpl) toObject(json.getJSONArray(OR_QUERIES).getJSONObject(i)));
        }
    }
    if (json.has(TASK_ID)) {
        query.taskId(json.getString(TASK_ID));
    }
    if (json.has(NAME)) {
        query.taskName(json.getString(NAME));
    }
    if (json.has(NAME_NOT_EQUAL)) {
        query.taskNameNotEqual(json.getString(NAME_NOT_EQUAL));
    }
    if (json.has(NAME_LIKE)) {
        query.taskNameLike(json.getString(NAME_LIKE));
    }
    if (json.has(NAME_NOT_LIKE)) {
        query.taskNameNotLike(json.getString(NAME_NOT_LIKE));
    }
    if (json.has(DESCRIPTION)) {
        query.taskDescription(json.getString(DESCRIPTION));
    }
    if (json.has(DESCRIPTION_LIKE)) {
        query.taskDescriptionLike(json.getString(DESCRIPTION_LIKE));
    }
    if (json.has(PRIORITY)) {
        query.taskPriority(json.getInt(PRIORITY));
    }
    if (json.has(MIN_PRIORITY)) {
        query.taskMinPriority(json.getInt(MIN_PRIORITY));
    }
    if (json.has(MAX_PRIORITY)) {
        query.taskMaxPriority(json.getInt(MAX_PRIORITY));
    }
    if (json.has(ASSIGNEE)) {
        query.taskAssignee(json.getString(ASSIGNEE));
    }
    if (json.has(ASSIGNEE_LIKE)) {
        query.taskAssigneeLike(json.getString(ASSIGNEE_LIKE));
    }
    if (json.has(INVOLVED_USER)) {
        query.taskInvolvedUser(json.getString(INVOLVED_USER));
    }
    if (json.has(OWNER)) {
        query.taskOwner(json.getString(OWNER));
    }
    if (json.has(ASSIGNED) && json.getBoolean(ASSIGNED)) {
        query.taskAssigned();
    }
    if (json.has(UNASSIGNED) && json.getBoolean(UNASSIGNED)) {
        query.taskUnassigned();
    }
    if (json.has(DELEGATION_STATE)) {
        query.taskDelegationState(DelegationState.valueOf(json.getString(DELEGATION_STATE)));
    }
    if (json.has(CANDIDATE_USER)) {
        query.taskCandidateUser(json.getString(CANDIDATE_USER));
    }
    if (json.has(CANDIDATE_GROUP)) {
        query.taskCandidateGroup(json.getString(CANDIDATE_GROUP));
    }
    if (json.has(CANDIDATE_GROUPS) && !json.has(CANDIDATE_USER) && !json.has(CANDIDATE_GROUP)) {
        query.taskCandidateGroupIn(getList(json.getJSONArray(CANDIDATE_GROUPS)));
    }
    if (json.has(WITH_CANDIDATE_GROUPS) && json.getBoolean(WITH_CANDIDATE_GROUPS)) {
        query.withCandidateGroups();
    }
    if (json.has(WITHOUT_CANDIDATE_GROUPS) && json.getBoolean(WITHOUT_CANDIDATE_GROUPS)) {
        query.withoutCandidateGroups();
    }
    if (json.has(WITH_CANDIDATE_USERS) && json.getBoolean(WITH_CANDIDATE_USERS)) {
        query.withCandidateUsers();
    }
    if (json.has(WITHOUT_CANDIDATE_USERS) && json.getBoolean(WITHOUT_CANDIDATE_USERS)) {
        query.withoutCandidateUsers();
    }
    if (json.has(INCLUDE_ASSIGNED_TASKS) && json.getBoolean(INCLUDE_ASSIGNED_TASKS)) {
        query.includeAssignedTasksInternal();
    }
    if (json.has(PROCESS_INSTANCE_ID)) {
        query.processInstanceId(json.getString(PROCESS_INSTANCE_ID));
    }
    if (json.has(EXECUTION_ID)) {
        query.executionId(json.getString(EXECUTION_ID));
    }
    if (json.has(ACTIVITY_INSTANCE_ID_IN)) {
        query.activityInstanceIdIn(getArray(json.getJSONArray(ACTIVITY_INSTANCE_ID_IN)));
    }
    if (json.has(CREATED)) {
        query.taskCreatedOn(new Date(json.getLong(CREATED)));
    }
    if (json.has(CREATED_BEFORE)) {
        query.taskCreatedBefore(new Date(json.getLong(CREATED_BEFORE)));
    }
    if (json.has(CREATED_AFTER)) {
        query.taskCreatedAfter(new Date(json.getLong(CREATED_AFTER)));
    }
    if (json.has(KEY)) {
        query.taskDefinitionKey(json.getString(KEY));
    }
    if (json.has(KEYS)) {
        query.taskDefinitionKeyIn(getArray(json.getJSONArray(KEYS)));
    }
    if (json.has(KEY_LIKE)) {
        query.taskDefinitionKeyLike(json.getString(KEY_LIKE));
    }
    if (json.has(PARENT_TASK_ID)) {
        query.taskParentTaskId(json.getString(PARENT_TASK_ID));
    }
    if (json.has(PROCESS_DEFINITION_KEY)) {
        query.processDefinitionKey(json.getString(PROCESS_DEFINITION_KEY));
    }
    if (json.has(PROCESS_DEFINITION_KEYS)) {
        query.processDefinitionKeyIn(getArray(json.getJSONArray(PROCESS_DEFINITION_KEYS)));
    }
    if (json.has(PROCESS_DEFINITION_ID)) {
        query.processDefinitionId(json.getString(PROCESS_DEFINITION_ID));
    }
    if (json.has(PROCESS_DEFINITION_NAME)) {
        query.processDefinitionName(json.getString(PROCESS_DEFINITION_NAME));
    }
    if (json.has(PROCESS_DEFINITION_NAME_LIKE)) {
        query.processDefinitionNameLike(json.getString(PROCESS_DEFINITION_NAME_LIKE));
    }
    if (json.has(PROCESS_INSTANCE_BUSINESS_KEY)) {
        query.processInstanceBusinessKey(json.getString(PROCESS_INSTANCE_BUSINESS_KEY));
    }
    if (json.has(PROCESS_INSTANCE_BUSINESS_KEYS)) {
        query.processInstanceBusinessKeyIn(getArray(json.getJSONArray(PROCESS_INSTANCE_BUSINESS_KEYS)));
    }
    if (json.has(PROCESS_INSTANCE_BUSINESS_KEY_LIKE)) {
        query.processInstanceBusinessKeyLike(json.getString(PROCESS_INSTANCE_BUSINESS_KEY_LIKE));
    }
    if (json.has(TASK_VARIABLES)) {
        addVariables(query, json.getJSONArray(TASK_VARIABLES), true, false);
    }
    if (json.has(PROCESS_VARIABLES)) {
        addVariables(query, json.getJSONArray(PROCESS_VARIABLES), false, true);
    }
    if (json.has(CASE_INSTANCE_VARIABLES)) {
        addVariables(query, json.getJSONArray(CASE_INSTANCE_VARIABLES), false, false);
    }
    if (json.has(DUE)) {
        query.dueDate(new Date(json.getLong(DUE)));
    }
    if (json.has(DUE_BEFORE)) {
        query.dueBefore(new Date(json.getLong(DUE_BEFORE)));
    }
    if (json.has(DUE_AFTER)) {
        query.dueAfter(new Date(json.getLong(DUE_AFTER)));
    }
    if (json.has(FOLLOW_UP)) {
        query.followUpDate(new Date(json.getLong(FOLLOW_UP)));
    }
    if (json.has(FOLLOW_UP_BEFORE)) {
        query.followUpBefore(new Date(json.getLong(FOLLOW_UP_BEFORE)));
    }
    if (json.has(FOLLOW_UP_AFTER)) {
        query.followUpAfter(new Date(json.getLong(FOLLOW_UP_AFTER)));
    }
    if (json.has(FOLLOW_UP_NULL_ACCEPTED)) {
        query.setFollowUpNullAccepted(json.getBoolean(FOLLOW_UP_NULL_ACCEPTED));
    }
    if (json.has(EXCLUDE_SUBTASKS) && json.getBoolean(EXCLUDE_SUBTASKS)) {
        query.excludeSubtasks();
    }
    if (json.has(SUSPENDED) && json.getBoolean(SUSPENDED)) {
        query.suspended();
    }
    if (json.has(ACTIVE) && json.getBoolean(ACTIVE)) {
        query.active();
    }
    if (json.has(CASE_DEFINITION_KEY)) {
        query.caseDefinitionKey(json.getString(CASE_DEFINITION_KEY));
    }
    if (json.has(CASE_DEFINITION_ID)) {
        query.caseDefinitionId(json.getString(CASE_DEFINITION_ID));
    }
    if (json.has(CASE_DEFINITION_NAME)) {
        query.caseDefinitionName(json.getString(CASE_DEFINITION_NAME));
    }
    if (json.has(CASE_DEFINITION_NAME_LIKE)) {
        query.caseDefinitionNameLike(json.getString(CASE_DEFINITION_NAME_LIKE));
    }
    if (json.has(CASE_INSTANCE_ID)) {
        query.caseInstanceId(json.getString(CASE_INSTANCE_ID));
    }
    if (json.has(CASE_INSTANCE_BUSINESS_KEY)) {
        query.caseInstanceBusinessKey(json.getString(CASE_INSTANCE_BUSINESS_KEY));
    }
    if (json.has(CASE_INSTANCE_BUSINESS_KEY_LIKE)) {
        query.caseInstanceBusinessKeyLike(json.getString(CASE_INSTANCE_BUSINESS_KEY_LIKE));
    }
    if (json.has(CASE_EXECUTION_ID)) {
        query.caseExecutionId(json.getString(CASE_EXECUTION_ID));
    }
    if (json.has(TENANT_IDS)) {
        query.tenantIdIn(getArray(json.getJSONArray(TENANT_IDS)));
    }
    if (json.has(WITHOUT_TENANT_ID)) {
        query.withoutTenantId();
    }
    if (json.has(ORDER_BY)) {
        List<QueryOrderingProperty> orderingProperties = JsonLegacyQueryOrderingPropertyConverter.INSTANCE.fromOrderByString(json.getString(ORDER_BY));
        query.setOrderingProperties(orderingProperties);
    }
    if (json.has(ORDERING_PROPERTIES)) {
        JSONArray jsonArray = json.getJSONArray(ORDERING_PROPERTIES);
        query.setOrderingProperties(JsonQueryOrderingPropertyConverter.ARRAY_CONVERTER.toObject(jsonArray));
    }
    // expressions
    Iterator jsonIterator = json.keys();
    while (jsonIterator.hasNext()) {
        String key = (String) jsonIterator.next();
        if (key.endsWith("Expression")) {
            String expression = json.getString(key);
            query.addExpression(key.substring(0, key.length() - "Expression".length()), expression);
        }
    }
    return query;
}
Also used : TaskQueryImpl(org.camunda.bpm.engine.impl.TaskQueryImpl) JSONArray(org.camunda.bpm.engine.impl.util.json.JSONArray) Iterator(java.util.Iterator) QueryOrderingProperty(org.camunda.bpm.engine.impl.QueryOrderingProperty) Date(java.util.Date)

Example 25 with TaskQueryImpl

use of org.camunda.bpm.engine.impl.TaskQueryImpl in project camunda-bpm-platform by camunda.

the class TaskQueryExpressionTest method testExpressionOverrideQuery.

public void testExpressionOverrideQuery() {
    String queryString = "query";
    String expressionString = "expression";
    String testStringExpression = "${'" + expressionString + "'}";
    Date queryDate = new DateTime(now()).minusYears(1).toDate();
    String testDateExpression = "${now()}";
    TaskQueryImpl taskQuery = (TaskQueryImpl) taskQuery().taskAssignee(queryString).taskAssigneeExpression(testStringExpression).taskAssigneeLike(queryString).taskAssigneeLikeExpression(testStringExpression).taskOwnerExpression(queryString).taskOwnerExpression(expressionString).taskInvolvedUser(queryString).taskInvolvedUserExpression(expressionString).taskCreatedBefore(queryDate).taskCreatedBeforeExpression(testDateExpression).taskCreatedOn(queryDate).taskCreatedOnExpression(testDateExpression).taskCreatedAfter(queryDate).taskCreatedAfterExpression(testDateExpression).dueBefore(queryDate).dueBeforeExpression(testDateExpression).dueDate(queryDate).dueDateExpression(testDateExpression).dueAfter(queryDate).dueAfterExpression(testDateExpression).followUpBefore(queryDate).followUpBeforeExpression(testDateExpression).followUpDate(queryDate).followUpDateExpression(testDateExpression).followUpAfter(queryDate).followUpAfterExpression(testDateExpression);
    // execute query so expression will be evaluated
    taskQuery.count();
    assertEquals(expressionString, taskQuery.getAssignee());
    assertEquals(expressionString, taskQuery.getAssigneeLike());
    assertEquals(expressionString, taskQuery.getOwner());
    assertEquals(expressionString, taskQuery.getInvolvedUser());
    assertTrue(taskQuery.getCreateTimeBefore().after(queryDate));
    assertTrue(taskQuery.getCreateTime().after(queryDate));
    assertTrue(taskQuery.getCreateTimeAfter().after(queryDate));
    assertTrue(taskQuery.getDueBefore().after(queryDate));
    assertTrue(taskQuery.getDueDate().after(queryDate));
    assertTrue(taskQuery.getDueAfter().after(queryDate));
    assertTrue(taskQuery.getFollowUpBefore().after(queryDate));
    assertTrue(taskQuery.getFollowUpDate().after(queryDate));
    assertTrue(taskQuery.getFollowUpAfter().after(queryDate));
    // candidates has to be tested separately cause they have to be set exclusively
    taskQuery = (TaskQueryImpl) taskQuery().taskCandidateGroup(queryString).taskCandidateGroupExpression(testStringExpression);
    // execute query so expression will be evaluated
    taskQuery.count();
    assertEquals(expressionString, taskQuery.getCandidateGroup());
    taskQuery = (TaskQueryImpl) taskQuery().taskCandidateUser(queryString).taskCandidateUserExpression(testStringExpression);
    // execute query so expression will be evaluated
    taskQuery.count();
    assertEquals(expressionString, taskQuery.getCandidateUser());
    setCurrentUser(user);
    List<String> queryList = Arrays.asList("query");
    String testGroupsExpression = "${currentUserGroups()}";
    taskQuery = (TaskQueryImpl) taskQuery().taskCandidateGroupIn(queryList).taskCandidateGroupInExpression(testGroupsExpression);
    // execute query so expression will be evaluated
    taskQuery.count();
    assertEquals(2, taskQuery.getCandidateGroups().size());
}
Also used : TaskQueryImpl(org.camunda.bpm.engine.impl.TaskQueryImpl) Date(java.util.Date) DateTime(org.joda.time.DateTime)

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