mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Finish ALF-4134 - running action cancel request webscript
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21676 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.action;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.action.ExecutionDetails;
|
||||
import org.alfresco.service.cmr.action.ExecutionSummary;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* @author Nick Burch
|
||||
* @since 3.4
|
||||
*/
|
||||
public class RunningActionDelete extends AbstractActionWebscript
|
||||
{
|
||||
@Override
|
||||
protected Map<String, Object> buildModel(
|
||||
RunningActionModelBuilder modelBuilder, WebScriptRequest req,
|
||||
Status status, Cache cache) {
|
||||
// Which action did they ask for?
|
||||
String actionTrackingId =
|
||||
req.getServiceMatch().getTemplateVars().get("action_tracking_id");
|
||||
|
||||
// Check it exists
|
||||
ExecutionSummary action =
|
||||
getSummaryFromKey(actionTrackingId);
|
||||
if(action == null) {
|
||||
throw new WebScriptException(
|
||||
Status.STATUS_NOT_FOUND,
|
||||
"No Running Action found with that tracking id"
|
||||
);
|
||||
}
|
||||
|
||||
ExecutionDetails details =
|
||||
actionTrackingService.getExecutionDetails(action);
|
||||
if(details == null) {
|
||||
throw new WebScriptException(
|
||||
Status.STATUS_NOT_FOUND,
|
||||
"No Running Action found with that tracking id"
|
||||
);
|
||||
}
|
||||
|
||||
// Request the cancel
|
||||
actionTrackingService.requestActionCancellation(action);
|
||||
|
||||
// Report it cancelled
|
||||
throw new WebScriptException(
|
||||
Status.STATUS_GONE,
|
||||
"Action cancellation requested"
|
||||
);
|
||||
}
|
||||
}
|
@@ -473,6 +473,54 @@ public class RunningActionRestApiTest extends BaseWebScriptTest
|
||||
assertEquals("/" + URL_RUNNING_ACTION + key1, jsonRD.get("details"));
|
||||
}
|
||||
|
||||
public void testRunningActionCancel() throws Exception
|
||||
{
|
||||
Response response;
|
||||
|
||||
|
||||
// Not allowed if you're not an admin
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
|
||||
response = sendRequest(new DeleteRequest(URL_RUNNING_ACTION + "MadeUp"), Status.STATUS_UNAUTHORIZED);
|
||||
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
|
||||
response = sendRequest(new DeleteRequest(URL_RUNNING_ACTION + "MadeUp"), Status.STATUS_UNAUTHORIZED);
|
||||
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
|
||||
|
||||
|
||||
// If not found, you get a 404
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
response = sendRequest(new DeleteRequest(URL_RUNNING_ACTION + "MadeUp"), Status.STATUS_NOT_FOUND);
|
||||
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
|
||||
|
||||
|
||||
// Create one
|
||||
ReplicationDefinition rd = replicationService.createReplicationDefinition("Test1", "Testing");
|
||||
replicationService.saveReplicationDefinition(rd);
|
||||
actionTrackingService.recordActionExecuting(rd);
|
||||
String id = rd.getId();
|
||||
String instance = Integer.toString( ((ActionImpl)rd).getExecutionInstance() );
|
||||
String key = "replicationActionExecutor=" + id + "=" + instance;
|
||||
|
||||
assertEquals(false, actionTrackingService.isCancellationRequested(rd));
|
||||
|
||||
|
||||
// Request it to cancel
|
||||
response = sendRequest(new DeleteRequest(URL_RUNNING_ACTION + key), Status.STATUS_GONE);
|
||||
assertEquals(Status.STATUS_GONE, response.getStatus());
|
||||
|
||||
|
||||
// Check it was cancelled
|
||||
assertEquals(true, actionTrackingService.isCancellationRequested(rd));
|
||||
|
||||
|
||||
// Request again - no change
|
||||
response = sendRequest(new DeleteRequest(URL_RUNNING_ACTION + key), Status.STATUS_GONE);
|
||||
assertEquals(Status.STATUS_GONE, response.getStatus());
|
||||
|
||||
assertEquals(true, actionTrackingService.isCancellationRequested(rd));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
|
Reference in New Issue
Block a user