Search in sources :

Example 1 with LockInfo

use of org.apache.jackrabbit.spi.LockInfo in project jackrabbit by apache.

the class LockManagerImpl method buildLockState.

private LockState buildLockState(NodeState nodeState) throws RepositoryException {
    NodeId nId = nodeState.getNodeId();
    NodeState lockHoldingState;
    LockInfo lockInfo = wspManager.getLockInfo(nId);
    if (lockInfo == null) {
        // no lock present
        return null;
    }
    NodeId lockNodeId = lockInfo.getNodeId();
    if (lockNodeId.equals(nId)) {
        lockHoldingState = nodeState;
    } else {
        NodeEntry lockedEntry = wspManager.getHierarchyManager().getNodeEntry(lockNodeId);
        try {
            lockHoldingState = lockedEntry.getNodeState();
        } catch (RepositoryException e) {
            log.warn("Cannot build LockState");
            throw new RepositoryException("Cannot build LockState", e);
        }
    }
    if (lockHoldingState == null) {
        return null;
    } else {
        return new LockState(lockHoldingState, lockInfo);
    }
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) NodeId(org.apache.jackrabbit.spi.NodeId) LockInfo(org.apache.jackrabbit.spi.LockInfo) RepositoryException(javax.jcr.RepositoryException)

Example 2 with LockInfo

use of org.apache.jackrabbit.spi.LockInfo in project jackrabbit by apache.

the class RepositoryServiceImpl method retrieveLockInfo.

private LockInfo retrieveLockInfo(LockDiscovery lockDiscovery, SessionInfo sessionInfo, NodeId nodeId, NodeId parentId) throws RepositoryException {
    checkSessionInfo(sessionInfo);
    List<ActiveLock> activeLocks = lockDiscovery.getValue();
    ActiveLock activeLock = null;
    for (ActiveLock l : activeLocks) {
        Scope sc = l.getScope();
        if (l.getType() == Type.WRITE && (Scope.EXCLUSIVE.equals(sc) || sc == ItemResourceConstants.EXCLUSIVE_SESSION)) {
            if (activeLock != null) {
                throw new RepositoryException("Node " + saveGetIdString(nodeId, sessionInfo) + " contains multiple exclusive write locks.");
            } else {
                activeLock = l;
            }
        }
    }
    if (activeLock == null) {
        log.debug("No lock present on node " + saveGetIdString(nodeId, sessionInfo));
        return null;
    }
    NodeId holder = null;
    String lockroot = activeLock.getLockroot();
    if (activeLock.getLockroot() != null) {
        holder = uriResolver.getNodeId(lockroot, sessionInfo);
    }
    if (activeLock.isDeep() && holder == null && parentId != null) {
        // deep lock, parent known, but holder is not
        LockInfo pLockInfo = getLockInfo(sessionInfo, parentId);
        if (pLockInfo != null) {
            return pLockInfo;
        }
    }
    return new LockInfoImpl(activeLock, holder == null ? nodeId : holder, ((SessionInfoImpl) sessionInfo).getAllLockTokens());
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) Scope(org.apache.jackrabbit.webdav.lock.Scope) AuthScope(org.apache.http.auth.AuthScope) NodeId(org.apache.jackrabbit.spi.NodeId) RepositoryException(javax.jcr.RepositoryException) LockInfo(org.apache.jackrabbit.spi.LockInfo)

Example 3 with LockInfo

use of org.apache.jackrabbit.spi.LockInfo in project jackrabbit by apache.

the class RepositoryServiceImpl method lock.

/**
 * {@inheritDoc}
 */
public LockInfo lock(SessionInfo sessionInfo, final NodeId nodeId, final boolean deep, final boolean sessionScoped, final long timeoutHint, final String ownerHint) throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException {
    final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    return (LockInfo) executeWithLocalEvents(new Callable() {

        public Object run() throws RepositoryException {
            Node n = getNode(nodeId, sInfo);
            Lock lock;
            javax.jcr.lock.LockManager lMgr = (sInfo.getSession().getWorkspace()).getLockManager();
            lock = lMgr.lock(n.getPath(), deep, sessionScoped, timeoutHint, ownerHint);
            return LockInfoImpl.createLockInfo(lock, idFactory);
        }
    }, sInfo);
}
Also used : Node(javax.jcr.Node) LockInfo(org.apache.jackrabbit.spi.LockInfo) Lock(javax.jcr.lock.Lock)

Example 4 with LockInfo

use of org.apache.jackrabbit.spi.LockInfo in project jackrabbit by apache.

the class RepositoryServiceImpl method lock.

/**
 * {@inheritDoc}
 */
public LockInfo lock(final SessionInfo sessionInfo, final NodeId nodeId, final boolean deep, final boolean sessionScoped) throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException {
    final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    return (LockInfo) executeWithLocalEvents(new Callable() {

        public Object run() throws RepositoryException {
            Node n = getNode(nodeId, sInfo);
            Lock lock = n.lock(deep, sessionScoped);
            return LockInfoImpl.createLockInfo(lock, idFactory);
        }
    }, sInfo);
}
Also used : Node(javax.jcr.Node) LockInfo(org.apache.jackrabbit.spi.LockInfo) Lock(javax.jcr.lock.Lock)

Example 5 with LockInfo

use of org.apache.jackrabbit.spi.LockInfo in project jackrabbit by apache.

the class RepositoryServiceImpl method lock.

@Override
public LockInfo lock(SessionInfo sessionInfo, NodeId nodeId, boolean deep, boolean sessionScoped, long timeoutHint, String ownerHint) throws RepositoryException {
    HttpLock request = null;
    try {
        checkSessionInfo(sessionInfo);
        long davTimeout = (timeoutHint == Long.MAX_VALUE) ? INFINITE_TIMEOUT : timeoutHint * 1000;
        String ownerInfo = (ownerHint == null) ? sessionInfo.getUserID() : ownerHint;
        String uri = getItemUri(nodeId, sessionInfo);
        Scope scope = (sessionScoped) ? ItemResourceConstants.EXCLUSIVE_SESSION : Scope.EXCLUSIVE;
        request = new HttpLock(uri, new org.apache.jackrabbit.webdav.lock.LockInfo(scope, Type.WRITE, ownerInfo, davTimeout, deep));
        HttpResponse response = execute(request, sessionInfo);
        String lockToken = request.getLockToken(response);
        ((SessionInfoImpl) sessionInfo).addLockToken(lockToken, sessionScoped);
        LockDiscovery disc = request.getResponseBodyAsLockDiscovery(response);
        return retrieveLockInfo(disc, sessionInfo, nodeId, null);
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) LockDiscovery(org.apache.jackrabbit.webdav.lock.LockDiscovery) Scope(org.apache.jackrabbit.webdav.lock.Scope) AuthScope(org.apache.http.auth.AuthScope) LockInfo(org.apache.jackrabbit.spi.LockInfo) HttpLock(org.apache.jackrabbit.webdav.client.methods.HttpLock)

Aggregations

LockInfo (org.apache.jackrabbit.spi.LockInfo)5 RepositoryException (javax.jcr.RepositoryException)3 Node (javax.jcr.Node)2 Lock (javax.jcr.lock.Lock)2 AuthScope (org.apache.http.auth.AuthScope)2 NodeId (org.apache.jackrabbit.spi.NodeId)2 Scope (org.apache.jackrabbit.webdav.lock.Scope)2 IOException (java.io.IOException)1 HttpResponse (org.apache.http.HttpResponse)1 NodeEntry (org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry)1 NodeState (org.apache.jackrabbit.jcr2spi.state.NodeState)1 DavException (org.apache.jackrabbit.webdav.DavException)1 HttpLock (org.apache.jackrabbit.webdav.client.methods.HttpLock)1 ActiveLock (org.apache.jackrabbit.webdav.lock.ActiveLock)1 LockDiscovery (org.apache.jackrabbit.webdav.lock.LockDiscovery)1