Class DefaultLockHelper

  • All Implemented Interfaces:
    ILockHelper

    public class DefaultLockHelper
    extends Object
    implements ILockHelper
    Default implementation of ILockHelper. If user suzy in tenant acme locks a file with UUID abc then this implementation will store the lock token xyz as /pentaho/acme/home/suzy/.lockTokens/abc/xyz. It is assumed that /pentaho/acme/home/suzy is never versioned! Putting lock token storage beneath the user's home folder provides access control.

    This implementation stores a lock owner, lock date, and lock message in the ownerInfo payload. See JCR 2.0 section 17.3. If implemented as custom properties, then a versioned node would require a checkout and checkin to lock a file. There is one caveat: implementations of JCR are free to ignore the ownerInfo payload. In that case, the implementation sets the value. If that happens, we simply return that value as the lock owner and date and message are null.

    Author:
    mlowery
    • Constructor Detail

      • DefaultLockHelper

        public DefaultLockHelper​(org.pentaho.platform.api.mt.ITenantedPrincipleNameResolver userNameUtils)
    • Method Detail

      • addLockToken

        protected void addLockToken​(javax.jcr.Session session,
                                    PentahoJcrConstants pentahoJcrConstants,
                                    javax.jcr.lock.Lock lock)
                             throws javax.jcr.RepositoryException
        Stores a lock token associated with the session's user.
        Throws:
        javax.jcr.RepositoryException
      • getLockToken

        protected String getLockToken​(javax.jcr.Session session,
                                      PentahoJcrConstants pentahoJcrConstants,
                                      javax.jcr.lock.Lock lock)
                               throws javax.jcr.RepositoryException
        Returns all lock tokens belonging to the session's user. Lock tokens can then be added to the session by calling Session.addLockToken(token).

        Callers should call {#link canUnlock(Session, PentahoJcrConstants, Lock) if the token is being retrieved for the purpose of an unlock.

        Throws:
        javax.jcr.RepositoryException
      • removeLockToken

        public void removeLockToken​(javax.jcr.Session session,
                                    PentahoJcrConstants pentahoJcrConstants,
                                    javax.jcr.lock.Lock lock)
                             throws javax.jcr.RepositoryException
        Removes a lock token so that it can never be associated with anyone's session again. (To be called after the file has been unlocked and therefore the token associated with the lock is unnecessary.)
        Specified by:
        removeLockToken in interface ILockHelper
        Parameters:
        session - session
        pentahoJcrConstants - constants
        lock - lock
        Throws:
        javax.jcr.RepositoryException - if anything goes wrong
      • getOrCreateLockTokensNode

        protected javax.jcr.Node getOrCreateLockTokensNode​(javax.jcr.Session session,
                                                           PentahoJcrConstants pentahoJcrConstants,
                                                           javax.jcr.lock.Lock lock)
                                                    throws javax.jcr.RepositoryException
        Throws:
        javax.jcr.RepositoryException
      • canUnlock

        public boolean canUnlock​(javax.jcr.Session session,
                                 PentahoJcrConstants pentahoJcrConstants,
                                 javax.jcr.lock.Lock lock)
                          throws javax.jcr.RepositoryException
        Returns true if user represented by session can potentially unlock the given lock. This can be a function of access control or some other mechanism.
        Specified by:
        canUnlock in interface ILockHelper
        Parameters:
        session - session
        pentahoJcrConstants - constants
        lock - lock
        Throws:
        javax.jcr.RepositoryException - if anything goes wrong
      • addLockTokenToSessionIfNecessary

        public void addLockTokenToSessionIfNecessary​(javax.jcr.Session session,
                                                     PentahoJcrConstants pentahoJcrConstants,
                                                     Serializable fileId)
                                              throws javax.jcr.RepositoryException
        Adds the lock token associated with the file with the given file id if the file is locked.
        Specified by:
        addLockTokenToSessionIfNecessary in interface ILockHelper
        Parameters:
        session - session
        pentahoJcrConstants - constants
        fileId - file id
        Throws:
        javax.jcr.RepositoryException - if anything goes wrong
      • removeLockTokenFromSessionIfNecessary

        public void removeLockTokenFromSessionIfNecessary​(javax.jcr.Session session,
                                                          PentahoJcrConstants pentahoJcrConstants,
                                                          Serializable fileId)
                                                   throws javax.jcr.RepositoryException
        Removes the lock token associated with the file with the given file id
        Specified by:
        removeLockTokenFromSessionIfNecessary in interface ILockHelper
        Parameters:
        session - session
        pentahoJcrConstants - constants
        fileId - file id
        Throws:
        javax.jcr.RepositoryException - if anything goes wrong
      • unlockFile

        public void unlockFile​(javax.jcr.Session session,
                               PentahoJcrConstants pentahoJcrConstants,
                               Serializable fileId)
                        throws javax.jcr.RepositoryException
        Unlocks a file.
        Specified by:
        unlockFile in interface ILockHelper
        Parameters:
        session - session
        pentahoJcrConstants - constants
        fileId - file id
        Throws:
        javax.jcr.RepositoryException - if anything goes wrong
      • lockFile

        public void lockFile​(javax.jcr.Session session,
                             PentahoJcrConstants pentahoJcrConstants,
                             Serializable fileId,
                             String message)
                      throws javax.jcr.RepositoryException
        Locks a file.
        Specified by:
        lockFile in interface ILockHelper
        Parameters:
        session - session
        pentahoJcrConstants - constants
        fileId - file id
        message - lock message
        Throws:
        javax.jcr.RepositoryException - if anything goes wrong
      • getLockDate

        public Date getLockDate​(javax.jcr.Session session,
                                PentahoJcrConstants pentahoJcrConstants,
                                javax.jcr.lock.Lock lock)
                         throws javax.jcr.RepositoryException
        Specified by:
        getLockDate in interface ILockHelper
        Throws:
        javax.jcr.RepositoryException
      • getLockMessage

        public String getLockMessage​(javax.jcr.Session session,
                                     PentahoJcrConstants pentahoJcrConstants,
                                     javax.jcr.lock.Lock lock)
                              throws javax.jcr.RepositoryException
        Specified by:
        getLockMessage in interface ILockHelper
        Throws:
        javax.jcr.RepositoryException
      • getLockOwner

        public String getLockOwner​(javax.jcr.Session session,
                                   PentahoJcrConstants pentahoJcrConstants,
                                   javax.jcr.lock.Lock lock)
                            throws javax.jcr.RepositoryException
        Specified by:
        getLockOwner in interface ILockHelper
        Throws:
        javax.jcr.RepositoryException