Search in sources :

Example 1 with ItemNotFoundException

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

the class RepositoryChecker method checkVersionHistory.

private void checkVersionHistory(NodeState node) {
    String message = null;
    NodeId nid = node.getNodeId();
    boolean isVersioned = node.hasPropertyName(JCR_VERSIONHISTORY);
    NodeId vhid = null;
    try {
        String type = isVersioned ? "in-use" : "candidate";
        log.debug("Checking " + type + " version history of node {}", nid);
        String intro = "Removing references to an inconsistent " + type + " version history of node " + nid;
        message = intro + " (getting the VersionInfo)";
        VersionHistoryInfo vhi = versionManager.getVersionHistoryInfoForNode(node);
        if (vhi != null) {
            // get the version history's node ID as early as possible
            // so we can attempt a fixup even when the next call fails
            vhid = vhi.getVersionHistoryId();
        }
        message = intro + " (getting the InternalVersionHistory)";
        InternalVersionHistory vh = null;
        try {
            vh = versionManager.getVersionHistoryOfNode(nid);
        } catch (ItemNotFoundException ex) {
            // it's ok if we get here if the node didn't claim to be versioned
            if (isVersioned) {
                throw ex;
            }
        }
        if (vh == null) {
            if (isVersioned) {
                message = intro + "getVersionHistoryOfNode returned null";
                throw new InconsistentVersioningState(message);
            }
        } else {
            vhid = vh.getId();
            // additional checks, see JCR-3101
            message = intro + " (getting the version names failed)";
            Name[] versionNames = vh.getVersionNames();
            boolean seenRoot = false;
            for (Name versionName : versionNames) {
                seenRoot |= JCR_ROOTVERSION.equals(versionName);
                log.debug("Checking version history of node {}, version {}", nid, versionName);
                message = intro + " (getting version " + versionName + "  failed)";
                InternalVersion v = vh.getVersion(versionName);
                message = intro + "(frozen node of root version " + v.getId() + " missing)";
                if (null == v.getFrozenNode()) {
                    throw new InconsistentVersioningState(message);
                }
            }
            if (!seenRoot) {
                message = intro + " (root version is missing)";
                throw new InconsistentVersioningState(message);
            }
        }
    } catch (InconsistentVersioningState e) {
        log.info(message, e);
        NodeId nvhid = e.getVersionHistoryNodeId();
        if (nvhid != null) {
            if (vhid != null && !nvhid.equals(vhid)) {
                log.error("vhrid returned with InconsistentVersioningState does not match the id we already had: " + vhid + " vs " + nvhid);
            }
            vhid = nvhid;
        }
        removeVersionHistoryReferences(node, vhid);
    } catch (Exception e) {
        log.info(message, e);
        removeVersionHistoryReferences(node, vhid);
    }
}
Also used : VersionHistoryInfo(org.apache.jackrabbit.core.version.VersionHistoryInfo) InconsistentVersioningState(org.apache.jackrabbit.core.version.InconsistentVersioningState) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalVersionHistory(org.apache.jackrabbit.core.version.InternalVersionHistory) RepositoryException(javax.jcr.RepositoryException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) ItemNotFoundException(javax.jcr.ItemNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException) Name(org.apache.jackrabbit.spi.Name) InternalVersion(org.apache.jackrabbit.core.version.InternalVersion)

Example 2 with ItemNotFoundException

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

the class InternalVersionManagerBase method getVersionHistoryOfNode.

/**
     * {@inheritDoc}
     */
public InternalVersionHistory getVersionHistoryOfNode(NodeId id) throws RepositoryException {
    VersioningLock.ReadLock lock = acquireReadLock();
    try {
        String uuid = id.toString();
        Name name = getName(uuid);
        NodeStateEx parent = getParentNode(getHistoryRoot(), uuid, null);
        if (parent != null && parent.hasNode(name)) {
            NodeStateEx history = parent.getNode(name, 1);
            if (history == null) {
                throw new InconsistentVersioningState("Unexpected failure to get child node " + name + " on parent node" + parent.getNodeId());
            }
            return getVersionHistory(history.getNodeId());
        } else {
            throw new ItemNotFoundException("Version history of node " + id + " not found.");
        }
    } finally {
        lock.release();
    }
}
Also used : Name(org.apache.jackrabbit.spi.Name) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 3 with ItemNotFoundException

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

the class PathPropertyTest method testGetNode.

/**
     * Since JCR 2.0 a path property can be dereferenced if it points to a
     * Node.
     * TODO: create several tests out of this one
     */
public void testGetNode() throws RepositoryException {
    if (!multiple) {
        String nodePath = prop.getParent().getPath();
        String propName = prop.getName();
        // absolute nodes path
        prop.getParent().setProperty(propName, nodePath, PropertyType.PATH);
        String value = prop.getString();
        Node n = prop.getNode();
        assertEquals("The path of the dereferenced property must be equal to the value", n.getPath(), value);
        assertTrue("The property value must be resolved to the correct node.", prop.getParent().isSame(n));
        // relative node path
        prop.getParent().setProperty(propName, ".", PropertyType.PATH);
        n = prop.getNode();
        assertTrue("The property value must be resolved to the correct node.", prop.getParent().getNode(".").isSame(n));
        // non-existing property path
        while (session.nodeExists(nodePath)) {
            nodePath += "x";
        }
        prop.getParent().setProperty(propName, nodePath, PropertyType.PATH);
        try {
            prop.getNode();
            fail("Calling Property.getNode() for a PATH value that doesn't have a corresponding Node, ItemNotFoundException is expected");
        } catch (ItemNotFoundException e) {
        //ok
        }
    } else {
        try {
            prop.getNode();
            fail("Property.getNode() called on a multivalue property " + "should throw a ValueFormatException.");
        } catch (ValueFormatException vfe) {
        //ok
        }
    }
}
Also used : Node(javax.jcr.Node) ValueFormatException(javax.jcr.ValueFormatException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 4 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException 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 ItemNotFoundException

use of javax.jcr.ItemNotFoundException 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

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