diff --git a/source/java/org/alfresco/repo/policy/PolicyComponent.java b/source/java/org/alfresco/repo/policy/PolicyComponent.java index f58807ab78..d1ebfbccc1 100644 --- a/source/java/org/alfresco/repo/policy/PolicyComponent.java +++ b/source/java/org/alfresco/repo/policy/PolicyComponent.java @@ -39,8 +39,14 @@ import org.alfresco.service.namespace.QName; * supports the policy interface) until the Policy is registered. Otherwise, * the behaviour is validated at bind-time. * + * Policies may be selectively "turned off" by the Behaviour Filter. + * + * + * * @see org.alfresco.repo.policy.BehaviourFilter * + * @see org.alfresco.repo.node.NodeServicePolicies + * * * @author David Caruana * @@ -94,7 +100,7 @@ public interface PolicyComponent * Determine if the specified policy has been registered * * @param policyType the policy type - * @param policy the policy name + * @param policy the fully qualified name of the policy * @return true => registered, false => not yet */ public boolean isRegisteredPolicy(PolicyType policyType, QName policy); @@ -108,13 +114,13 @@ public interface PolicyComponent * Example of calling this method *
      *         this.policyComponent.bindClassBehaviour(
-     *           QName.createQName(NamespaceService.ALFRESCO_URI, "beforeUpdateNode"),
+     *           NodeServicePolicies.BeforeUpdateNodePolicy.QNAME,
      *           ContentModel.ASPECT_LOCKABLE,
      *           new JavaBehaviour(this, "beforeUpdateNode"));
      * 
* @param policy the fully qualified policy name * @param className the qualified name of a type or aspect that the policy is bound to - * @param behaviour the behaviour, what gets executed by the policy + * @param behaviour the behaviour. What gets executed by the policy * @return the registered behaviour definition */ public BehaviourDefinition bindClassBehaviour(QName policy, QName className, Behaviour behaviour); @@ -124,7 +130,7 @@ public interface PolicyComponent * * @param policy the fully qualified policy name * @param service the service (any object, in fact) - * @param behaviour the behaviour, what gets executed by the policy + * @param behaviour the behaviour. What gets executed by the policy * @return the registered behaviour definition */ public BehaviourDefinition bindClassBehaviour(QName policy, Object service, Behaviour behaviour); @@ -135,7 +141,7 @@ public interface PolicyComponent * @param policy the fully qualified policy name * @param className the qualified name of the class (type or aspect) to bind against * @param propertyName the name of the property to bind against - * @param behaviour the behaviour, what gets executed by the policy + * @param behaviour the behaviour. What gets executed by the policy * @return the registered behaviour definition */ public BehaviourDefinition bindPropertyBehaviour(QName policy, QName className, QName propertyName, Behaviour behaviour); @@ -143,7 +149,7 @@ public interface PolicyComponent /** * Bind a Property specific behaviour to a Property-level Policy (for all properties of a Class) * - * @param policy the policy name + * @param policy the fully qualified policy name * @param className the name of the class (type or aspect) to bind against * @param behaviour the behaviour, what gets executed by the policy * @return the registered behaviour definition @@ -153,7 +159,7 @@ public interface PolicyComponent /** * Bind a Service specific behaviour to a Property-level Policy * - * @param policy the policy name + * @param policy the fully qualified policy name * @param service the binding service * @param behaviour the behaviour * @return the registered behaviour definition @@ -166,7 +172,7 @@ public interface PolicyComponent * For example, before a rule folder association is created. *
      *         policyComponent.bindAssociationBehaviour(
-     *           QName.createQName(NamespaceService.ALFRESCO_URI, "beforeCreateChildAssociation"),
+     *           NodeServicePolicies.BeforeCreateChildAssociationPolicy.QNAME,
      *           RuleModel.ASPECT_RULES,
      *           RuleModel.ASSOC_RULE_FOLDER,
      *           new JavaBehaviour(this, "beforeCreateChildAssociation"));
@@ -175,7 +181,7 @@ public interface PolicyComponent
      * @param policy  the policy name
      * @param className  the name of the class (type or aspect) to bind against
      * @param assocName the name of the association to bind against
-     * @param behaviour  the behaviour, what gets executed by the policy
+     * @param behaviour  the behaviour. What gets executed by the policy
      * @return  the registered behaviour definition
      */
     public BehaviourDefinition bindAssociationBehaviour(QName policy, QName className, QName assocName, Behaviour behaviour);
@@ -185,7 +191,7 @@ public interface PolicyComponent
      * 
      * @param policy  the policy name
      * @param className  the name of the class (type or aspect) to bind against
-     * @param behaviour  the behaviour
+     * @param behaviour  the behaviour. What gets executed by the policy
      * @return  the registered behaviour definition
      */
     public BehaviourDefinition bindAssociationBehaviour(QName policy, QName className, Behaviour behaviour);
@@ -195,7 +201,7 @@ public interface PolicyComponent
      * 
      * @param policy  the policy name
      * @param service  the binding service
-     * @param behaviour  the behaviour
+     * @param behaviour  the behaviour. What gets executed by the policy
      * @return  the registered behaviour definition
      */
     public BehaviourDefinition bindAssociationBehaviour(QName policy, Object service, Behaviour behaviour);
diff --git a/source/java/org/alfresco/repo/transfer/RepoPrimaryManifestProcessorImpl.java b/source/java/org/alfresco/repo/transfer/RepoPrimaryManifestProcessorImpl.java
index 19ed35d358..08fd1db906 100644
--- a/source/java/org/alfresco/repo/transfer/RepoPrimaryManifestProcessorImpl.java
+++ b/source/java/org/alfresco/repo/transfer/RepoPrimaryManifestProcessorImpl.java
@@ -29,6 +29,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.alfresco.model.ContentModel;
+import org.alfresco.repo.security.authentication.AuthenticationUtil;
 import org.alfresco.repo.transfer.CorrespondingNodeResolver.ResolvedParentChildPair;
 import org.alfresco.repo.transfer.manifest.ManifestAccessControl;
 import org.alfresco.repo.transfer.manifest.ManifestPermission;
@@ -38,6 +39,8 @@ import org.alfresco.repo.transfer.manifest.TransferManifestNode;
 import org.alfresco.repo.transfer.manifest.TransferManifestNormalNode;
 import org.alfresco.service.cmr.dictionary.AspectDefinition;
 import org.alfresco.service.cmr.dictionary.DictionaryService;
+import org.alfresco.service.cmr.lock.LockService;
+import org.alfresco.service.cmr.lock.LockType;
 import org.alfresco.service.cmr.repository.ChildAssociationRef;
 import org.alfresco.service.cmr.repository.ContentData;
 import org.alfresco.service.cmr.repository.ContentService;
@@ -87,6 +90,7 @@ public class RepoPrimaryManifestProcessorImpl extends AbstractManifestProcessorB
     private ContentService contentService;
     private DictionaryService dictionaryService;
     private CorrespondingNodeResolver nodeResolver;
+    private LockService lockService;
     
     // State within this class
     /**
@@ -290,7 +294,16 @@ public class RepoPrimaryManifestProcessorImpl extends AbstractManifestProcessorB
             props.put(TransferModel.PROP_REPOSITORY_ID, header.getRepositoryId());
         }
         props.put(TransferModel.PROP_FROM_REPOSITORY_ID, header.getRepositoryId());
-
+        
+        // Do we need to worry about locking this new node ?
+        if(header.isReadOnly())
+        {
+            log.debug("new node needs to be locked");
+            props.put(ContentModel.PROP_LOCK_OWNER, AuthenticationUtil.getAdminUserName());
+            props.put(ContentModel.PROP_LOCK_TYPE, LockType.READ_ONLY_LOCK.toString());
+            props.put(ContentModel.PROP_EXPIRY_DATE, null);
+         }
+ 
         // Create the corresponding node...
         ChildAssociationRef newNode = nodeService.createNode(parentNodeRef, parentAssocType, parentAssocName, node
                 .getType(), props);
@@ -312,6 +325,7 @@ public class RepoPrimaryManifestProcessorImpl extends AbstractManifestProcessorB
             nodeService.addAspect(newNode.getChildRef(), aspect, null);
         }
         
+        
         ManifestAccessControl acl = node.getAccessControl();        
         // Apply new ACL to this node
         if(acl != null)
@@ -412,6 +426,15 @@ public class RepoPrimaryManifestProcessorImpl extends AbstractManifestProcessorB
                 props.put(TransferModel.PROP_REPOSITORY_ID, header.getRepositoryId());
             }
             props.put(TransferModel.PROP_FROM_REPOSITORY_ID, header.getRepositoryId());
+            
+            // Do we need to worry about locking this updated ?
+            if(header.isReadOnly())
+            {
+                props.put(ContentModel.PROP_LOCK_OWNER, AuthenticationUtil.getAdminUserName());
+                props.put(ContentModel.PROP_LOCK_TYPE, LockType.READ_ONLY_LOCK.toString());
+                props.put(ContentModel.PROP_EXPIRY_DATE, null);
+                log.debug("updated node needs to be locked");
+            }
 
             // Split out the content properties and sanitise the others
             Map contentProps = processProperties(nodeToUpdate, props, existingProps);
@@ -434,6 +457,11 @@ public class RepoPrimaryManifestProcessorImpl extends AbstractManifestProcessorB
                 suppliedAspects.add(aspectDef.getName());
             }
             
+            if(header.isReadOnly())
+            {
+                suppliedAspects.add(ContentModel.ASPECT_LOCKABLE);
+            }
+            
             aspectsToRemove.removeAll(suppliedAspects);
             aspectsToRemove.remove(TransferModel.ASPECT_TRANSFERRED);
             suppliedAspects.removeAll(existingAspects);
diff --git a/source/java/org/alfresco/repo/transfer/RepoTertiaryManifestProcessorImpl.java b/source/java/org/alfresco/repo/transfer/RepoTertiaryManifestProcessorImpl.java
index 834042768f..dd49b91eb2 100644
--- a/source/java/org/alfresco/repo/transfer/RepoTertiaryManifestProcessorImpl.java
+++ b/source/java/org/alfresco/repo/transfer/RepoTertiaryManifestProcessorImpl.java
@@ -45,7 +45,7 @@ import org.apache.commons.logging.LogFactory;
  * For a complete transfer it is responsible for deleting any replicated nodes 
  * which exist in the target repository that do not exist in the source repository.
  * 
- * If the transfer is not "complete" then this processor does nothing.
+ * If the transfer is not "sync" then this processor does nothing.
  * 
  */
 public class RepoTertiaryManifestProcessorImpl extends AbstractManifestProcessorBase
diff --git a/source/java/org/alfresco/repo/transfer/TransferServiceImpl.java b/source/java/org/alfresco/repo/transfer/TransferServiceImpl.java
index 9c29dd465e..b2f313cc18 100644
--- a/source/java/org/alfresco/repo/transfer/TransferServiceImpl.java
+++ b/source/java/org/alfresco/repo/transfer/TransferServiceImpl.java
@@ -573,6 +573,7 @@ public class TransferServiceImpl implements TransferService
             header.setCreatedDate(new Date());
             header.setNodeCount(nodes.size());
             header.setSync(definition.isSync());
+            header.setReadOnly(definition.isReadOnly());
             formatter.startTransferManifest(snapshotWriter);
             formatter.writeTransferManifestHeader(header);
             for(NodeRef nodeRef : nodes)
diff --git a/source/java/org/alfresco/repo/transfer/TransferServiceImplTest.java b/source/java/org/alfresco/repo/transfer/TransferServiceImplTest.java
index 7168050f86..30a865b64b 100644
--- a/source/java/org/alfresco/repo/transfer/TransferServiceImplTest.java
+++ b/source/java/org/alfresco/repo/transfer/TransferServiceImplTest.java
@@ -20,6 +20,7 @@ package org.alfresco.repo.transfer;
 
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
@@ -34,10 +35,16 @@ import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
 import javax.xml.validation.Validator;
 
+import org.alfresco.error.AlfrescoRuntimeException;
 import org.alfresco.model.ContentModel;
+import org.alfresco.repo.dictionary.DictionaryDAOImpl.DictionaryRegistry;
 import org.alfresco.repo.security.authentication.AuthenticationComponent;
+import org.alfresco.repo.security.authentication.AuthenticationUtil;
+import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
 import org.alfresco.repo.transfer.manifest.TransferManifestNodeFactory;
 import org.alfresco.service.cmr.action.ActionService;
+import org.alfresco.service.cmr.lock.LockService;
+import org.alfresco.service.cmr.lock.LockType;
 import org.alfresco.service.cmr.repository.ChildAssociationRef;
 import org.alfresco.service.cmr.repository.ContentReader;
 import org.alfresco.service.cmr.repository.ContentService;
@@ -51,6 +58,7 @@ import org.alfresco.service.cmr.search.SearchService;
 import org.alfresco.service.cmr.security.AccessPermission;
 import org.alfresco.service.cmr.security.MutableAuthenticationService;
 import org.alfresco.service.cmr.security.PermissionService;
+import org.alfresco.service.cmr.security.PersonService;
 import org.alfresco.service.cmr.transfer.TransferCallback;
 import org.alfresco.service.cmr.transfer.TransferDefinition;
 import org.alfresco.service.cmr.transfer.TransferEvent;
@@ -65,6 +73,7 @@ import org.alfresco.service.transaction.TransactionService;
 import org.alfresco.util.BaseAlfrescoSpringTest;
 import org.alfresco.util.GUID;
 import org.alfresco.util.Pair;
+import org.alfresco.util.PropertyMap;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.transaction.TransactionDefinition;
@@ -74,7 +83,7 @@ import org.springframework.util.ResourceUtils;
 /**
  * Unit test for TransferServiceImpl
  * 
- * Contains some unit tests for the transfer definitions.
+ * Contains some integration tests for the transfer service
  *
  * @author Mark Rogers
  */
@@ -89,6 +98,10 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest
     private TransferReceiver receiver;
     private TransferManifestNodeFactory transferManifestNodeFactory; 
     private PermissionService permissionService;
+    private LockService lockService;
+    private PersonService personService;
+    
+ 
     
     String COMPANY_HOME_XPATH_QUERY = "/{http://www.alfresco.org/model/application/1.0}company_home";
     String GUEST_HOME_XPATH_QUERY = "/{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/application/1.0}guest_home";
@@ -123,10 +136,15 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest
         this.receiver = (TransferReceiver)this.applicationContext.getBean("transferReceiver");
         this.transferManifestNodeFactory = (TransferManifestNodeFactory)this.applicationContext.getBean("transferManifestNodeFactory");
         this.authenticationComponent = (AuthenticationComponent) this.applicationContext.getBean("authenticationComponent");
+        this.lockService = (LockService) this.applicationContext.getBean("lockService");
+        this.personService = (PersonService)this.applicationContext.getBean("PersonService");
+        
         authenticationComponent.setSystemUserAsCurrentUser();
         setTransactionDefinition(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW));
         assertNotNull("receiver is null", this.receiver);
         
+
+        
     }
     
     /**
@@ -3280,354 +3298,763 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest
 //      
 //     }
 //    
-//    /**
-//     * Test the transfer method with regard to permissions on a node.
-//     * 
-//     * Step 1:  
-//     * Create a node with a single permission 
-//     *     Inherit:false
-//     *     Read, Admin, Allow
-//     *     Transfer
-//     * 
-//     * Step 2:
-//     * Update it to have several permissions 
-//     *     Inherit:false
-//     *     Read, Everyone, DENY
-//     *     Read, Admin, Allow
-//     * 
-//     * Step 3:
-//     * Remove a permission
-//     *     Inherit:false
-//     *     Read, Admin, Allow
-//     * 
-//     * Step 4:
-//     * Revert to inherit all permissions
-//     *     Inherit:true
-//     * 
-//     * This is a unit test so it does some shenanigans to send to the same instance of alfresco.
-//     */
-//    public void testTransferWithPermissions() throws Exception
-//    {
-//        setDefaultRollback(false);
-//        
-//        String CONTENT_TITLE = "ContentTitle";
-//        String CONTENT_TITLE_UPDATED = "ContentTitleUpdated";
-//        Locale CONTENT_LOCALE = Locale.GERMAN; 
-//        String CONTENT_STRING = "Hello";
-//
-//        /**
-//         *  For unit test 
-//         *  - replace the HTTP transport with the in-process transport
-//         *  - replace the node factory with one that will map node refs, paths etc.
-//         */
-//        TransferTransmitter transmitter = new UnitTestInProcessTransmitterImpl(receiver, contentService, transactionService);
-//        transferServiceImpl.setTransmitter(transmitter);
-//        UnitTestTransferManifestNodeFactory testNodeFactory = new UnitTestTransferManifestNodeFactory(this.transferManifestNodeFactory); 
-//        transferServiceImpl.setTransferManifestNodeFactory(testNodeFactory); 
-//        List> pathMap = testNodeFactory.getPathMap();
-//        // Map company_home/guest_home to company_home so tranferred nodes and moved "up" one level.
-//        pathMap.add(new Pair(PathHelper.stringToPath(GUEST_HOME_XPATH_QUERY), PathHelper.stringToPath(COMPANY_HOME_XPATH_QUERY)));
-//          
-//        /**
-//          * Now go ahead and create our transfer target
-//          */
-//        String targetName = "testTransferWithPermissions";
-//        TransferTarget transferMe;
-//        NodeRef contentNodeRef;
-//        NodeRef destNodeRef;
-//        
-//        startNewTransaction();
-//        try
-//        {
-//            /**
-//              * Get guest home
-//              */
-//            String guestHomeQuery = "/app:company_home/app:guest_home";
-//            ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery);
-//            assertEquals("", 1, guestHomeResult.length());
-//            NodeRef guestHome = guestHomeResult.getNodeRef(0); 
-//    
-//            /**
-//             * Create a test node that we will read and write
-//             */        
-//            String name = GUID.generate();
-//            ChildAssociationRef child = nodeService.createNode(guestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(name), ContentModel.TYPE_CONTENT);
-//            contentNodeRef = child.getChildRef();
-//            nodeService.setProperty(contentNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE);   
-//            nodeService.setProperty(contentNodeRef, ContentModel.PROP_NAME, name);
-//            
-//            ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
-//            writer.setLocale(CONTENT_LOCALE);
-//            writer.putContent(CONTENT_STRING);
-//            
-//            permissionService.setInheritParentPermissions(contentNodeRef, false);
-//            permissionService.setPermission(contentNodeRef, "admin", PermissionService.READ, true);
-//              
-//            if(!transferService.targetExists(targetName))
-//            {
-//                transferMe = createTransferTarget(targetName);
-//            }
-//            else
-//            {
-//                transferMe = transferService.getTransferTarget(targetName);
-//            }
-//        }
-//        finally
-//        {
-//            endTransaction();
-//        }
-//        
-//        /**
-//         * Step 1
-//         */
-//        logger.debug("First transfer - create new node with inheritParent permission off");
-//        startNewTransaction();
-//        try 
-//        {
-//           /**
-//             * Transfer our transfer target node 
-//             */
-//            {
-//                    TransferDefinition definition = new TransferDefinition();
-//                    Setnodes = new HashSet();
-//                    nodes.add(contentNodeRef);
-//                    definition.setNodes(nodes);
-//                    transferService.transfer(targetName, definition);
-//            }  
-//        }
-//        finally
-//        {
-//            endTransaction();
-//        }
-//            
-//        startNewTransaction();
-//        try
-//        {
-//            // Now validate that the target node exists with the correct permissions 
-//            destNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef);
-//            assertFalse("unit test stuffed up - comparing with self", destNodeRef.equals(transferMe.getNodeRef()));
-//            assertTrue("dest node ref does not exist", nodeService.exists(destNodeRef));
-//            assertEquals("title is wrong", (String)nodeService.getProperty(destNodeRef, ContentModel.PROP_TITLE), CONTENT_TITLE); 
-//            assertEquals("type is wrong", nodeService.getType(contentNodeRef), nodeService.getType(destNodeRef));
-//            
-//            // Check ACL of destination node
-//            boolean srcInherit = permissionService.getInheritParentPermissions(contentNodeRef);
-//            Set srcPerm = permissionService.getAllSetPermissions(contentNodeRef);
-//            
-//            boolean destInherit = permissionService.getInheritParentPermissions(destNodeRef);
-//            Set destPerm = permissionService.getAllSetPermissions(destNodeRef);
-//            
-//            assertFalse("inherit parent permissions (src) flag is incorrect", srcInherit);
-//            assertFalse("inherit parent permissions (dest) flag is incorrect", destInherit);
-//            
-//            // Check destination has the source's permissions
-//            for (AccessPermission p : srcPerm)
-//            {
-//                logger.debug("checking permission :" + p);
-//                assertTrue("permission is missing", destPerm.contains(p));
-//            }
-//        }
-//        finally
-//        {
-//            endTransaction();
-//        }      
-//        
-//        /**
-//         * Step 2
-//         * Update it to have several permissions 
-//         *     Inherit:false
-//         *     Read, Everyone, DENY
-//         *     Read, Admin, Allow 
-//         */
-//        startNewTransaction();
-//        try
-//        {
-//            permissionService.setPermission(contentNodeRef, "EVERYONE", PermissionService.READ, false);
-//            permissionService.setPermission(contentNodeRef, "admin", PermissionService.FULL_CONTROL, true);
-//        }
-//        finally
-//        {
-//            endTransaction();
-//        }
-//        
-//        startNewTransaction();
-//        try 
-//        {
-//           /**
-//             * Transfer our transfer target node 
-//             */
-//            {
-//                    TransferDefinition definition = new TransferDefinition();
-//                    Setnodes = new HashSet();
-//                    nodes.add(contentNodeRef);
-//                    definition.setNodes(nodes);
-//                    transferService.transfer(targetName, definition);
-//            }  
-//        }
-//        finally
-//        {
-//            endTransaction();
-//        }
-//  
-//        
-//        startNewTransaction();
-//        try
-//        {
-//            // Now validate that the target node exists with the correct permissions 
-//            destNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef);
-//            
-//            // Check ACL of destination node
-//            boolean srcInherit = permissionService.getInheritParentPermissions(contentNodeRef);
-//            Set srcPerm = permissionService.getAllSetPermissions(contentNodeRef);
-//            
-//            boolean destInherit = permissionService.getInheritParentPermissions(destNodeRef);
-//            Set destPerm = permissionService.getAllSetPermissions(destNodeRef);
-//            
-//            assertFalse("inherit parent permissions (src) flag is incorrect", srcInherit);
-//            assertFalse("inherit parent permissions (dest) flag is incorrect", destInherit);
-//            
-//            // Check destination has the source's permissions
-//            for (AccessPermission p : srcPerm)
-//            {
-//                logger.debug("checking permission :" + p);
-//                assertTrue("Step2, permission is missing", destPerm.contains(p));
-//            }
-//        }
-//        finally
-//        {
-//            endTransaction();
-//        }    
-//        
-//        /**
-//         * Step 3 Remove a permission
-//         */
-//        startNewTransaction();
-//        try
-//        {
-//            permissionService.deletePermission(contentNodeRef, "admin", PermissionService.FULL_CONTROL);
-//        }
-//        finally
-//        {
-//            endTransaction();
-//        }
-//        
-//        startNewTransaction();
-//        try 
-//        {
-//           /**
-//             * Transfer our transfer target node 
-//             */
-//            {
-//                    TransferDefinition definition = new TransferDefinition();
-//                    Setnodes = new HashSet();
-//                    nodes.add(contentNodeRef);
-//                    definition.setNodes(nodes);
-//                    transferService.transfer(targetName, definition);
-//            }  
-//        }
-//        finally
-//        {
-//            endTransaction();
-//        }
-//  
-//        startNewTransaction();
-//        try
-//        {
-//            // Now validate that the target node exists with the correct permissions 
-//            destNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef);
-//           
-//            // Check ACL of destination node
-//            boolean srcInherit = permissionService.getInheritParentPermissions(contentNodeRef);
-//            Set srcPerm = permissionService.getAllSetPermissions(contentNodeRef);
-//            
-//            boolean destInherit = permissionService.getInheritParentPermissions(destNodeRef);
-//            Set destPerm = permissionService.getAllSetPermissions(destNodeRef);
-//            
-//            assertFalse("inherit parent permissions (src) flag is incorrect", srcInherit);
-//            assertFalse("inherit parent permissions (dest) flag is incorrect", destInherit);
-//            
-//            // Check destination has the source's permissions
-//            for (AccessPermission p : srcPerm)
-//            {
-//                logger.debug("checking permission :" + p);
-//                assertTrue("permission is missing", destPerm.contains(p));
-//            }
-//        }
-//        finally
-//        {
-//            endTransaction();
-//        }    
-//        
-//        /**
-//         * Step 4
-//         * Revert to inherit all permissions
-//         */
-//        startNewTransaction();
-//        try
-//        {
-//            permissionService.setInheritParentPermissions(contentNodeRef, true);
-//        }
-//        finally
-//        {
-//            endTransaction();
-//        }
-//        
-//        startNewTransaction();
-//        try 
-//        {
-//           /**
-//             * Transfer our transfer target node 
-//             */
-//            {
-//                    TransferDefinition definition = new TransferDefinition();
-//                    Setnodes = new HashSet();
-//                    nodes.add(contentNodeRef);
-//                    definition.setNodes(nodes);
-//                    transferService.transfer(targetName, definition);
-//            }  
-//        }
-//        finally
-//        {
-//            endTransaction();
-//        }
-//  
-//        startNewTransaction();
-//        try
-//        {
-//            // Now validate that the target node exists with the correct permissions 
-//            destNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef);
-//            assertFalse("unit test stuffed up - comparing with self", destNodeRef.equals(transferMe.getNodeRef()));
-//            assertTrue("dest node ref does not exist", nodeService.exists(destNodeRef));
-//            assertEquals("title is wrong", (String)nodeService.getProperty(destNodeRef, ContentModel.PROP_TITLE), CONTENT_TITLE); 
-//            assertEquals("type is wrong", nodeService.getType(contentNodeRef), nodeService.getType(destNodeRef));
-//            
-//            // Check ACL of destination node
-//            boolean srcInherit = permissionService.getInheritParentPermissions(contentNodeRef);
-//            Set srcPerm = permissionService.getAllSetPermissions(contentNodeRef);
-//            
-//            boolean destInherit = permissionService.getInheritParentPermissions(destNodeRef);
-//            Set destPerm = permissionService.getAllSetPermissions(destNodeRef);
-//            
-//            assertTrue("inherit parent permissions (src) flag is incorrect", srcInherit);
-//            assertTrue("inherit parent permissions (dest) flag is incorrect", destInherit);
-//            
-//            // Check destination has the source's permissions
-//            for (AccessPermission p : srcPerm)
-//            {
-//                if(p.isSetDirectly())
-//                {
-//                    logger.debug("checking permission :" + p);
-//                    assertTrue("permission is missing:" + p, destPerm.contains(p));
-//                }
-//            }
-//        }
-//        finally
-//        {
-//            endTransaction();
-//        }    
-//     }
+    /**
+     * Test the transfer method with regard to permissions on a node.
+     * 
+     * Step 1:  
+     * Create a node with a single permission 
+     *     Inherit:false
+     *     Read, Admin, Allow
+     *     Transfer
+     * 
+     * Step 2:
+     * Update it to have several permissions 
+     *     Inherit:false
+     *     Read, Everyone, DENY
+     *     Read, Admin, Allow
+     * 
+     * Step 3:
+     * Remove a permission
+     *     Inherit:false
+     *     Read, Admin, Allow
+     * 
+     * Step 4:
+     * Revert to inherit all permissions
+     *     Inherit:true
+     * 
+     * This is a unit test so it does some shenanigans to send to the same instance of alfresco.
+     */
+    public void testTransferWithPermissions() throws Exception
+    {
+        setDefaultRollback(false);
+        
+        String CONTENT_TITLE = "ContentTitle";
+        String CONTENT_TITLE_UPDATED = "ContentTitleUpdated";
+        Locale CONTENT_LOCALE = Locale.GERMAN; 
+        String CONTENT_STRING = "Hello";
+
+        /**
+         *  For unit test 
+         *  - replace the HTTP transport with the in-process transport
+         *  - replace the node factory with one that will map node refs, paths etc.
+         */
+        TransferTransmitter transmitter = new UnitTestInProcessTransmitterImpl(receiver, contentService, transactionService);
+        transferServiceImpl.setTransmitter(transmitter);
+        UnitTestTransferManifestNodeFactory testNodeFactory = new UnitTestTransferManifestNodeFactory(this.transferManifestNodeFactory); 
+        transferServiceImpl.setTransferManifestNodeFactory(testNodeFactory); 
+        List> pathMap = testNodeFactory.getPathMap();
+        // Map company_home/guest_home to company_home so tranferred nodes and moved "up" one level.
+        pathMap.add(new Pair(PathHelper.stringToPath(GUEST_HOME_XPATH_QUERY), PathHelper.stringToPath(COMPANY_HOME_XPATH_QUERY)));
+          
+        /**
+          * Now go ahead and create our transfer target
+          */
+        String targetName = "testTransferWithPermissions";
+        TransferTarget transferMe;
+        NodeRef contentNodeRef;
+        NodeRef destNodeRef;
+        
+        startNewTransaction();
+        try
+        {
+            /**
+              * Get guest home
+              */
+            String guestHomeQuery = "/app:company_home/app:guest_home";
+            ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery);
+            assertEquals("", 1, guestHomeResult.length());
+            NodeRef guestHome = guestHomeResult.getNodeRef(0); 
+    
+            /**
+             * Create a test node that we will read and write
+             */        
+            String name = GUID.generate();
+            ChildAssociationRef child = nodeService.createNode(guestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(name), ContentModel.TYPE_CONTENT);
+            contentNodeRef = child.getChildRef();
+            nodeService.setProperty(contentNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE);   
+            nodeService.setProperty(contentNodeRef, ContentModel.PROP_NAME, name);
+            
+            ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
+            writer.setLocale(CONTENT_LOCALE);
+            writer.putContent(CONTENT_STRING);
+            
+            permissionService.setInheritParentPermissions(contentNodeRef, false);
+            permissionService.setPermission(contentNodeRef, "admin", PermissionService.READ, true);
+              
+            if(!transferService.targetExists(targetName))
+            {
+                transferMe = createTransferTarget(targetName);
+            }
+            else
+            {
+                transferMe = transferService.getTransferTarget(targetName);
+            }
+        }
+        finally
+        {
+            endTransaction();
+        }
+        
+        /**
+         * Step 1
+         */
+        logger.debug("First transfer - create new node with inheritParent permission off");
+        startNewTransaction();
+        try 
+        {
+           /**
+             * Transfer our transfer target node 
+             */
+            {
+                    TransferDefinition definition = new TransferDefinition();
+                    Setnodes = new HashSet();
+                    nodes.add(contentNodeRef);
+                    definition.setNodes(nodes);
+                    transferService.transfer(targetName, definition);
+            }  
+        }
+        finally
+        {
+            endTransaction();
+        }
+            
+        startNewTransaction();
+        try
+        {
+            // Now validate that the target node exists with the correct permissions 
+            destNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef);
+            assertFalse("unit test stuffed up - comparing with self", destNodeRef.equals(transferMe.getNodeRef()));
+            assertTrue("dest node ref does not exist", nodeService.exists(destNodeRef));
+            assertEquals("title is wrong", (String)nodeService.getProperty(destNodeRef, ContentModel.PROP_TITLE), CONTENT_TITLE); 
+            assertEquals("type is wrong", nodeService.getType(contentNodeRef), nodeService.getType(destNodeRef));
+            
+            // Check ACL of destination node
+            boolean srcInherit = permissionService.getInheritParentPermissions(contentNodeRef);
+            Set srcPerm = permissionService.getAllSetPermissions(contentNodeRef);
+            
+            boolean destInherit = permissionService.getInheritParentPermissions(destNodeRef);
+            Set destPerm = permissionService.getAllSetPermissions(destNodeRef);
+            
+            assertFalse("inherit parent permissions (src) flag is incorrect", srcInherit);
+            assertFalse("inherit parent permissions (dest) flag is incorrect", destInherit);
+            
+            // Check destination has the source's permissions
+            for (AccessPermission p : srcPerm)
+            {
+                logger.debug("checking permission :" + p);
+                assertTrue("permission is missing", destPerm.contains(p));
+            }
+        }
+        finally
+        {
+            endTransaction();
+        }      
+        
+        /**
+         * Step 2
+         * Update it to have several permissions 
+         *     Inherit:false
+         *     Read, Everyone, DENY
+         *     Read, Admin, Allow 
+         */
+        startNewTransaction();
+        try
+        {
+            permissionService.setPermission(contentNodeRef, "EVERYONE", PermissionService.READ, false);
+            permissionService.setPermission(contentNodeRef, "admin", PermissionService.FULL_CONTROL, true);
+        }
+        finally
+        {
+            endTransaction();
+        }
+        
+        startNewTransaction();
+        try 
+        {
+           /**
+             * Transfer our transfer target node 
+             */
+            {
+                    TransferDefinition definition = new TransferDefinition();
+                    Setnodes = new HashSet();
+                    nodes.add(contentNodeRef);
+                    definition.setNodes(nodes);
+                    transferService.transfer(targetName, definition);
+            }  
+        }
+        finally
+        {
+            endTransaction();
+        }
+  
+        
+        startNewTransaction();
+        try
+        {
+            // Now validate that the target node exists with the correct permissions 
+            destNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef);
+            
+            // Check ACL of destination node
+            boolean srcInherit = permissionService.getInheritParentPermissions(contentNodeRef);
+            Set srcPerm = permissionService.getAllSetPermissions(contentNodeRef);
+            
+            boolean destInherit = permissionService.getInheritParentPermissions(destNodeRef);
+            Set destPerm = permissionService.getAllSetPermissions(destNodeRef);
+            
+            assertFalse("inherit parent permissions (src) flag is incorrect", srcInherit);
+            assertFalse("inherit parent permissions (dest) flag is incorrect", destInherit);
+            
+            // Check destination has the source's permissions
+            for (AccessPermission p : srcPerm)
+            {
+                logger.debug("checking permission :" + p);
+                assertTrue("Step2, permission is missing", destPerm.contains(p));
+            }
+        }
+        finally
+        {
+            endTransaction();
+        }    
+        
+        /**
+         * Step 3 Remove a permission
+         */
+        startNewTransaction();
+        try
+        {
+            permissionService.deletePermission(contentNodeRef, "admin", PermissionService.FULL_CONTROL);
+        }
+        finally
+        {
+            endTransaction();
+        }
+        
+        startNewTransaction();
+        try 
+        {
+           /**
+             * Transfer our transfer target node 
+             */
+            {
+                    TransferDefinition definition = new TransferDefinition();
+                    Setnodes = new HashSet();
+                    nodes.add(contentNodeRef);
+                    definition.setNodes(nodes);
+                    transferService.transfer(targetName, definition);
+            }  
+        }
+        finally
+        {
+            endTransaction();
+        }
+  
+        startNewTransaction();
+        try
+        {
+            // Now validate that the target node exists with the correct permissions 
+            destNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef);
+           
+            // Check ACL of destination node
+            boolean srcInherit = permissionService.getInheritParentPermissions(contentNodeRef);
+            Set srcPerm = permissionService.getAllSetPermissions(contentNodeRef);
+            
+            boolean destInherit = permissionService.getInheritParentPermissions(destNodeRef);
+            Set destPerm = permissionService.getAllSetPermissions(destNodeRef);
+            
+            assertFalse("inherit parent permissions (src) flag is incorrect", srcInherit);
+            assertFalse("inherit parent permissions (dest) flag is incorrect", destInherit);
+            
+            // Check destination has the source's permissions
+            for (AccessPermission p : srcPerm)
+            {
+                logger.debug("checking permission :" + p);
+                assertTrue("permission is missing", destPerm.contains(p));
+            }
+        }
+        finally
+        {
+            endTransaction();
+        }    
+        
+        /**
+         * Step 4
+         * Revert to inherit all permissions
+         */
+        startNewTransaction();
+        try
+        {
+            permissionService.setInheritParentPermissions(contentNodeRef, true);
+        }
+        finally
+        {
+            endTransaction();
+        }
+        
+        startNewTransaction();
+        try 
+        {
+           /**
+             * Transfer our transfer target node 
+             */
+            {
+                    TransferDefinition definition = new TransferDefinition();
+                    Setnodes = new HashSet();
+                    nodes.add(contentNodeRef);
+                    definition.setNodes(nodes);
+                    transferService.transfer(targetName, definition);
+            }  
+        }
+        finally
+        {
+            endTransaction();
+        }
+  
+        startNewTransaction();
+        try
+        {
+            // Now validate that the target node exists with the correct permissions 
+            destNodeRef = testNodeFactory.getMappedNodeRef(contentNodeRef);
+            assertFalse("unit test stuffed up - comparing with self", destNodeRef.equals(transferMe.getNodeRef()));
+            assertTrue("dest node ref does not exist", nodeService.exists(destNodeRef));
+            assertEquals("title is wrong", (String)nodeService.getProperty(destNodeRef, ContentModel.PROP_TITLE), CONTENT_TITLE); 
+            assertEquals("type is wrong", nodeService.getType(contentNodeRef), nodeService.getType(destNodeRef));
+            
+            // Check ACL of destination node
+            boolean srcInherit = permissionService.getInheritParentPermissions(contentNodeRef);
+            Set srcPerm = permissionService.getAllSetPermissions(contentNodeRef);
+            
+            boolean destInherit = permissionService.getInheritParentPermissions(destNodeRef);
+            Set destPerm = permissionService.getAllSetPermissions(destNodeRef);
+            
+            assertTrue("inherit parent permissions (src) flag is incorrect", srcInherit);
+            assertTrue("inherit parent permissions (dest) flag is incorrect", destInherit);
+            
+            // Check destination has the source's permissions
+            for (AccessPermission p : srcPerm)
+            {
+                if(p.isSetDirectly())
+                {
+                    logger.debug("checking permission :" + p);
+                    assertTrue("permission is missing:" + p, destPerm.contains(p));
+                }
+            }
+        }
+        finally
+        {
+            endTransaction();
+        }    
+     }
+    
+    
+    /**
+     * Transfer with read only flag
+     * 
+     * Node tree for this test
+     * 
 
+     *           A (Folder)
+     *   |                 | 
+     *   B (Content)   C (Folder)
+     *                     |
+     *                     D (Content)
+     * 
+ * Step 1 + * transfer Nodes ABCD with read only flag set - content should all be locked on destination + *

+ * Step 2 + * lock B (Content node) as user fred + * transfer (read only) - destination lock should change to Admin + *

+ * Step 3 + * lock C (Folder) as user fred + * transfer (read only) - destination lock should change to Admin + *

+ * Step 4 + * transfer without read only flag - locks should revert from Admin to Fred. + *

+ * Step 5 + * remove locks on A and B - transfer without read only flag - content should all be unlocked. + */ + public void testReadOnlyFlag() throws Exception + { + setDefaultRollback(false); + + String CONTENT_TITLE = "ContentTitle"; + String CONTENT_TITLE_UPDATED = "ContentTitleUpdated"; + String CONTENT_NAME = "Demo Node 1"; + Locale CONTENT_LOCALE = Locale.GERMAN; + String CONTENT_STRING = "The quick brown fox"; + Setnodes = new HashSet(); + String USER_ONE = "TransferServiceImplTest"; + String PASSWORD = "Password"; + + String targetName = "testReadOnlyFlag"; + + NodeRef nodeA; + NodeRef nodeB; + NodeRef nodeC; + NodeRef nodeD; + + ChildAssociationRef child; + + /** + * For unit test + * - replace the HTTP transport with the in-process transport + * - replace the node factory with one that will map node refs, paths etc. + */ + TransferTransmitter transmitter = new UnitTestInProcessTransmitterImpl(this.receiver, this.contentService, transactionService); + transferServiceImpl.setTransmitter(transmitter); + UnitTestTransferManifestNodeFactory testNodeFactory = new UnitTestTransferManifestNodeFactory(this.transferManifestNodeFactory); + transferServiceImpl.setTransferManifestNodeFactory(testNodeFactory); + List> pathMap = testNodeFactory.getPathMap(); + // Map company_home/guest_home to company_home so tranferred nodes and moved "up" one level. + pathMap.add(new Pair(PathHelper.stringToPath(GUEST_HOME_XPATH_QUERY), PathHelper.stringToPath(COMPANY_HOME_XPATH_QUERY))); + + TransferTarget transferMe; + + startNewTransaction(); + try + { + /** + * Get guest home + */ + String guestHomeQuery = "/app:company_home/app:guest_home"; + ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); + assertEquals("", 1, guestHomeResult.length()); + NodeRef guestHome = guestHomeResult.getNodeRef(0); + + /** + * Create a test node that we will read and write + */ + String guid = GUID.generate(); + + child = nodeService.createNode(guestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(guid), ContentModel.TYPE_FOLDER); + nodeA = child.getChildRef(); + nodeService.setProperty(nodeA , ContentModel.PROP_TITLE, guid); + nodeService.setProperty(nodeA , ContentModel.PROP_NAME, guid); + nodes.add(nodeA); + + child = nodeService.createNode(nodeA, ContentModel.ASSOC_CONTAINS, QName.createQName("testNodeB"), ContentModel.TYPE_CONTENT); + nodeB = child.getChildRef(); + nodeService.setProperty(nodeB , ContentModel.PROP_TITLE, CONTENT_TITLE + "B"); + nodeService.setProperty(nodeB , ContentModel.PROP_NAME, "DemoNodeB"); + + { + ContentWriter writer = contentService.getWriter(nodeB , ContentModel.PROP_CONTENT, true); + writer.setLocale(CONTENT_LOCALE); + writer.putContent(CONTENT_STRING); + nodes.add(nodeB); + } + + child = nodeService.createNode(nodeA, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,"testNodeC"), ContentModel.TYPE_FOLDER); + nodeC = child.getChildRef(); + nodeService.setProperty(nodeC , ContentModel.PROP_TITLE, "TestNodeC"); + nodeService.setProperty(nodeC , ContentModel.PROP_NAME, "TestNodeC"); + nodes.add(nodeC); + + child = nodeService.createNode(nodeC, ContentModel.ASSOC_CONTAINS, QName.createQName("testNodeD"), ContentModel.TYPE_CONTENT); + nodeD = child.getChildRef(); + nodeService.setProperty(nodeD , ContentModel.PROP_TITLE, CONTENT_TITLE + "D"); + nodeService.setProperty(nodeD , ContentModel.PROP_NAME, "DemoNodeD"); + { + ContentWriter writer = contentService.getWriter(nodeD , ContentModel.PROP_CONTENT, true); + writer.setLocale(CONTENT_LOCALE); + writer.putContent(CONTENT_STRING); + nodes.add(nodeD); + } + + // Create users + createUser(USER_ONE, PASSWORD); + + /** + * Now go ahead and create our first transfer target + */ + if(!transferService.targetExists(targetName)) + { + transferMe = createTransferTarget(targetName); + } + else + { + transferMe = transferService.getTransferTarget(targetName); + } + } + finally + { + endTransaction(); + } + + /** + * Step 1. + * transfer Nodes ABCD with read only flag set - content should all be locked on destination + */ + logger.debug("transfer read only - step 1"); + startNewTransaction(); + try + { + /** + * Transfer our transfer target nodes + */ + { + TransferDefinition definition = new TransferDefinition(); + definition.setNodes(nodes); + definition.setReadOnly(true); + transferService.transfer(targetName, definition); + } + } + finally + { + endTransaction(); + } + + startNewTransaction(); + try + { + // Check destination nodes are locked. + assertTrue("dest node A does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeA))); + assertTrue("dest node B does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeB))); + assertTrue("dest node C does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeC))); + assertTrue("dest node D does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeD))); + + assertTrue("dest node A not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeA), ContentModel.ASPECT_LOCKABLE)); + assertTrue("dest node B not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeB), ContentModel.ASPECT_LOCKABLE)); + assertTrue("dest node C not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeC), ContentModel.ASPECT_LOCKABLE)); + assertTrue("dest node D not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeD), ContentModel.ASPECT_LOCKABLE)); + } + finally + { + endTransaction(); + } + + /** + * Step 2 + * lock B (Content node) as user ONE + * transfer (read only) - destination lock should change user to "Admin" + */ + startNewTransaction(); + try + { + AuthenticationUtil.pushAuthentication(); + AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE); + lockService.lock(nodeB, LockType.READ_ONLY_LOCK); + } + finally + { + assertEquals("test error: dest node B lock ownership", nodeService.getProperty(nodeB, ContentModel.PROP_LOCK_OWNER), USER_ONE); + AuthenticationUtil.popAuthentication(); + endTransaction(); + } + + logger.debug("transfer read only - step 2"); + startNewTransaction(); + try + { + /** + * Transfer our transfer target nodes + */ + { + TransferDefinition definition = new TransferDefinition(); + definition.setNodes(nodes); + definition.setReadOnly(true); + transferService.transfer(targetName, definition); + } + } + finally + { + endTransaction(); + } + + startNewTransaction(); + try + { + // Check destination nodes are locked. + assertTrue("dest node A does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeA))); + assertTrue("dest node B does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeB))); + assertTrue("dest node C does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeC))); + assertTrue("dest node D does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeD))); + + assertTrue("dest node A not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeA), ContentModel.ASPECT_LOCKABLE)); + assertTrue("dest node B not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeB), ContentModel.ASPECT_LOCKABLE)); + assertTrue("dest node C not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeC), ContentModel.ASPECT_LOCKABLE)); + assertTrue("dest node D not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeD), ContentModel.ASPECT_LOCKABLE)); + + // check that the lock owner is no longer USER_ONE + assertTrue("lock owner not changed", !USER_ONE.equalsIgnoreCase((String)nodeService.getProperty(testNodeFactory.getMappedNodeRef(nodeB), ContentModel.PROP_LOCK_OWNER))); + } + finally + { + endTransaction(); + } + + + /** + * Step 3 + * lock C (Folder node) as user ONE + * transfer (read only) - destination lock should change to Admin + */ + startNewTransaction(); + try + { + AuthenticationUtil.pushAuthentication(); + AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE); + lockService.lock(nodeC, LockType.READ_ONLY_LOCK); + } + finally + { + assertEquals("test error: dest node C lock ownership", nodeService.getProperty(nodeC, ContentModel.PROP_LOCK_OWNER), USER_ONE); + AuthenticationUtil.popAuthentication(); + endTransaction(); + } + + logger.debug("transfer read only - step 3"); + startNewTransaction(); + try + { + /** + * Transfer our transfer target nodes + */ + { + TransferDefinition definition = new TransferDefinition(); + definition.setNodes(nodes); + definition.setReadOnly(true); + transferService.transfer(targetName, definition); + } + } + finally + { + endTransaction(); + } + + startNewTransaction(); + try + { + // Check destination nodes are locked. + assertTrue("dest node A does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeA))); + assertTrue("dest node B does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeB))); + assertTrue("dest node C does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeC))); + assertTrue("dest node D does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeD))); + + assertTrue("dest node A not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeA), ContentModel.ASPECT_LOCKABLE)); + assertTrue("dest node B not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeB), ContentModel.ASPECT_LOCKABLE)); + assertTrue("dest node C not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeC), ContentModel.ASPECT_LOCKABLE)); + assertTrue("dest node D not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeD), ContentModel.ASPECT_LOCKABLE)); + + // check that the lock owner is no longer USER_ONE for content node B and folder node C + assertTrue("lock owner not changed", !USER_ONE.equalsIgnoreCase((String)nodeService.getProperty(testNodeFactory.getMappedNodeRef(nodeB), ContentModel.PROP_LOCK_OWNER))); + assertTrue("lock owner not changed", !USER_ONE.equalsIgnoreCase((String)nodeService.getProperty(testNodeFactory.getMappedNodeRef(nodeC), ContentModel.PROP_LOCK_OWNER))); + } + finally + { + endTransaction(); + } + + + /** + * Step 4 + * transfer without read only flag - locks should revert from Admin to USER_ONE. + */ + logger.debug("transfer read only - step 4"); + startNewTransaction(); + try + { + /** + * Transfer our transfer target nodes + */ + { + TransferDefinition definition = new TransferDefinition(); + definition.setNodes(nodes); + definition.setReadOnly(false); // turn off read-only + transferService.transfer(targetName, definition); + } + } + finally + { + endTransaction(); + } + startNewTransaction(); + try + { + // Check destination nodes are not locked. + assertTrue("dest node A does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeA))); + assertTrue("dest node B does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeB))); + assertTrue("dest node C does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeC))); + assertTrue("dest node D does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeD))); + + assertFalse("dest node A not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeA), ContentModel.ASPECT_LOCKABLE)); + assertTrue("dest node B not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeB), ContentModel.ASPECT_LOCKABLE)); + assertTrue("dest node C not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeC), ContentModel.ASPECT_LOCKABLE)); + assertFalse("dest node D not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeD), ContentModel.ASPECT_LOCKABLE)); + + assertEquals("dest node B lock ownership", nodeService.getProperty(testNodeFactory.getMappedNodeRef(nodeB), ContentModel.PROP_LOCK_OWNER), USER_ONE); + assertEquals("dest node C lock ownership", nodeService.getProperty(testNodeFactory.getMappedNodeRef(nodeC), ContentModel.PROP_LOCK_OWNER), USER_ONE); + + } + finally + { + endTransaction(); + } + + + /** + * Step 5 + * remove locks on A and B - transfer without read only flag - content should all be unlocked. + */ + logger.debug("transfer read only - step 5"); + startNewTransaction(); + try + { + lockService.unlock(nodeB); + lockService.unlock(nodeC); + AuthenticationUtil.runAs(new RunAsWork() + { + public Void doWork() + { + + return null; + } + }, USER_ONE); + } + finally + { + endTransaction(); + } + startNewTransaction(); + try + { + /** + * Transfer our transfer target nodes + */ + { + TransferDefinition definition = new TransferDefinition(); + definition.setNodes(nodes); + definition.setReadOnly(false); // turn off read-only + transferService.transfer(targetName, definition); + } + } + finally + { + endTransaction(); + } + startNewTransaction(); + try + { + // Check destination nodes are not locked. + assertTrue("dest node A does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeA))); + assertTrue("dest node B does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeB))); + assertTrue("dest node C does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeC))); + assertTrue("dest node D does not exist", nodeService.exists(testNodeFactory.getMappedNodeRef(nodeD))); + + assertFalse("dest node A not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeA), ContentModel.ASPECT_LOCKABLE)); + assertFalse("dest node B not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeB), ContentModel.ASPECT_LOCKABLE)); + assertFalse("dest node C not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeC), ContentModel.ASPECT_LOCKABLE)); + assertFalse("dest node D not locked", nodeService.hasAspect(testNodeFactory.getMappedNodeRef(nodeD), ContentModel.ASPECT_LOCKABLE)); + } + finally + { + endTransaction(); + } + } // end test read only flag + // Utility methods below. private TransferTarget createTransferTarget(String name) { String title = "title"; @@ -3645,4 +4072,21 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest TransferTarget target = transferService.createAndSaveTransferTarget(name, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password); return target; } + + private void createUser(String userName, String password) + { + if (this.authenticationService.authenticationExists(userName) == false) + { + this.authenticationService.createAuthentication(userName, password.toCharArray()); + + PropertyMap ppOne = new PropertyMap(4); + ppOne.put(ContentModel.PROP_USERNAME, userName); + ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName"); + ppOne.put(ContentModel.PROP_LASTNAME, "lastName"); + ppOne.put(ContentModel.PROP_EMAIL, "email@email.com"); + ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle"); + + this.personService.createPerson(ppOne); + } + } } diff --git a/source/java/org/alfresco/service/cmr/lock/package-info.java b/source/java/org/alfresco/service/cmr/lock/package-info.java index 31f33c79c5..7fdae69410 100644 --- a/source/java/org/alfresco/service/cmr/lock/package-info.java +++ b/source/java/org/alfresco/service/cmr/lock/package-info.java @@ -17,11 +17,9 @@ * along with Alfresco. If not, see . */ /** - * Provides the public interface for the invitation service that is used - * to invite users to sites. - *

- * Two types of invitation are provided, Nominated invitations, where a user - * nominates another user to become a member of a site and moderated invitations where a user askes to become a member of a site and - * its then up to an administrator to either accept or reject the invitation. + * Provides the public interface for the lock service that is used + * to lock nodes. + *

+ * @see org.alfresco.service.cmr.lock.LockService */ package org.alfresco.service.cmr.lock;