cancel
Showing results for 
Search instead for 
Did you mean: 

[Solved] LockService : does it work?

zomurn
Champ in-the-making
Champ in-the-making
Hello,

According to the fact that lockService allow only lock and unlock methods on a nodeRef, it is supposed to be able to unlock whatever NodeRef that is lock or not.
So why with this code, my javascript return a number greater than zero?

Java code executed on all nodeRefs (~1300)

NB : the pUsername is the owner of the lock. I attempt to unlock wih the owner and with the admin…

private void unlockWith(final NodeRef pNodeRef, String pUsername) {

      System.out.println( "pUsername:" + pUsername );
      String lCurrentUsername = AuthenticationUtil.getCurrentUserName();
      System.out.println( "lCurrentUsername:" + lCurrentUsername );
      AuthenticationUtil.RunAsWork<Object> lWork = new AuthenticationUtil.RunAsWork<Object>() {

         public Object doWork() throws Exception {

            lockService.unlock( pNodeRef );
            return null;
         }
      };
      

      AuthenticationUtil.runAs( lWork, pUsername );
//maybe usefull
      AuthenticationUtil.runAs( lWork, "admin" );

      AuthenticationUtil.setCurrentUser( lCurrentUsername );
      System.out.println( "AuthenticationUtil.getCurrentUserName():"
            + AuthenticationUtil.getCurrentUserName() );
   }

The javascript code

var query = "TYPE:\"msc:courrier\"";
   var nodes = search.luceneSearch(query);
   var i;
   var j =0;
   for (i = 0; i < nodes.length; i++)
   {
      if (nodes[i].isLocked || nodes[i].isLockedOwner) {
         j++;
      }
   }
   if (logger.isLoggingEnabled())
      logger.log("noeud lockes="+j);

If I launch java code (unlock all) and then javascript code (count number of lock), the output of javascript is still  greater than one (= 16 precisely).
So my question is simple : how to unlock a document ?
1 REPLY 1

zomurn
Champ in-the-making
Champ in-the-making
I found the solution and I am going to answer to myself one more time.
To my mind, In fact, the method "checkForLock" doesn't do its job like said in its description.
To ACTUALLY check if a nodeRef is locked or not, we need to do the following code and not use "checkForLock" :

To Check For a lock on a NodeRef :

LockStatus lLockStatus = lockService.getLockStatus( lNodeRef );
         if (lLockStatus.equals( LockStatus.LOCK_OWNER ))
         {
            unlockWith( lNodeRef, AuthenticationUtil.getCurrentUserName() );
         }
         if (lLockStatus.equals( LockStatus.LOCKED ))
         {
            String lUsername = (String) nodeService.getProperty( lNodeRef,
                  ContentModel.PROP_LOCK_OWNER );
            unlockWith( lNodeRef, lUsername );
         }

To Unlock a nodeRef :

private void unlockWith(final NodeRef pNodeRef, String pUsername) {
      String lCurrentUsername = AuthenticationUtil.getCurrentUserName();
      AuthenticationUtil.RunAsWork<Object> lWork = new AuthenticationUtil.RunAsWork<Object>() {

         public Object doWork() throws Exception {

            lockService.unlock( pNodeRef );
            return null;
         }
      };
      AuthenticationUtil.runAs( lWork, pUsername );
      AuthenticationUtil.setCurrentUser( lCurrentUsername );   
   }
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.