Search in sources :

Example 6 with ExecutionEntity

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;
}
Also used : HashMap(java.util.HashMap) PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) TransitionInstanceImpl(org.camunda.bpm.engine.impl.persistence.entity.TransitionInstanceImpl) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ActivityInstanceImpl(org.camunda.bpm.engine.impl.persistence.entity.ActivityInstanceImpl) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with ExecutionEntity

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;
}
Also used : PropertyChange(org.camunda.bpm.engine.impl.persistence.entity.PropertyChange) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) AttachmentEntity(org.camunda.bpm.engine.impl.persistence.entity.AttachmentEntity) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)

Example 8 with ExecutionEntity

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;
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ActivityExecutionTreeMapping(org.camunda.bpm.engine.impl.ActivityExecutionTreeMapping) NotValidException(org.camunda.bpm.engine.exception.NotValidException)

Example 9 with ExecutionEntity

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;
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) BpmnExecutionContext(org.camunda.bpm.engine.impl.context.BpmnExecutionContext)

Example 10 with 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);
        }
    }
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ActivityExecution(org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution) VariableInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity)

Aggregations

ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)170 Deployment (org.camunda.bpm.engine.test.Deployment)42 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)18 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)17 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)16 Execution (org.camunda.bpm.engine.runtime.Execution)14 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)13 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)12 Task (org.camunda.bpm.engine.task.Task)12 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)10 ArrayList (java.util.ArrayList)9 VariableInstanceEntity (org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity)9 Test (org.junit.Test)9 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)7 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)7 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)7 ProcessDefinitionImpl (org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl)6 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)5