Search in sources :

Example 66 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ExecutionResourceTest method testIllegalExecutionAction.

/**
   * Test executing an illegal action on an execution.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testIllegalExecutionAction() throws Exception {
    Execution execution = runtimeService.startProcessInstanceByKey("processOne");
    assertNotNull(execution);
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("action", "badaction");
    HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, execution.getId()));
    httpPut.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST);
    closeResponse(response);
}
Also used : StringEntity(org.apache.http.entity.StringEntity) Execution(org.activiti.engine.runtime.Execution) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Example 67 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ExecutionVariableResourceTest method testGetExecutionVariable.

/**
   * Test getting an execution variable. GET
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecutionVariable() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne");
    runtimeService.setVariable(processInstance.getId(), "variable", "processValue");
    Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
    assertNotNull(childExecution);
    runtimeService.setVariableLocal(childExecution.getId(), "variable", "childValue");
    // Get local scope variable
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "variable")), HttpStatus.SC_OK);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("local", responseNode.get("scope").asText());
    assertEquals("childValue", responseNode.get("value").asText());
    assertEquals("variable", responseNode.get("name").asText());
    assertEquals("string", responseNode.get("type").asText());
    // Get global scope variable
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "variable") + "?scope=global"), HttpStatus.SC_OK);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("global", responseNode.get("scope").asText());
    assertEquals("processValue", responseNode.get("value").asText());
    assertEquals("variable", responseNode.get("name").asText());
    assertEquals("string", responseNode.get("type").asText());
    // Illegal scope
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, processInstance.getId(), "variable") + "?scope=illegal"), HttpStatus.SC_BAD_REQUEST);
    closeResponse(response);
    // Unexisting process
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, "unexisting", "variable")), HttpStatus.SC_NOT_FOUND);
    closeResponse(response);
    // Unexisting variable
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, processInstance.getId(), "unexistingVariable")), HttpStatus.SC_NOT_FOUND);
    closeResponse(response);
}
Also used : Execution(org.activiti.engine.runtime.Execution) 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 68 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ExecutionVariableResourceTest method testGetExecutionVariableData.

/**
   * Test getting execution variable data.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecutionVariableData() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne");
    runtimeService.setVariableLocal(processInstance.getId(), "var", "This is a binary piece of text".getBytes());
    Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
    assertNotNull(childExecution);
    runtimeService.setVariableLocal(childExecution.getId(), "var", "This is a binary piece of text in the child execution".getBytes());
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, childExecution.getId(), "var")), HttpStatus.SC_OK);
    String actualResponseBytesAsText = IOUtils.toString(response.getEntity().getContent());
    closeResponse(response);
    assertEquals("This is a binary piece of text in the child execution", actualResponseBytesAsText);
    assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());
    // Test global scope
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, childExecution.getId(), "var") + "?scope=global"), HttpStatus.SC_OK);
    actualResponseBytesAsText = IOUtils.toString(response.getEntity().getContent());
    closeResponse(response);
    assertEquals("This is a binary piece of text", actualResponseBytesAsText);
    assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());
}
Also used : Execution(org.activiti.engine.runtime.Execution) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 69 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ExecutionVariableResourceTest method testDeleteExecutionVariable.

/**
   * Test deleting a single execution variable, including "not found" check.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testDeleteExecutionVariable() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", Collections.singletonMap("myVariable", (Object) "processValue"));
    Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
    assertNotNull(childExecution);
    runtimeService.setVariableLocal(childExecution.getId(), "myVariable", "childValue");
    // Delete variable local
    HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "myVariable"));
    CloseableHttpResponse response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);
    assertFalse(runtimeService.hasVariableLocal(childExecution.getId(), "myVariable"));
    // Global variable should remain unaffected
    assertTrue(runtimeService.hasVariable(childExecution.getId(), "myVariable"));
    // Delete variable global
    httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "myVariable") + "?scope=global");
    response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);
    assertFalse(runtimeService.hasVariableLocal(childExecution.getId(), "myVariable"));
    assertFalse(runtimeService.hasVariable(childExecution.getId(), "myVariable"));
    // Run the same delete again, variable is not there so 404 should be returned
    response = executeRequest(httpDelete, HttpStatus.SC_NOT_FOUND);
    closeResponse(response);
}
Also used : Execution(org.activiti.engine.runtime.Execution) HttpDelete(org.apache.http.client.methods.HttpDelete) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 70 with Execution

use of org.activiti.engine.runtime.Execution in project midpoint by Evolveum.

the class DumpVariables method dumpExecutionVariables.

private void dumpExecutionVariables(String executionId, DelegateExecution delegateExecution, Execution execution, Set<String> variablesSeen, RuntimeService runtimeService) {
    Map<String, Object> variablesLocal = runtimeService.getVariablesLocal(executionId);
    LOGGER.trace("Execution id={} ({} variables); class={}/{}", executionId, variablesLocal.size(), delegateExecution != null ? delegateExecution.getClass().getName() : null, execution != null ? execution.getClass().getName() : null);
    TreeSet<String> names = new TreeSet<>(variablesLocal.keySet());
    names.forEach(n -> LOGGER.trace(" - {} = {} {}", n, variablesLocal.get(n), variablesSeen.contains(n) ? "(dup)" : ""));
    variablesSeen.addAll(variablesLocal.keySet());
    if (delegateExecution instanceof ExecutionEntity) {
        ExecutionEntity executionEntity = (ExecutionEntity) delegateExecution;
        if (executionEntity.getParent() != null) {
            dumpExecutionVariables(executionEntity.getParentId(), executionEntity.getParent(), null, variablesSeen, runtimeService);
        }
    } else if (delegateExecution instanceof ExecutionImpl) {
        ExecutionImpl executionImpl = (ExecutionImpl) delegateExecution;
        if (executionImpl.getParent() != null) {
            dumpExecutionVariables(executionImpl.getParentId(), executionImpl.getParent(), null, variablesSeen, runtimeService);
        }
    } else {
        Execution execution1 = runtimeService.createExecutionQuery().executionId(executionId).singleResult();
        if (execution1 == null) {
            LOGGER.trace("Execution with id {} was not found.", executionId);
        } else if (execution1.getParentId() != null) {
            Execution execution2 = runtimeService.createExecutionQuery().executionId(execution1.getParentId()).singleResult();
            dumpExecutionVariables(execution.getParentId(), null, execution2, variablesSeen, runtimeService);
        }
    }
}
Also used : DelegateExecution(org.activiti.engine.delegate.DelegateExecution) Execution(org.activiti.engine.runtime.Execution) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ExecutionImpl(org.activiti.engine.impl.pvm.runtime.ExecutionImpl)

Aggregations

Execution (org.activiti.engine.runtime.Execution)131 Deployment (org.activiti.engine.test.Deployment)105 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)75 Task (org.activiti.engine.task.Task)33 HashMap (java.util.HashMap)30 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)12 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)10 ExecutionQuery (org.activiti.engine.runtime.ExecutionQuery)10 HttpPut (org.apache.http.client.methods.HttpPut)10 StringEntity (org.apache.http.entity.StringEntity)9 ArrayList (java.util.ArrayList)8 ActivitiException (org.activiti.engine.ActivitiException)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Date (java.util.Date)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5