Search in sources :

Example 1 with PathNotFoundException

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

the class SessionImpl method getImportContentHandler.

/**
     * {@inheritDoc}
     */
public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException {
    // check sanity of this session
    sanityCheck();
    NodeImpl parent;
    try {
        Path p = getQPath(parentAbsPath).getNormalizedPath();
        if (!p.isAbsolute()) {
            throw new RepositoryException("not an absolute path: " + parentAbsPath);
        }
        parent = getItemManager().getNode(p);
    } catch (NameException e) {
        String msg = parentAbsPath + ": invalid path";
        log.debug(msg);
        throw new RepositoryException(msg, e);
    } catch (AccessDeniedException ade) {
        throw new PathNotFoundException(parentAbsPath);
    }
    // verify that parent node is checked-out, not locked and not protected
    // by either node type constraints nor by some retention or hold.
    int options = ItemValidator.CHECK_LOCK | ItemValidator.CHECK_CHECKED_OUT | ItemValidator.CHECK_CONSTRAINTS | ItemValidator.CHECK_HOLD | ItemValidator.CHECK_RETENTION;
    context.getItemValidator().checkModify(parent, options, Permission.NONE);
    SessionImporter importer = new SessionImporter(parent, this, uuidBehavior, context.getWorkspace().getConfig().getImportConfig());
    return new ImportHandler(importer, this);
}
Also used : Path(org.apache.jackrabbit.spi.Path) AccessDeniedException(javax.jcr.AccessDeniedException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) ImportHandler(org.apache.jackrabbit.core.xml.ImportHandler) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) SessionImporter(org.apache.jackrabbit.core.xml.SessionImporter)

Example 2 with PathNotFoundException

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

the class SessionTest method testMovePathNotFoundExceptionSrcInvalid.

/**
     * Calls {@link javax.jcr.Session#move(String src, String dest)} with
     * invalid source path.
     * <p>
     * Should throw a {@link javax.jcr.PathNotFoundException}.
     */
public void testMovePathNotFoundExceptionSrcInvalid() throws RepositoryException {
    // get default workspace test root node using superuser session
    Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
    // create a node that will serve as new parent
    Node destParentNode = defaultRootNode.addNode(nodeName3, testNodeType);
    // save the new nodes
    superuser.save();
    // move the node
    try {
        superuser.move(defaultRootNode.getPath() + "/" + nodeName1, destParentNode.getPath() + "/" + nodeName2);
        fail("Invalid source path during Session.move() must throw PathNotFoundException");
    } catch (PathNotFoundException e) {
    // ok. works as expected
    }
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 3 with PathNotFoundException

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

the class HoldTest method testPropertyPath.

public void testPropertyPath() throws RepositoryException, NotExecutableException {
    String propPath = null;
    for (PropertyIterator it = testRootNode.getProperties(); it.hasNext(); ) {
        String path = it.nextProperty().getPath();
        if (!superuser.nodeExists(path)) {
            propPath = path;
            break;
        }
    }
    if (propPath == null) {
        throw new NotExecutableException();
    }
    try {
        retentionMgr.getHolds(propPath);
        fail("Accessing holds from non-existing node must throw PathNotFoundException.");
    } catch (PathNotFoundException e) {
    // success
    }
    try {
        retentionMgr.addHold(propPath, getHoldName(), true);
        fail("Adding a hold for a non-existing node must throw PathNotFoundException.");
    } catch (PathNotFoundException e) {
    // success
    }
    try {
        Hold h = retentionMgr.addHold(testNodePath, getHoldName(), true);
        retentionMgr.removeHold(propPath, h);
        fail("Removing a hold at a non-existing node must throw PathNotFoundException.");
    } catch (PathNotFoundException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) PropertyIterator(javax.jcr.PropertyIterator) PathNotFoundException(javax.jcr.PathNotFoundException) Hold(javax.jcr.retention.Hold)

Example 4 with PathNotFoundException

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

the class UpdateTest method testUpdateAddsMissingSubtree.

public void testUpdateAddsMissingSubtree() throws RepositoryException, NotExecutableException {
    String srcWorkspace = getAnotherWorkspace();
    // get the root node in the second workspace
    Session session2 = getHelper().getSuperuserSession(srcWorkspace);
    try {
        // make sure the source-session has the corresponding node.
        Node testRootW2 = (Node) session2.getItem(testRootNode.getCorrespondingNodePath(srcWorkspace));
        // create test node in second workspace
        Node aNode2 = testRootW2.addNode(nodeName1, testNodeType);
        aNode2.addNode(nodeName2, testNodeType);
        aNode2.setProperty(propertyName2, "test");
        Property p2 = testRootW2.setProperty(propertyName1, "test");
        testRootW2.save();
        // call the update method on test node in default workspace
        testRootNode.update(srcWorkspace);
        // ok check if the child has been added
        boolean allPresent = testRootNode.hasNode(nodeName1) && testRootNode.hasNode(nodeName1 + "/" + nodeName2) && testRootNode.hasProperty(nodeName1 + "/" + propertyName2) && testRootNode.hasProperty(propertyName1);
        assertTrue("Node updated with Node.update() should have received childrens", allPresent);
    } catch (PathNotFoundException e) {
        throw new NotExecutableException();
    } catch (ItemNotFoundException e) {
        throw new NotExecutableException();
    } finally {
        session2.logout();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 5 with PathNotFoundException

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

the class UpdateTest method testUpdateRemovesExtraProperty.

public void testUpdateRemovesExtraProperty() throws RepositoryException, NotExecutableException {
    // create test node in default workspace
    testRootNode.setProperty(propertyName2, "test");
    testRootNode.save();
    String srcWorkspace = getAnotherWorkspace();
    // get the root node in the second workspace
    Session session2 = getHelper().getSuperuserSession(srcWorkspace);
    try {
        // make sure the source-session has the corresponding node.
        Node testRootW2 = (Node) session2.getItem(testRootNode.getCorrespondingNodePath(srcWorkspace));
        if (testRootW2.hasProperty(propertyName2)) {
            throw new NotExecutableException();
        }
        // call the update method on test node in default workspace
        testRootNode.update(srcWorkspace);
        // ok first check if node has no longer properties
        assertFalse("Node updated with Node.update() should have property removed", testRootNode.hasProperty(propertyName2));
    } catch (PathNotFoundException e) {
        throw new NotExecutableException();
    } catch (ItemNotFoundException e) {
        throw new NotExecutableException();
    } finally {
        session2.logout();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

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