ALF-13474 possibility of deleting compleded workflows + explorer ui cancel action fix

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@35900 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Frederik Heremans
2012-04-30 12:07:23 +00:00
parent 2989f1b809
commit a8ecba78b1
3 changed files with 55 additions and 7 deletions

View File

@@ -53,6 +53,7 @@ import org.alfresco.service.cmr.workflow.WorkflowException;
import org.alfresco.service.cmr.workflow.WorkflowInstance;
import org.alfresco.service.cmr.workflow.WorkflowNode;
import org.alfresco.service.cmr.workflow.WorkflowPath;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.cmr.workflow.WorkflowTaskDefinition;
import org.alfresco.service.cmr.workflow.WorkflowTimer;
import org.alfresco.service.namespace.QName;
@@ -403,6 +404,50 @@ public class ActivitiWorkflowComponentTest extends AbstractActivitiComponentTest
assertNull(historicProcessInstance);
}
@Test
public void testDeleteFinishedWorkflow() throws Exception
{
WorkflowDefinition def = deployTestAdhocDefinition();
ProcessInstance processInstance = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(def.getId()));
// Validate if a workflow exists
List<WorkflowInstance> instances = workflowEngine.getActiveWorkflows(def.getId());
assertNotNull(instances);
assertEquals(1, instances.size());
assertEquals(processInstance.getId(), BPMEngineRegistry.getLocalId(instances.get(0).getId()));
WorkflowInstance instance = instances.get(0);
WorkflowTask startTask = workflowEngine.getStartTask(instance.getId());
workflowEngine.endTask(startTask.getId(), null);
WorkflowTask adhocTask = workflowEngine.getTasksForWorkflowPath(instance.getId()).get(0);
workflowEngine.endTask(adhocTask.getId(), null);
// Validate if workflow is ended and has history
instances = workflowEngine.getActiveWorkflows(def.getId());
assertNotNull(instances);
assertEquals(0, instances.size());
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInstance.getProcessInstanceId())
.singleResult();
assertNotNull(historicProcessInstance);
// Call delete method on component
workflowEngine.deleteWorkflow(instance.getId());
// Historic process instance shouldn't be present anymore
historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInstance.getProcessInstanceId())
.singleResult();
assertNull(historicProcessInstance);
}
@Test
public void testDeleteUnexistingWorkflow() throws Exception
{

View File

@@ -280,19 +280,22 @@ public class ActivitiWorkflowEngine extends BPMEngine implements WorkflowEngine
String localId = createLocalId(workflowId);
try
{
// Delete the runtime process instance if still running, this calls the end-listeners if any
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(localId).singleResult();
if(processInstance == null)
if(processInstance != null)
{
throw new WorkflowException(messageService.getMessage(ERR_DELETE_UNEXISTING_WORKFLOW));
runtimeService.deleteProcessInstance(processInstance.getId(), ActivitiConstants.DELETE_REASON_DELETED);
}
// Delete the process instance
runtimeService.deleteProcessInstance(processInstance.getId(), ActivitiConstants.DELETE_REASON_DELETED);
// Convert historic process instance
HistoricProcessInstance deletedInstance = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInstance.getId())
.processInstanceId(localId)
.singleResult();
if(deletedInstance == null) {
throw new WorkflowException(messageService.getMessage(ERR_DELETE_UNEXISTING_WORKFLOW, localId));
}
WorkflowInstance result = typeConverter.convert(deletedInstance);
// Delete the historic process instance

View File

@@ -307,7 +307,7 @@ public interface WorkflowService
public List<WorkflowInstance> cancelWorkflows(List<String> workflowIds);
/**
* Delete an "in-flight" Workflow instance
* Delete a Workflow instance.
*
* NOTE: This will force a delete, meaning that the workflow instance may not
* go through all the appropriate cancel events.