use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class ScopeUtil method throwCompensationEvent.
/**
* we create a separate execution for each compensation handler invocation.
*/
public static void throwCompensationEvent(List<CompensateEventSubscriptionEntity> eventSubscriptions, DelegateExecution execution, boolean async) {
ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
// first spawn the compensating executions
for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
ExecutionEntity compensatingExecution = null;
// where the compensating execution is created when leaving the subprocess and holds snapshot data).
if (eventSubscription.getConfiguration() != null) {
compensatingExecution = executionEntityManager.findById(eventSubscription.getConfiguration());
compensatingExecution.setParent(compensatingExecution.getProcessInstance());
compensatingExecution.setEventScope(false);
} else {
compensatingExecution = executionEntityManager.createChildExecution((ExecutionEntity) execution);
eventSubscription.setConfiguration(compensatingExecution.getId());
}
}
// signal compensation events in reverse order of their 'created' timestamp
Collections.sort(eventSubscriptions, new Comparator<EventSubscriptionEntity>() {
public int compare(EventSubscriptionEntity o1, EventSubscriptionEntity o2) {
return o2.getCreated().compareTo(o1.getCreated());
}
});
for (CompensateEventSubscriptionEntity compensateEventSubscriptionEntity : eventSubscriptions) {
Context.getCommandContext().getEventSubscriptionEntityManager().eventReceived(compensateEventSubscriptionEntity, null, async);
}
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class FindActiveActivityIdsCmd method execute.
public List<String> execute(CommandContext commandContext) {
if (executionId == null) {
throw new ActivitiIllegalArgumentException("executionId is null");
}
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
ExecutionEntity execution = executionEntityManager.findById(executionId);
if (execution == null) {
throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
}
return findActiveActivityIds(execution);
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class DestroyScopeOperation method run.
@Override
public void run() {
// Find the actual scope that needs to be destroyed.
// This could be the incoming execution, or the first parent execution where isScope = true
// Find parent scope execution
ExecutionEntity scopeExecution = execution.isScope() ? execution : findFirstParentScopeExecution(execution);
if (scopeExecution == null) {
throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event");
}
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
deleteAllChildExecutions(executionEntityManager, scopeExecution);
// Delete all scope tasks
TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager();
deleteAllScopeTasks(scopeExecution, taskEntityManager);
// Delete all scope jobs
TimerJobEntityManager timerJobEntityManager = commandContext.getTimerJobEntityManager();
deleteAllScopeJobs(scopeExecution, timerJobEntityManager);
// Remove variables associated with this scope
VariableInstanceEntityManager variableInstanceEntityManager = commandContext.getVariableInstanceEntityManager();
removeAllVariablesFromScope(scopeExecution, variableInstanceEntityManager);
commandContext.getHistoryManager().recordActivityEnd(scopeExecution, scopeExecution.getDeleteReason());
executionEntityManager.delete(scopeExecution);
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class EndExecutionOperation method handleProcessInstanceExecution.
protected void handleProcessInstanceExecution(ExecutionEntity processInstanceExecution) {
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
// No parent execution == process instance id
String processInstanceId = processInstanceExecution.getId();
logger.debug("No parent execution found. Verifying if process instance {} can be stopped.", processInstanceId);
ExecutionEntity superExecution = processInstanceExecution.getSuperExecution();
SubProcessActivityBehavior subProcessActivityBehavior = null;
// copy variables before destroying the ended sub process instance (call activity)
if (superExecution != null) {
FlowNode superExecutionElement = (FlowNode) superExecution.getCurrentFlowElement();
subProcessActivityBehavior = (SubProcessActivityBehavior) superExecutionElement.getBehavior();
try {
subProcessActivityBehavior.completing(superExecution, processInstanceExecution);
} catch (RuntimeException e) {
logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
throw e;
} catch (Exception e) {
logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
throw new ActivitiException("Error while completing sub process of execution " + processInstanceExecution, e);
}
}
int activeExecutions = getNumberOfActiveChildExecutionsForProcessInstance(executionEntityManager, processInstanceId);
if (activeExecutions == 0) {
logger.debug("No active executions found. Ending process instance {} ", processInstanceId);
// note the use of execution here vs processinstance execution for getting the flowelement
executionEntityManager.deleteProcessInstanceExecutionEntity(processInstanceId, execution.getCurrentFlowElement() != null ? execution.getCurrentFlowElement().getId() : null, null, false, false);
} else {
logger.debug("Active executions found. Process instance {} will not be ended.", processInstanceId);
}
Process process = ProcessDefinitionUtil.getProcess(processInstanceExecution.getProcessDefinitionId());
// Execute execution listeners for process end.
if (CollectionUtil.isNotEmpty(process.getExecutionListeners())) {
executeExecutionListeners(process, processInstanceExecution, ExecutionListener.EVENTNAME_END);
}
// and trigger execution afterwards if doing a call activity
if (superExecution != null) {
superExecution.setSubProcessInstance(null);
try {
subProcessActivityBehavior.completed(superExecution);
} catch (RuntimeException e) {
logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
throw e;
} catch (Exception e) {
logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
throw new ActivitiException("Error while completing sub process of execution " + processInstanceExecution, e);
}
}
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class CallActivityBehavior method execute.
public void execute(DelegateExecution execution) {
String finalProcessDefinitonKey = null;
if (processDefinitionExpression != null) {
finalProcessDefinitonKey = (String) processDefinitionExpression.getValue(execution);
} else {
finalProcessDefinitonKey = processDefinitonKey;
}
ProcessDefinition processDefinition = findProcessDefinition(finalProcessDefinitonKey, execution.getTenantId());
// Get model from cache
Process subProcess = ProcessDefinitionUtil.getProcess(processDefinition.getId());
if (subProcess == null) {
throw new ActivitiException("Cannot start a sub process instance. Process model " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") could not be found");
}
FlowElement initialFlowElement = subProcess.getInitialFlowElement();
if (initialFlowElement == null) {
throw new ActivitiException("No start element found for process definition " + processDefinition.getId());
}
// Do not start a process instance if the process definition is suspended
if (ProcessDefinitionUtil.isProcessDefinitionSuspended(processDefinition.getId())) {
throw new ActivitiException("Cannot start process instance. Process definition " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") is suspended");
}
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager();
ExecutionEntity executionEntity = (ExecutionEntity) execution;
CallActivity callActivity = (CallActivity) executionEntity.getCurrentFlowElement();
String businessKey = null;
if (!StringUtils.isEmpty(callActivity.getBusinessKey())) {
Expression expression = expressionManager.createExpression(callActivity.getBusinessKey());
businessKey = expression.getValue(execution).toString();
} else if (callActivity.isInheritBusinessKey()) {
ExecutionEntity processInstance = executionEntityManager.findById(execution.getProcessInstanceId());
businessKey = processInstance.getBusinessKey();
}
ExecutionEntity subProcessInstance = Context.getCommandContext().getExecutionEntityManager().createSubprocessInstance(processDefinition, executionEntity, businessKey);
Context.getCommandContext().getHistoryManager().recordSubProcessInstanceStart(executionEntity, subProcessInstance, initialFlowElement);
// process template-defined data objects
Map<String, Object> variables = processDataObjects(subProcess.getDataObjects());
if (callActivity.isInheritVariables()) {
Map<String, Object> executionVariables = execution.getVariables();
for (Map.Entry<String, Object> entry : executionVariables.entrySet()) {
variables.put(entry.getKey(), entry.getValue());
}
}
Map<String, Object> variablesFromExtensionFile = calculateInboundVariables(execution, processDefinition);
variables.putAll(variablesFromExtensionFile);
if (!variables.isEmpty()) {
initializeVariables(subProcessInstance, variables);
}
// Create the first execution that will visit all the process definition elements
ExecutionEntity subProcessInitialExecution = executionEntityManager.createChildExecution(subProcessInstance);
subProcessInitialExecution.setCurrentFlowElement(initialFlowElement);
Context.getAgenda().planContinueProcessOperation(subProcessInitialExecution);
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createProcessStartedEvent(subProcessInitialExecution, variables, false));
}
Aggregations