Search in sources :

Example 66 with PathNotFoundException

use of javax.jcr.PathNotFoundException in project sling by apache.

the class MockSession method getProperty.

@Override
public Property getProperty(final String absPath) throws RepositoryException {
    checkLive();
    Item item = getItem(absPath);
    if (item instanceof Property) {
        return (Property) item;
    } else {
        throw new PathNotFoundException(String.format("No property found at: %s.", absPath));
    }
}
Also used : Item(javax.jcr.Item) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property)

Example 67 with PathNotFoundException

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

the class SessionMoveOperation method perform.

public Object perform(SessionContext context) throws RepositoryException {
    // Get node instances
    NodeImpl targetNode = getNode(context, srcPath, srcAbsPath);
    NodeImpl srcParentNode = getNode(context, srcPath.getAncestor(1), srcAbsPath);
    NodeImpl destParentNode = getNode(context, destPath.getAncestor(1), destAbsPath);
    if (context.getHierarchyManager().isShareAncestor(targetNode.getNodeId(), destParentNode.getNodeId())) {
        throw new RepositoryException("Move not possible because of a share cycle between " + srcAbsPath + " and " + destAbsPath);
    }
    // check for name collisions
    NodeImpl existing = null;
    try {
        existing = context.getItemManager().getNode(destPath);
        // 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(destAbsPath);
    } catch (PathNotFoundException pnfe) {
    // no name collision, fall through
    }
    // verify that the targetNode can be removed
    int options = ItemValidator.CHECK_HOLD | ItemValidator.CHECK_RETENTION;
    context.getItemValidator().checkRemove(targetNode, options, Permission.NONE);
    // verify for both source and destination parent nodes that
    // - they are checked-out
    // - are not protected neither by node type constraints nor by retention/hold
    options = ItemValidator.CHECK_CHECKED_OUT | ItemValidator.CHECK_LOCK | ItemValidator.CHECK_CONSTRAINTS | ItemValidator.CHECK_HOLD | ItemValidator.CHECK_RETENTION;
    context.getItemValidator().checkModify(srcParentNode, options, Permission.NONE);
    context.getItemValidator().checkModify(destParentNode, options, Permission.NONE);
    // check constraints
    // get applicable definition of target node at new location
    NodeTypeImpl nt = (NodeTypeImpl) targetNode.getPrimaryNodeType();
    org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl newTargetDef;
    try {
        newTargetDef = destParentNode.getApplicableChildNodeDefinition(destPath.getName(), nt.getQName());
    } catch (RepositoryException re) {
        String msg = destAbsPath + ": no definition found in parent node's node type for new 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);
    }
    NodeId targetId = targetNode.getNodeId();
    // check permissions
    AccessManager acMgr = context.getAccessManager();
    if (!(acMgr.isGranted(srcPath, Permission.REMOVE_NODE) && acMgr.isGranted(destPath, Permission.ADD_NODE | Permission.NODE_TYPE_MNGMT))) {
        String msg = "Not allowed to move node " + srcAbsPath + " to " + destAbsPath;
        log.debug(msg);
        throw new AccessDeniedException(msg);
    }
    if (srcParentNode.isSame(destParentNode)) {
        // change definition of target
        targetNode.onRedefine(newTargetDef.unwrap());
        // do rename
        destParentNode.renameChildNode(targetId, destPath.getName(), false);
    } else {
        // check shareable case
        if (targetNode.getNodeState().isShareable()) {
            String msg = "Moving a shareable node is not supported.";
            log.debug(msg);
            throw new UnsupportedRepositoryOperationException(msg);
        }
        // change definition of target
        targetNode.onRedefine(newTargetDef.unwrap());
        // Get the transient states
        NodeState srcParentState = (NodeState) srcParentNode.getOrCreateTransientItemState();
        NodeState targetState = (NodeState) targetNode.getOrCreateTransientItemState();
        NodeState destParentState = (NodeState) destParentNode.getOrCreateTransientItemState();
        // 1. remove child node entry from old parent
        if (srcParentState.removeChildNodeEntry(targetId)) {
            // 2. re-parent target node
            targetState.setParentId(destParentNode.getNodeId());
            // 3. add child node entry to new parent
            destParentState.addChildNodeEntry(destPath.getName(), targetId);
        }
    }
    return this;
}
Also used : AccessManager(org.apache.jackrabbit.core.security.AccessManager) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) AccessDeniedException(javax.jcr.AccessDeniedException) NodeTypeImpl(org.apache.jackrabbit.core.nodetype.NodeTypeImpl) NodeState(org.apache.jackrabbit.core.state.NodeState) RepositoryException(javax.jcr.RepositoryException) ItemExistsException(javax.jcr.ItemExistsException) NodeId(org.apache.jackrabbit.core.id.NodeId) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 68 with PathNotFoundException

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

the class LostFromCacheIssueTest method getOrCreate.

private static Node getOrCreate(Node parent, String path) throws RepositoryException {
    if (parent == null || path == null || path.trim().isEmpty()) {
        throw new IllegalArgumentException("Missing `parent` or `path`");
    }
    String p = path;
    if (path.startsWith("/")) {
        p = path.substring(1);
    }
    Node node = null;
    try {
        node = parent.getNode(p);
    } catch (PathNotFoundException e) {
    // swallowing exception
    }
    if (node == null) {
        // if null is not there and therefore creating it
        for (String n : p.split("/")) {
            if (node == null) {
                node = parent.addNode(n);
            } else {
                node = node.addNode(n);
            }
        }
    }
    return node;
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 69 with PathNotFoundException

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

the class ConcurrentCyclicMoveTest method testConcurrentWorkspaceMove.

public void testConcurrentWorkspaceMove() throws RepositoryException {
    testRootPath = testRootNode.getPath();
    testRootNode.addNode("b");
    Node aa = testRootNode.addNode("a").addNode("aa");
    testRootNode.getSession().save();
    String aaId = aa.getIdentifier();
    Session session1 = getHelper().getReadWriteSession();
    Session session2 = getHelper().getReadWriteSession();
    // results in /b/a/aa
    session1.getWorkspace().move(testRootPath + "/a", testRootPath + "/b/a");
    assertEquals(testRootPath + "/b/a/aa", session1.getNodeByIdentifier(aaId).getPath());
    // try to move b into a/aa (should fail as the above move is persisted
    try {
        session2.getWorkspace().move(testRootPath + "/b", testRootPath + "/a/aa/b");
        fail("Workspace.move() should not have succeeded. Possible cyclic path created.");
    } catch (PathNotFoundException e) {
    // expected.
    }
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) Session(javax.jcr.Session)

Example 70 with PathNotFoundException

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

the class NodeTest method testRemoveNodeParentSave.

/**
     * Removes a node using {@link javax.jcr.Node#remove()}, then saves with
     * parent's nodes {@link javax.jcr.Node#save()} method.
     */
public void testRemoveNodeParentSave() throws RepositoryException {
    // get default workspace test root node using superuser session
    Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
    // create the node
    Node defaultTestNode = defaultRootNode.addNode(nodeName1, testNodeType);
    // save the nodes
    defaultRootNode.save();
    // remove them
    defaultTestNode.remove();
    defaultRootNode.save();
    // check if the node has been properly removed
    try {
        defaultRootNode.getNode(nodeName1);
        fail("Permanently removed node should no longer be adressable using Parent Node's getNode() method");
    } catch (PathNotFoundException e) {
    // ok, works as expected
    }
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Aggregations

PathNotFoundException (javax.jcr.PathNotFoundException)136 Node (javax.jcr.Node)58 RepositoryException (javax.jcr.RepositoryException)46 ItemNotFoundException (javax.jcr.ItemNotFoundException)24 Session (javax.jcr.Session)23 Path (org.apache.jackrabbit.spi.Path)22 AccessDeniedException (javax.jcr.AccessDeniedException)14 Property (javax.jcr.Property)14 Test (org.junit.Test)14 Item (javax.jcr.Item)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 NodeIterator (javax.jcr.NodeIterator)9 Value (javax.jcr.Value)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 Name (org.apache.jackrabbit.spi.Name)8 PropertyIterator (javax.jcr.PropertyIterator)7 NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)7 HashSet (java.util.HashSet)6 ItemExistsException (javax.jcr.ItemExistsException)6 ValueFormatException (javax.jcr.ValueFormatException)6