Search in sources :

Example 1 with ExecutionManager

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager in project camunda-bpm-platform by camunda.

the class FindActiveActivityIdsCmd method execute.

public List<String> execute(CommandContext commandContext) {
    ensureNotNull("executionId", executionId);
    // fetch execution
    ExecutionManager executionManager = commandContext.getExecutionManager();
    ExecutionEntity execution = executionManager.findExecutionById(executionId);
    ensureNotNull("execution " + executionId + " doesn't exist", "execution", execution);
    checkGetActivityIds(execution, commandContext);
    // fetch active activities
    return execution.findActiveActivityIds();
}
Also used : ExecutionManager(org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)

Example 2 with ExecutionManager

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmd method execute.

public Void execute(CommandContext commandContext) {
    ProcessEngineConfigurationImpl configuration = commandContext.getProcessEngineConfiguration();
    // check that the new process definition is just another version of the same
    // process definition that the process instance is using
    ExecutionManager executionManager = commandContext.getExecutionManager();
    final ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);
    if (processInstance == null) {
        throw new ProcessEngineException("No process instance found for id = '" + processInstanceId + "'.");
    } else if (!processInstance.isProcessInstanceExecution()) {
        throw new ProcessEngineException("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.");
    }
    ProcessDefinitionImpl currentProcessDefinitionImpl = processInstance.getProcessDefinition();
    DeploymentCache deploymentCache = configuration.getDeploymentCache();
    ProcessDefinitionEntity currentProcessDefinition;
    if (currentProcessDefinitionImpl instanceof ProcessDefinitionEntity) {
        currentProcessDefinition = (ProcessDefinitionEntity) currentProcessDefinitionImpl;
    } else {
        currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(currentProcessDefinitionImpl.getId());
    }
    ProcessDefinitionEntity newProcessDefinition = deploymentCache.findDeployedProcessDefinitionByKeyVersionAndTenantId(currentProcessDefinition.getKey(), processDefinitionVersion, currentProcessDefinition.getTenantId());
    validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition);
    HistoryLevel historyLevel = configuration.getHistoryLevel();
    if (historyLevel.isHistoryEventProduced(HistoryEventTypes.PROCESS_INSTANCE_UPDATE, processInstance)) {
        HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {

            @Override
            public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
                return producer.createProcessInstanceUpdateEvt(processInstance);
            }
        });
    }
    // switch all sub-executions of the process instance to the new process definition version
    List<ExecutionEntity> childExecutions = executionManager.findExecutionsByProcessInstanceId(processInstanceId);
    for (ExecutionEntity executionEntity : childExecutions) {
        validateAndSwitchVersionOfExecution(commandContext, executionEntity, newProcessDefinition);
    }
    // switch all jobs to the new process definition version
    List<JobEntity> jobs = commandContext.getJobManager().findJobsByProcessInstanceId(processInstanceId);
    List<JobDefinitionEntity> currentJobDefinitions = commandContext.getJobDefinitionManager().findByProcessDefinitionId(currentProcessDefinition.getId());
    List<JobDefinitionEntity> newVersionJobDefinitions = commandContext.getJobDefinitionManager().findByProcessDefinitionId(newProcessDefinition.getId());
    Map<String, String> jobDefinitionMapping = getJobDefinitionMapping(currentJobDefinitions, newVersionJobDefinitions);
    for (JobEntity jobEntity : jobs) {
        switchVersionOfJob(jobEntity, newProcessDefinition, jobDefinitionMapping);
    }
    // switch all incidents to the new process definition version
    List<IncidentEntity> incidents = commandContext.getIncidentManager().findIncidentsByProcessInstance(processInstanceId);
    for (IncidentEntity incidentEntity : incidents) {
        switchVersionOfIncident(commandContext, incidentEntity, newProcessDefinition);
    }
    // add an entry to the op log
    PropertyChange change = new PropertyChange("processDefinitionVersion", currentProcessDefinition.getVersion(), processDefinitionVersion);
    commandContext.getOperationLogManager().logProcessInstanceOperation(UserOperationLogEntry.OPERATION_TYPE_MODIFY_PROCESS_INSTANCE, processInstanceId, null, null, Collections.singletonList(change));
    return null;
}
Also used : ExecutionManager(org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager) PropertyChange(org.camunda.bpm.engine.impl.persistence.entity.PropertyChange) ProcessDefinitionImpl(org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl) IncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity) HistoryEventProducer(org.camunda.bpm.engine.impl.history.producer.HistoryEventProducer) HistoryEvent(org.camunda.bpm.engine.impl.history.event.HistoryEvent) JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) HistoryLevel(org.camunda.bpm.engine.impl.history.HistoryLevel) HistoryEventProcessor(org.camunda.bpm.engine.impl.history.event.HistoryEventProcessor) DeploymentCache(org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 3 with ExecutionManager

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager in project camunda-bpm-platform by camunda.

the class SignalEventReceivedCmd method sendSignalToExecution.

protected void sendSignalToExecution(CommandContext commandContext, String signalName, String executionId) {
    ExecutionManager executionManager = commandContext.getExecutionManager();
    ExecutionEntity execution = executionManager.findExecutionById(executionId);
    ensureNotNull("Cannot find execution with id '" + executionId + "'", "execution", execution);
    EventSubscriptionManager eventSubscriptionManager = commandContext.getEventSubscriptionManager();
    List<EventSubscriptionEntity> signalEvents = eventSubscriptionManager.findSignalEventSubscriptionsByNameAndExecution(signalName, executionId);
    ensureNotEmpty("Execution '" + executionId + "' has not subscribed to a signal event with name '" + signalName + "'.", signalEvents);
    checkAuthorizationOfCatchSignals(commandContext, signalEvents);
    notifyExecutions(signalEvents);
}
Also used : EventSubscriptionManager(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionManager) ExecutionManager(org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 4 with ExecutionManager

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager in project camunda-bpm-platform by camunda.

the class ModifyProcessInstanceCmd method execute.

@Override
public Void execute(CommandContext commandContext) {
    String processInstanceId = builder.getProcessInstanceId();
    ExecutionManager executionManager = commandContext.getExecutionManager();
    ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);
    ensureProcessInstanceExist(processInstanceId, processInstance);
    checkUpdateProcessInstance(processInstance, commandContext);
    processInstance.setPreserveScope(true);
    List<AbstractProcessInstanceModificationCommand> instructions = builder.getModificationOperations();
    checkCancellation(commandContext);
    for (int i = 0; i < instructions.size(); i++) {
        AbstractProcessInstanceModificationCommand instruction = instructions.get(i);
        LOG.debugModificationInstruction(processInstanceId, i + 1, instruction.describe());
        instruction.setSkipCustomListeners(builder.isSkipCustomListeners());
        instruction.setSkipIoMappings(builder.isSkipIoMappings());
        instruction.execute(commandContext);
    }
    processInstance = executionManager.findExecutionById(processInstanceId);
    if (!processInstance.hasChildren()) {
        if (processInstance.getActivity() == null) {
            // process instance was cancelled
            checkDeleteProcessInstance(processInstance, commandContext);
            deletePropagate(processInstance, builder.getModificationReason(), builder.isSkipCustomListeners(), builder.isSkipIoMappings());
        } else if (processInstance.isEnded()) {
            // process instance has ended regularly
            processInstance.propagateEnd();
        }
    }
    if (writeOperationLog) {
        commandContext.getOperationLogManager().logProcessInstanceOperation(getLogEntryOperation(), processInstanceId, null, null, Collections.singletonList(PropertyChange.EMPTY_CHANGE));
    }
    return null;
}
Also used : ExecutionManager(org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)

Example 5 with ExecutionManager

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager in project camunda-bpm-platform by camunda.

the class AbstractDeleteProcessInstanceCmd method deleteProcessInstance.

protected void deleteProcessInstance(final CommandContext commandContext, String processInstanceId, final String deleteReason, final boolean skipCustomListeners, boolean externallyTerminated, final boolean skipIoMappings, boolean skipSubprocesses) {
    ensureNotNull(BadUserRequestException.class, "processInstanceId is null", "processInstanceId", processInstanceId);
    // fetch process instance
    ExecutionManager executionManager = commandContext.getExecutionManager();
    final ExecutionEntity execution = executionManager.findExecutionById(processInstanceId);
    ensureNotNull(BadUserRequestException.class, "No process instance found for id '" + processInstanceId + "'", "processInstance", execution);
    checkDeleteProcessInstance(execution, commandContext);
    // delete process instance
    commandContext.getExecutionManager().deleteProcessInstance(processInstanceId, deleteReason, false, skipCustomListeners, externallyTerminated, skipIoMappings, skipSubprocesses);
    if (skipSubprocesses) {
        List<ProcessInstance> superProcesslist = commandContext.getProcessEngineConfiguration().getRuntimeService().createProcessInstanceQuery().superProcessInstanceId(processInstanceId).list();
        triggerHistoryEvent(superProcesslist);
    }
    final ExecutionEntity superExecution = execution.getSuperExecution();
    if (superExecution != null) {
        commandContext.runWithoutAuthorization(new Callable<Void>() {

            public Void call() {
                ProcessInstanceModificationBuilderImpl builder = (ProcessInstanceModificationBuilderImpl) new ProcessInstanceModificationBuilderImpl(commandContext, superExecution.getProcessInstanceId(), deleteReason).cancelActivityInstance(superExecution.getActivityInstanceId());
                builder.execute(false, skipCustomListeners, skipIoMappings);
                return null;
            }
        });
    }
    // create user operation log
    commandContext.getOperationLogManager().logProcessInstanceOperation(UserOperationLogEntry.OPERATION_TYPE_DELETE, processInstanceId, null, null, Collections.singletonList(PropertyChange.EMPTY_CHANGE));
}
Also used : ExecutionManager(org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessInstanceModificationBuilderImpl(org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl)

Aggregations

ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)5 ExecutionManager (org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 ProcessInstanceModificationBuilderImpl (org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl)1 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)1 HistoryLevel (org.camunda.bpm.engine.impl.history.HistoryLevel)1 HistoryEvent (org.camunda.bpm.engine.impl.history.event.HistoryEvent)1 HistoryEventProcessor (org.camunda.bpm.engine.impl.history.event.HistoryEventProcessor)1 HistoryEventProducer (org.camunda.bpm.engine.impl.history.producer.HistoryEventProducer)1 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)1 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)1 EventSubscriptionManager (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionManager)1 IncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity)1 JobDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)1 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)1 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)1 PropertyChange (org.camunda.bpm.engine.impl.persistence.entity.PropertyChange)1 ProcessDefinitionImpl (org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl)1 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1