Search in sources :

Example 71 with HistoricProcessInstance

use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.

the class ProcessInstanceCollectionResourceTest method testStartProcessWithSameHttpClient.

/**
   * Explicitly testing the statelessness of the Rest API.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testStartProcessWithSameHttpClient() throws Exception {
    ObjectNode requestNode = objectMapper.createObjectNode();
    // Start using process definition key
    requestNode.put("processDefinitionKey", "processOne");
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    // First call
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));
    // Second call
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
    assertEquals(2, processInstances.size());
    for (ProcessInstance processInstance : processInstances) {
        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
        assertNotNull(historicProcessInstance);
        assertEquals("kermit", historicProcessInstance.getStartUserId());
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 72 with HistoricProcessInstance

use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.

the class ProcessInstanceCollectionResourceTest method testStartProcess.

/**
   * Test starting a process instance using procDefinitionId, key procDefinitionKey business-key.
   */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testStartProcess() throws Exception {
    ObjectNode requestNode = objectMapper.createObjectNode();
    // Start using process definition key
    requestNode.put("processDefinitionKey", "processOne");
    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(processInstance);
    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(historicProcessInstance);
    assertEquals("kermit", historicProcessInstance.getStartUserId());
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertTrue(responseNode.get("businessKey").isNull());
    assertEquals("processTask", responseNode.get("activityId").textValue());
    assertFalse(responseNode.get("suspended").booleanValue());
    assertTrue(responseNode.get("url").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId())));
    assertTrue(responseNode.get("processDefinitionUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId())));
    runtimeService.deleteProcessInstance(processInstance.getId(), "testing");
    // Start using process definition id
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionId", repositoryService.createProcessDefinitionQuery().processDefinitionKey("processOne").singleResult().getId());
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPost, HttpStatus.SC_CREATED);
    processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(processInstance);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertTrue(responseNode.get("businessKey").isNull());
    assertEquals("processTask", responseNode.get("activityId").textValue());
    assertFalse(responseNode.get("suspended").booleanValue());
    assertTrue(responseNode.get("url").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId())));
    assertTrue(responseNode.get("processDefinitionUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId())));
    runtimeService.deleteProcessInstance(processInstance.getId(), "testing");
    // Start using message
    requestNode = objectMapper.createObjectNode();
    requestNode.put("message", "newInvoiceMessage");
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPost, HttpStatus.SC_CREATED);
    processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertNotNull(processInstance);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals(processInstance.getId(), responseNode.get("id").textValue());
    assertTrue(responseNode.get("businessKey").isNull());
    assertEquals("processTask", responseNode.get("activityId").textValue());
    assertFalse(responseNode.get("suspended").booleanValue());
    assertTrue(responseNode.get("url").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId())));
    assertTrue(responseNode.get("processDefinitionUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId())));
    // Start using process definition id and business key
    requestNode = objectMapper.createObjectNode();
    requestNode.put("processDefinitionId", repositoryService.createProcessDefinitionQuery().processDefinitionKey("processOne").singleResult().getId());
    requestNode.put("businessKey", "myBusinessKey");
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    response = executeRequest(httpPost, HttpStatus.SC_CREATED);
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertNotNull(responseNode);
    assertEquals("myBusinessKey", responseNode.get("businessKey").textValue());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 73 with HistoricProcessInstance

use of org.activiti.engine.history.HistoricProcessInstance in project Activiti by Activiti.

the class IntermediateTimerEventRepeatWithEndTest method testRepeatWithEnd.

@Deployment
public void testRepeatWithEnd() throws Throwable {
    Calendar calendar = Calendar.getInstance();
    Date baseTime = calendar.getTime();
    //expect to stop boundary jobs after 20 minutes
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    calendar.setTime(baseTime);
    calendar.add(Calendar.HOUR, 2);
    //expect to wait after competing task B for 1 hour even I set the end date for 2 hours (the expression will trigger the execution)
    DateTime dt = new DateTime(calendar.getTime());
    String dateStr1 = fmt.print(dt);
    calendar.setTime(baseTime);
    calendar.add(Calendar.HOUR, 1);
    calendar.add(Calendar.MINUTE, 30);
    //expect to wait after competing task B for 1 hour and 30 minutes (the end date will be reached, the expression will not be considered)
    dt = new DateTime(calendar.getTime());
    String dateStr2 = fmt.print(dt);
    //reset the timer
    Calendar nextTimeCal = Calendar.getInstance();
    nextTimeCal.setTime(baseTime);
    processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("repeatWithEnd");
    runtimeService.setVariable(processInstance.getId(), "EndDateForCatch1", dateStr1);
    runtimeService.setVariable(processInstance.getId(), "EndDateForCatch2", dateStr2);
    List<Task> tasks = taskService.createTaskQuery().list();
    assertEquals(1, tasks.size());
    tasks = taskService.createTaskQuery().list();
    assertEquals(1, tasks.size());
    Task task = tasks.get(0);
    assertEquals("Task A", task.getName());
    //Test Timer Catch Intermediate Events after completing Task B (endDate not reached but it will be executed accrding to the expression)
    taskService.complete(task.getId());
    try {
        waitForJobExecutorToProcessAllJobs(2000, 500);
        fail("Expected that job isn't executed because the timer is in t0");
    } catch (Exception e) {
    // expected
    }
    //after 1 hour the event must be triggered and the flow will go to the next step
    nextTimeCal.add(Calendar.HOUR, 1);
    processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
    waitForJobExecutorToProcessAllJobs(2000, 200);
    //expect to execute because the time is reached.
    List<Job> jobs = managementService.createJobQuery().list();
    assertEquals(0, jobs.size());
    tasks = taskService.createTaskQuery().list();
    assertEquals(1, tasks.size());
    task = tasks.get(0);
    assertEquals("Task C", task.getName());
    //Test Timer Catch Intermediate Events after completing Task C
    taskService.complete(task.getId());
    //after 1H 30 minutes from process start, the timer will trigger because of the endDate
    nextTimeCal.add(Calendar.MINUTE, 30);
    processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
    waitForJobExecutorToProcessAllJobs(2000, 500);
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstance historicInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
        assertNotNull(historicInstance.getEndTime());
    }
    //now all the process instances should be completed
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
    assertEquals(0, processInstances.size());
    //no jobs
    jobs = managementService.createJobQuery().list();
    assertEquals(0, jobs.size());
    //no tasks
    tasks = taskService.createTaskQuery().list();
    assertEquals(0, tasks.size());
}
Also used : Task(org.activiti.engine.task.Task) Calendar(java.util.Calendar) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) Date(java.util.Date) DateTime(org.joda.time.DateTime) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Deployment(org.activiti.engine.test.Deployment)

Example 74 with HistoricProcessInstance

use of org.activiti.engine.history.HistoricProcessInstance in project midpoint by Evolveum.

the class ProcessInstanceManager method getActivitiToMidpoint.

private Map<String, String> getActivitiToMidpoint(Set<String> activeProcessInstances, OperationResult result) {
    Map<String, String> rv = new HashMap<>();
    int processWithoutTaskOidCount = 0;
    HistoricProcessInstanceQuery query = activitiEngine.getHistoryService().createHistoricProcessInstanceQuery().includeProcessVariables().excludeSubprocesses(true);
    List<HistoricProcessInstance> processes = query.list();
    for (HistoricProcessInstance process : processes) {
        String taskOid = (String) process.getProcessVariables().get(CommonProcessVariableNames.VARIABLE_MIDPOINT_TASK_OID);
        rv.put(process.getId(), taskOid);
        if (taskOid == null) {
            processWithoutTaskOidCount++;
        }
        if (process.getEndTime() == null) {
            activeProcessInstances.add(process.getId());
        }
    }
    LOGGER.info("Found {} processes; among these, {} have no task OID. Active processes: {}", rv.size(), processWithoutTaskOidCount, activeProcessInstances.size());
    return rv;
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Aggregations

HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)74 Deployment (org.activiti.engine.test.Deployment)34 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)29 Task (org.activiti.engine.task.Task)14 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)9 Item (com.vaadin.data.Item)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)6 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)6 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)6 Test (org.junit.Test)6 Property (com.vaadin.data.Property)4 ValueChangeEvent (com.vaadin.data.Property.ValueChangeEvent)4 Table (com.vaadin.ui.Table)4 Calendar (java.util.Calendar)4 Date (java.util.Date)4 HashSet (java.util.HashSet)4 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3