Search in sources :

Example 1 with StartProcessInstanceCmd

use of org.activiti.engine.impl.cmd.StartProcessInstanceCmd in project Activiti by Activiti.

the class TimerStartEventJobHandler method execute.

public void execute(JobEntity job, String configuration, ExecutionEntity execution, CommandContext commandContext) {
    ProcessDefinitionEntity processDefinitionEntity = ProcessDefinitionUtil.getProcessDefinitionFromDatabase(// From DB -> need to get latest suspended state
    job.getProcessDefinitionId());
    if (processDefinitionEntity == null) {
        throw new ActivitiException("Could not find process definition needed for timer start event");
    }
    try {
        if (!processDefinitionEntity.isSuspended()) {
            if (commandContext.getEventDispatcher().isEnabled()) {
                commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TIMER_FIRED, job));
            }
            // Find initial flow element matching the signal start event
            org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(job.getProcessDefinitionId());
            String activityId = TimerEventHandler.getActivityIdFromConfiguration(configuration);
            if (activityId != null) {
                FlowElement flowElement = process.getFlowElement(activityId, true);
                if (flowElement == null) {
                    throw new ActivitiException("Could not find matching FlowElement for activityId " + activityId);
                }
                ProcessInstanceHelper processInstanceHelper = commandContext.getProcessEngineConfiguration().getProcessInstanceHelper();
                processInstanceHelper.createAndStartProcessInstanceWithInitialFlowElement(processDefinitionEntity, null, null, flowElement, process, null, null, true);
            } else {
                new StartProcessInstanceCmd(processDefinitionEntity.getKey(), null, null, null, job.getTenantId()).execute(commandContext);
            }
        } else {
            log.debug("ignoring timer of suspended process definition {}", processDefinitionEntity.getName());
        }
    } catch (RuntimeException e) {
        log.error("exception during timer execution", e);
        throw e;
    } catch (Exception e) {
        log.error("exception during timer execution", e);
        throw new ActivitiException("exception during timer execution: " + e.getMessage(), e);
    }
}
Also used : ProcessInstanceHelper(org.activiti.engine.impl.util.ProcessInstanceHelper) ActivitiException(org.activiti.engine.ActivitiException) FlowElement(org.activiti.bpmn.model.FlowElement) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) StartProcessInstanceCmd(org.activiti.engine.impl.cmd.StartProcessInstanceCmd) ActivitiException(org.activiti.engine.ActivitiException)

Aggregations

FlowElement (org.activiti.bpmn.model.FlowElement)1 ActivitiException (org.activiti.engine.ActivitiException)1 StartProcessInstanceCmd (org.activiti.engine.impl.cmd.StartProcessInstanceCmd)1 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)1 ProcessInstanceHelper (org.activiti.engine.impl.util.ProcessInstanceHelper)1