diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.delete.desc.xml
new file mode 100644
index 0000000000..2bcb771766
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/replication/replication-definition.delete.desc.xml
@@ -0,0 +1,8 @@
+
+ Deletes a persisted Replication Definition
+ Deletes a previously persisted replication defintion with the supplied name
+ /api/replication-definition/{replication_definition_name}
+
+ admin
+ required
+
diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml
index 824aefea1d..cf27e0cfb2 100644
--- a/config/alfresco/web-scripts-application-context.xml
+++ b/config/alfresco/web-scripts-application-context.xml
@@ -876,4 +876,10 @@
parent="abstractReplicationWebScript">
+
+
+
+
diff --git a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionDelete.java b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionDelete.java
new file mode 100644
index 0000000000..18a11e1fba
--- /dev/null
+++ b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationDefinitionDelete.java
@@ -0,0 +1,63 @@
+/*
+ * 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.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 ReplicationDefinitionDelete 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"
+ );
+ }
+
+ // Delete it
+ replicationService.deleteReplicationDefinition(replicationDefinition);
+
+ // Report it as gone
+ throw new WebScriptException(
+ Status.STATUS_GONE,
+ "Replication Definition deleted"
+ );
+ }
+}
\ No newline at end of file
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 85f2a22acc..3821fe5311 100644
--- a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationRestApiTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationRestApiTest.java
@@ -44,6 +44,7 @@ import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
+import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
/**
@@ -1113,6 +1114,117 @@ public class ReplicationRestApiTest extends BaseWebScriptTest
assertEquals(0, json.getJSONArray("payload").length());
}
+ public void testReplicationDefinitionDelete() throws Exception
+ {
+ Response response;
+
+
+ // Not allowed if you're not an admin
+ AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getGuestUserName());
+ response = sendRequest(new DeleteRequest(URL_DEFINITION + "MadeUp"), Status.STATUS_UNAUTHORIZED);
+ assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
+
+ AuthenticationUtil.setFullyAuthenticatedUser(USER_NORMAL);
+ response = sendRequest(new DeleteRequest(URL_DEFINITION + "MadeUp"), Status.STATUS_UNAUTHORIZED);
+ assertEquals(Status.STATUS_UNAUTHORIZED, response.getStatus());
+
+
+ // Ensure there aren't any to start with
+ AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
+ assertEquals(0, replicationService.loadReplicationDefinitions().size());
+
+
+ // You need to specify a real definition
+ response = sendRequest(new DeleteRequest(URL_DEFINITION + "MadeUp"), Status.STATUS_NOT_FOUND);
+ assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
+
+
+ // Create one, and then delete it
+ ReplicationDefinition rd = replicationService.createReplicationDefinition("Test", "Testing");
+ replicationService.saveReplicationDefinition(rd);
+ assertEquals(1, replicationService.loadReplicationDefinitions().size());
+
+ // Because some of the delete operations happen post-commit, and
+ // because we don't have real transactions, fake it
+ UserTransaction txn = transactionService.getUserTransaction();
+ txn.begin();
+
+ // Call the delete webscript
+ response = sendRequest(new DeleteRequest(URL_DEFINITION + "Test"), Status.STATUS_GONE);
+ assertEquals(Status.STATUS_GONE, response.getStatus());
+
+ // Let the node service do its work
+ txn.commit();
+ Thread.sleep(50);
+
+
+ // Check the details webscript to ensure it went
+ response = sendRequest(new GetRequest(URL_DEFINITION + "Test"), Status.STATUS_NOT_FOUND);
+ assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
+
+
+ // Check the replication service to ensure it went
+ assertNull(replicationService.loadReplicationDefinition("Test"));
+ assertEquals(0, replicationService.loadReplicationDefinitions().size());
+
+
+ // If there are several, make sure the right one goes
+ rd = replicationService.createReplicationDefinition("Test", "Testing");
+ replicationService.saveReplicationDefinition(rd);
+ rd = replicationService.createReplicationDefinition("Test 2", "Testing");
+ replicationService.saveReplicationDefinition(rd);
+ rd = replicationService.createReplicationDefinition("Test 3", "Testing");
+ replicationService.saveReplicationDefinition(rd);
+
+ // Delete one of three, correct one goes
+ assertEquals(3, replicationService.loadReplicationDefinitions().size());
+
+ txn = transactionService.getUserTransaction();
+ txn.begin();
+
+ response = sendRequest(new DeleteRequest(URL_DEFINITION + "Test"), Status.STATUS_GONE);
+ assertEquals(Status.STATUS_GONE, response.getStatus());
+
+ txn.commit();
+ Thread.sleep(50);
+
+ assertEquals(2, replicationService.loadReplicationDefinitions().size());
+ assertNull(replicationService.loadReplicationDefinition("Test"));
+ assertNotNull(replicationService.loadReplicationDefinition("Test 2"));
+ assertNotNull(replicationService.loadReplicationDefinition("Test 3"));
+
+ // Delete the next one, correct one goes
+ txn = transactionService.getUserTransaction();
+ txn.begin();
+
+ response = sendRequest(new DeleteRequest(URL_DEFINITION + "Test 3"), Status.STATUS_GONE);
+ assertEquals(Status.STATUS_GONE, response.getStatus());
+
+ txn.commit();
+ Thread.sleep(50);
+
+ assertEquals(1, replicationService.loadReplicationDefinitions().size());
+ assertNull(replicationService.loadReplicationDefinition("Test"));
+ assertNotNull(replicationService.loadReplicationDefinition("Test 2"));
+ assertNull(replicationService.loadReplicationDefinition("Test 3"));
+
+
+ // Ensure you can't delete for a 2nd time
+ txn = transactionService.getUserTransaction();
+ txn.begin();
+
+ response = sendRequest(new DeleteRequest(URL_DEFINITION + "Test 3"), Status.STATUS_NOT_FOUND);
+ assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
+
+ txn.commit();
+ Thread.sleep(50);
+
+ assertEquals(1, replicationService.loadReplicationDefinitions().size());
+ assertNull(replicationService.loadReplicationDefinition("Test"));
+ assertNotNull(replicationService.loadReplicationDefinition("Test 2"));
+ assertNull(replicationService.loadReplicationDefinition("Test 3"));
+ }
+
@Override
protected void setUp() throws Exception
@@ -1121,7 +1233,7 @@ public class ReplicationRestApiTest extends BaseWebScriptTest
ApplicationContext appContext = getServer().getApplicationContext();
nodeService = (NodeService)appContext.getBean("nodeService");
- replicationService = (ReplicationService)appContext.getBean("replicationService");
+ replicationService = (ReplicationService)appContext.getBean("ReplicationService");
actionTrackingService = (ActionTrackingService)appContext.getBean("actionTrackingService");
repositoryHelper = (Repository)appContext.getBean("repositoryHelper");
transactionService = (TransactionService)appContext.getBean("transactionService");