Search in sources :

Example 46 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class ItemImpl method getAncestor.

/**
     * @see javax.jcr.Item#getAncestor(int)
     */
public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
    checkStatus();
    if (depth == 0) {
        return session.getRootNode();
    }
    String msg = "No ancestor at depth = " + depth;
    try {
        // Path.getAncestor requires relative degree, i.e. we need
        // to convert absolute to relative ancestor degree
        Path path = getQPath();
        int relDegree = path.getAncestorCount() - depth;
        if (relDegree < 0) {
            throw new ItemNotFoundException(msg);
        }
        Path ancestorPath = path.getAncestor(relDegree);
        if (relDegree == 0) {
            return this;
        } else {
            return getItemManager().getNode(ancestorPath);
        }
    } catch (PathNotFoundException e) {
        throw new ItemNotFoundException(msg);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 47 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class WorkspaceRestoreTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    version = versionManager.checkin(path);
    versionManager.checkout(path);
    version2 = versionManager.checkin(path);
    versionManager.checkout(path);
    rootVersion = versionManager.getVersionHistory(path).getRootVersion();
    // build a second versionable node below the testroot
    try {
        versionableNode2 = createVersionableNode(testRootNode, nodeName2, versionableNodeType);
    } catch (RepositoryException e) {
        fail("Failed to create a second versionable node: " + e.getMessage());
    }
    try {
        wSuperuser = getHelper().getSuperuserSession(workspaceName);
    } catch (RepositoryException e) {
        fail("Failed to retrieve superuser session for second workspace '" + workspaceName + "': " + e.getMessage());
    }
    // test if the required nodes exist in the second workspace if not try to clone them
    try {
        testRootNode.getCorrespondingNodePath(workspaceName);
    } catch (ItemNotFoundException e) {
        // clone testRoot
        wSuperuser.getWorkspace().clone(superuser.getWorkspace().getName(), testRoot, testRoot, true);
    }
    try {
        versionableNode.getCorrespondingNodePath(workspaceName);
    } catch (ItemNotFoundException e) {
        // clone versionable node
        wSuperuser.getWorkspace().clone(superuser.getWorkspace().getName(), versionableNode.getPath(), versionableNode.getPath(), true);
    }
    try {
        versionableNode2.getCorrespondingNodePath(workspaceName);
    } catch (ItemNotFoundException e) {
        // clone second versionable node
        wSuperuser.getWorkspace().clone(superuser.getWorkspace().getName(), versionableNode2.getPath(), versionableNode2.getPath(), true);
    }
    try {
        // set node-fields (wTestRoot, wVersionableNode, wVersionableNode2)
        // and check versionable nodes out.
        wTestRoot = (Node) wSuperuser.getItem(testRootNode.getPath());
        wVersionableNode = wSuperuser.getNodeByIdentifier(versionableNode.getIdentifier());
        wVersionableNode.getSession().getWorkspace().getVersionManager().checkout(wVersionableNode.getPath());
        wVersionableNode2 = wSuperuser.getNodeByIdentifier(versionableNode2.getIdentifier());
        wVersionableNode2.getSession().getWorkspace().getVersionManager().checkout(wVersionableNode2.getPath());
    } catch (RepositoryException e) {
        fail("Failed to setup test environment in workspace: " + e.toString());
    }
    // that is not present in the default workspace.
    try {
        wVersionableChildNode = createVersionableNode(wVersionableNode, nodeName4, versionableNodeType);
    } catch (RepositoryException e) {
        fail("Failed to create versionable child node in second workspace: " + e.getMessage());
    }
    // create a version of the versionable child node
    VersionManager wVersionManager = wVersionableChildNode.getSession().getWorkspace().getVersionManager();
    String wPath = wVersionableChildNode.getPath();
    wVersionManager.checkout(wPath);
    wChildVersion = wVersionManager.checkin(wPath);
    wVersionManager.checkout(wPath);
}
Also used : RepositoryException(javax.jcr.RepositoryException) VersionManager(javax.jcr.version.VersionManager) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 48 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class ItemManagerImpl method getItem.

/**
     * @see ItemManager#getItem(HierarchyEntry)
     */
public Item getItem(HierarchyEntry hierarchyEntry) throws ItemNotFoundException, RepositoryException {
    session.checkIsAlive();
    ItemState state = hierarchyEntry.getItemState();
    if (!state.isValid()) {
        throw new ItemNotFoundException(LogUtil.safeGetJCRPath(state, session.getPathResolver()));
    }
    // first try to access item from cache
    Item item = itemCache.getItem(state);
    // not yet in cache, need to create instance
    if (item == null) {
        // create instance of item
        if (hierarchyEntry.denotesNode()) {
            item = createNodeInstance((NodeState) state);
        } else {
            item = createPropertyInstance((PropertyState) state);
        }
    }
    return item;
}
Also used : Item(javax.jcr.Item) NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) ItemState(org.apache.jackrabbit.jcr2spi.state.ItemState) ItemNotFoundException(javax.jcr.ItemNotFoundException) PropertyState(org.apache.jackrabbit.jcr2spi.state.PropertyState)

Example 49 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class ItemManagerImpl method hasChildProperties.

/**
     * @see ItemManager#hasChildProperties(NodeEntry)
     */
public synchronized boolean hasChildProperties(NodeEntry parentEntry) throws ItemNotFoundException, RepositoryException {
    // check sanity of session
    session.checkIsAlive();
    Iterator<PropertyEntry> iter = parentEntry.getPropertyEntries();
    while (iter.hasNext()) {
        try {
            PropertyEntry entry = iter.next();
            // check read access by accessing the propState (also implicit validation).
            entry.getPropertyState();
            return true;
        } catch (ItemNotFoundException e) {
            // should not occur. ignore
            log.debug("Failed to access node state.", e);
        }
    }
    return false;
}
Also used : PropertyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 50 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class ItemManagerImpl method hasChildNodes.

/**
     * @see ItemManager#hasChildNodes(NodeEntry)
     */
public synchronized boolean hasChildNodes(NodeEntry parentEntry) throws ItemNotFoundException, RepositoryException {
    // check sanity of session
    session.checkIsAlive();
    Iterator<NodeEntry> iter = parentEntry.getNodeEntries();
    while (iter.hasNext()) {
        try {
            // check read access by accessing the nodeState (implicit validation check)
            NodeEntry entry = iter.next();
            entry.getNodeState();
            return true;
        } catch (ItemNotFoundException e) {
            // should not occur. ignore
            log.debug("Failed to access node state.", e);
        }
    }
    return false;
}
Also used : NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

ItemNotFoundException (javax.jcr.ItemNotFoundException)139 RepositoryException (javax.jcr.RepositoryException)61 Node (javax.jcr.Node)44 Path (org.apache.jackrabbit.spi.Path)25 PathNotFoundException (javax.jcr.PathNotFoundException)23 NodeId (org.apache.jackrabbit.core.id.NodeId)22 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)16 IOException (java.io.IOException)14 InvalidItemStateException (javax.jcr.InvalidItemStateException)14 NodeState (org.apache.jackrabbit.core.state.NodeState)14 Name (org.apache.jackrabbit.spi.Name)14 AccessDeniedException (javax.jcr.AccessDeniedException)13 HttpResponse (org.apache.http.HttpResponse)13 DavException (org.apache.jackrabbit.webdav.DavException)13 ItemExistsException (javax.jcr.ItemExistsException)12 Session (javax.jcr.Session)12 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)10