Search in sources :

Example 31 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class VersionManagementTest method testVersionableChildNode.

/**
     * @since oak
     */
@Test
public void testVersionableChildNode() throws Exception {
    Node testNode = superuser.getNode(path).addNode("n1").addNode("n2").addNode("n3").addNode("jcr:content");
    superuser.save();
    testNode.addMixin("mix:versionable");
    superuser.save();
    assertTrue(testNode.isNodeType("mix:versionable"));
    VersionHistory vh = testNode.getVersionHistory();
    Property versionablePath = vh.getProperty(superuser.getWorkspace().getName());
    assertEquals(testNode.getPath(), versionablePath.getString());
}
Also used : Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) Test(org.junit.Test)

Example 32 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class VersionManagementTest method testAccessVersionHistoryVersionableNodeRemoved.

/**
     * @since oak
     */
@Test
public void testAccessVersionHistoryVersionableNodeRemoved() throws Exception {
    Node n = createVersionableNode(superuser.getNode(path));
    allow(n.getPath(), versionPrivileges);
    n.checkin();
    n.checkout();
    String versionablePath = n.getPath();
    VersionHistory vh = n.getVersionHistory();
    String vhPath = vh.getPath();
    String vhUUID = vh.getIdentifier();
    // remove the versionable node
    n.remove();
    superuser.save();
    testSession.refresh(false);
    assertTrue(testSession.nodeExists(path));
    assertFalse(testSession.nodeExists(versionablePath));
    // accessing the version history directly should still succeed as
    // read permission is still granted on the tree defined by the parent.
    VersionHistory history = (VersionHistory) testSession.getNode(vhPath);
    history = (VersionHistory) testSession.getNodeByIdentifier(vhUUID);
    history = (VersionHistory) testSession.getNodeByUUID(vhUUID);
    // revoking read permission on the parent node -> version history
    // must no longer be accessible
    modify(path, Privilege.JCR_READ, false);
    assertFalse(testSession.nodeExists(vhPath));
}
Also used : Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Test(org.junit.Test)

Example 33 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class VersionManagementTest method testVersionablePath.

/**
     * @since oak
     */
@Test
public void testVersionablePath() throws Exception {
    Node n = createVersionableNode(superuser.getNode(path));
    VersionHistory vh = n.getVersionHistory();
    Property versionablePath = vh.getProperty(superuser.getWorkspace().getName());
    assertEquals(n.getPath(), versionablePath.getString());
}
Also used : Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) Test(org.junit.Test)

Example 34 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class CopyVersionHistoryTest method assertMissingHistories.

private static void assertMissingHistories(final Session session, final String... names) throws RepositoryException {
    for (final String mixin : MIXINS) {
        final String pathPrefix = VERSIONABLES_PATH_PREFIX + mixin + "/";
        for (final String name : names) {
            final String path = pathPrefix + name;
            final VersionHistory history = getVersionHistoryForPath(session, path);
            assertNull("Should not have found history for " + path, history);
        }
    }
}
Also used : VersionHistory(javax.jcr.version.VersionHistory)

Example 35 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit by apache.

the class VersionControlledResourceImpl method getVersionHistory.

/**
     * Returns the {@link javax.jcr.version.VersionHistory} associated with the repository node.
     * If the node is not versionable an exception is thrown.
     *
     * @return the {@link VersionHistoryResource} associated with this resource.
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#getVersionHistory()
     * @see javax.jcr.Node#getVersionHistory()
     */
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    if (!isVersionControlled()) {
        throw new DavException(DavServletResponse.SC_FORBIDDEN);
    }
    try {
        VersionHistory vh = getNode().getVersionHistory();
        DavResourceLocator loc = getLocatorFromNode(vh);
        DavResource vhr = createResourceFromLocator(loc);
        if (vhr instanceof VersionHistoryResource) {
            return (VersionHistoryResource) vhr;
        } else {
            // severe error since resource factory doesn't behave correctly.
            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Aggregations

VersionHistory (javax.jcr.version.VersionHistory)73 Node (javax.jcr.Node)45 Version (javax.jcr.version.Version)29 Test (org.junit.Test)25 RepositoryException (javax.jcr.RepositoryException)17 VersionManager (javax.jcr.version.VersionManager)17 Session (javax.jcr.Session)12 VersionIterator (javax.jcr.version.VersionIterator)12 Property (javax.jcr.Property)7 DavException (org.apache.jackrabbit.webdav.DavException)7 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)7 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 ArrayList (java.util.ArrayList)6 DavResource (org.apache.jackrabbit.webdav.DavResource)6 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)4 Workspace (javax.jcr.Workspace)3 VersionException (javax.jcr.version.VersionException)3 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)3 PathNotFoundException (javax.jcr.PathNotFoundException)2