Search in sources :

Example 21 with ItemNotFoundException

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

the class NodeTest method testGetCorrespondingNodePathItemNotFoundException.

/**
     * Calls {@link javax.jcr.Node#getCorrespondingNodePath(String)} on  a node
     * that has no corresponding node in second workspace
     */
public void testGetCorrespondingNodePathItemNotFoundException() throws RepositoryException, NotExecutableException {
    // make sure the repository supports multiple workspaces
    super.ensureMultipleWorkspacesSupported();
    // get default workspace test root node using superuser session
    Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
    // create testNode in default workspace
    Node defaultTestNode = defaultRootNode.addNode(nodeName1, testNodeType);
    // save changes
    superuser.save();
    try {
        // call the update method on test node in default workspace
        defaultTestNode.getCorrespondingNodePath(workspaceName);
        fail("Calling Node.getCorrespondingNodePath() on node that has no correspondend node should throw ItemNotFoundException");
    } catch (ItemNotFoundException e) {
    // ok, works as expected
    }
}
Also used : Node(javax.jcr.Node) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 22 with ItemNotFoundException

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

the class NodeReadMethodsTest method testGetPrimaryItemItemNotFoundException.

/**
     * Test if getPrimaryItem does throw an ItemNotFoundException if the primary
     * node type does not define a primary item. Therefor a node without a
     * primary item is located recursively in the entire repository. A
     * NotExecutableException is thrown when no such node is found.
     */
public void testGetPrimaryItemItemNotFoundException() throws NotExecutableException, RepositoryException {
    Node node = locateNodeWithoutPrimaryItem(testRootNode);
    if (node == null) {
        throw new NotExecutableException("Workspace does not contain a node without primary item defined");
    }
    try {
        node.getPrimaryItem();
        fail("getPrimaryItem() must throw a ItemNotFoundException " + "if the primary node type does not define one");
    } catch (ItemNotFoundException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 23 with ItemNotFoundException

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

the class SessionImpl method getNodeById.

/**
     * Retrieve the <code>Node</code> with the given id.
     *
     * @param id
     * @return node with the given <code>NodeId</code>.
     * @throws ItemNotFoundException if no such node exists or if this
     * <code>Session</code> does not have permission to access the node.
     * @throws RepositoryException
     */
private Node getNodeById(NodeId id) throws ItemNotFoundException, RepositoryException {
    // check sanity of this session
    checkIsAlive();
    try {
        NodeEntry nodeEntry = getHierarchyManager().getNodeEntry(id);
        Item item = getItemManager().getItem(nodeEntry);
        if (item.isNode()) {
            return (Node) item;
        } else {
            log.error("NodeId '" + id + " does not point to a Node");
            throw new ItemNotFoundException(LogUtil.saveGetIdString(id, getPathResolver()));
        }
    } catch (AccessDeniedException e) {
        throw new ItemNotFoundException(LogUtil.saveGetIdString(id, getPathResolver()));
    }
}
Also used : Item(javax.jcr.Item) AccessDeniedException(javax.jcr.AccessDeniedException) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) Node(javax.jcr.Node) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 24 with ItemNotFoundException

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

the class NodeImpl method orderBefore.

/**
     * @see Node#orderBefore(String, String)
     */
public synchronized void orderBefore(String srcChildRelPath, String destChildRelPath) throws UnsupportedRepositoryOperationException, VersionException, ConstraintViolationException, ItemNotFoundException, LockException, RepositoryException {
    checkIsWritable();
    if (!getPrimaryNodeType().hasOrderableChildNodes()) {
        throw new UnsupportedRepositoryOperationException("Child node ordering not supported on node " + safeGetJCRPath());
    }
    // check arguments
    if (srcChildRelPath.equals(destChildRelPath)) {
        // there's nothing to do
        return;
    }
    // check existence
    if (!hasNode(srcChildRelPath)) {
        throw new ItemNotFoundException("Node " + safeGetJCRPath() + " has no child node with name " + srcChildRelPath);
    }
    if (destChildRelPath != null && !hasNode(destChildRelPath)) {
        throw new ItemNotFoundException("Node " + safeGetJCRPath() + " has no child node with name " + destChildRelPath);
    }
    Path srcPath = getReorderPath(srcChildRelPath);
    Path beforePath = null;
    if (destChildRelPath != null) {
        beforePath = getReorderPath(destChildRelPath);
    }
    Operation op = ReorderNodes.create(getNodeState(), srcPath, beforePath);
    session.getSessionItemStateManager().execute(op);
}
Also used : Path(org.apache.jackrabbit.spi.Path) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 25 with ItemNotFoundException

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

the class NodeImpl method getProperty.

/**
     * @see Node#getProperty(String)
     */
public Property getProperty(String relPath) throws PathNotFoundException, RepositoryException {
    checkStatus();
    PropertyEntry entry = resolveRelativePropertyPath(relPath);
    if (entry == null) {
        throw new PathNotFoundException(relPath);
    }
    try {
        return (Property) getItemManager().getItem(entry);
    } catch (AccessDeniedException e) {
        throw new PathNotFoundException(relPath);
    } catch (ItemNotFoundException e) {
        throw new PathNotFoundException(relPath);
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) PropertyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property) AddProperty(org.apache.jackrabbit.jcr2spi.operation.AddProperty) 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