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);
}
}
Aggregations