Search in sources :

Example 6 with HistoricActivityInstanceEntity

use of org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity in project Activiti by Activiti.

the class TerminateEndEventActivityBehavior method endAllHistoricActivities.

protected void endAllHistoricActivities(String processInstanceId) {
    if (!Context.getProcessEngineConfiguration().getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        return;
    }
    Map<String, HistoricActivityInstanceEntity> historicActivityInstancMap = new HashMap<String, HistoricActivityInstanceEntity>();
    List<HistoricActivityInstance> historicActivityInstances = new HistoricActivityInstanceQueryImpl(Context.getCommandContext()).processInstanceId(processInstanceId).unfinished().list();
    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        historicActivityInstancMap.put(historicActivityInstance.getId(), (HistoricActivityInstanceEntity) historicActivityInstance);
    }
    // Cached version overwites entity
    List<HistoricActivityInstanceEntity> cachedHistoricActivityInstances = Context.getCommandContext().getDbSqlSession().findInCache(HistoricActivityInstanceEntity.class);
    for (HistoricActivityInstanceEntity cachedHistoricActivityInstance : cachedHistoricActivityInstances) {
        if (processInstanceId.equals(cachedHistoricActivityInstance.getProcessInstanceId()) && (cachedHistoricActivityInstance.getEndTime() == null)) {
            historicActivityInstancMap.put(cachedHistoricActivityInstance.getId(), cachedHistoricActivityInstance);
        }
    }
    for (HistoricActivityInstanceEntity historicActivityInstance : historicActivityInstancMap.values()) {
        historicActivityInstance.markEnded(null);
        // Fire event
        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, historicActivityInstance));
        }
    }
}
Also used : HistoricActivityInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity) HashMap(java.util.HashMap) HistoricActivityInstanceQueryImpl(org.activiti.engine.impl.HistoricActivityInstanceQueryImpl) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Aggregations

HistoricActivityInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity)6 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)4 HistoricActivityInstanceQueryImpl (org.activiti.engine.impl.HistoricActivityInstanceQueryImpl)3 IdGenerator (org.activiti.engine.impl.cfg.IdGenerator)3 Date (java.util.Date)2 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)2 HistoricProcessInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity)2 HashMap (java.util.HashMap)1 List (java.util.List)1 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)1