Skip to content

Commit

Permalink
chore(merge): release-10.0.0 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bonita-ci committed Mar 18, 2024
2 parents d105312 + a02616d commit d39e054
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.bonitasoft.engine.bpm.flownode.HumanTaskInstance;
import org.bonitasoft.engine.bpm.process.ActivationState;
import org.bonitasoft.engine.bpm.process.ArchivedProcessInstance;
import org.bonitasoft.engine.bpm.process.ArchivedProcessInstancesSearchDescriptor;
import org.bonitasoft.engine.bpm.process.DesignProcessDefinition;
import org.bonitasoft.engine.bpm.process.InvalidProcessDefinitionException;
import org.bonitasoft.engine.bpm.process.Problem;
Expand Down Expand Up @@ -716,18 +717,33 @@ public void disableAndDeleteProcess(final ProcessDefinition processDefinition) t
}

public void disableAndDeleteProcess(final long processDefinitionId) throws BonitaException {
getProcessAPI().disableProcess(processDefinitionId);
var processApi = getProcessAPI();
processApi.disableProcess(processDefinitionId);

// Delete all process instances
long nbDeletedProcessInstances;
do {
nbDeletedProcessInstances = getProcessAPI().deleteProcessInstances(processDefinitionId, 0, 100);
nbDeletedProcessInstances = processApi.deleteProcessInstances(processDefinitionId, 0, 100);
} while (nbDeletedProcessInstances > 0);

// Search all root archived process instances ids for the given processDefinition
var rootArchivedProcessInstancesIds = processApi
.searchArchivedProcessInstancesInAllStates(new SearchOptionsBuilder(0, Integer.MAX_VALUE)
.filter(ArchivedProcessInstancesSearchDescriptor.PROCESS_DEFINITION_ID, processDefinitionId)
.differentFrom(ArchivedProcessInstancesSearchDescriptor.CALLER_ID, "-1")
.done())
.getResult()
.stream()
.map(ArchivedProcessInstance::getRootProcessInstanceId)
.collect(Collectors.toList());
if (!rootArchivedProcessInstancesIds.isEmpty()) {
processApi.deleteArchivedProcessInstancesInAllStates(rootArchivedProcessInstancesIds);
}

// Delete all archived process instances
long nbDeletedArchivedProcessInstances;
do {
nbDeletedArchivedProcessInstances = getProcessAPI().deleteArchivedProcessInstances(processDefinitionId, 0,
nbDeletedArchivedProcessInstances = processApi.deleteArchivedProcessInstances(processDefinitionId, 0,
100);
} while (nbDeletedArchivedProcessInstances > 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ public void deleteProcessDefinition(final long processDefinitionId) throws Delet
final boolean hasOpenProcessInstances = searchProcessInstances(getServiceAccessor(), searchOptions)
.getCount() > 0;
checkIfItIsPossibleToDeleteProcessInstance(processDefinitionId, hasOpenProcessInstances);
final boolean hasArchivedProcessInstances = searchArchivedProcessInstances(searchOptions).getCount() > 0;
final boolean hasArchivedProcessInstances = searchArchivedProcessInstancesInAllStates(searchOptions)
.getCount() > 0;
checkIfItIsPossibleToDeleteProcessInstance(processDefinitionId, hasArchivedProcessInstances);

removeAllCategoriesFromProcessDefinition(processDefinitionId);
Expand Down

0 comments on commit d39e054

Please sign in to comment.