mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Start on ALF-4134 - Get Details webscript
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21666 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<webscript>
|
||||
<shortname>Get Running Action Details</shortname>
|
||||
<description>
|
||||
Returns (limited) details on a currently running actions.
|
||||
</description>
|
||||
<url>/api/running-action/{action_tracking_id}</url>
|
||||
<format default="json"/>
|
||||
<authentication>admin</authentication>
|
||||
<transaction allow="readonly">required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,2 @@
|
||||
<#import "running-action.lib.ftl" as actionLib />
|
||||
<@actionLib.runningActionJSON action=runningAction />
|
@@ -897,6 +897,12 @@
|
||||
<property name="actionTrackingService" ref="actionTrackingService" />
|
||||
</bean>
|
||||
|
||||
<!-- Gets the details of a running action -->
|
||||
<bean id="webscript.org.alfresco.repository.action.running-action.get"
|
||||
class="org.alfresco.repo.web.scripts.action.RunningActionGet"
|
||||
parent="abstractActionWebScript">
|
||||
</bean>
|
||||
|
||||
<!-- Lists the running actions -->
|
||||
<bean id="webscript.org.alfresco.repository.action.running-actions.get"
|
||||
class="org.alfresco.repo.web.scripts.action.RunningActionsGet"
|
||||
|
@@ -19,6 +19,7 @@
|
||||
package org.alfresco.repo.web.scripts.action;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.alfresco.repo.action.ActionTrackingServiceImpl;
|
||||
import org.alfresco.repo.action.RuntimeActionService;
|
||||
@@ -31,6 +32,7 @@ import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
|
||||
/**
|
||||
* @author Nick Burch
|
||||
* @since 3.4
|
||||
@@ -112,7 +114,13 @@ public abstract class AbstractActionWebscript extends DeclarativeWebScript
|
||||
|
||||
private static ExecutionSummary getSummaryFromKey(String key)
|
||||
{
|
||||
try {
|
||||
// Try to have the key turned into a summary for us
|
||||
return ActionTrackingServiceImpl.buildExecutionSummary(key);
|
||||
} catch(NoSuchElementException e) {
|
||||
// Wrong format
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.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 RunningActionGet 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");
|
||||
|
||||
ExecutionSummary action =
|
||||
getSummaryFromKey(actionTrackingId);
|
||||
|
||||
// Get the details, if we can
|
||||
Map<String,Object> model = modelBuilder.buildSimpleModel(action);
|
||||
|
||||
if(model == null) {
|
||||
throw new WebScriptException(
|
||||
Status.STATUS_NOT_FOUND,
|
||||
"No Running Action found with that tracking id"
|
||||
);
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
@@ -19,7 +19,6 @@
|
||||
package org.alfresco.repo.web.scripts.action;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -28,7 +27,6 @@ import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.action.ActionTrackingService;
|
||||
import org.alfresco.service.cmr.action.ExecutionDetails;
|
||||
import org.alfresco.service.cmr.action.ExecutionSummary;
|
||||
import org.alfresco.service.cmr.replication.ReplicationDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.util.ISO8601DateFormat;
|
||||
|
||||
@@ -66,6 +64,20 @@ public class RunningActionModelBuilder
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a model containing a single running action
|
||||
*/
|
||||
protected Map<String,Object> buildSimpleModel(ExecutionSummary summary)
|
||||
{
|
||||
Map<String, Object> ram = buildModel(summary);
|
||||
if(ram != null) {
|
||||
Map<String, Object> model = new HashMap<String,Object>();
|
||||
model.put(MODEL_DATA_ITEM, ram);
|
||||
return model;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a model containing a list of running actions for the given
|
||||
* list of Running Actions
|
||||
@@ -75,6 +87,28 @@ public class RunningActionModelBuilder
|
||||
List<Map<String,Object>> models = new ArrayList<Map<String,Object>>();
|
||||
|
||||
for(ExecutionSummary summary : runningActions) {
|
||||
Map<String, Object> ram = buildModel(summary);
|
||||
if(ram != null) {
|
||||
models.add(ram);
|
||||
}
|
||||
}
|
||||
|
||||
// Finish up
|
||||
Map<String, Object> model = new HashMap<String,Object>();
|
||||
model.put(MODEL_DATA_LIST, models);
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a model for a single action
|
||||
*/
|
||||
private Map<String,Object> buildModel(ExecutionSummary summary)
|
||||
{
|
||||
if(summary == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the details, if we can
|
||||
ExecutionDetails details = actionTrackingService.getExecutionDetails(summary);
|
||||
|
||||
// Only record if still running - may have finished
|
||||
@@ -91,13 +125,9 @@ public class RunningActionModelBuilder
|
||||
ram.put(ACTION_RUNNING_ON, details.getRunningOn());
|
||||
ram.put(ACTION_CANCEL_REQUESTED, details.isCancelRequested());
|
||||
|
||||
models.add(ram);
|
||||
}
|
||||
return ram;
|
||||
}
|
||||
|
||||
// Finish up
|
||||
Map<String, Object> model = new HashMap<String,Object>();
|
||||
model.put(MODEL_DATA_LIST, models);
|
||||
return model;
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -367,6 +367,113 @@ public class RunningActionRestApiTest extends BaseWebScriptTest
|
||||
}
|
||||
|
||||
|
||||
public void testRunningActionGet() throws Exception
|
||||
{
|
||||
Response response;
|
||||
|
||||
|
||||
// Not allowed if you're not an admin
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
|
||||
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + "MadeUp"), Status.STATUS_UNAUTHORIZED);
|
||||
assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
|
||||
response = sendRequest(new GetRequest(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 GetRequest(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 startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
|
||||
String key1 = "replicationActionExecutor=" + id + "=" + instance;
|
||||
|
||||
|
||||
// Fetch the details of it
|
||||
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + key1), Status.STATUS_OK);
|
||||
assertEquals(Status.STATUS_OK, response.getStatus());
|
||||
|
||||
String jsonStr = response.getContentAsString();
|
||||
JSONObject jsonRD = new JSONObject(jsonStr);
|
||||
assertNotNull(jsonRD);
|
||||
assertEquals(id, jsonRD.get("actionId"));
|
||||
assertEquals("replicationActionExecutor", jsonRD.get("actionType"));
|
||||
assertEquals(instance, jsonRD.get("actionInstance"));
|
||||
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
|
||||
assertEquals(startedAt, jsonRD.get("startedAt"));
|
||||
assertEquals(false, jsonRD.getBoolean("cancelRequested"));
|
||||
assertEquals("/" + URL_RUNNING_ACTION + key1, jsonRD.get("details"));
|
||||
|
||||
|
||||
// Ensure we didn't get any unexpected data back,
|
||||
// only the keys we should have done
|
||||
JSONArray keys = jsonRD.names();
|
||||
for(int i=0; i<keys.length(); i++) {
|
||||
String key = keys.getString(0);
|
||||
if(key.equals("actionId") || key.equals("actionType") ||
|
||||
key.equals("actionInstance") || key.equals("actionNodeRef") ||
|
||||
key.equals("startedAt") || key.equals("cancelRequested") ||
|
||||
key.equals("details")) {
|
||||
// All good
|
||||
} else {
|
||||
fail("Unexpected key '"+key+"' found in json, raw json is\n" + jsonStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add another which is cancelled, check that
|
||||
// we get the correct, different details for it
|
||||
rd = replicationService.createReplicationDefinition("Test2", "Testing");
|
||||
replicationService.saveReplicationDefinition(rd);
|
||||
actionTrackingService.recordActionExecuting(rd);
|
||||
actionTrackingService.requestActionCancellation(rd);
|
||||
String id2 = rd.getId();
|
||||
String instance2 = Integer.toString( ((ActionImpl)rd).getExecutionInstance() );
|
||||
String startedAt2 = ISO8601DateFormat.format(rd.getExecutionStartDate());
|
||||
String key2 = "replicationActionExecutor=" + id2 + "=" + instance2;
|
||||
|
||||
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + key2), Status.STATUS_OK);
|
||||
assertEquals(Status.STATUS_OK, response.getStatus());
|
||||
|
||||
jsonStr = response.getContentAsString();
|
||||
jsonRD = new JSONObject(jsonStr);
|
||||
assertNotNull(jsonRD);
|
||||
assertEquals(id2, jsonRD.get("actionId"));
|
||||
assertEquals("replicationActionExecutor", jsonRD.get("actionType"));
|
||||
assertEquals(instance2, jsonRD.get("actionInstance"));
|
||||
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
|
||||
assertEquals(startedAt2, jsonRD.get("startedAt"));
|
||||
assertEquals(true, jsonRD.getBoolean("cancelRequested"));
|
||||
assertEquals("/" + URL_RUNNING_ACTION + key2, jsonRD.get("details"));
|
||||
|
||||
|
||||
// Check that the original is unchanged
|
||||
response = sendRequest(new GetRequest(URL_RUNNING_ACTION + key1), Status.STATUS_OK);
|
||||
assertEquals(Status.STATUS_OK, response.getStatus());
|
||||
|
||||
rd = replicationService.loadReplicationDefinition("Test1");
|
||||
jsonStr = response.getContentAsString();
|
||||
jsonRD = new JSONObject(jsonStr);
|
||||
assertNotNull(jsonRD);
|
||||
assertEquals(id, jsonRD.get("actionId"));
|
||||
assertEquals("replicationActionExecutor", jsonRD.get("actionType"));
|
||||
assertEquals(instance, jsonRD.get("actionInstance"));
|
||||
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
|
||||
assertEquals(startedAt, jsonRD.get("startedAt"));
|
||||
assertEquals(false, jsonRD.getBoolean("cancelRequested"));
|
||||
assertEquals("/" + URL_RUNNING_ACTION + key1, jsonRD.get("details"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
|
Reference in New Issue
Block a user