Search in sources :

Example 11 with ProcessDefinitionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity 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 12 with ProcessDefinitionEntity

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

the class SignalEventReceivedCmd method startProcessInstances.

private void startProcessInstances(List<EventSubscriptionEntity> startSignalEventSubscriptions, Map<String, ProcessDefinitionEntity> processDefinitions) {
    for (EventSubscriptionEntity signalStartEventSubscription : startSignalEventSubscriptions) {
        ProcessDefinitionEntity processDefinition = processDefinitions.get(signalStartEventSubscription.getId());
        if (processDefinition != null) {
            ActivityImpl signalStartEvent = processDefinition.findActivity(signalStartEventSubscription.getActivityId());
            PvmProcessInstance processInstance = processDefinition.createProcessInstanceForInitial(signalStartEvent);
            processInstance.start(builder.getVariables());
        }
    }
}
Also used : PvmProcessInstance(org.camunda.bpm.engine.impl.pvm.PvmProcessInstance) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 13 with ProcessDefinitionEntity

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

the class StartProcessInstanceCmd method execute.

public ProcessInstanceWithVariables execute(CommandContext commandContext) {
    ProcessDefinitionEntity processDefinition = new GetDeployedProcessDefinitionCmd(instantiationBuilder, false).execute(commandContext);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkCreateProcessInstance(processDefinition);
    }
    // Start the process instance
    ExecutionEntity processInstance = processDefinition.createProcessInstance(instantiationBuilder.getBusinessKey(), instantiationBuilder.getCaseInstanceId());
    if (instantiationBuilder.getTenantId() != null) {
        processInstance.setTenantId(instantiationBuilder.getTenantId());
    }
    final ExecutionVariableSnapshotObserver variablesListener = new ExecutionVariableSnapshotObserver(processInstance);
    processInstance.start(instantiationBuilder.getVariables());
    return new ProcessInstanceWithVariablesImpl(processInstance, variablesListener.getVariables());
}
Also used : ExecutionVariableSnapshotObserver(org.camunda.bpm.engine.impl.persistence.entity.ExecutionVariableSnapshotObserver) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ProcessInstanceWithVariablesImpl(org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 14 with ProcessDefinitionEntity

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

the class GetFormKeyCmd method execute.

public String execute(CommandContext commandContext) {
    ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
    DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache();
    ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkReadProcessDefinition(processDefinition);
    }
    Expression formKeyExpression = null;
    if (taskDefinitionKey == null) {
        // TODO: Maybe add getFormKey() to FormHandler interface to avoid the following cast
        FormHandler formHandler = processDefinition.getStartFormHandler();
        if (formHandler instanceof DelegateStartFormHandler) {
            DelegateStartFormHandler delegateFormHandler = (DelegateStartFormHandler) formHandler;
            formHandler = delegateFormHandler.getFormHandler();
        }
        // form handler (for a startForm) has always to extend the DefaultStartFormHandler!
        if (formHandler instanceof DefaultStartFormHandler) {
            DefaultStartFormHandler startFormHandler = (DefaultStartFormHandler) formHandler;
            formKeyExpression = startFormHandler.getFormKey();
        }
    } else {
        TaskDefinition taskDefinition = processDefinition.getTaskDefinitions().get(taskDefinitionKey);
        formKeyExpression = taskDefinition.getFormKey();
    }
    String formKey = null;
    if (formKeyExpression != null) {
        formKey = formKeyExpression.getExpressionText();
    }
    return formKey;
}
Also used : TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) Expression(org.camunda.bpm.engine.delegate.Expression) DefaultStartFormHandler(org.camunda.bpm.engine.impl.form.handler.DefaultStartFormHandler) FormHandler(org.camunda.bpm.engine.impl.form.handler.FormHandler) DelegateStartFormHandler(org.camunda.bpm.engine.impl.form.handler.DelegateStartFormHandler) DelegateStartFormHandler(org.camunda.bpm.engine.impl.form.handler.DelegateStartFormHandler) DeploymentCache(org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache) DefaultStartFormHandler(org.camunda.bpm.engine.impl.form.handler.DefaultStartFormHandler) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 15 with ProcessDefinitionEntity

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

the class GetIdentityLinksForProcessDefinitionCmd method execute.

@SuppressWarnings({ "unchecked", "rawtypes" })
public List<IdentityLink> execute(CommandContext commandContext) {
    ProcessDefinitionEntity processDefinition = Context.getCommandContext().getProcessDefinitionManager().findLatestProcessDefinitionById(processDefinitionId);
    ensureNotNull("Cannot find process definition with id " + processDefinitionId, "processDefinition", processDefinition);
    List<IdentityLink> identityLinks = (List) processDefinition.getIdentityLinks();
    return identityLinks;
}
Also used : List(java.util.List) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) IdentityLink(org.camunda.bpm.engine.task.IdentityLink)

Aggregations

ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)75 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)15 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)14 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)13 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)10 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)10 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)8 ArrayList (java.util.ArrayList)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)4 Deployment (org.camunda.bpm.engine.test.Deployment)4 InputStream (java.io.InputStream)3 ProcessInstanceModificationBuilderImpl (org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl)3 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)3 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)3 IncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity)3 ProcessInstanceWithVariablesImpl (org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl)3 Element (org.camunda.bpm.engine.impl.util.xml.Element)3 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2