use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class SetProcessDefinitionVersionCmd method execute.
public Void execute(CommandContext commandContext) {
// check that the new process definition is just another version of the same
// process definition that the process instance is using
ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();
ExecutionEntity processInstance = executionManager.findById(processInstanceId);
if (processInstance == null) {
throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
} else if (!processInstance.isProcessInstanceType()) {
throw new ActivitiIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'" + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
}
DeploymentManager deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentManager();
ProcessDefinition currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(processInstance.getProcessDefinitionId());
ProcessDefinition newProcessDefinition = deploymentCache.findDeployedProcessDefinitionByKeyAndVersionAndTenantId(currentProcessDefinition.getKey(), processDefinitionVersion, currentProcessDefinition.getTenantId());
validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition);
// switch the historic process instance to the new process definition version
commandContext.getHistoryManager().recordProcessDefinitionChange(processInstanceId, newProcessDefinition.getId());
// switch all sub-executions of the process instance to the new process definition version
Collection<ExecutionEntity> childExecutions = executionManager.findChildExecutionsByProcessInstanceId(processInstanceId);
for (ExecutionEntity executionEntity : childExecutions) {
validateAndSwitchVersionOfExecution(commandContext, executionEntity, newProcessDefinition);
}
return null;
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class SetProcessInstanceBusinessKeyCmd method execute.
public Void execute(CommandContext commandContext) {
ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();
ExecutionEntity processInstance = executionManager.findById(processInstanceId);
if (processInstance == null) {
throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
} else if (!processInstance.isProcessInstanceType()) {
throw new ActivitiIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'" + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
}
executionManager.updateProcessInstanceBusinessKey(processInstance, businessKey);
return null;
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class CancelEndEventActivityBehavior method execute.
@Override
public void execute(DelegateExecution execution) {
ExecutionEntity executionEntity = (ExecutionEntity) execution;
CommandContext commandContext = Context.getCommandContext();
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
// find cancel boundary event:
ExecutionEntity parentScopeExecution = null;
ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(executionEntity.getParentId());
while (currentlyExaminedExecution != null && parentScopeExecution == null) {
if (currentlyExaminedExecution.getCurrentFlowElement() instanceof SubProcess) {
parentScopeExecution = currentlyExaminedExecution;
SubProcess subProcess = (SubProcess) currentlyExaminedExecution.getCurrentFlowElement();
if (subProcess.getLoopCharacteristics() != null) {
ExecutionEntity miExecution = parentScopeExecution.getParent();
FlowElement miElement = miExecution.getCurrentFlowElement();
if (miElement != null && miElement.getId().equals(subProcess.getId())) {
parentScopeExecution = miExecution;
}
}
} else {
currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId());
}
}
if (parentScopeExecution == null) {
throw new ActivitiException("No sub process execution found for cancel end event " + executionEntity.getCurrentActivityId());
}
SubProcess subProcess = (SubProcess) parentScopeExecution.getCurrentFlowElement();
BoundaryEvent cancelBoundaryEvent = null;
if (CollectionUtil.isNotEmpty(subProcess.getBoundaryEvents())) {
for (BoundaryEvent boundaryEvent : subProcess.getBoundaryEvents()) {
if (CollectionUtil.isNotEmpty(boundaryEvent.getEventDefinitions()) && boundaryEvent.getEventDefinitions().get(0) instanceof CancelEventDefinition) {
cancelBoundaryEvent = boundaryEvent;
break;
}
}
}
if (cancelBoundaryEvent == null) {
throw new ActivitiException("Could not find cancel boundary event for cancel end event " + executionEntity.getCurrentActivityId());
}
ExecutionEntity newParentScopeExecution = null;
currentlyExaminedExecution = executionEntityManager.findById(parentScopeExecution.getParentId());
while (currentlyExaminedExecution != null && newParentScopeExecution == null) {
if (currentlyExaminedExecution.isScope()) {
newParentScopeExecution = currentlyExaminedExecution;
} else {
currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId());
}
}
if (newParentScopeExecution == null) {
throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event " + cancelBoundaryEvent.getId());
}
ScopeUtil.createCopyOfSubProcessExecutionForCompensation(parentScopeExecution);
if (subProcess.getLoopCharacteristics() != null) {
List<? extends ExecutionEntity> multiInstanceExecutions = parentScopeExecution.getExecutions();
List<ExecutionEntity> executionsToDelete = new ArrayList<ExecutionEntity>();
for (ExecutionEntity multiInstanceExecution : multiInstanceExecutions) {
if (!multiInstanceExecution.getId().equals(parentScopeExecution.getId())) {
ScopeUtil.createCopyOfSubProcessExecutionForCompensation(multiInstanceExecution);
// end all executions in the scope of the transaction
executionsToDelete.add(multiInstanceExecution);
deleteChildExecutions(multiInstanceExecution, executionEntity, commandContext, DeleteReason.TRANSACTION_CANCELED);
}
}
for (ExecutionEntity executionEntityToDelete : executionsToDelete) {
deleteChildExecutions(executionEntityToDelete, executionEntity, commandContext, DeleteReason.TRANSACTION_CANCELED);
}
}
// The current activity is finished (and will not be ended in the deleteChildExecutions)
commandContext.getHistoryManager().recordActivityEnd(executionEntity, null);
// set new parent for boundary event execution
executionEntity.setParent(newParentScopeExecution);
executionEntity.setCurrentFlowElement(cancelBoundaryEvent);
// end all executions in the scope of the transaction
deleteChildExecutions(parentScopeExecution, executionEntity, commandContext, DeleteReason.TRANSACTION_CANCELED);
commandContext.getHistoryManager().recordActivityEnd(parentScopeExecution, DeleteReason.TRANSACTION_CANCELED);
Context.getAgenda().planTriggerExecutionOperation(executionEntity);
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class EventSubProcessMessageStartEventActivityBehavior method trigger.
@Override
public void trigger(DelegateExecution execution, String triggerName, Object triggerData) {
CommandContext commandContext = Context.getCommandContext();
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
ExecutionEntity executionEntity = (ExecutionEntity) execution;
StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement();
if (startEvent.isInterrupting()) {
List<ExecutionEntity> childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(executionEntity.getParentId());
for (ExecutionEntity childExecution : childExecutions) {
if (!childExecution.getId().equals(executionEntity.getId())) {
executionEntityManager.cancelExecutionAndRelatedData(childExecution, DeleteReason.EVENT_SUBPROCESS_INTERRUPTING + "(" + startEvent.getId() + ")");
}
}
}
// Should we use triggerName and triggerData, because message name expression can change?
String messageName = messageExecutionContext.getMessageName(execution);
EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager();
List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions();
for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
if (eventSubscription instanceof MessageEventSubscriptionEntity && eventSubscription.getEventName().equals(messageName)) {
eventSubscriptionEntityManager.delete(eventSubscription);
}
}
executionEntity.setCurrentFlowElement((SubProcess) executionEntity.getCurrentFlowElement().getParentContainer());
executionEntity.setScope(true);
ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(executionEntity);
outgoingFlowExecution.setCurrentFlowElement(startEvent);
leave(outgoingFlowExecution);
}
use of org.activiti.engine.impl.persistence.entity.ExecutionEntityManager in project Activiti by Activiti.
the class InclusiveGatewayActivityBehavior method executeInclusiveGatewayLogic.
protected void executeInclusiveGatewayLogic(ExecutionEntity execution) {
CommandContext commandContext = Context.getCommandContext();
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
lockFirstParentScope(execution);
Collection<ExecutionEntity> allExecutions = executionEntityManager.findChildExecutionsByProcessInstanceId(execution.getProcessInstanceId());
Iterator<ExecutionEntity> executionIterator = allExecutions.iterator();
boolean oneExecutionCanReachGateway = false;
while (!oneExecutionCanReachGateway && executionIterator.hasNext()) {
ExecutionEntity executionEntity = executionIterator.next();
if (!executionEntity.getActivityId().equals(execution.getCurrentActivityId())) {
boolean canReachGateway = ExecutionGraphUtil.isReachable(execution.getProcessDefinitionId(), executionEntity.getActivityId(), execution.getCurrentActivityId());
if (canReachGateway) {
oneExecutionCanReachGateway = true;
}
} else if (executionEntity.getActivityId().equals(execution.getCurrentActivityId()) && executionEntity.isActive()) {
// Special case: the execution has reached the inc gw, but the operation hasn't been executed yet for that execution
oneExecutionCanReachGateway = true;
}
}
// If no execution can reach the gateway, the gateway activates and executes fork behavior
if (!oneExecutionCanReachGateway) {
logger.debug("Inclusive gateway cannot be reached by any execution and is activated");
// Kill all executions here (except the incoming)
Collection<ExecutionEntity> executionsInGateway = executionEntityManager.findInactiveExecutionsByActivityIdAndProcessInstanceId(execution.getCurrentActivityId(), execution.getProcessInstanceId());
for (ExecutionEntity executionEntityInGateway : executionsInGateway) {
if (!executionEntityInGateway.getId().equals(execution.getId())) {
commandContext.getHistoryManager().recordActivityEnd(executionEntityInGateway, null);
executionEntityManager.deleteExecutionAndRelatedData(executionEntityInGateway, null);
}
}
// Leave
commandContext.getAgenda().planTakeOutgoingSequenceFlowsOperation(execution, true);
}
}
Aggregations