Search in sources :

Example 71 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class HistoricDetailCollectionResourceTest method testQueryDetail.

/**
   * Test querying historic detail. 
   * GET history/historic-detail
   */
@Deployment
public void testQueryDetail() throws Exception {
    HashMap<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("stringVar", "Azerty");
    processVariables.put("intVar", 67890);
    processVariables.put("booleanVar", false);
    processVariables.put("byteVar", "test".getBytes());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(task.getId());
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.setVariableLocal(task.getId(), "taskVariable", "test");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_DETAIL);
    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance.getId(), 5, "stringVar", "Azerty");
    assertResultsPresentInDataResponse(url + "?taskId=" + task.getId(), 1, "taskVariable", "test");
    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance2.getId(), 4, "intVar", 67890);
    assertResultsPresentInDataResponse(url + "?processInstanceId=" + processInstance2.getId() + "&selectOnlyVariableUpdates=true", 4, "booleanVar", false);
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url + "?processInstanceId=" + processInstance2.getId()), HttpStatus.SC_OK);
    // Check status and size
    JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
    closeResponse(response);
    boolean byteVarFound = false;
    Iterator<JsonNode> it = dataNode.iterator();
    while (it.hasNext()) {
        JsonNode variableNode = it.next().get("variable");
        String name = variableNode.get("name").textValue();
        if ("byteVar".equals(name)) {
            byteVarFound = true;
            String valueUrl = variableNode.get("valueUrl").textValue();
            response = executeRequest(new HttpGet(valueUrl), HttpStatus.SC_OK);
            byte[] varInput = IOUtils.toByteArray(response.getEntity().getContent());
            closeResponse(response);
            assertEquals("test", new String(varInput));
            break;
        }
    }
    assertTrue(byteVarFound);
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 72 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class JpaRestTest method testGetJpaVariableViaHistoricProcessCollection.

@Deployment(resources = { "org/activiti/rest/api/jpa/jpa-process.bpmn20.xml" })
public void testGetJpaVariableViaHistoricProcessCollection() throws Exception {
    // Get JPA managed entity through the repository
    Message message = messageRepository.findOne(1L);
    assertNotNull(message);
    assertEquals("Hello World", message.getText());
    // add the entity to the process variables and start the process
    Map<String, Object> processVariables = new HashMap<String, Object>();
    processVariables.put("message", message);
    ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("jpa-process", processVariables);
    assertNotNull(processInstance);
    Task task = processEngine.getTaskService().createTaskQuery().singleResult();
    assertEquals("Activiti is awesome!", task.getName());
    // Request all variables (no scope provides) which include global and local
    HttpResponse response = executeHttpRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCES) + "?processInstanceId=" + processInstance.getId() + "&includeProcessVariables=true"), HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    // check for message variable of type serializable
    assertNotNull(responseNode);
    JsonNode variablesArrayNode = responseNode.get("data").get(0).get("variables");
    assertEquals(1, variablesArrayNode.size());
    JsonNode variableNode = variablesArrayNode.get(0);
    assertEquals("message", variableNode.get("name").asText());
    assertEquals("serializable", variableNode.get("type").asText());
    assertNotNull(variableNode.get("valueUrl"));
}
Also used : Task(org.activiti.engine.task.Task) Message(org.activiti.rest.api.jpa.model.Message) HashMap(java.util.HashMap) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 73 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskIdentityLinkFamilyResource method getIdentityLinksForFamily.

@RequestMapping(value = "/runtime/tasks/{taskId}/identitylinks/{family}", method = RequestMethod.GET, produces = "application/json")
public List<RestIdentityLink> getIdentityLinksForFamily(@PathVariable("taskId") String taskId, @PathVariable("family") String family, HttpServletRequest request) {
    Task task = getTaskFromRequest(taskId);
    if (family == null || (!RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS.equals(family) && !RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS.equals(family))) {
        throw new ActivitiIllegalArgumentException("Identity link family should be 'users' or 'groups'.");
    }
    boolean isUser = family.equals(RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS);
    List<RestIdentityLink> results = new ArrayList<RestIdentityLink>();
    List<IdentityLink> allLinks = taskService.getIdentityLinksForTask(task.getId());
    for (IdentityLink link : allLinks) {
        boolean match = false;
        if (isUser) {
            match = link.getUserId() != null;
        } else {
            match = link.getGroupId() != null;
        }
        if (match) {
            results.add(restResponseFactory.createRestIdentityLink(link));
        }
    }
    return results;
}
Also used : Task(org.activiti.engine.task.Task) RestIdentityLink(org.activiti.rest.service.api.engine.RestIdentityLink) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ArrayList(java.util.ArrayList) RestIdentityLink(org.activiti.rest.service.api.engine.RestIdentityLink) IdentityLink(org.activiti.engine.task.IdentityLink) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 74 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskResource method deleteTask.

@RequestMapping(value = "/runtime/tasks/{taskId}", method = RequestMethod.DELETE)
public void deleteTask(@PathVariable String taskId, @RequestParam(value = "cascadeHistory", required = false) Boolean cascadeHistory, @RequestParam(value = "deleteReason", required = false) String deleteReason, HttpServletResponse response) {
    Task taskToDelete = getTaskFromRequest(taskId);
    if (taskToDelete.getExecutionId() != null) {
        // Can't delete a task that is part of a process instance
        throw new ActivitiForbiddenException("Cannot delete a task that is part of a process-instance.");
    }
    if (cascadeHistory != null) {
        // Ignore delete-reason since the task-history (where the reason is recorded) will be deleted anyway 
        taskService.deleteTask(taskToDelete.getId(), cascadeHistory);
    } else {
        // Delete with delete-reason
        taskService.deleteTask(taskToDelete.getId(), deleteReason);
    }
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
Also used : ActivitiForbiddenException(org.activiti.rest.exception.ActivitiForbiddenException) Task(org.activiti.engine.task.Task) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 75 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskVariableCollectionResource method getVariables.

@RequestMapping(value = "/runtime/tasks/{taskId}/variables", method = RequestMethod.GET, produces = "application/json")
public List<RestVariable> getVariables(@PathVariable String taskId, @RequestParam(value = "scope", required = false) String scope, HttpServletRequest request) {
    List<RestVariable> result = new ArrayList<RestVariable>();
    Map<String, RestVariable> variableMap = new HashMap<String, RestVariable>();
    // Check if it's a valid task to get the variables for
    Task task = getTaskFromRequest(taskId);
    RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
    if (variableScope == null) {
        // Use both local and global variables
        addLocalVariables(task, variableMap);
        addGlobalVariables(task, variableMap);
    } else if (variableScope == RestVariableScope.GLOBAL) {
        addGlobalVariables(task, variableMap);
    } else if (variableScope == RestVariableScope.LOCAL) {
        addLocalVariables(task, variableMap);
    }
    // Get unique variables from map
    result.addAll(variableMap.values());
    return result;
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RestVariableScope(org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Task (org.activiti.engine.task.Task)955 Deployment (org.activiti.engine.test.Deployment)548 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)502 HashMap (java.util.HashMap)197 Test (org.junit.Test)123 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)109 ArrayList (java.util.ArrayList)74 Date (java.util.Date)65 Execution (org.activiti.engine.runtime.Execution)59 DelegateTask (org.activiti.engine.delegate.DelegateTask)54 TaskQuery (org.activiti.engine.task.TaskQuery)54 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)51 Job (org.activiti.engine.runtime.Job)49 Calendar (java.util.Calendar)44 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)44 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)44 JsonNode (com.fasterxml.jackson.databind.JsonNode)41 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)41 JSONObject (org.json.simple.JSONObject)40 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)38