cancel
Showing results for 
Search instead for 
Did you mean: 

unlocking and locking a node in wcm

boneill
Star Contributor
Star Contributor
Hi All.

Can anyone tell me the correct way to unlock a node in wcm avm and then apply a new lock that is owned by a different user. 

Regards
1 REPLY 1

boneill
Star Contributor
Star Contributor
FYI of how you do this.  I am posting the code I used for this.  Basically you use the AVMLockingService. 


/**
    * Move the lock from the src node to a new person.  ie this is used to move the lock
    * for a node to the owner of a different sandbox.
    *
    * @param avmLockingService
    * @param src  -  This will be used to determine both the source and destination path when moving lock.
    * @param lockOwner - Current lock owner
    * @param newLockOwner - User you want to give the lock to.
    */
   @SuppressWarnings("unchecked")
    static public void reassignLocks(AVMLockingService avmLockingService,
          NodeRef src, String lockOwner, String newLockOwner){
       
        logger.debug("Entered method ForewardWizardHelper.reassignLocks");
       logger.debug("Current Lock Owner " + lockOwner);
        logger.debug("New Lock Owner " + newLockOwner);

       String webProject = WCMUtil.getWebProjectStoreIdFromPath(AVMNodeConverter.ToAVMVersionPath(src).getSecond());
        logger.debug("Web Project Name is " + webProject);
       
        String srcPath = WCMUtil.splitPath(AVMNodeConverter.ToAVMVersionPath(src).getSecond())[1];
        logger.debug("Source Path is " + srcPath);
       
        String newStore = webProject + "–" + newLockOwner;
        logger.debug("New Store " + newStore);   
       
        List<String> removelist = new ArrayList<String>();
        List<String> addlist = new ArrayList<String>();

        removelist.add(lockOwner);
        addlist.add(newLockOwner);
          
       avmLockingService.modifyLock(webProject, srcPath, srcPath, newStore, removelist, addlist);
       logger.debug("Moved Lock from " + lockOwner + " to " + newLockOwner);    
    }