Hi there, a code issue:
Bonita Studio 6.3.7, Java 1.7.0.67, Windows 8.1
I’m trying to delete some processes as details … click here …
but it’s not working…telling me the system will not process the request as follows:
2014-10-25 15:12:37 org.bonitasoft
SEVERE: Disable and Delete Process: 11 Disable Process Error: org.bonitasoft.engine.core.process.definition.exception.SProcessDisablementException: Process Pain Point Rankings with version 1.1 is already disabled
2014-10-25 15:12:37 org.bonitasoft
SEVERE: Disable and Delete Process: 12 Delete Process Instances:
2014-10-25 15:12:37 org.bonitasoft
SEVERE: Disable and Delete Process: 12.1 Delete Process Instances:
2014-10-25 15:12:37 org.bonitasoft
SEVERE: Disable and Delete Process: 13 processAPI.deleteProcessInstances Error: org.bonitasoft.engine.transaction.STransactionCreationException: We do not support nested calls to the transaction service.
2014-10-25 15:12:37 org.bonitasoft
SEVERE: Disable and Delete Process: 14 Delete Archived Process Instances:
2014-10-25 15:12:37 org.bonitasoft
SEVERE: Disable and Delete Process: 14.1 Delete Archived Process Instances:
2014-10-25 15:12:37 org.bonitasoft
SEVERE: Disable and Delete Process: 14.2 Delete Archived Process Instances:
2014-10-25 15:12:37 org.bonitasoft
SEVERE: Disable and Delete Process: Trace End:
I’m only doing what the Javadoc indicates…
How do I use deleteProcessInstances to delete processes?
My code is as follows:
Code Summary:
In GROOVY
- prepare and print out existing processes
- disable the process
- delete the processes - using a modified while as groovy does not support do{…}while
- delete the archived processes - using a modified while as groovy does not support do{…}while
The code:
import org.bonitasoft.engine.api.ProcessAPI;
import org.bonitasoft.engine.api.ProcessRuntimeAPI;
import org.bonitasoft.engine.bpm.flownode.ActivityInstance;
import org.bonitasoft.engine.bpm.flownode.HumanTaskInstance;
import org.bonitasoft.engine.bpm.flownode.HumanTaskInstanceSearchDescriptor;
import org.bonitasoft.engine.bpm.flownode.TaskInstance;
import org.bonitasoft.engine.bpm.flownode.UserTaskInstance;
import org.bonitasoft.engine.bpm.process.ProcessDefinition;
import org.bonitasoft.engine.bpm.process.ProcessDeploymentInfo;
import org.bonitasoft.engine.bpm.process.ProcessDeploymentInfoCriterion;
import org.bonitasoft.engine.bpm.process.ProcessDeploymentInfoSearchDescriptor;
import org.bonitasoft.engine.bpm.process.ProcessInstance;
import org.bonitasoft.engine.search.SearchOptions;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.engine.search.SearchResult;
import java.util.logging.Logger;
Logger logger = Logger.getLogger(“org.bonitasoft”);
String thisTrace = "Disable and Delete Process: "
logger.severe(thisTrace+"Trace Start: ");
ProcessAPI processAPI = apiAccessor.getProcessAPI();
int counter;
int stopAfter = 100;
//prepare and print out existing processes
String monitoringProcess = “Pain Point Rankings”;
SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(0, 500);
searchOptionsBuilder.filter(HumanTaskInstanceSearchDescriptor.NAME, monitoringProcess);
SearchOptions searchOptions = searchOptionsBuilder.done();
SearchResult searchHumanTaskInstancesT = processAPI.searchHumanTaskInstances(searchOptions);
logger.severe(thisTrace+"01 searchHumanTaskInstancesT: Count: "+searchHumanTaskInstancesT.getCount());
logger.severe(thisTrace+"02 searchHumanTaskInstancesT: Result: "+searchHumanTaskInstancesT.getResult());
try{
// disable the process
Long delprocessDefinitionId=4812640494579983314;
long nbDeleted = 0;
try{
processAPI.disableProcess(delprocessDefinitionId);
}
catch(Exception e9){
logger.severe(thisTrace+"11 Disable Process Error: "+e9.message);
}
// delete the processes
counter = 0;
while(true){
logger.severe(thisTrace+"12 Delete Process Instances: ");
try{
logger.severe(thisTrace+"12.1 Delete Process Instances: ");
nbDeleted = processAPI.deleteProcessInstances(delprocessDefinitionId, 0, 100);
logger.severe(thisTrace+"12.2 Delete Process Instances: ");
}
catch(Exception e8){
logger.severe(thisTrace+"13 processAPI.deleteProcessInstances Error: "+e8.message);
}
finally{
if (nbDeleted <= 0) break;
counter++;
if (counter > stopAfter) break;
}
}
// delete the archived processes
counter = 0;
while(true){
logger.severe(thisTrace+"14 Delete Archived Process Instances: ");
try{
logger.severe(thisTrace+"14.1 Delete Archived Process Instances: ");
nbDeleted = processAPI.deleteArchivedProcessInstances(delprocessDefinitionId, 0, 100);
logger.severe(thisTrace+"14.2 Delete Archived Process Instances: ");
}
catch(Exception e7){
logger.severe(thisTrace+"15 processAPI.deleteArchivedProcessInstances Error: "+e7.message);
}
finally{
if (nbDeleted <= 0) break;
counter++;
if (counter > stopAfter) break;
}
}
}
catch (Exception e0) {
logger.severe(thisTrace+"20 Exception e0: "+e0.toString());
}
logger.severe(thisTrace+"Trace End: ");