diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.get.desc.xml
new file mode 100644
index 0000000000..3175c2626d
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.get.desc.xml
@@ -0,0 +1,8 @@
+
+ Get Replication Definition
+ Gets the details of a persisted replication definition.
+ /api/replication-definition/{replication_definition_name}
+
+ admin
+ required
+
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.get.json.ftl
new file mode 100644
index 0000000000..e92ce023ee
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.get.json.ftl
@@ -0,0 +1,2 @@
+<#import "replication-definition.lib.ftl" as replicationDefLib />
+<@replicationDefLib.replicationDefinitionJSON replicationDefinition=replicationDefinition />
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.lib.ftl
index efbfc2efa8..ca89527c8f 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.lib.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.lib.ftl
@@ -17,6 +17,8 @@
{
"name": "${replicationDefinition.name}",
"status" : "${replicationDefinition.status}",
+ "startedAt" : <#if replicationDefinition.startedAt??>"${replicationDefinition.startedAt}"<#else>null#if>,
+ "endedAt" : <#if replicationDefinition.endedAt??>"${replicationDefinition.endedAt}"<#else>null#if>,
"enabled" : ${replicationDefinition.enabled?string},
<#-- TODO The rest of the fields -->
}
diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml
index d3470a62bb..3fd10b4592 100644
--- a/config/alfresco/web-scripts-application-context.xml
+++ b/config/alfresco/web-scripts-application-context.xml
@@ -853,4 +853,10 @@
parent="abstractReplicationWebScript">
+
+
+
+
diff --git a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionGet.java b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionGet.java
new file mode 100644
index 0000000000..f59475f76f
--- /dev/null
+++ b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionGet.java
@@ -0,0 +1,59 @@
+/*
+ * 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 .
+ */
+package org.alfresco.repo.web.scripts.replication;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+import org.alfresco.service.cmr.replication.ReplicationDefinition;
+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 ReplicationDefinitionGet extends AbstractReplicationWebscript
+{
+ @Override
+ protected Map buildModel(ReplicationModelBuilder modelBuilder,
+ WebScriptRequest req, Status status, Cache cache)
+ {
+ // Which definition did they ask for?
+ String replicationDefinitionName =
+ req.getServiceMatch().getTemplateVars().get("replication_definition_name");
+ ReplicationDefinition replicationDefinition =
+ replicationService.loadReplicationDefinition(replicationDefinitionName);
+
+ // Does it exist?
+ if(replicationDefinition == null) {
+ throw new WebScriptException(
+ Status.STATUS_NOT_FOUND,
+ "No Replication Definition found with that name"
+ );
+ }
+
+ // Have it turned into simple models
+ return modelBuilder.buildDetails(replicationDefinition);
+ }
+}
\ No newline at end of file
diff --git a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationModelBuilder.java b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationModelBuilder.java
index 071f010401..5fcfc8e9de 100644
--- a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationModelBuilder.java
+++ b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationModelBuilder.java
@@ -43,6 +43,7 @@ import org.alfresco.util.ISO8601DateFormat;
*/
public class ReplicationModelBuilder
{
+ protected static final String MODEL_DATA_ITEM = "replicationDefinition";
protected static final String MODEL_DATA_LIST = "replicationDefinitions";
protected static final String DEFINITION_NAME = "name";
@@ -163,6 +164,30 @@ public class ReplicationModelBuilder
return model;
}
+
+ /**
+ * Build a model containing the full, detailed definition for the given
+ * Replication Definition.
+ */
+ protected Map buildDetails(ReplicationDefinition rd) {
+ Map rdm = new HashMap();
+
+ // Set the core details
+ rdm.put(DEFINITION_NAME, rd.getReplicationName());
+ rdm.put(DEFINITION_ENABLED, rd.isEnabled());
+ // TODO
+
+ // Do the status
+ setStatus(rd, rdm);
+
+ // Expand out the payload details
+ // TODO
+
+ Map model = new HashMap();
+ model.put(MODEL_DATA_ITEM, rdm);
+ return model;
+ }
+
/**
* Figures out the status that's one of:
diff --git a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationRestApiTest.java
index b24af5dfd8..96c5c0596d 100644
--- a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationRestApiTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationRestApiTest.java
@@ -326,6 +326,72 @@ public class ReplicationRestApiTest extends BaseWebScriptTest
assertEquals("/api/replication-definition/Test2", jsonRD.get("details"));
}
+ public void testReplicationDefinitionGet() throws Exception
+ {
+ Response response;
+
+
+ // Not allowed if you're not an admin
+ AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
+ response = sendRequest(new GetRequest(URL_DEFINITION + "madeup"), Status.STATUS_UNAUTHORIZED);
+ assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
+
+ AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
+ response = sendRequest(new GetRequest(URL_DEFINITION + "madeup"), Status.STATUS_UNAUTHORIZED);
+ assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
+
+
+ // If an invalid name is given, you get a 404
+ AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
+ response = sendRequest(new GetRequest(URL_DEFINITION + "madeup"), 404);
+ assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
+
+
+ // Add a definition, it should show up
+ ReplicationDefinition rd = replicationService.createReplicationDefinition("Test1", "Testing");
+ replicationService.saveReplicationDefinition(rd);
+ response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200);
+ assertEquals(Status.STATUS_OK, response.getStatus());
+
+ String jsonStr = response.getContentAsString();
+System.err.println(jsonStr);
+ JSONObject json = new JSONObject(jsonStr);
+ assertNotNull(json);
+
+ // Check
+ // TODO
+ assertEquals("Test1", json.get("name"));
+ assertEquals("New", json.get("status"));
+ assertEquals(true, json.get("enabled"));
+ assertEquals(JSONObject.NULL, json.get("startedAt"));
+
+
+ // Change the status to running, and re-check
+ actionTrackingService.recordActionExecuting(rd);
+ String startedAt = ISO8601DateFormat.format(rd.getExecutionStartDate());
+
+ response = sendRequest(new GetRequest(URL_DEFINITIONS), 200);
+ assertEquals(Status.STATUS_OK, response.getStatus());
+
+ jsonStr = response.getContentAsString();
+ json = new JSONObject(jsonStr);
+
+
+ // Add some payload details, ensure that they get expanded
+ // as they should be
+
+
+ // Add a 2nd and 3rd
+ rd = replicationService.createReplicationDefinition("Test2", "2nd Testing");
+ replicationService.saveReplicationDefinition(rd);
+
+ // Original one comes back unchanged
+ // TODO
+
+ // They show up things as expected
+ // TODO
+ }
+
@Override
protected void setUp() throws Exception
{