Search in sources :

Example 11 with SetProcessDefinitionVersionCmd

use of org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmdTest method testSetProcessDefinitionVersionPIIsSubExecution.

@Deployment(resources = { TEST_PROCESS_WITH_PARALLEL_GATEWAY })
public void testSetProcessDefinitionVersionPIIsSubExecution() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("forkJoin");
    Execution execution = runtimeService.createExecutionQuery().activityId("receivePayment").singleResult();
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    SetProcessDefinitionVersionCmd command = new SetProcessDefinitionVersionCmd(execution.getId(), 1);
    try {
        commandExecutor.execute(command);
        fail("ProcessEngineException expected");
    } catch (ProcessEngineException ae) {
        assertTextPresent("A process instance id is required, but the provided id '" + execution.getId() + "' points to a child execution of process instance '" + pi.getId() + "'. Please invoke the " + command.getClass().getSimpleName() + " with a root execution id.", ae.getMessage());
    }
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 12 with SetProcessDefinitionVersionCmd

use of org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmdTest method setProcessDefinitionVersion.

protected void setProcessDefinitionVersion(String processInstanceId, int newProcessDefinitionVersion) {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequiresNew();
    commandExecutor.execute(new SetProcessDefinitionVersionCmd(processInstanceId, newProcessDefinitionVersion));
}
Also used : CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd)

Example 13 with SetProcessDefinitionVersionCmd

use of org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmdTest method testMigrateJobWithMultipleDefinitionsOnActivity.

@Deployment(resources = TEST_PROCESS_TWO_JOBS)
public void testMigrateJobWithMultipleDefinitionsOnActivity() {
    // given a process instance
    ProcessInstance asyncAfterInstance = runtimeService.startProcessInstanceByKey("twoJobsProcess");
    // with an async after job
    String jobId = managementService.createJobQuery().singleResult().getId();
    managementService.executeJob(jobId);
    Job asyncAfterJob = managementService.createJobQuery().singleResult();
    // and a process instance with an before after job
    ProcessInstance asyncBeforeInstance = runtimeService.startProcessInstanceByKey("twoJobsProcess");
    Job asyncBeforeJob = managementService.createJobQuery().processInstanceId(asyncBeforeInstance.getId()).singleResult();
    // and a second deployment of the process
    org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_TWO_JOBS).deploy();
    ProcessDefinition newDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
    assertNotNull(newDefinition);
    JobDefinition asnycBeforeJobDefinition = managementService.createJobDefinitionQuery().jobConfiguration(MessageJobDeclaration.ASYNC_BEFORE).processDefinitionId(newDefinition.getId()).singleResult();
    JobDefinition asnycAfterJobDefinition = managementService.createJobDefinitionQuery().jobConfiguration(MessageJobDeclaration.ASYNC_AFTER).processDefinitionId(newDefinition.getId()).singleResult();
    assertNotNull(asnycBeforeJobDefinition);
    assertNotNull(asnycAfterJobDefinition);
    // when the process instances are migrated
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new SetProcessDefinitionVersionCmd(asyncBeforeInstance.getId(), 2));
    commandExecutor.execute(new SetProcessDefinitionVersionCmd(asyncAfterInstance.getId(), 2));
    // then the the job's definition reference should also be migrated
    Job migratedAsyncBeforeJob = managementService.createJobQuery().processInstanceId(asyncBeforeInstance.getId()).singleResult();
    assertEquals(asyncBeforeJob.getId(), migratedAsyncBeforeJob.getId());
    assertNotNull(migratedAsyncBeforeJob);
    assertEquals(asnycBeforeJobDefinition.getId(), migratedAsyncBeforeJob.getJobDefinitionId());
    Job migratedAsyncAfterJob = managementService.createJobQuery().processInstanceId(asyncAfterInstance.getId()).singleResult();
    assertEquals(asyncAfterJob.getId(), migratedAsyncAfterJob.getId());
    assertNotNull(migratedAsyncAfterJob);
    assertEquals(asnycAfterJobDefinition.getId(), migratedAsyncAfterJob.getJobDefinitionId());
    repositoryService.deleteDeployment(deployment.getId(), true);
}
Also used : CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Job(org.camunda.bpm.engine.runtime.Job) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 14 with SetProcessDefinitionVersionCmd

use of org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmdTest method testSetProcessDefinitionVersionAttachedTimer.

@Deployment(resources = TEST_PROCESS_ATTACHED_TIMER)
public void testSetProcessDefinitionVersionAttachedTimer() {
    // given a process instance
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("attachedTimer");
    // and a second deployment of the process
    org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_ATTACHED_TIMER).deploy();
    ProcessDefinition newDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
    assertNotNull(newDefinition);
    // when the process instance is migrated
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new SetProcessDefinitionVersionCmd(instance.getId(), 2));
    Job job = managementService.createJobQuery().singleResult();
    assertNotNull(job);
    assertEquals(newDefinition.getId(), job.getProcessDefinitionId());
    repositoryService.deleteDeployment(deployment.getId(), true);
}
Also used : CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 15 with SetProcessDefinitionVersionCmd

use of org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd in project camunda-bpm-platform by camunda.

the class MigrateProcessInstanceDelegate method execute.

public void execute(DelegateExecution execution) throws Exception {
    RepositoryService repoService = execution.getProcessEngineServices().getRepositoryService();
    ProcessDefinition targetDefinition = repoService.createProcessDefinitionQuery().latestVersion().singleResult();
    SetProcessDefinitionVersionCmd migrationCommand = new SetProcessDefinitionVersionCmd(execution.getProcessInstanceId(), targetDefinition.getVersion());
    Context.getProcessEngineConfiguration().getCommandExecutorTxRequired().execute(migrationCommand);
}
Also used : SetProcessDefinitionVersionCmd(org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Aggregations

SetProcessDefinitionVersionCmd (org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd)15 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)13 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)12 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)12 Deployment (org.camunda.bpm.engine.test.Deployment)12 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)9 Execution (org.camunda.bpm.engine.runtime.Execution)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 Job (org.camunda.bpm.engine.runtime.Job)4 JobDefinition (org.camunda.bpm.engine.management.JobDefinition)2 Task (org.camunda.bpm.engine.task.Task)2 RepositoryService (org.camunda.bpm.engine.RepositoryService)1 Incident (org.camunda.bpm.engine.runtime.Incident)1