Search in sources :

Example 41 with HistoricProcessInstance

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

the class HistoricProcessInstanceQueryVersionTest method testHistoricProcessInstanceOrQueryByProcessDefinitionVersion.

public void testHistoricProcessInstanceOrQueryByProcessDefinitionVersion() {
    assertEquals(1, historyService.createHistoricProcessInstanceQuery().or().processDefinitionVersion(1).processDefinitionId("undefined").endOr().count());
    assertEquals(1, historyService.createHistoricProcessInstanceQuery().or().processDefinitionVersion(2).processDefinitionId("undefined").endOr().count());
    assertEquals(0, historyService.createHistoricProcessInstanceQuery().or().processDefinitionVersion(3).processDefinitionId("undefined").endOr().count());
    assertEquals(1, historyService.createHistoricProcessInstanceQuery().or().processDefinitionVersion(1).processDefinitionId("undefined").endOr().list().size());
    assertEquals(1, historyService.createHistoricProcessInstanceQuery().or().processDefinitionVersion(2).processDefinitionId("undefined").endOr().list().size());
    assertEquals(0, historyService.createHistoricProcessInstanceQuery().or().processDefinitionVersion(3).processDefinitionId("undefined").endOr().list().size());
    // Variables Case
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("test", "invalid").processDefinitionVersion(1).endOr().singleResult();
        assertEquals(1, processInstance.getProcessDefinitionVersion().intValue());
        Map<String, Object> variableMap = processInstance.getProcessVariables();
        assertEquals(123, variableMap.get("test"));
        processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionVersion(2).endOr().singleResult();
        assertEquals(2, processInstance.getProcessDefinitionVersion().intValue());
        variableMap = processInstance.getProcessVariables();
        assertEquals(456, variableMap.get("anothertest"));
        processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().variableValueEquals("anothertest", "invalid").processDefinitionVersion(3).singleResult();
        assertNull(processInstance);
    }
}
Also used : HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 42 with HistoricProcessInstance

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

the class HistoricProcessInstanceQueryVersionTest method testHistoricProcessInstanceQueryByProcessDefinitionVersion.

public void testHistoricProcessInstanceQueryByProcessDefinitionVersion() {
    assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(1).list().get(0).getProcessDefinitionVersion().intValue());
    assertEquals(2, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(2).list().get(0).getProcessDefinitionVersion().intValue());
    assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(1).count());
    assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(2).count());
    assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(3).count());
    assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(1).count());
    assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(2).list().size());
    assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(3).list().size());
    // Variables Case
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().variableValueEquals("test", 123).processDefinitionVersion(1).singleResult();
        assertEquals(1, processInstance.getProcessDefinitionVersion().intValue());
        Map<String, Object> variableMap = processInstance.getProcessVariables();
        assertEquals(123, variableMap.get("test"));
        processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().variableValueEquals("anothertest", 456).processDefinitionVersion(1).singleResult();
        assertNull(processInstance);
        processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().variableValueEquals("anothertest", 456).processDefinitionVersion(2).singleResult();
        assertEquals(2, processInstance.getProcessDefinitionVersion().intValue());
        variableMap = processInstance.getProcessVariables();
        assertEquals(456, variableMap.get("anothertest"));
    }
}
Also used : HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 43 with HistoricProcessInstance

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

the class IntermediateTimerEventRepeatCompatibilityTest 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 completing task A 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 endDateForIntermediate1 = fmt.print(dt);
    calendar.setTime(baseTime);
    calendar.add(Calendar.HOUR, 1);
    calendar.add(Calendar.MINUTE, 30);
    //expect to wait after completing 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 endDateForIntermediate2 = 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", endDateForIntermediate1);
    runtimeService.setVariable(processInstance.getId(), "EndDateForCatch2", endDateForIntermediate2);
    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 according 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, 500);
    //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 40 minutes from process start, the timer will trigger because of the endDate
    nextTimeCal.add(Calendar.HOUR, 1);
    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 44 with HistoricProcessInstance

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

the class AttachmentEntityManager method deleteAttachmentsByProcessInstanceId.

@SuppressWarnings("unchecked")
public void deleteAttachmentsByProcessInstanceId(String processInstanceId) {
    checkHistoryEnabled();
    List<AttachmentEntity> attachments = getDbSqlSession().selectList("selectAttachmentsByProcessInstanceId", processInstanceId);
    boolean dispatchEvents = getProcessEngineConfiguration().getEventDispatcher().isEnabled();
    String processDefinitionId = null;
    String executionId = null;
    if (dispatchEvents && attachments != null && !attachments.isEmpty()) {
        // Forced to fetch the process instance to get hold of the process definition for event-dispatching, if available
        HistoricProcessInstance processInstance = getHistoricProcessInstanceManager().findHistoricProcessInstance(processInstanceId);
        if (processInstance != null) {
            processDefinitionId = processInstance.getProcessDefinitionId();
            executionId = processInstance.getId();
        }
    }
    for (AttachmentEntity attachment : attachments) {
        if (attachment.getTaskId() != null) {
            continue;
        }
        String contentId = attachment.getContentId();
        if (contentId != null) {
            getByteArrayManager().deleteByteArrayById(contentId);
        }
        getDbSqlSession().delete(attachment);
        if (dispatchEvents) {
            getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, attachment, executionId, processInstanceId, processDefinitionId));
        }
    }
}
Also used : HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 45 with HistoricProcessInstance

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

the class WebServiceTaskTest method testFaultManagement.

@Deployment
public void testFaultManagement() throws Exception {
    assertEquals(-1, webServiceMock.getCount());
    // Expected fault catched with a boundary error event
    webServiceMock.setTo(Integer.MAX_VALUE);
    ProcessInstance processInstanceWithExpectedFault = runtimeService.startProcessInstanceByKey("webServiceInvocation");
    waitForJobExecutorToProcessAllJobs(10000L, 250L);
    assertTrue(processInstanceWithExpectedFault.isEnded());
    final List<HistoricProcessInstance> historicProcessInstanceWithExpectedFault = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceWithExpectedFault.getId()).list();
    assertEquals(1, historicProcessInstanceWithExpectedFault.size());
    assertEquals("theEndWithError", historicProcessInstanceWithExpectedFault.get(0).getEndActivityId());
    // RuntimException occurring during processing of the web-service, so not catched in the process definition. The RuntimeException
    // is embedded as an unexpected fault at web-service server side
    webServiceMock.setTo(123456);
    try {
        runtimeService.startProcessInstanceByKey("webServiceInvocation");
    } catch (ActivitiException e) {
        assertFalse("Exception processed as Business fault", e instanceof BpmnError);
        assertTrue(e.getCause() instanceof SoapFault);
    }
    // Unexpected fault at ws-client side invoking the web-service, so not catched in the process definition
    server.stop();
    try {
        runtimeService.startProcessInstanceByKey("webServiceInvocation");
    } catch (ActivitiException e) {
        assertFalse("Exception processed as Business fault", e instanceof BpmnError);
        assertTrue(e.getCause() instanceof Fault);
    } finally {
        server.start();
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) SoapFault(org.apache.cxf.binding.soap.SoapFault) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Fault(org.apache.cxf.interceptor.Fault) SoapFault(org.apache.cxf.binding.soap.SoapFault) BpmnError(org.activiti.engine.delegate.BpmnError) Deployment(org.activiti.engine.test.Deployment)

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