Search in sources :

Example 51 with ItemNotFoundException

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

the class CheckoutTest method testIsCheckedOutNonVersionableNode.

/**
      * Test calling Node.isCheckedOut() on a non-versionable.
      */
public void testIsCheckedOutNonVersionableNode() throws RepositoryException {
    boolean isCheckedOut = nonVersionableNode.isCheckedOut();
    Node vParent = null;
    try {
        vParent = nonVersionableNode.getParent();
        while (!vParent.isNodeType(mixVersionable)) {
            vParent = vParent.getParent();
        }
    } catch (ItemNotFoundException e) {
    // root reached.
    }
    if (vParent != null && vParent.isNodeType(mixVersionable)) {
        if (vParent.isCheckedOut()) {
            assertTrue("Node.isCheckedOut() must return true if the node is non-versionable and its nearest versionable ancestor is checked-out.", isCheckedOut);
        } else {
            assertFalse("Node.isCheckedOut() must return false if the node is non-versionable and its nearest versionable ancestor is checked-in.", isCheckedOut);
        }
    } else {
        assertTrue("Node.isCheckedOut() must return true if the node is non-versionable and has no versionable ancestor", isCheckedOut);
    }
}
Also used : Node(javax.jcr.Node) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 52 with ItemNotFoundException

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

the class NodeImpl method rename.

//-------------------------------------------------------< JackrabbitNode >
/**
     * {@inheritDoc}
     */
public void rename(String newName) throws RepositoryException {
    // check if this is the root node
    if (getDepth() == 0) {
        throw new RepositoryException("Cannot rename the root node");
    }
    Name qName;
    try {
        qName = sessionContext.getQName(newName);
    } catch (NameException e) {
        throw new RepositoryException("invalid node name: " + newName, e);
    }
    NodeImpl parent = (NodeImpl) getParent();
    // check for name collisions
    NodeImpl existing = null;
    try {
        existing = parent.getNode(qName);
        // check same-name sibling setting of existing node
        if (!existing.getDefinition().allowsSameNameSiblings()) {
            throw new ItemExistsException("Same name siblings are not allowed: " + existing);
        }
    } catch (AccessDeniedException ade) {
        // FIXME by throwing ItemExistsException we're disclosing too much information
        throw new ItemExistsException();
    } catch (ItemNotFoundException infe) {
    // no name collision, fall through
    }
    // verify that parent node
    // - is checked-out
    // - is not protected neither by node type constraints nor by retention/hold
    int options = ItemValidator.CHECK_CHECKED_OUT | ItemValidator.CHECK_LOCK | ItemValidator.CHECK_CONSTRAINTS | ItemValidator.CHECK_HOLD | ItemValidator.CHECK_RETENTION;
    sessionContext.getItemValidator().checkRemove(parent, options, Permission.NONE);
    sessionContext.getItemValidator().checkModify(parent, options, Permission.NONE);
    // check constraints
    // get applicable definition of renamed target node
    NodeTypeImpl nt = (NodeTypeImpl) getPrimaryNodeType();
    org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl newTargetDef;
    try {
        newTargetDef = parent.getApplicableChildNodeDefinition(qName, nt.getQName());
    } catch (RepositoryException re) {
        String msg = safeGetJCRPath() + ": no definition found in parent node's node type for renamed node";
        log.debug(msg);
        throw new ConstraintViolationException(msg, re);
    }
    // necessarily have identical definitions
    if (existing != null && !newTargetDef.allowsSameNameSiblings()) {
        throw new ItemExistsException("Same name siblings not allowed: " + existing);
    }
    // check permissions:
    // 1. on the parent node the session must have permission to manipulate the child-entries
    AccessManager acMgr = sessionContext.getAccessManager();
    if (!acMgr.isGranted(parent.getPrimaryPath(), qName, Permission.MODIFY_CHILD_NODE_COLLECTION)) {
        String msg = "Not allowed to rename node " + safeGetJCRPath() + " to " + newName;
        log.debug(msg);
        throw new AccessDeniedException(msg);
    }
    //    the primary node type on this node itself.
    if (!nt.getName().equals(newTargetDef.getName()) && !(acMgr.isGranted(getPrimaryPath(), Permission.NODE_TYPE_MNGMT))) {
        String msg = "Not allowed to rename node " + safeGetJCRPath() + " to " + newName;
        log.debug(msg);
        throw new AccessDeniedException(msg);
    }
    // change definition
    onRedefine(newTargetDef.unwrap());
    // delegate to parent
    parent.renameChildNode(getNodeId(), qName, true);
}
Also used : AccessManager(org.apache.jackrabbit.core.security.AccessManager) AccessDeniedException(javax.jcr.AccessDeniedException) NodeDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl) NodeTypeImpl(org.apache.jackrabbit.core.nodetype.NodeTypeImpl) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) ItemExistsException(javax.jcr.ItemExistsException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 53 with ItemNotFoundException

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

the class SessionImporter method resolveUUIDConflict.

//----------------------------------------------------< Private methods >---
/**
     * @param parent
     * @param conflicting
     * @param nodeInfo
     * @return
     * @throws RepositoryException
     */
NodeState resolveUUIDConflict(NodeState parent, NodeEntry conflicting, NodeInfo nodeInfo) throws ItemExistsException, RepositoryException {
    NodeState nodeState;
    switch(uuidBehavior) {
        case ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW:
            String originalUUID = nodeInfo.getUUID();
            String newUUID = UUID.randomUUID().toString();
            // reset id on nodeInfo to force creation with new uuid:
            nodeInfo.setUUID(newUUID);
            nodeState = importNode(nodeInfo, parent);
            if (nodeState != null) {
                // remember uuid mapping
                refTracker.mappedUUIDs(originalUUID, newUUID);
            }
            break;
        case ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW:
            String msg = "a node with uuid " + nodeInfo.getUUID() + " already exists!";
            log.debug(msg);
            throw new ItemExistsException(msg);
        case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING:
            // make sure conflicting node is not importTarget or an ancestor thereof
            Path p0 = importTarget.getPath();
            Path p1 = conflicting.getPath();
            if (p1.equals(p0) || p1.isAncestorOf(p0)) {
                msg = "cannot remove ancestor node";
                log.debug(msg);
                throw new ConstraintViolationException(msg);
            }
            // do remove conflicting (recursive) including validation check
            try {
                Operation op = Remove.create(conflicting.getNodeState());
                stateMgr.execute(op);
            } catch (ItemNotFoundException e) {
            // conflicting does not exist any more. no need for a removal
            }
            // create new with given uuid:
            nodeState = importNode(nodeInfo, parent);
            break;
        case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING:
            if (conflicting.getNodeState().isRoot()) {
                msg = "Root node cannot be replaced";
                log.debug(msg);
                throw new RepositoryException(msg);
            }
            // 'replace' current parent with parent of conflicting
            parent = conflicting.getParent().getNodeState();
            // do remove conflicting (recursive), including validation checks
            Operation op = Remove.create(conflicting.getNodeState());
            stateMgr.execute(op);
            // create new with given uuid at same location as conflicting
            nodeState = importNode(nodeInfo, parent);
            break;
        default:
            msg = "Unknown uuidBehavior: " + uuidBehavior;
            log.debug(msg);
            throw new RepositoryException(msg);
    }
    return nodeState;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) ItemExistsException(javax.jcr.ItemExistsException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 54 with ItemNotFoundException

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

the class MixinModificationTest method testRemoveMixin.

public void testRemoveMixin() throws RepositoryException, NotExecutableException {
    String nPath;
    try {
        Node n = testRootNode.addNode(nodeName1);
        nPath = n.getPath();
        n.addMixin(mixReferenceable);
        testRootNode.save();
    } catch (RepositoryException e) {
        throw new NotExecutableException();
    }
    Session testSession = getHelper().getReadWriteSession();
    try {
        Node n = (Node) testSession.getItem(nPath);
        String uuid = n.getUUID();
        // remove the mixin again.
        n.removeMixin(mixReferenceable);
        assertFalse(n.hasProperty(jcrMixinTypes));
        n.save();
        // accessing node by uuid should not be possible any more.
        try {
            Node n2 = testSession.getNodeByUUID(uuid);
            fail();
        } catch (ItemNotFoundException e) {
        // ok
        }
        // however: the added node should still be valid. but not referenceable
        assertItemStatus(n, Status.EXISTING);
        assertFalse(n.isNodeType(mixReferenceable));
        assertTrue(testSession.itemExists(nPath));
        try {
            Node n2 = superuser.getNodeByUUID(uuid);
            fail();
        } catch (ItemNotFoundException e) {
        // ok
        }
    } finally {
        if (testSession != null) {
            testSession.logout();
        }
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 55 with ItemNotFoundException

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

the class BatchedItemOperations method copy.

/**
     * Copies the tree at <code>srcPath</code> retrieved using the specified
     * <code>srcStateMgr</code> to the new location at <code>destPath</code>.
     * Returns the id of the node at its new position.
     * <p>
     * <b>Precondition:</b> the state manager needs to be in edit mode.
     *
     * @param srcPath
     * @param srcStateMgr
     * @param srcHierMgr
     * @param srcAccessMgr
     * @param destPath
     * @param flag         one of
     *                     <ul>
     *                     <li><code>COPY</code></li>
     *                     <li><code>CLONE</code></li>
     *                     <li><code>CLONE_REMOVE_EXISTING</code></li>
     *                     </ul>
     * @return the id of the node at its new position
     * @throws ConstraintViolationException
     * @throws AccessDeniedException
     * @throws VersionException
     * @throws PathNotFoundException
     * @throws ItemExistsException
     * @throws LockException
     * @throws RepositoryException
     * @throws IllegalStateException if the state manager is not in edit mode.
     */
public NodeId copy(Path srcPath, ItemStateManager srcStateMgr, HierarchyManager srcHierMgr, AccessManager srcAccessMgr, Path destPath, int flag) throws ConstraintViolationException, AccessDeniedException, VersionException, PathNotFoundException, ItemExistsException, LockException, RepositoryException, IllegalStateException {
    // check precondition
    checkInEditMode();
    // 1. check paths & retrieve state
    NodeState srcState = getNodeState(srcStateMgr, srcHierMgr, srcPath);
    Path destParentPath = destPath.getAncestor(1);
    NodeState destParentState = getNodeState(destParentPath);
    int ind = destPath.getIndex();
    if (ind > 0) {
        // subscript in name element
        String msg = "invalid copy destination path: " + safeGetJCRPath(destPath) + " (subscript in name element is not allowed)";
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    // 2. check access rights, lock status, node type constraints, etc.
    // JCR-2269: store target node state in changelog early as a
    // precautionary measure in order to isolate it from concurrent
    // underlying changes while checking preconditions
    stateMgr.store(destParentState);
    checkAddNode(destParentState, destPath.getName(), srcState.getNodeTypeName(), CHECK_ACCESS | CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_CONSTRAINTS | CHECK_HOLD | CHECK_RETENTION);
    // check read access right on source node using source access manager
    try {
        if (!srcAccessMgr.isGranted(srcPath, Permission.READ)) {
            throw new PathNotFoundException(safeGetJCRPath(srcPath));
        }
    } catch (ItemNotFoundException infe) {
        String msg = "internal error: failed to check access rights for " + safeGetJCRPath(srcPath);
        log.debug(msg);
        throw new RepositoryException(msg, infe);
    }
    // 3. do copy operation (modify and store affected states)
    ReferenceChangeTracker refTracker = new ReferenceChangeTracker();
    // create deep copy of source node state
    NodeState newState = copyNodeState(srcState, srcPath, srcStateMgr, srcAccessMgr, destParentState.getNodeId(), flag, refTracker);
    // add to new parent
    destParentState.addChildNodeEntry(destPath.getName(), newState.getNodeId());
    // adjust references that refer to uuid's which have been mapped to
    // newly generated uuid's on copy/clone
    Iterator<Object> iter = refTracker.getProcessedReferences();
    while (iter.hasNext()) {
        PropertyState prop = (PropertyState) iter.next();
        // being paranoid...
        if (prop.getType() != PropertyType.REFERENCE && prop.getType() != PropertyType.WEAKREFERENCE) {
            continue;
        }
        boolean modified = false;
        InternalValue[] values = prop.getValues();
        InternalValue[] newVals = new InternalValue[values.length];
        for (int i = 0; i < values.length; i++) {
            NodeId adjusted = refTracker.getMappedId(values[i].getNodeId());
            if (adjusted != null) {
                boolean weak = prop.getType() == PropertyType.WEAKREFERENCE;
                newVals[i] = InternalValue.create(adjusted, weak);
                modified = true;
            } else {
                // reference doesn't need adjusting, just copy old value
                newVals[i] = values[i];
            }
        }
        if (modified) {
            prop.setValues(newVals);
            stateMgr.store(prop);
        }
    }
    refTracker.clear();
    // store states
    stateMgr.store(newState);
    stateMgr.store(destParentState);
    return newState.getNodeId();
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeState(org.apache.jackrabbit.core.state.NodeState) RepositoryException(javax.jcr.RepositoryException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) PropertyState(org.apache.jackrabbit.core.state.PropertyState) ReferenceChangeTracker(org.apache.jackrabbit.core.util.ReferenceChangeTracker) NodeId(org.apache.jackrabbit.core.id.NodeId) PathNotFoundException(javax.jcr.PathNotFoundException) 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