diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/action/running-replication-actions.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/action/running-replication-actions.get.desc.xml
new file mode 100644
index 0000000000..36be079720
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/action/running-replication-actions.get.desc.xml
@@ -0,0 +1,10 @@
+
+ List Running Replication Actions
+
+ Returns (limited) details on all currently running replication actions.
+
+ /api/running-replication-actions?name={name?}
+
+ admin
+ required
+
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/action/running-replication-actions.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/action/running-replication-actions.get.json.ftl
new file mode 100644
index 0000000000..f371f36b3e
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/action/running-replication-actions.get.json.ftl
@@ -0,0 +1,10 @@
+<#import "running-action.lib.ftl" as actionLib />
+{
+ "data":
+ [
+ <#list runningActions as action>
+ <@actionLib.runningActionJSON action=action />
+ <#if action_has_next>,#if>
+ #list>
+ ]
+}
diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml
index 4e6f921c56..ffaaf836d7 100644
--- a/config/alfresco/web-scripts-application-context.xml
+++ b/config/alfresco/web-scripts-application-context.xml
@@ -925,4 +925,11 @@
parent="abstractActionWebScript">
+
+
+
+
+
diff --git a/source/java/org/alfresco/repo/web/scripts/action/RunningActionRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/action/RunningActionRestApiTest.java
index c5381531ed..5ffe1009bc 100644
--- a/source/java/org/alfresco/repo/web/scripts/action/RunningActionRestApiTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/action/RunningActionRestApiTest.java
@@ -24,6 +24,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.cache.EhCacheAdapter;
import org.alfresco.repo.model.Repository;
+import org.alfresco.repo.replication.ReplicationDefinitionImpl;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.person.TestPersonManager;
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
@@ -58,7 +59,7 @@ public class RunningActionRestApiTest extends BaseWebScriptTest
{
private static final String URL_RUNNING_ACTION = "api/running-action/";
private static final String URL_RUNNING_ACTIONS = "api/running-actions";
- private static final String URL_RUNNING_REPLICATION_ACTIONS = "api/running-replication-actions/";
+ private static final String URL_RUNNING_REPLICATION_ACTIONS = "api/running-replication-actions";
private static final String JSON = "application/json";
@@ -121,7 +122,7 @@ public class RunningActionRestApiTest extends BaseWebScriptTest
JSONObject jsonRD = (JSONObject)results.get(0);
assertNotNull(jsonRD);
assertEquals(id, jsonRD.get("actionId"));
- assertEquals("replicationActionExecutor", jsonRD.get("actionType"));
+ assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(instance, jsonRD.get("actionInstance"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(startedAt, jsonRD.get("startedAt"));
@@ -161,7 +162,7 @@ public class RunningActionRestApiTest extends BaseWebScriptTest
jsonRD = (JSONObject)results.get(0);
assertNotNull(jsonRD);
assertEquals(id, jsonRD.get("actionId"));
- assertEquals("replicationActionExecutor", jsonRD.get("actionType"));
+ assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(instance, jsonRD.get("actionInstance"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(startedAt, jsonRD.get("startedAt"));
@@ -263,7 +264,7 @@ public class RunningActionRestApiTest extends BaseWebScriptTest
jsonRD = (JSONObject)results.get(0);
assertNotNull(jsonRD);
assertEquals(id, jsonRD.get("actionId"));
- assertEquals("replicationActionExecutor", jsonRD.get("actionType"));
+ assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(instance, jsonRD.get("actionInstance"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(startedAt, jsonRD.get("startedAt"));
@@ -288,7 +289,7 @@ public class RunningActionRestApiTest extends BaseWebScriptTest
jsonRD = (JSONObject)results.get(0);
assertNotNull(jsonRD);
assertEquals(id2, jsonRD.get("actionId"));
- assertEquals("replicationActionExecutor", jsonRD.get("actionType"));
+ assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, jsonRD.get("actionType"));
assertEquals(instance2, jsonRD.get("actionInstance"));
assertEquals(rd.getNodeRef().toString(), jsonRD.get("actionNodeRef"));
assertEquals(startedAt2, jsonRD.get("startedAt"));
@@ -367,6 +368,222 @@ public class RunningActionRestApiTest extends BaseWebScriptTest
}
+ public void testRunningReplicationActionsGet() throws Exception
+ {
+ Response response;
+
+
+ // Not allowed if you're not an admin
+ AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
+ response = sendRequest(new GetRequest(URL_RUNNING_REPLICATION_ACTIONS), Status.STATUS_UNAUTHORIZED);
+ assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
+
+ AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
+ response = sendRequest(new GetRequest(URL_RUNNING_REPLICATION_ACTIONS), Status.STATUS_UNAUTHORIZED);
+ assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
+
+
+ // If nothing running, you don't get anything back
+ AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
+ response = sendRequest(new GetRequest(URL_RUNNING_REPLICATION_ACTIONS), 200);
+ assertEquals(Status.STATUS_OK, response.getStatus());
+
+ String jsonStr = response.getContentAsString();
+ JSONObject json = new JSONObject(jsonStr);
+ JSONArray results = json.getJSONArray("data");
+ assertNotNull(results);
+ assertEquals(0, results.length());
+
+
+ // Add a running action, it should show up
+ 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());
+
+ response = sendRequest(new GetRequest(URL_RUNNING_REPLICATION_ACTIONS), 200);
+ assertEquals(Status.STATUS_OK, response.getStatus());
+
+ jsonStr = response.getContentAsString();
+ json = new JSONObject(jsonStr);
+ results = json.getJSONArray("data");
+ assertNotNull(results);
+ assertEquals(1, results.length());
+
+ JSONObject jsonRD = (JSONObject)results.get(0);
+ assertNotNull(jsonRD);
+ assertEquals(id, jsonRD.get("actionId"));
+ assertEquals(ReplicationDefinitionImpl.EXECUTOR_NAME, 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 + "replicationActionExecutor=" +
+ id + "=" + instance, 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.
+ */
+package org.alfresco.repo.web.scripts.action;
+
+import java.util.List;
+import java.util.Map;
+
+import org.alfresco.repo.replication.ReplicationDefinitionImpl;
+import org.alfresco.service.cmr.action.Action;
+import org.alfresco.service.cmr.action.ExecutionSummary;
+import org.alfresco.service.cmr.replication.ReplicationDefinition;
+import org.alfresco.service.cmr.replication.ReplicationService;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.springframework.extensions.webscripts.Cache;
+import org.springframework.extensions.webscripts.Status;
+import org.springframework.extensions.webscripts.WebScriptRequest;
+
+/**
+ * @author Nick Burch
+ * @since 3.4
+ */
+public class RunningReplicationActionsGet extends AbstractActionWebscript
+{
+ private ReplicationService replicationService;
+
+ @Override
+ protected Map buildModel(
+ RunningActionModelBuilder modelBuilder, WebScriptRequest req,
+ Status status, Cache cache) {
+ List actions = null;
+
+ // Do they want all replication actions, or only certain ones?
+ String name = req.getParameter("name");
+
+ if(name != null) {
+ // Try to find a replication definition with this name
+ ReplicationDefinition rd = replicationService.loadReplicationDefinition(name);
+
+ // Look up what's running
+ if(rd != null) {
+ actions = actionTrackingService.getExecutingActions(rd);
+ }
+ } else {
+ // All replication actions
+ actions = actionTrackingService.getExecutingActions(
+ ReplicationDefinitionImpl.EXECUTOR_NAME
+ );
+ }
+
+ // Build the model list
+ return modelBuilder.buildSimpleList(actions);
+ }
+
+ public void setReplicationService(ReplicationService replicationService)
+ {
+ this.replicationService = replicationService;
+ }
+}
\ No newline at end of file