Search in sources :

Example 1 with UnableToReleaseLockException

use of org.alfresco.service.cmr.lock.UnableToReleaseLockException in project alfresco-remote-api by Alfresco.

the class UnlockMethod method attemptUnlock.

/**
 * The main unlock implementation.
 *
 * @throws WebDAVServerException
 */
protected void attemptUnlock() throws WebDAVServerException {
    if (logger.isDebugEnabled()) {
        logger.debug("Unlock node; path=" + getPath() + ", token=" + getLockToken());
    }
    FileInfo lockNodeInfo = null;
    try {
        lockNodeInfo = getNodeForPath(getRootNodeRef(), getPath());
    } catch (FileNotFoundException e) {
        throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
    }
    // Parse the lock token
    String[] lockInfoFromRequest = WebDAV.parseLockToken(getLockToken());
    if (lockInfoFromRequest == null) {
        // Bad lock token
        throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
    }
    NodeRef nodeRef = lockNodeInfo.getNodeRef();
    LockInfo lockInfo = getDAVLockService().getLockInfo(nodeRef);
    if (lockInfo == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Unlock token=" + getLockToken() + " Not locked - no info in lock store.");
        }
        // Node is not locked
        throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
    }
    if (!lockInfo.isLocked()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Unlock token=" + getLockToken() + " Not locked");
        }
        // Node is not locked
        throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
    } else if (lockInfo.isExpired()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Unlock token=" + getLockToken() + " Lock expired");
        }
        // Return a success status
        m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        removeNoContentAspect(nodeRef);
    } else if (lockInfo.isExclusive()) {
        String currentUser = getAuthenticationService().getCurrentUserName();
        if (currentUser.equals(lockInfo.getOwner())) {
            try {
                getDAVLockService().unlock(nodeRef);
            } catch (UnableToReleaseLockException e) {
                throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED, e);
            }
            // Indicate that the unlock was successful
            m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
            removeNoContentAspect(nodeRef);
            if (logger.isDebugEnabled()) {
                logger.debug("Unlock token=" + getLockToken() + " Successful");
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Unlock token=" + getLockToken() + " Not lock owner");
            }
            // Node is not locked
            throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
        }
    } else if (lockInfo.isShared()) {
        Set<String> sharedLocks = lockInfo.getSharedLockTokens();
        if (sharedLocks.contains(m_strLockToken)) {
            sharedLocks.remove(m_strLockToken);
            // Indicate that the unlock was successful
            m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
            removeNoContentAspect(nodeRef);
            // DEBUG
            if (logger.isDebugEnabled()) {
                logger.debug("Unlock token=" + getLockToken() + " Successful");
            }
        }
    } else {
        throw new IllegalStateException("Invalid LockInfo state: " + lockInfo);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Set(java.util.Set) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) UnableToReleaseLockException(org.alfresco.service.cmr.lock.UnableToReleaseLockException)

Aggregations

Set (java.util.Set)1 UnableToReleaseLockException (org.alfresco.service.cmr.lock.UnableToReleaseLockException)1 FileInfo (org.alfresco.service.cmr.model.FileInfo)1 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1