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);
}
}
Aggregations