Search in sources :

Example 11 with TasksClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.

the class TaskWorkflowApiTest method testSetOutcome.

@Test
@SuppressWarnings("unchecked")
public void testSetOutcome() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    ProcessInfo processInf = startReviewPooledProcess(requestContext);
    Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInf.getId()).singleResult();
    TasksClient tasksClient = publicApiClient.tasksClient();
    activitiProcessEngine.getTaskService().saveTask(task);
    Map<String, String> params = new HashMap<String, String>();
    params.put("select", "state,variables");
    HttpResponse response = tasksClient.update("tasks", task.getId(), null, null, "{\"state\":\"completed\",\"variables\":[{\"name\":\"wf_reviewOutcome\",\"value\":\"Approve\",\"scope\":\"local\"},{\"name\":\"bpm_comment\",\"value\":\"approved by me\",\"scope\":\"local\"}]}", params, "Failed to update task", 200);
    HistoricTaskInstance historyTask = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery().taskId(task.getId()).includeProcessVariables().includeTaskLocalVariables().singleResult();
    String outcome = (String) historyTask.getTaskLocalVariables().get("bpm_outcome");
    assertEquals("Approve", outcome);
}
Also used : Task(org.activiti.engine.task.Task) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HashMap(java.util.HashMap) TasksClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Example 12 with TasksClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.

the class TaskWorkflowApiTest method testDeleteTaskVariable.

@Test
public void testDeleteTaskVariable() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    ProcessInstance processInstance = startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null);
    activitiProcessEngine.getRuntimeService().setVariable(processInstance.getId(), "overlappingVariable", "Value set in process");
    try {
        Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        assertNotNull(task);
        activitiProcessEngine.getTaskService().setVariableLocal(task.getId(), "myVariable", "This is a variable");
        activitiProcessEngine.getTaskService().setVariableLocal(task.getId(), "overlappingVariable", "Value set in task");
        // Delete a task-variable
        TasksClient tasksClient = publicApiClient.tasksClient();
        tasksClient.deleteTaskVariable(task.getId(), "myVariable");
        assertFalse(activitiProcessEngine.getTaskService().hasVariableLocal(task.getId(), "myVariable"));
        // Delete a task-variable that has the same name as a global process-variable - which should remain untouched after delete
        tasksClient.deleteTaskVariable(task.getId(), "overlappingVariable");
        assertFalse(activitiProcessEngine.getTaskService().hasVariableLocal(task.getId(), "overlappingVariable"));
        assertTrue(activitiProcessEngine.getRuntimeService().hasVariable(processInstance.getId(), "overlappingVariable"));
        assertEquals("Value set in process", activitiProcessEngine.getRuntimeService().getVariable(processInstance.getId(), "overlappingVariable"));
    } finally {
        cleanupProcessInstance(processInstance);
    }
}
Also used : Task(org.activiti.engine.task.Task) TasksClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 13 with TasksClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.

the class TaskWorkflowApiTest method testGetTasksWithSorting.

@Test
public void testGetTasksWithSorting() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    // Start 6 processes
    List<ProcessInstance> startedProcesses = new ArrayList<ProcessInstance>();
    try {
        int numberOfTasks = 6;
        for (int i = 0; i < numberOfTasks; i++) {
            startedProcesses.add(startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null));
        }
        List<Task> taskList = new ArrayList<Task>();
        for (int i = 0; i < numberOfTasks; i++) {
            Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(startedProcesses.get(i).getProcessInstanceId()).singleResult();
            activitiProcessEngine.getTaskService().setPriority(task.getId(), (i + 1) * 10);
            taskList.add(task);
        }
        // set last task priority to 1
        activitiProcessEngine.getTaskService().setPriority(taskList.get(numberOfTasks - 1).getId(), 1);
        TasksClient tasksClient = publicApiClient.tasksClient();
        // Test with existing processDefinitionId
        Map<String, String> params = new HashMap<String, String>();
        params.put("where", "(processDefinitionId = '" + startedProcesses.get(0).getProcessDefinitionId() + "')");
        params.put("orderBy", "priority ASC");
        JSONObject tasksResponseJSON = tasksClient.findTasks(params);
        JSONObject paginationJSON = (JSONObject) tasksResponseJSON.get("pagination");
        assertEquals(6l, paginationJSON.get("count"));
        assertEquals(6l, paginationJSON.get("totalItems"));
        JSONArray tasksListJSON = (JSONArray) tasksResponseJSON.get("entries");
        assertEquals(6, tasksListJSON.size());
        JSONObject taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(0)).get("entry");
        assertEquals(taskList.get(numberOfTasks - 1).getId(), taskJSON.get("id"));
        taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(1)).get("entry");
        assertEquals(taskList.get(0).getId(), taskJSON.get("id"));
        taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(2)).get("entry");
        assertEquals(taskList.get(1).getId(), taskJSON.get("id"));
        taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(3)).get("entry");
        assertEquals(taskList.get(2).getId(), taskJSON.get("id"));
        taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(4)).get("entry");
        assertEquals(taskList.get(3).getId(), taskJSON.get("id"));
        taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(5)).get("entry");
        assertEquals(taskList.get(4).getId(), taskJSON.get("id"));
        params.put("orderBy", "priority DESC");
        tasksResponseJSON = tasksClient.findTasks(params);
        paginationJSON = (JSONObject) tasksResponseJSON.get("pagination");
        assertEquals(6l, paginationJSON.get("count"));
        assertEquals(6l, paginationJSON.get("totalItems"));
        tasksListJSON = (JSONArray) tasksResponseJSON.get("entries");
        assertEquals(6, tasksListJSON.size());
        taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(0)).get("entry");
        assertEquals(taskList.get(4).getId(), taskJSON.get("id"));
        taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(1)).get("entry");
        assertEquals(taskList.get(3).getId(), taskJSON.get("id"));
        taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(2)).get("entry");
        assertEquals(taskList.get(2).getId(), taskJSON.get("id"));
        taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(3)).get("entry");
        assertEquals(taskList.get(1).getId(), taskJSON.get("id"));
        taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(4)).get("entry");
        assertEquals(taskList.get(0).getId(), taskJSON.get("id"));
        taskJSON = (JSONObject) ((JSONObject) tasksListJSON.get(5)).get("entry");
        assertEquals(taskList.get(numberOfTasks - 1).getId(), taskJSON.get("id"));
        params.put("orderBy", "dueAt DESC");
        tasksResponseJSON = tasksClient.findTasks(params);
        tasksListJSON = (JSONArray) tasksResponseJSON.get("entries");
        assertEquals(6, tasksListJSON.size());
    } finally {
        cleanupProcessInstance(startedProcesses.toArray(new ProcessInstance[] {}));
    }
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) TasksClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 14 with TasksClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.

the class TaskWorkflowApiTest method testChangeDueDate.

@Test
@SuppressWarnings("unchecked")
public void testChangeDueDate() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    ProcessInstance processInstance = startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null);
    try {
        Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        TasksClient tasksClient = publicApiClient.tasksClient();
        JSONObject taskObject = tasksClient.findTaskById(task.getId());
        assertNull(taskObject.get("dueAt"));
        List<String> selectedFields = new ArrayList<String>();
        selectedFields.addAll(Arrays.asList(new String[] { "name", "description", "dueAt", "priority", "assignee", "owner" }));
        // set due date
        JSONObject taskBody = new JSONObject();
        String dueAt = formatDate(new Date());
        taskBody.put("dueAt", dueAt);
        JSONObject result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
        assertNotNull(result.get("dueAt"));
        taskObject = tasksClient.findTaskById(task.getId());
        assertNotNull(taskObject.get("dueAt"));
        taskBody = new JSONObject();
        taskBody.put("dueAt", taskObject.get("dueAt"));
        result = tasksClient.updateTask(task.getId(), taskBody, selectedFields);
        assertNotNull(result.get("dueAt"));
        taskObject = tasksClient.findTaskById(task.getId());
        assertNotNull(taskObject.get("dueAt"));
        JSONObject variableBody = new JSONObject();
        variableBody.put("name", "bpm_workflowDueDate");
        variableBody.put("value", formatDate(new Date()));
        variableBody.put("type", "d:date");
        variableBody.put("scope", "global");
        tasksClient.updateTaskVariable(task.getId(), "bpm_workflowDueDate", variableBody);
    } finally {
        cleanupProcessInstance(processInstance);
    }
}
Also used : Task(org.activiti.engine.task.Task) JSONObject(org.json.simple.JSONObject) TasksClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient) ArrayList(java.util.ArrayList) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Date(java.util.Date) Test(org.junit.Test)

Example 15 with TasksClient

use of org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient in project alfresco-remote-api by Alfresco.

the class TaskWorkflowApiTest method testGetTasksWithPaging.

@Test
public void testGetTasksWithPaging() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    // Start 6 processes
    List<ProcessInstance> startedProcesses = new ArrayList<ProcessInstance>();
    try {
        int numberOfTasks = 6;
        for (int i = 0; i < numberOfTasks; i++) {
            startedProcesses.add(startAdhocProcess(requestContext.getRunAsUser(), requestContext.getNetworkId(), null));
        }
        String processDefinitionId = startedProcesses.get(0).getProcessDefinitionId();
        TasksClient tasksClient = publicApiClient.tasksClient();
        // Test with existing processDefinitionId
        Map<String, String> params = new HashMap<String, String>();
        params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
        JSONObject taskListJSONObject = tasksClient.findTasks(params);
        assertNotNull(taskListJSONObject);
        JSONObject paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
        assertEquals(6l, paginationJSON.get("count"));
        assertEquals(6l, paginationJSON.get("totalItems"));
        assertEquals(0l, paginationJSON.get("skipCount"));
        assertEquals(false, paginationJSON.get("hasMoreItems"));
        JSONArray jsonEntries = (JSONArray) taskListJSONObject.get("entries");
        assertEquals(6, jsonEntries.size());
        validateVariables((JSONObject) jsonEntries.get(0), requestContext);
        // Test with existing processDefinitionId and max items
        params.clear();
        params.put("maxItems", "3");
        params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
        taskListJSONObject = tasksClient.findTasks(params);
        assertNotNull(taskListJSONObject);
        paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
        assertEquals(3l, paginationJSON.get("count"));
        assertEquals(6l, paginationJSON.get("totalItems"));
        assertEquals(0l, paginationJSON.get("skipCount"));
        assertEquals(true, paginationJSON.get("hasMoreItems"));
        jsonEntries = (JSONArray) taskListJSONObject.get("entries");
        assertEquals(3, jsonEntries.size());
        validateVariables((JSONObject) jsonEntries.get(0), requestContext);
        // Test with existing processDefinitionId and skip count
        params.clear();
        params.put("skipCount", "2");
        params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
        taskListJSONObject = tasksClient.findTasks(params);
        assertNotNull(taskListJSONObject);
        paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
        assertEquals(4l, paginationJSON.get("count"));
        assertEquals(6l, paginationJSON.get("totalItems"));
        assertEquals(2l, paginationJSON.get("skipCount"));
        assertEquals(false, paginationJSON.get("hasMoreItems"));
        jsonEntries = (JSONArray) taskListJSONObject.get("entries");
        assertEquals(4, jsonEntries.size());
        // Test with existing processDefinitionId and max items and skip count
        params.clear();
        params.put("maxItems", "3");
        params.put("skipCount", "2");
        params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
        taskListJSONObject = tasksClient.findTasks(params);
        assertNotNull(taskListJSONObject);
        paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
        assertEquals(3l, paginationJSON.get("count"));
        assertEquals(6l, paginationJSON.get("totalItems"));
        assertEquals(2l, paginationJSON.get("skipCount"));
        assertEquals(true, paginationJSON.get("hasMoreItems"));
        jsonEntries = (JSONArray) taskListJSONObject.get("entries");
        assertEquals(3, jsonEntries.size());
        // Test with existing processDefinitionId and max items and skip count
        params.clear();
        params.put("maxItems", "3");
        params.put("skipCount", "4");
        params.put("where", "(processDefinitionId = '" + processDefinitionId + "' AND includeProcessVariables = true AND includeTaskVariables = true)");
        taskListJSONObject = tasksClient.findTasks(params);
        assertNotNull(taskListJSONObject);
        paginationJSON = (JSONObject) taskListJSONObject.get("pagination");
        assertEquals(2l, paginationJSON.get("count"));
        assertEquals(6l, paginationJSON.get("totalItems"));
        assertEquals(4l, paginationJSON.get("skipCount"));
        assertEquals(false, paginationJSON.get("hasMoreItems"));
        jsonEntries = (JSONArray) taskListJSONObject.get("entries");
        assertEquals(2, jsonEntries.size());
    } finally {
        cleanupProcessInstance(startedProcesses.toArray(new ProcessInstance[] {}));
    }
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) TasksClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Aggregations

TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)41 Test (org.junit.Test)41 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)39 Task (org.activiti.engine.task.Task)38 JSONObject (org.json.simple.JSONObject)36 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)32 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)22 ArrayList (java.util.ArrayList)17 JSONArray (org.json.simple.JSONArray)14 HashMap (java.util.HashMap)9 ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)8 Calendar (java.util.Calendar)5 Date (java.util.Date)5 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)5 MemberOfSite (org.alfresco.rest.api.tests.client.data.MemberOfSite)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)3 HashSet (java.util.HashSet)2 TaskService (org.activiti.engine.TaskService)2 Clock (org.activiti.engine.runtime.Clock)2