diff --git a/source/java/org/alfresco/repo/replication/ReplicationDefinitionImpl.java b/source/java/org/alfresco/repo/replication/ReplicationDefinitionImpl.java index df18a3276e..ede4edcd95 100644 --- a/source/java/org/alfresco/repo/replication/ReplicationDefinitionImpl.java +++ b/source/java/org/alfresco/repo/replication/ReplicationDefinitionImpl.java @@ -41,11 +41,9 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication private static final long serialVersionUID = 3183721054220388564L; public static final String REPLICATION_DEFINITION_NAME = "replicationActionName"; - - public String description; - public String targetName; - public List payload; - public NodeRef localTransferReport; + public static final String REPLICATION_DEFINITION_TARGET = "replicationTarget"; + public static final String REPLICATION_DEFINITION_PAYLOAD = "replicationPayload"; + public static final String REPLICATION_DEFINITION_TRANSFER_REPORT = "replicationTransferReport"; /** * @param id @@ -68,7 +66,7 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication */ public ReplicationDefinitionImpl(String id, QName replicationName, String description) { - super(null, id); + super(null, id, description); setParameterValue(REPLICATION_DEFINITION_NAME, replicationName); setDescription(description); } @@ -91,11 +89,15 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication * @see * org.alfresco.service.cmr.replication.ReplicationDefinition#getPayload() */ + @SuppressWarnings("unchecked") public List getPayload() { - if(this.payload == null) { - this.payload = new ArrayList(); + List payload = (List) + getParameterValue(REPLICATION_DEFINITION_PAYLOAD); + if(payload == null) { + payload = new ArrayList(); + setParameterValue(REPLICATION_DEFINITION_PAYLOAD, (Serializable)payload); } - return this.payload; + return payload; } /* @@ -103,7 +105,7 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication * org.alfresco.service.cmr.replication.ReplicationDefinition#getTargetName() */ public String getTargetName() { - return this.targetName; + return (String)getParameterValue(REPLICATION_DEFINITION_TARGET); } /* @@ -111,7 +113,7 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication * org.alfresco.service.cmr.replication.ReplicationDefinition#setTargetName(String) */ public void setTargetName(String targetName) { - this.targetName = targetName; + setParameterValue(REPLICATION_DEFINITION_TARGET, targetName); } /* @@ -119,7 +121,7 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication * org.alfresco.service.cmr.replication.ReplicationDefinition#getLocalTransferReport() */ public NodeRef getLocalTransferReport() { - return localTransferReport; + return (NodeRef)getParameterValue(REPLICATION_DEFINITION_TRANSFER_REPORT); } /* @@ -127,6 +129,6 @@ public class ReplicationDefinitionImpl extends ActionImpl implements Replication * org.alfresco.service.cmr.replication.ReplicationDefinition#setLocalTransferReport(NodeRef) */ public void setLocalTransferReport(NodeRef report) { - this.localTransferReport = report; + setParameterValue(REPLICATION_DEFINITION_TRANSFER_REPORT, report); } } diff --git a/source/java/org/alfresco/repo/replication/ReplicationDefinitionPersisterImpl.java b/source/java/org/alfresco/repo/replication/ReplicationDefinitionPersisterImpl.java index 87e660750e..c4252efb0c 100644 --- a/source/java/org/alfresco/repo/replication/ReplicationDefinitionPersisterImpl.java +++ b/source/java/org/alfresco/repo/replication/ReplicationDefinitionPersisterImpl.java @@ -20,6 +20,7 @@ package org.alfresco.repo.replication; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -47,6 +48,9 @@ public class ReplicationDefinitionPersisterImpl implements ReplicationDefinition /** Reference to the replication action space node */ private static final StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); protected static final NodeRef REPLICATION_ACTION_ROOT_NODE_REF = new NodeRef(SPACES_STORE, "replication_actions_space"); + protected static final Set ACTION_TYPES = new HashSet( + Arrays.asList(new QName[] { ActionModel.TYPE_ACTION })); + /* Injected services */ private NodeService nodeService; @@ -79,10 +83,8 @@ public class ReplicationDefinitionPersisterImpl implements ReplicationDefinition // Note that in the call to getChildAssocs below, only the specified // types are included. // Subtypes of the type action:action will not be returned. - Set actionTypes = new HashSet(); - actionTypes.add(ActionModel.TYPE_ACTION); - List childAssocs = nodeService.getChildAssocs(REPLICATION_ACTION_ROOT_NODE_REF, actionTypes); + List childAssocs = nodeService.getChildAssocs(REPLICATION_ACTION_ROOT_NODE_REF, ACTION_TYPES); List renderingActions = new ArrayList(childAssocs.size()); for (ChildAssociationRef actionAssoc : childAssocs) diff --git a/source/java/org/alfresco/repo/replication/ReplicationServiceImplTest.java b/source/java/org/alfresco/repo/replication/ReplicationServiceImplTest.java new file mode 100644 index 0000000000..854ebaac68 --- /dev/null +++ b/source/java/org/alfresco/repo/replication/ReplicationServiceImplTest.java @@ -0,0 +1,72 @@ +/* + * 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.replication; + +import static org.mockito.Mockito.mock; +import junit.framework.TestCase; + +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.replication.ReplicationDefinition; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; + +/** + * @author Nick Burch + */ +public class ReplicationServiceImplTest extends TestCase +{ + private ActionService actionService = mock(ActionService.class); + private NodeService nodeService = mock(NodeService.class); + + private final ReplicationDefinitionPersisterImpl replicationDefinitionPersister = mock(ReplicationDefinitionPersisterImpl.class); + private ReplicationServiceImpl replicationService; + + private final QName ACTION_NAME = QName.createQName(NamespaceService.ALFRESCO_URI, "testName"); + private final QName ACTION_NAME2 = QName.createQName(NamespaceService.ALFRESCO_URI, "testName2"); + + @Override + protected void setUp() throws Exception + { + replicationService = new ReplicationServiceImpl(); + replicationService.setActionService(actionService); + replicationService.setNodeService(nodeService); + replicationService.setReplicationDefinitionPersister(replicationDefinitionPersister); + } + + public void testCreation() throws Exception + { + ReplicationDefinition replicationAction = + replicationService.createReplicationDefinition(ACTION_NAME, "Test Definition"); + assertNotNull(replicationAction); + assertEquals("Test Definition", replicationAction.getDescription()); + assertEquals(ACTION_NAME, replicationAction.getReplicationName()); + + String id = replicationAction.getId(); + assertNotNull(id); + assertTrue(id.length() > 0); + + assertNotNull(replicationAction.getPayload()); + assertEquals(0, replicationAction.getPayload().size()); + + assertNull(replicationAction.getLocalTransferReport()); + } + +} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/replication/ReplicationServiceIntegrationTest.java b/source/java/org/alfresco/repo/replication/ReplicationServiceIntegrationTest.java new file mode 100644 index 0000000000..72ba88ce7f --- /dev/null +++ b/source/java/org/alfresco/repo/replication/ReplicationServiceIntegrationTest.java @@ -0,0 +1,140 @@ +/* + * 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.replication; + +import org.alfresco.repo.model.Repository; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.service.cmr.replication.ReplicationDefinition; +import org.alfresco.service.cmr.replication.ReplicationService; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.BaseAlfrescoSpringTest; + +/** + * @author Nick Burch + */ +public class ReplicationServiceIntegrationTest extends BaseAlfrescoSpringTest +{ + private ReplicationService replicationService; + private NodeService nodeService; + + private final QName ACTION_NAME = QName.createQName(NamespaceService.ALFRESCO_URI, "testName"); + private final QName ACTION_NAME2 = QName.createQName(NamespaceService.ALFRESCO_URI, "testName2"); + + @Override + protected void onSetUpInTransaction() throws Exception + { + super.onSetUpInTransaction(); + replicationService = (ReplicationService) this.applicationContext.getBean("replicationService"); + nodeService = (NodeService) this.applicationContext.getBean("nodeService"); + + // Set the current security context as admin + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + + // Zap any existing entries + NodeRef replicationRoot = ReplicationDefinitionPersisterImpl.REPLICATION_ACTION_ROOT_NODE_REF; + for(ChildAssociationRef child : nodeService.getChildAssocs(replicationRoot)) { + QName type = nodeService.getType( child.getChildRef() ); + if(ReplicationDefinitionPersisterImpl.ACTION_TYPES.contains(type)) { + nodeService.deleteNode(child.getChildRef()); + } + } + } + + public void testCreation() throws Exception + { + ReplicationDefinition replicationAction = + replicationService.createReplicationDefinition(ACTION_NAME, "Test Definition"); + assertNotNull(replicationAction); + assertEquals("Test Definition", replicationAction.getDescription()); + assertEquals(ACTION_NAME, replicationAction.getReplicationName()); + + String id = replicationAction.getId(); + assertNotNull(id); + assertTrue(id.length() > 0); + + assertNotNull(replicationAction.getPayload()); + assertEquals(0, replicationAction.getPayload().size()); + + assertNull(replicationAction.getLocalTransferReport()); + } + + public void testCreateSaveLoad() throws Exception + { + ReplicationDefinition replicationAction = + replicationService.createReplicationDefinition(ACTION_NAME, "Test Definition"); + replicationAction.getPayload().add( + new NodeRef("workspace://SpacesStore/Testing") + ); + replicationAction.getPayload().add( + new NodeRef("workspace://SpacesStore/Testing2") + ); + assertEquals(2, replicationAction.getPayload().size()); + + replicationService.saveReplicationDefinition(replicationAction); + + ReplicationDefinition retrieved = + replicationService.loadReplicationDefinition(ACTION_NAME); + assertNotNull(retrieved); + assertEquals(ACTION_NAME, retrieved.getReplicationName()); + assertEquals("Test Definition", retrieved.getDescription()); + assertEquals(2, retrieved.getPayload().size()); + } + + public void testLoadList() throws Exception + { + assertEquals(0, replicationService.loadReplicationDefinitions().size()); + + // Create and store + ReplicationDefinition rd1 = replicationService.createReplicationDefinition(ACTION_NAME, "Test 1"); + ReplicationDefinition rd2 = replicationService.createReplicationDefinition(ACTION_NAME2, "Test 2"); + + assertEquals(0, replicationService.loadReplicationDefinitions().size()); + + replicationService.saveReplicationDefinition(rd1); + + assertEquals(1, replicationService.loadReplicationDefinitions().size()); + assertEquals(ACTION_NAME, replicationService.loadReplicationDefinitions().get(0).getReplicationName()); + + replicationService.saveReplicationDefinition(rd2); + assertEquals(2, replicationService.loadReplicationDefinitions().size()); + } + + public void testLoadByTarget() throws Exception + { + assertEquals(0, replicationService.loadReplicationDefinitions().size()); + assertEquals(0, replicationService.loadReplicationDefinitions("TestTarget").size()); + assertEquals(0, replicationService.loadReplicationDefinitions("TestTarget2").size()); + + // Store some + ReplicationDefinition rdTT = replicationService.createReplicationDefinition(ACTION_NAME, "Test"); + rdTT.setTargetName("TestTarget"); + replicationService.saveReplicationDefinition(rdTT); + + // Check it shows up correctly + assertEquals(1, replicationService.loadReplicationDefinitions().size()); + assertEquals(1, replicationService.loadReplicationDefinitions("TestTarget").size()); + assertEquals(0, replicationService.loadReplicationDefinitions("TestTarget2").size()); + } + +} \ No newline at end of file