Search in sources :

Example 16 with HistoricActivityInstance

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

the class ProcessInstanceMigrationTest method testSetProcessDefinitionVersion.

@Deployment
public void testSetProcessDefinitionVersion() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("receiveTask");
    // check that receive task has been reached
    Execution execution = runtimeService.createExecutionQuery().processInstanceId(pi.getId()).activityId("waitState1").singleResult();
    assertNotNull(execution);
    // deploy new version of the process definition
    org.activiti.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS).deploy();
    assertEquals(2, repositoryService.createProcessDefinitionQuery().count());
    // migrate process instance to new process definition version
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));
    // signal process instance
    runtimeService.signal(execution.getId());
    // check that the instance now uses the new process definition version
    ProcessDefinition newProcessDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionVersion(2).singleResult();
    pi = runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).singleResult();
    assertEquals(newProcessDefinition.getId(), pi.getProcessDefinitionId());
    // check history
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstance historicPI = historyService.createHistoricProcessInstanceQuery().processInstanceId(pi.getId()).singleResult();
        assertEquals(newProcessDefinition.getId(), historicPI.getProcessDefinitionId());
        List<HistoricActivityInstance> historicActivities = historyService.createHistoricActivityInstanceQuery().processInstanceId(pi.getId()).unfinished().list();
        assertEquals(1, historicActivities.size());
        assertEquals(newProcessDefinition.getId(), historicActivities.get(0).getProcessDefinitionId());
    }
    // undeploy "manually" deployed process definition
    repositoryService.deleteDeployment(deployment.getId(), true);
}
Also used : Execution(org.activiti.engine.runtime.Execution) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.activiti.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 17 with HistoricActivityInstance

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

the class BaseProcessDefinitionDiagramLayoutResource method getHighLightedFlows.

private List<String> getHighLightedFlows(String processInstanceId, ProcessDefinitionEntity processDefinition) {
    List<String> highLightedFlows = new ArrayList<String>();
    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceStartTime().asc().list();
    List<String> historicActivityInstanceList = new ArrayList<String>();
    for (HistoricActivityInstance hai : historicActivityInstances) {
        historicActivityInstanceList.add(hai.getActivityId());
    }
    // add current activities to list
    List<String> highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId);
    historicActivityInstanceList.addAll(highLightedActivities);
    // activities and their sequence-flows
    for (ActivityImpl activity : processDefinition.getActivities()) {
        int index = historicActivityInstanceList.indexOf(activity.getId());
        if (index >= 0 && index + 1 < historicActivityInstanceList.size()) {
            List<PvmTransition> pvmTransitionList = activity.getOutgoingTransitions();
            for (PvmTransition pvmTransition : pvmTransitionList) {
                String destinationFlowId = pvmTransition.getDestination().getId();
                if (destinationFlowId.equals(historicActivityInstanceList.get(index + 1))) {
                    highLightedFlows.add(pvmTransition.getId());
                }
            }
        }
    }
    return highLightedFlows;
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ArrayList(java.util.ArrayList) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 18 with HistoricActivityInstance

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

the class ProcessInstanceHighlightsResource method getHighlightedFlows.

/**
	 * find out single activity's highlighted flowIds
	 * 
	 * @param activity
	 * @param hisActInstList
	 * @param isExclusive if true only return one flowId(Such as exclusiveGateway, BoundaryEvent On Task)
	 * @return
	 */
private List<String> getHighlightedFlows(List<PvmTransition> pvmTransitionList, LinkedList<HistoricActivityInstance> hisActInstList, boolean isParallel) {
    List<String> highLightedFlowIds = new ArrayList<String>();
    PvmTransition earliestTrans = null;
    HistoricActivityInstance earliestHisActInst = null;
    for (PvmTransition pvmTransition : pvmTransitionList) {
        String destActId = pvmTransition.getDestination().getId();
        HistoricActivityInstance destHisActInst = findHisActInst(hisActInstList, destActId);
        if (destHisActInst != null) {
            if (isParallel) {
                highLightedFlowIds.add(pvmTransition.getId());
            } else if (earliestHisActInst == null || (earliestHisActInst.getId().compareTo(destHisActInst.getId()) > 0)) {
                earliestTrans = pvmTransition;
                earliestHisActInst = destHisActInst;
            }
        }
    }
    if ((!isParallel) && earliestTrans != null) {
        highLightedFlowIds.add(earliestTrans.getId());
    }
    return highLightedFlowIds;
}
Also used : ArrayList(java.util.ArrayList) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 19 with HistoricActivityInstance

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

the class ProcessInstanceHighlightsResource method getHighlightedFlows.

/**
	 * getHighlightedFlows
	 * 
	 * code logic: 
	 * 1. Loop all activities by id asc order;
	 * 2. Check each activity's outgoing transitions and eventBoundery outgoing transitions, if outgoing transitions's destination.id is in other executed activityIds, add this transition to highLightedFlows List;
	 * 3. But if activity is not a parallelGateway or inclusiveGateway, only choose the earliest flow.
	 * 
	 * @param activityList
	 * @param hisActInstList
	 * @param highLightedFlows
	 */
private void getHighlightedFlows(List<ActivityImpl> activityList, LinkedList<HistoricActivityInstance> hisActInstList, List<String> highLightedFlows) {
    //check out startEvents in activityList
    List<ActivityImpl> startEventActList = new ArrayList<ActivityImpl>();
    Map<String, ActivityImpl> activityMap = new HashMap<String, ActivityImpl>(activityList.size());
    for (ActivityImpl activity : activityList) {
        activityMap.put(activity.getId(), activity);
        String actType = (String) activity.getProperty("type");
        if (actType != null && actType.toLowerCase().indexOf("startevent") >= 0) {
            startEventActList.add(activity);
        }
    }
    //These codes is used to avoid a bug: 
    //ACT-1728 If the process instance was started by a callActivity, it will be not have the startEvent activity in ACT_HI_ACTINST table 
    //Code logic:
    //Check the first activity if it is a startEvent, if not check out the startEvent's highlight outgoing flow.
    HistoricActivityInstance firstHistActInst = hisActInstList.getFirst();
    String firstActType = (String) firstHistActInst.getActivityType();
    if (firstActType != null && firstActType.toLowerCase().indexOf("startevent") < 0) {
        PvmTransition startTrans = getStartTransaction(startEventActList, firstHistActInst);
        if (startTrans != null) {
            highLightedFlows.add(startTrans.getId());
        }
    }
    while (!hisActInstList.isEmpty()) {
        HistoricActivityInstance histActInst = hisActInstList.removeFirst();
        ActivityImpl activity = activityMap.get(histActInst.getActivityId());
        if (activity != null) {
            boolean isParallel = false;
            String type = histActInst.getActivityType();
            if ("parallelGateway".equals(type) || "inclusiveGateway".equals(type)) {
                isParallel = true;
            } else if ("subProcess".equals(histActInst.getActivityType())) {
                getHighlightedFlows(activity.getActivities(), hisActInstList, highLightedFlows);
            }
            List<PvmTransition> allOutgoingTrans = new ArrayList<PvmTransition>();
            allOutgoingTrans.addAll(activity.getOutgoingTransitions());
            allOutgoingTrans.addAll(getBoundaryEventOutgoingTransitions(activity));
            List<String> activityHighLightedFlowIds = getHighlightedFlows(allOutgoingTrans, hisActInstList, isParallel);
            highLightedFlows.addAll(activityHighLightedFlowIds);
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 20 with HistoricActivityInstance

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

the class FullHistoryTest method testHistoricFormPropertiesOnReEnteringActivity.

/**
   * Test created to validate ACT-621 fix.
   */
@Deployment
public void testHistoricFormPropertiesOnReEnteringActivity() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("comeBack", Boolean.TRUE);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("HistoricFormPropertiesProcess", variables);
    assertNotNull(processInstance);
    // Submit form on task
    Map<String, String> data = new HashMap<String, String>();
    data.put("formProp1", "Property value");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    formService.submitTaskFormData(task.getId(), data);
    // Historic property should be available
    List<HistoricDetail> details = historyService.createHistoricDetailQuery().formProperties().processInstanceId(processInstance.getId()).list();
    assertNotNull(details);
    assertEquals(1, details.size());
    // Task should be active in the same activity as the previous one
    task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    formService.submitTaskFormData(task.getId(), data);
    details = historyService.createHistoricDetailQuery().formProperties().processInstanceId(processInstance.getId()).list();
    assertNotNull(details);
    assertEquals(2, details.size());
    // Should have 2 different historic activity instance ID's, with the same activityId
    assertNotSame(details.get(0).getActivityInstanceId(), details.get(1).getActivityInstanceId());
    HistoricActivityInstance historicActInst1 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(details.get(0).getActivityInstanceId()).singleResult();
    HistoricActivityInstance historicActInst2 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(details.get(1).getActivityInstanceId()).singleResult();
    assertEquals(historicActInst1.getActivityId(), historicActInst2.getActivityId());
}
Also used : HistoricDetail(org.activiti.engine.history.HistoricDetail) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)44 Deployment (org.activiti.engine.test.Deployment)30 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)24 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)18 Task (org.activiti.engine.task.Task)17 HashMap (java.util.HashMap)11 HistoricDetail (org.activiti.engine.history.HistoricDetail)6 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)6 DelegateTask (org.activiti.engine.delegate.DelegateTask)5 ArrayList (java.util.ArrayList)4 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)4 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)4 HistoricActivityInstanceQuery (org.activiti.engine.history.HistoricActivityInstanceQuery)3 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