Skip to content

Commit

Permalink
feat(engine): add support for externallyTerminated for modification
Browse files Browse the repository at this point in the history
Related to CAM-11131
  • Loading branch information
mboskamp committed Dec 2, 2019
1 parent 8bf3d8b commit bcc42f3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public ProcessInstanceModificationBuilder cancelActivityInstance(String activity
return cancelActivityInstance(activityInstanceId, false);
}

@Override
public ProcessInstanceModificationBuilder cancelActivityInstance(String activityInstanceId, boolean externallyTerminated) {
ensureNotNull(NotValidException.class, "activityInstanceId", activityInstanceId);
this.externallyTerminated = externallyTerminated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ public interface ProcessInstanceModificationBuilder extends
*/
ProcessInstanceModificationBuilder cancelActivityInstance(String activityInstanceId);

/**
* <p><i>Submits the instruction:</i></p>
*
* <p>Cancel an activity instance in a process. If this instance has child activity instances
* (e.g. in a subprocess instance), these children, their grandchildren, etc. are cancelled as well.</p>
*
* <p>Process instance cancellation will propagate upward, removing any parent process instances that are
* only waiting on the cancelled process to complete.</p>
*
* <p>All canceled activity instances will be marked as terminated internally or externally to indicate if
* the cancelation was triggered from internal or external context. (internal = engine, external = e.g. API call)</p>
*
* @param activityInstanceId the id of the activity instance to cancel
* @param externallyTerminated indicator if deletion triggered from external context, for instance API call
*/
ProcessInstanceModificationBuilder cancelActivityInstance(String activityInstanceId, boolean externallyTerminated);

/**
* <p><i>Submits the instruction:</i></p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.history.HistoricProcessInstance;
import org.camunda.bpm.engine.repository.Deployment;
import org.camunda.bpm.engine.runtime.ActivityInstance;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.camunda.bpm.engine.test.RequiredHistoryLevel;
Expand Down Expand Up @@ -141,6 +142,66 @@ public void shouldNotCascadeStateFromProcessDownDeletion() {
assertHistoricProcessInstances();
}

@Test
public void shouldNotCascadeStateFromSubprocessUpCancelation() {
// given
runtimeService.startProcessInstanceByKey("process");
ProcessInstance subProcess = runtimeService.createProcessInstanceQuery().processDefinitionKey("subProcess").singleResult();
ActivityInstance activityInstance = runtimeService.getActivityInstance(subProcess.getId());
externallyTerminated = false;

// when
runtimeService.createProcessInstanceModification(subProcess.getId()).cancelActivityInstance(activityInstance.getId(), externallyTerminated).execute();

// then
assertHistoricProcessInstances();
}

@Test
public void shouldNotCascadeStateFromProcessDownCancelation() {
// given
runtimeService.startProcessInstanceByKey("process");
ProcessInstance process = runtimeService.createProcessInstanceQuery().processDefinitionKey("process").singleResult();
ActivityInstance activityInstance = runtimeService.getActivityInstance(process.getId());
externallyTerminated = false;

// when
runtimeService.createProcessInstanceModification(process.getId()).cancelActivityInstance(activityInstance.getId(), externallyTerminated).execute();

// then
assertHistoricProcessInstances();
}

@Test
public void shouldCascadeStateFromSubprocessUpCancelation() {
// given
runtimeService.startProcessInstanceByKey("process");
ProcessInstance subProcess = runtimeService.createProcessInstanceQuery().processDefinitionKey("subProcess").singleResult();
ActivityInstance activityInstance = runtimeService.getActivityInstance(subProcess.getId());
externallyTerminated = true;

// when
runtimeService.createProcessInstanceModification(subProcess.getId()).cancelActivityInstance(activityInstance.getId(), externallyTerminated).execute();

// then
assertHistoricProcessInstances();
}

@Test
public void shouldCascadeStateFromProcessDownCancelation() {
// given
runtimeService.startProcessInstanceByKey("process");
ProcessInstance process = runtimeService.createProcessInstanceQuery().processDefinitionKey("process").singleResult();
ActivityInstance activityInstance = runtimeService.getActivityInstance(process.getId());
externallyTerminated = true;

// when
runtimeService.createProcessInstanceModification(process.getId()).cancelActivityInstance(activityInstance.getId(), externallyTerminated).execute();

// then
assertHistoricProcessInstances();
}

protected void assertHistoricProcessInstances() {
List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().list();
assertThat(historicProcessInstances.size()).isEqualTo(2);
Expand Down

0 comments on commit bcc42f3

Please sign in to comment.