From f4789e91bf82603a2a2903892822d658f823045c Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 10 Sep 2010 10:08:14 +0000 Subject: [PATCH] ALF-4704 - Filter out deleted nodes in the replication model builder, otherwise the freemarker for the replication webscripts chokes on deleted ones. Includes new unit test. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22376 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../replication/ReplicationModelBuilder.java | 12 ++++- .../replication/ReplicationRestApiTest.java | 45 ++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) 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 899b1ee567..e907ab0b4f 100644 --- a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationModelBuilder.java +++ b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationModelBuilder.java @@ -32,6 +32,7 @@ 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.replication.ReplicationService; +import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.util.ISO8601DateFormat; @@ -219,9 +220,16 @@ public class ReplicationModelBuilder // Includes start+end times, and running action details setStatus(rd, rdm); - // Expand out the payload details - rdm.put(DEFINITION_PAYLOAD, rd.getPayload()); + // Only include the payload entries that still exist + // Otherwise the freemarker layer gets upset about deleted nodes + List payload = new ArrayList(); + for(NodeRef node : rd.getPayload()) { + if(nodeService.exists(node)) + payload.add(node); + } + rdm.put(DEFINITION_PAYLOAD, payload); + // Save in the usual way Map model = new HashMap(); model.put(MODEL_DATA_ITEM, rdm); return model; 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 9fec2198c8..30e1874e58 100644 --- a/source/java/org/alfresco/repo/web/scripts/replication/ReplicationRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/replication/ReplicationRestApiTest.java @@ -34,6 +34,7 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.PersonService; +import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.GUID; import org.alfresco.util.ISO8601DateFormat; @@ -568,6 +569,48 @@ public class ReplicationRestApiTest extends BaseWebScriptTest assertEquals(true, payload.get("isFolder")); assertEquals("Data Dictionary", payload.get("name")); assertEquals("/Company Home/Data Dictionary", payload.get("path")); + + + // Add a deleted NodeRef too, will be silently ignored + // by the webscript layer + UserTransaction txn = transactionService.getUserTransaction(); + txn.begin(); + NodeRef deleted = nodeService.createNode( + dataDictionary, ContentModel.ASSOC_CONTAINS, + QName.createQName("IwillBEdeleted"), + ContentModel.TYPE_CONTENT + ).getChildRef(); + nodeService.deleteNode(deleted); + txn.commit(); + + rd.getPayload().add( deleted ); + replicationService.saveReplicationDefinition(rd); + + response = sendRequest(new GetRequest(URL_DEFINITION + "Test1"), 200); + assertEquals(Status.STATUS_OK, response.getStatus()); + + jsonStr = response.getContentAsString(); + json = new JSONObject(jsonStr).getJSONObject("data"); + + assertEquals("Test1", json.get("name")); + assertEquals("Testing", json.get("description")); + assertEquals("CancelRequested", json.get("status")); + assertEquals(startedAt, json.getJSONObject("startedAt").get("iso8601")); + assertEquals(JSONObject.NULL, json.get("endedAt")); + assertEquals(JSONObject.NULL, json.get("failureMessage")); + assertEquals("/" + URL_RUNNING_ACTION + "replicationActionExecutor="+ + actionId + "=" + instanceId, json.get("executionDetails")); + assertEquals(JSONObject.NULL, json.get("transferLocalReport")); + assertEquals(JSONObject.NULL, json.get("transferRemoteReport")); + assertEquals(true, json.get("enabled")); + assertEquals(JSONObject.NULL, json.get("targetName")); + + // Check Payload + assertEquals(2, json.getJSONArray("payload").length()); + payload = json.getJSONArray("payload").getJSONObject(0); + assertEquals("Company Home", payload.get("name")); + payload = json.getJSONArray("payload").getJSONObject(1); + assertEquals("Data Dictionary", payload.get("name")); // Add a 2nd and 3rd definition @@ -580,7 +623,7 @@ public class ReplicationRestApiTest extends BaseWebScriptTest rd.setEnabled(false); // Have the 3rd one flagged as having failed - UserTransaction txn = transactionService.getUserTransaction(); + txn = transactionService.getUserTransaction(); txn.begin(); replicationService.saveReplicationDefinition(rd); actionTrackingService.recordActionExecuting(rd);