Merged BRANCHES/DEV/BELARUS/HEAD_2010_08_04 to HEAD:

21652: ALF-3898 : F68 REST API to cancel/delete a workflow instance

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21672 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2010-08-06 21:33:08 +00:00
parent 5a053460df
commit d4f999b227
5 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.workflow;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* @author unknown
* @since 3.4
*
*/
public class WorkflowInstanceDelete extends AbstractWorkflowWebscript
{
public static final String PARAM_FORCED = "forced";
@Override
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache)
{
Map<String, String> params = req.getServiceMatch().getTemplateVars();
// getting workflow instance id from request parameters
String workflowInstanceId = params.get("workflow_instance_id");
boolean forced = getForced(req);
if (forced)
{
workflowService.deleteWorkflow(workflowInstanceId);
}
else
{
workflowService.cancelWorkflow(workflowInstanceId);
}
status.setCode(HttpServletResponse.SC_NO_CONTENT);
return null;
}
private boolean getForced(WebScriptRequest req)
{
String forced = req.getParameter(PARAM_FORCED);
if (forced != null)
{
try
{
return Boolean.valueOf(forced);
}
catch (Exception e)
{
// do nothing, false will be returned
}
}
// Defaults to false.
return false;
}
}

View File

@@ -53,6 +53,7 @@ import org.springframework.extensions.surf.util.ISO8601DateFormat;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
/**
@@ -487,6 +488,31 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
assertTrue(stateFilteredResult.length() > 1);
}
public void testWorkflowInstanceDelete() throws Exception
{
//Start workflow as USER1 and assign task to USER2.
personManager.setUser(USER1);
WorkflowDefinition adhocDef = workflowService.getDefinitionByName("jbpm$wf:adhoc");
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
Date dueDate = new Date();
params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
params.put(WorkflowModel.PROP_PRIORITY, 1);
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
params.put(WorkflowModel.PROP_CONTEXT, packageRef);
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
startTask = workflowService.endTask(startTask.getId(), null);
WorkflowInstance adhocInstance = startTask.getPath().getInstance();
Response response = sendRequest(new DeleteRequest(URL_WORKFLOW_INSTANCES + "/" + adhocInstance.getId()), 204);
assertEquals(Status.STATUS_NO_CONTENT, response.getStatus());
assertNull(workflowService.getWorkflowById(adhocInstance.getId()));
}
@Override
protected void setUp() throws Exception
{