use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class GetActivityInstanceCmd method execute.
public ActivityInstance execute(CommandContext commandContext) {
ensureNotNull("processInstanceId", processInstanceId);
List<ExecutionEntity> executionList = loadProcessInstance(processInstanceId, commandContext);
if (executionList.isEmpty()) {
return null;
}
checkGetActivityInstance(processInstanceId, commandContext);
List<ExecutionEntity> nonEventScopeExecutions = filterNonEventScopeExecutions(executionList);
List<ExecutionEntity> leaves = filterLeaves(nonEventScopeExecutions);
// Leaves must be ordered in a predictable way (e.g. by ID)
// in order to return a stable execution tree with every repeated invocation of this command.
// For legacy process instances, there may miss scope executions for activities that are now a scope.
// In this situation, there may be multiple scope candidates for the same instance id; which one
// can depend on the order the leaves are iterated.
orderById(leaves);
ExecutionEntity processInstance = filterProcessInstance(executionList);
if (processInstance.isEnded()) {
return null;
}
// create act instance for process instance
ActivityInstanceImpl processActInst = createActivityInstance(processInstance, processInstance.getProcessDefinition(), processInstanceId, null);
Map<String, ActivityInstanceImpl> activityInstances = new HashMap<String, ActivityInstanceImpl>();
activityInstances.put(processInstanceId, processActInst);
Map<String, TransitionInstanceImpl> transitionInstances = new HashMap<String, TransitionInstanceImpl>();
for (ExecutionEntity leaf : leaves) {
// it will not have an activity set
if (leaf.getActivity() == null) {
continue;
}
Map<ScopeImpl, PvmExecutionImpl> activityExecutionMapping = leaf.createActivityExecutionMapping();
Map<ScopeImpl, PvmExecutionImpl> scopeInstancesToCreate = new HashMap<ScopeImpl, PvmExecutionImpl>(activityExecutionMapping);
// and does not throw compensation
if (leaf.getActivityInstanceId() != null) {
if (!CompensationBehavior.isCompensationThrowing(leaf) || LegacyBehavior.isCompensationThrowing(leaf, activityExecutionMapping)) {
String parentActivityInstanceId = null;
parentActivityInstanceId = activityExecutionMapping.get(leaf.getActivity().getFlowScope()).getParentActivityInstanceId();
ActivityInstanceImpl leafInstance = createActivityInstance(leaf, leaf.getActivity(), leaf.getActivityInstanceId(), parentActivityInstanceId);
activityInstances.put(leafInstance.getId(), leafInstance);
scopeInstancesToCreate.remove(leaf.getActivity());
}
} else {
TransitionInstanceImpl transitionInstance = createTransitionInstance(leaf);
transitionInstances.put(transitionInstance.getId(), transitionInstance);
scopeInstancesToCreate.remove(leaf.getActivity());
}
LegacyBehavior.removeLegacyNonScopesFromMapping(scopeInstancesToCreate);
scopeInstancesToCreate.remove(leaf.getProcessDefinition());
// create an activity instance for each scope (including compensation throwing executions)
for (Map.Entry<ScopeImpl, PvmExecutionImpl> scopeExecutionEntry : scopeInstancesToCreate.entrySet()) {
ScopeImpl scope = scopeExecutionEntry.getKey();
PvmExecutionImpl scopeExecution = scopeExecutionEntry.getValue();
String activityInstanceId = null;
String parentActivityInstanceId = null;
activityInstanceId = scopeExecution.getParentActivityInstanceId();
parentActivityInstanceId = activityExecutionMapping.get(scope.getFlowScope()).getParentActivityInstanceId();
if (activityInstances.containsKey(activityInstanceId)) {
continue;
} else {
// regardless of the tree structure (compacted or not), the scope's activity instance id
// is the activity instance id of the parent execution and the parent activity instance id
// of that is the actual parent activity instance id
ActivityInstanceImpl scopeInstance = createActivityInstance(scopeExecution, scope, activityInstanceId, parentActivityInstanceId);
activityInstances.put(activityInstanceId, scopeInstance);
}
}
}
LegacyBehavior.repairParentRelationships(activityInstances.values(), processInstanceId);
populateChildInstances(activityInstances, transitionInstances);
return processActInst;
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class CreateAttachmentCmd method execute.
@Override
public Attachment execute(CommandContext commandContext) {
if (taskId != null) {
task = commandContext.getTaskManager().findTaskById(taskId);
} else {
ensureNotNull("taskId or processInstanceId has to be provided", this.processInstanceId);
List<ExecutionEntity> executionsByProcessInstanceId = commandContext.getExecutionManager().findExecutionsByProcessInstanceId(processInstanceId);
ensureNumberOfElements("processInstances", executionsByProcessInstanceId, 1);
processInstance = executionsByProcessInstanceId.get(0);
}
AttachmentEntity attachment = new AttachmentEntity();
attachment.setName(attachmentName);
attachment.setDescription(attachmentDescription);
attachment.setType(attachmentType);
attachment.setTaskId(taskId);
attachment.setProcessInstanceId(processInstanceId);
attachment.setUrl(url);
DbEntityManager dbEntityManger = commandContext.getDbEntityManager();
dbEntityManger.insert(attachment);
if (content != null) {
byte[] bytes = IoUtil.readInputStream(content, attachmentName);
ByteArrayEntity byteArray = new ByteArrayEntity(bytes);
dbEntityManger.insert(byteArray);
attachment.setContentId(byteArray.getId());
}
PropertyChange propertyChange = new PropertyChange("name", null, attachmentName);
if (task != null) {
commandContext.getOperationLogManager().logAttachmentOperation(UserOperationLogEntry.OPERATION_TYPE_ADD_ATTACHMENT, task, propertyChange);
} else if (processInstance != null) {
commandContext.getOperationLogManager().logAttachmentOperation(UserOperationLogEntry.OPERATION_TYPE_ADD_ATTACHMENT, processInstance, propertyChange);
}
return attachment;
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class ActivityInstanceCancellationCmd method determineSourceInstanceExecution.
protected ExecutionEntity determineSourceInstanceExecution(final CommandContext commandContext) {
ExecutionEntity processInstance = commandContext.getExecutionManager().findExecutionById(processInstanceId);
// rebuild the mapping because the execution tree changes with every iteration
ActivityExecutionTreeMapping mapping = new ActivityExecutionTreeMapping(commandContext, processInstanceId);
ActivityInstance instance = commandContext.runWithoutAuthorization(new Callable<ActivityInstance>() {
public ActivityInstance call() throws Exception {
return new GetActivityInstanceCmd(processInstanceId).execute(commandContext);
}
});
ActivityInstance instanceToCancel = findActivityInstance(instance, activityInstanceId);
EnsureUtil.ensureNotNull(NotValidException.class, describeFailure("Activity instance '" + activityInstanceId + "' does not exist"), "activityInstance", instanceToCancel);
ExecutionEntity scopeExecution = getScopeExecutionForActivityInstance(processInstance, mapping, instanceToCancel);
return scopeExecution;
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class DelegateExecutionContext method getCurrentDelegationExecution.
/**
* Returns the current delegation execution or null if the
* execution is not available.
*
* @return the current delegation execution or null if not available
*/
public static DelegateExecution getCurrentDelegationExecution() {
BpmnExecutionContext bpmnExecutionContext = Context.getBpmnExecutionContext();
ExecutionEntity executionEntity = null;
if (bpmnExecutionContext != null) {
executionEntity = bpmnExecutionContext.getExecution();
}
return executionEntity;
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class ParallelMultiInstanceActivityBehavior method onParseMigratingInstance.
@Override
public void onParseMigratingInstance(MigratingInstanceParseContext parseContext, MigratingActivityInstance migratingInstance) {
ExecutionEntity scopeExecution = migratingInstance.resolveRepresentativeExecution();
List<ActivityExecution> concurrentInActiveExecutions = scopeExecution.findInactiveChildExecutions(getInnerActivity((ActivityImpl) migratingInstance.getSourceScope()));
// them from the parse context here to avoid a validation exception
for (ActivityExecution execution : concurrentInActiveExecutions) {
for (VariableInstanceEntity variable : ((ExecutionEntity) execution).getVariablesInternal()) {
parseContext.consume(variable);
}
}
}
Aggregations