Search in sources :

Example 46 with HistoricActivityInstance

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

the class MultiInstanceTest method testSequentialSubProcessHistory.

@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testSequentialSubProcess.bpmn20.xml" })
public void testSequentialSubProcessHistory() {
    runtimeService.startProcessInstanceByKey("miSequentialSubprocess");
    for (int i = 0; i < 4; i++) {
        List<Task> tasks = taskService.createTaskQuery().list();
        taskService.complete(tasks.get(0).getId());
        taskService.complete(tasks.get(1).getId());
    }
    // Validate history
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        List<HistoricActivityInstance> onlySubProcessInstances = historyService.createHistoricActivityInstanceQuery().activityType("subProcess").list();
        assertEquals(4, onlySubProcessInstances.size());
        List<HistoricActivityInstance> historicInstances = historyService.createHistoricActivityInstanceQuery().activityType("subProcess").list();
        assertEquals(4, historicInstances.size());
        for (HistoricActivityInstance hai : historicInstances) {
            assertNotNull(hai.getStartTime());
            assertNotNull(hai.getEndTime());
        }
        historicInstances = historyService.createHistoricActivityInstanceQuery().activityType("userTask").list();
        assertEquals(8, historicInstances.size());
        for (HistoricActivityInstance hai : historicInstances) {
            assertNotNull(hai.getStartTime());
            assertNotNull(hai.getEndTime());
        }
    }
}
Also used : Task(org.activiti.engine.task.Task) DelegateTask(org.activiti.engine.delegate.DelegateTask) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 47 with HistoricActivityInstance

use of org.activiti.engine.history.HistoricActivityInstance in project daijie-example by daijiejay.

the class BaseService method getProcesses.

@Override
public ModelResult<PageResult<Map<String, Object>>> getProcesses() {
    List<Map<String, Object>> rows = new ArrayList<>();
    PageResult<Map<String, Object>> datas = new PageResult<>();
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
    List<ProcessInstance> processInstances = query.list();
    processInstances.forEach(processInstance -> {
        List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).unfinished().list();
        if (!historicActivityInstances.isEmpty()) {
            historicActivityInstances.forEach(historicActivityInstance -> {
                Map<String, Object> row = new HashMap<>();
                row.put("processInstanceId", processInstance.getId());
                Task task = taskService.createTaskQuery().taskId(historicActivityInstance.getTaskId()).singleResult();
                row.put("activityName", historicActivityInstance.getActivityName());
                row.put("taskId", historicActivityInstance.getTaskId());
                row.put("createTime", task.getCreateTime());
                row.put("assignee", task.getAssignee());
                rows.add(row);
            });
        } else {
            Map<String, Object> row = new HashMap<>();
            row.put("processInstanceId", processInstance.getId());
            row.put("activityName", "流程结束");
            rows.add(row);
        }
    });
    datas.setTotal(query.count());
    datas.setRows(rows);
    return Result.build(datas);
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PageResult(org.daijie.core.result.PageResult) ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HashMap(java.util.HashMap) Map(java.util.Map) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 48 with HistoricActivityInstance

use of org.activiti.engine.history.HistoricActivityInstance in project herd by FINRAOS.

the class ActivitiServiceTest method testGetHistoricActivityInstancesByProcessInstanceId.

@Test
public void testGetHistoricActivityInstancesByProcessInstanceId() {
    String processInstanceId = "processInstanceId";
    HistoricActivityInstanceQuery historicActivityInstanceQuery = mock(HistoricActivityInstanceQuery.class);
    when(activitiHistoryService.createHistoricActivityInstanceQuery()).thenReturn(historicActivityInstanceQuery);
    when(historicActivityInstanceQuery.processInstanceId(processInstanceId)).thenReturn(historicActivityInstanceQuery);
    when(historicActivityInstanceQuery.orderByHistoricActivityInstanceStartTime()).thenReturn(historicActivityInstanceQuery);
    when(historicActivityInstanceQuery.asc()).thenReturn(historicActivityInstanceQuery);
    when(historicActivityInstanceQuery.orderByHistoricActivityInstanceEndTime()).thenReturn(historicActivityInstanceQuery);
    when(historicActivityInstanceQuery.asc()).thenReturn(historicActivityInstanceQuery);
    List<HistoricActivityInstance> expectedHistoricActivityInstances = new ArrayList<>();
    when(historicActivityInstanceQuery.list()).thenReturn(expectedHistoricActivityInstances);
    List<HistoricActivityInstance> actualHistoricActivityInstances = activitiService.getHistoricActivityInstancesByProcessInstanceId(processInstanceId);
    assertSame(expectedHistoricActivityInstances, actualHistoricActivityInstances);
    InOrder inOrder = inOrder(historicActivityInstanceQuery);
    inOrder.verify(historicActivityInstanceQuery).processInstanceId(processInstanceId);
    inOrder.verify(historicActivityInstanceQuery).orderByHistoricActivityInstanceStartTime();
    inOrder.verify(historicActivityInstanceQuery).asc();
    inOrder.verify(historicActivityInstanceQuery).orderByHistoricActivityInstanceEndTime();
    inOrder.verify(historicActivityInstanceQuery).asc();
    inOrder.verify(historicActivityInstanceQuery).list();
    inOrder.verifyNoMoreInteractions();
}
Also used : HistoricActivityInstanceQuery(org.activiti.engine.history.HistoricActivityInstanceQuery) InOrder(org.mockito.InOrder) ArrayList(java.util.ArrayList) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Test(org.junit.Test)

Example 49 with HistoricActivityInstance

use of org.activiti.engine.history.HistoricActivityInstance in project alfresco-remote-api by Alfresco.

the class ActivitiesImpl method getActivities.

@Override
public CollectionWithPagingInfo<Activity> getActivities(String processId, Parameters parameters) {
    Paging paging = parameters.getPaging();
    String status = parameters.getParameter("status");
    validateIfUserAllowedToWorkWithProcess(processId);
    HistoricActivityInstanceQuery query = activitiProcessEngine.getHistoryService().createHistoricActivityInstanceQuery();
    if (STATUS_ACTIVE.equals(status))
        query.unfinished();
    else if (STATUS_COMPLETED.equals(status))
        query.finished();
    query.processInstanceId(processId);
    query.orderByExecutionId().asc();
    List<HistoricActivityInstance> activities = query.listPage(paging.getSkipCount(), paging.getMaxItems());
    List<Activity> page = new ArrayList<Activity>(activities.size());
    for (HistoricActivityInstance activityInstance : activities) {
        Activity activity = new Activity(activityInstance);
        page.add(activity);
    }
    return CollectionWithPagingInfo.asPaged(paging, page, false, page.size());
}
Also used : HistoricActivityInstanceQuery(org.activiti.engine.history.HistoricActivityInstanceQuery) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) Activity(org.alfresco.rest.workflow.api.model.Activity) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 50 with HistoricActivityInstance

use of org.activiti.engine.history.HistoricActivityInstance in project modesti by jlsalmon.

the class HistoryService method getHistoryForRequest.

/**
 * Retrieve the workflow history for a particular request.
 *
 * @param requestId the id of the request
 * @return the list of historic events
 */
public List<HistoricEvent> getHistoryForRequest(String requestId) {
    log.info("querying history for request id " + requestId + "...");
    Request request = requestRepository.findOneByRequestId(requestId);
    if (request == null) {
        throw new IllegalArgumentException("No request with id " + requestId + " was found");
    }
    List<HistoricEvent> history = new ArrayList<>();
    // Find the process instance for this request
    HistoricProcessInstance process = historyService.createHistoricProcessInstanceQuery().processInstanceBusinessKey(requestId).singleResult();
    // Find all the activities that happened so far for this process
    List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().processInstanceId(process.getId()).orderByTaskCreateTime().asc().list();
    // Find all the activities that happened so far for this process
    List<HistoricActivityInstance> activities = historyService.createHistoricActivityInstanceQuery().processInstanceId(process.getId()).orderByHistoricActivityInstanceStartTime().asc().list();
    for (HistoricActivityInstance activity : activities) {
        // Only interested in user tasks
        if (activity.getActivityType().equals("userTask")) {
            String description = "";
            for (HistoricTaskInstance task : tasks) {
                if (task.getId().equals(activity.getTaskId())) {
                    description = task.getDescription();
                }
            }
            HistoricEvent event = new HistoricEvent(activity.getStartTime(), activity.getEndTime(), activity.getDurationInMillis(), activity.getActivityName(), activity.getActivityType(), description, activity.getAssignee());
            history.add(event);
        }
    }
    return history;
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) Request(cern.modesti.request.Request) ArrayList(java.util.ArrayList) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Aggregations

HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)50 Deployment (org.activiti.engine.test.Deployment)30 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)25 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)19 Task (org.activiti.engine.task.Task)18 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)9 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)7 HistoricDetail (org.activiti.engine.history.HistoricDetail)6 DelegateTask (org.activiti.engine.delegate.DelegateTask)5 HistoricActivityInstanceQuery (org.activiti.engine.history.HistoricActivityInstanceQuery)5 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)4 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)4 HistoricVariableInstanceQuery (org.activiti.engine.history.HistoricVariableInstanceQuery)3 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)3 Date (java.util.Date)2 AssertionFailedError (junit.framework.AssertionFailedError)2 BpmnModel (org.activiti.bpmn.model.BpmnModel)2 HistoricData (org.activiti.engine.history.HistoricData)2 HistoricActivityInstanceQueryImpl (org.activiti.engine.impl.HistoricActivityInstanceQueryImpl)2