Search in sources :

Example 1 with IdGenerator

use of org.activiti.engine.impl.cfg.IdGenerator in project Activiti by Activiti.

the class DefaultHistoryManager method recordProcessInstanceStart.

/* (non-Javadoc)
   * @see org.activiti.engine.impl.history.HistoryManagerInterface#recordProcessInstanceStart(org.activiti.engine.impl.persistence.entity.ExecutionEntity)
   */
@Override
public void recordProcessInstanceStart(ExecutionEntity processInstance) {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstanceEntity historicProcessInstance = new HistoricProcessInstanceEntity(processInstance);
        // Insert historic process-instance
        getDbSqlSession().insert(historicProcessInstance);
        // Fire event
        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
        }
        // Also record the start-event manually, as there is no "start" activity history listener for this
        IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator();
        String processDefinitionId = processInstance.getProcessDefinitionId();
        String processInstanceId = processInstance.getProcessInstanceId();
        String executionId = processInstance.getId();
        HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity();
        historicActivityInstance.setId(idGenerator.getNextId());
        historicActivityInstance.setProcessDefinitionId(processDefinitionId);
        historicActivityInstance.setProcessInstanceId(processInstanceId);
        historicActivityInstance.setExecutionId(executionId);
        historicActivityInstance.setActivityId(processInstance.getActivityId());
        historicActivityInstance.setActivityName((String) processInstance.getActivity().getProperty("name"));
        historicActivityInstance.setActivityType((String) processInstance.getActivity().getProperty("type"));
        Date now = Context.getProcessEngineConfiguration().getClock().getCurrentTime();
        historicActivityInstance.setStartTime(now);
        // Inherit tenant id (if applicable)
        if (processInstance.getTenantId() != null) {
            historicActivityInstance.setTenantId(processInstance.getTenantId());
        }
        getDbSqlSession().insert(historicActivityInstance);
        // Fire event
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstance));
        }
    }
}
Also used : HistoricActivityInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) IdGenerator(org.activiti.engine.impl.cfg.IdGenerator) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) Date(java.util.Date)

Example 2 with IdGenerator

use of org.activiti.engine.impl.cfg.IdGenerator in project Activiti by Activiti.

the class DefaultHistoryManager method createHistoricActivityInstanceEntity.

protected HistoricActivityInstanceEntity createHistoricActivityInstanceEntity(ExecutionEntity execution) {
    IdGenerator idGenerator = getProcessEngineConfiguration().getIdGenerator();
    String processDefinitionId = execution.getProcessDefinitionId();
    String processInstanceId = execution.getProcessInstanceId();
    HistoricActivityInstanceEntity historicActivityInstance = getHistoricActivityInstanceEntityManager().create();
    historicActivityInstance.setId(idGenerator.getNextId());
    historicActivityInstance.setProcessDefinitionId(processDefinitionId);
    historicActivityInstance.setProcessInstanceId(processInstanceId);
    historicActivityInstance.setExecutionId(execution.getId());
    historicActivityInstance.setActivityId(execution.getActivityId());
    if (execution.getCurrentFlowElement() != null) {
        historicActivityInstance.setActivityName(execution.getCurrentFlowElement().getName());
        historicActivityInstance.setActivityType(parseActivityType(execution.getCurrentFlowElement()));
    }
    Date now = getClock().getCurrentTime();
    historicActivityInstance.setStartTime(now);
    // Inherit tenant id (if applicable)
    if (execution.getTenantId() != null) {
        historicActivityInstance.setTenantId(execution.getTenantId());
    }
    getHistoricActivityInstanceEntityManager().insert(historicActivityInstance);
    return historicActivityInstance;
}
Also used : HistoricActivityInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity) IdGenerator(org.activiti.engine.impl.cfg.IdGenerator) Date(java.util.Date)

Example 3 with IdGenerator

use of org.activiti.engine.impl.cfg.IdGenerator in project Activiti by Activiti.

the class DefaultHistoryManager method recordSubProcessInstanceStart.

/* (non-Javadoc)
   * @see org.activiti.engine.impl.history.HistoryManagerInterface#recordSubProcessInstanceStart(org.activiti.engine.impl.persistence.entity.ExecutionEntity, org.activiti.engine.impl.persistence.entity.ExecutionEntity)
   */
@Override
public void recordSubProcessInstanceStart(ExecutionEntity parentExecution, ExecutionEntity subProcessInstance) {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstanceEntity historicProcessInstance = new HistoricProcessInstanceEntity((ExecutionEntity) subProcessInstance);
        ActivityImpl initialActivity = subProcessInstance.getActivity();
        // Fix for ACT-1728: startActivityId not initialized with subprocess-instance
        if (historicProcessInstance.getStartActivityId() == null) {
            historicProcessInstance.setStartActivityId(subProcessInstance.getProcessDefinition().getInitial().getId());
            initialActivity = subProcessInstance.getProcessDefinition().getInitial();
        }
        getDbSqlSession().insert(historicProcessInstance);
        // Fire event
        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
        }
        HistoricActivityInstanceEntity activitiyInstance = findActivityInstance(parentExecution);
        if (activitiyInstance != null) {
            activitiyInstance.setCalledProcessInstanceId(subProcessInstance.getProcessInstanceId());
        }
        // Fix for ACT-1728: start-event not recorded for subprocesses
        IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator();
        // Also record the start-event manually, as there is no "start" activity history listener for this
        HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity();
        historicActivityInstance.setId(idGenerator.getNextId());
        historicActivityInstance.setProcessDefinitionId(subProcessInstance.getProcessDefinitionId());
        historicActivityInstance.setProcessInstanceId(subProcessInstance.getProcessInstanceId());
        historicActivityInstance.setExecutionId(subProcessInstance.getId());
        historicActivityInstance.setActivityId(initialActivity.getId());
        historicActivityInstance.setActivityName((String) initialActivity.getProperty("name"));
        historicActivityInstance.setActivityType((String) initialActivity.getProperty("type"));
        Date now = Context.getProcessEngineConfiguration().getClock().getCurrentTime();
        historicActivityInstance.setStartTime(now);
        getDbSqlSession().insert(historicActivityInstance);
        // Fire event
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstance));
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) HistoricActivityInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) IdGenerator(org.activiti.engine.impl.cfg.IdGenerator) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) Date(java.util.Date)

Aggregations

Date (java.util.Date)3 IdGenerator (org.activiti.engine.impl.cfg.IdGenerator)3 HistoricActivityInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity)3 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)2 HistoricProcessInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity)2 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)1