use of org.activiti.engine.impl.util.ProcessInstanceHelper in project Activiti by Activiti.
the class StartCreatedProcessInstanceCmd method execute.
@Override
public ProcessInstance execute(CommandContext commandContext) {
if (this.internalProcessInstance.getStartTime() != null) {
throw new ActivitiIllegalArgumentException("Process instance " + this.internalProcessInstance.getProcessInstanceId() + " has already been started");
}
ExecutionEntity processExecution = (ExecutionEntity) internalProcessInstance;
ProcessInstanceHelper processInstanceHelper = commandContext.getProcessEngineConfiguration().getProcessInstanceHelper();
Process process = ProcessDefinitionUtil.getProcess(internalProcessInstance.getProcessDefinitionId());
processInstanceHelper.startProcessInstance(processExecution, commandContext, variables, process.getInitialFlowElement(), Collections.emptyMap());
return processExecution;
}
use of org.activiti.engine.impl.util.ProcessInstanceHelper 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);
}
}
use of org.activiti.engine.impl.util.ProcessInstanceHelper in project Activiti by Activiti.
the class SignalEventHandler method handleEvent.
@SuppressWarnings("unchecked")
@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, CommandContext commandContext) {
if (eventSubscription.getExecutionId() != null) {
dispatchActivitySignalledEvent(eventSubscription.getExecution(), eventSubscription.getEventName(), payload, commandContext);
super.handleEvent(eventSubscription, payload, commandContext);
} else if (eventSubscription.getProcessDefinitionId() != null) {
// Find initial flow element matching the signal start event
String processDefinitionId = eventSubscription.getProcessDefinitionId();
ProcessDefinition processDefinition = ProcessDefinitionUtil.getProcessDefinition(processDefinitionId);
if (processDefinition == null) {
throw new ActivitiObjectNotFoundException("No process definition found for id '" + processDefinitionId + "'", ProcessDefinition.class);
}
if (processDefinition.isSuspended()) {
throw new ActivitiException("Could not handle signal: process definition with id: " + processDefinitionId + " is suspended");
}
org.activiti.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(processDefinitionId);
FlowElement flowElement = process.getFlowElement(eventSubscription.getActivityId(), true);
if (flowElement == null) {
throw new ActivitiException("Could not find matching FlowElement for activityId " + eventSubscription.getActivityId());
}
// Start process instance via that flow element
Map<String, Object> variables = null;
if (payload instanceof Map) {
variables = (Map<String, Object>) payload;
}
ProcessInstanceHelper processInstanceHelper = commandContext.getProcessEngineConfiguration().getProcessInstanceHelper();
ExecutionEntity executionEntity = processInstanceHelper.createProcessInstanceWithInitialFlowElement(processDefinition, null, null, flowElement, process);
DelegateExecution execution = executionEntity.getExecutions().get(0);
dispatchActivitySignalledEvent(execution, eventSubscription.getEventName(), payload, commandContext);
processInstanceHelper.startProcessInstance(executionEntity, commandContext, variables, flowElement, null);
} else {
throw new ActivitiException("Invalid signal handling: no execution nor process definition set");
}
}
use of org.activiti.engine.impl.util.ProcessInstanceHelper in project Activiti by Activiti.
the class StartProcessInstanceByMessageCmd method execute.
public ProcessInstance execute(CommandContext commandContext) {
if (messageName == null) {
throw new ActivitiIllegalArgumentException("Cannot start process instance by message: message name is null");
}
MessageEventSubscriptionEntity messageEventSubscription = commandContext.getEventSubscriptionEntityManager().findMessageStartEventSubscriptionByName(messageName, tenantId);
if (messageEventSubscription == null) {
throw new ActivitiObjectNotFoundException("Cannot start process instance by message: no subscription to message with name '" + messageName + "' found.", MessageEventSubscriptionEntity.class);
}
String processDefinitionId = messageEventSubscription.getConfiguration();
if (processDefinitionId == null) {
throw new ActivitiException("Cannot start process instance by message: subscription to message with name '" + messageName + "' is not a message start event.");
}
DeploymentManager deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentManager();
ProcessDefinition processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
if (processDefinition == null) {
throw new ActivitiObjectNotFoundException("No process definition found for id '" + processDefinitionId + "'", ProcessDefinition.class);
}
ProcessInstanceHelper processInstanceHelper = commandContext.getProcessEngineConfiguration().getProcessInstanceHelper();
ProcessInstance processInstance = processInstanceHelper.createAndStartProcessInstanceByMessage(processDefinition, businessKey, messageName, processVariables, transientVariables);
return processInstance;
}
Aggregations