Search in sources :

Example 16 with VersionHistory

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

the class RepositoryServiceImpl method removeVersion.

/**
     * {@inheritDoc}
     */
public void removeVersion(final SessionInfo sessionInfo, final NodeId versionHistoryId, final NodeId versionId) throws ReferentialIntegrityException, AccessDeniedException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
    final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    executeWithLocalEvents(new Callable() {

        public Object run() throws RepositoryException {
            Node vHistory = getNode(versionHistoryId, sInfo);
            Node version = getNode(versionId, sInfo);
            if (vHistory instanceof VersionHistory) {
                ((VersionHistory) vHistory).removeVersion(version.getName());
            } else {
                throw new RepositoryException("versionHistoryId does not reference a VersionHistor node");
            }
            return null;
        }
    }, sInfo);
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory)

Example 17 with VersionHistory

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

the class VersionControlledItemCollection method getVersionHistory.

/**
     * Returns the {@link 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()
     */
@Override
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    try {
        VersionHistory vh = ((Node) item).getVersionHistory();
        DavResourceLocator loc = getLocatorFromItem(vh);
        return (VersionHistoryResource) createResourceFromLocator(loc);
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 18 with VersionHistory

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

the class CopyVersionHistoryTest method assertExistingHistories.

private static void assertExistingHistories(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);
            assertNotNull("No history found for " + path, history);
            VersionCopyTestUtils.assertLabeledVersions(history);
        }
    }
}
Also used : VersionHistory(javax.jcr.version.VersionHistory)

Example 19 with VersionHistory

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

the class CopyTest method testCopyVersionableNodeCreatesJcrCopiedFrom.

@Test
public void testCopyVersionableNodeCreatesJcrCopiedFrom() throws Exception {
    Session session = getAdminSession();
    Node toCopy = session.getNode(TEST_PATH + "/source/node");
    toCopy.addMixin(JcrConstants.MIX_VERSIONABLE);
    session.save();
    Version baseV = toCopy.getBaseVersion();
    session.getWorkspace().copy(TEST_PATH + "/source/node", TEST_PATH + "/target/copied");
    Node copy = testNode.getNode("target/copied");
    VersionHistory copiedVh = copy.getVersionHistory();
    assertTrue(copiedVh.hasProperty(VersionConstants.JCR_COPIED_FROM));
    Property prop = copiedVh.getProperty(VersionConstants.JCR_COPIED_FROM);
    assertEquals(PropertyType.WEAKREFERENCE, prop.getType());
    Node copiedFrom = prop.getNode();
    assertTrue(baseV.isSame(copiedFrom));
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) Session(javax.jcr.Session) Test(org.junit.Test)

Example 20 with VersionHistory

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

the class CopyTest method testCopyVersionableNodeClearsVersions.

@Test
public void testCopyVersionableNodeClearsVersions() throws Exception {
    Session session = getAdminSession();
    Node toCopy = session.getNode(TEST_PATH + "/source/node");
    toCopy.addMixin(JcrConstants.MIX_VERSIONABLE);
    session.save();
    Version v1 = toCopy.checkin();
    toCopy.checkout();
    Version v2 = toCopy.checkin();
    toCopy.checkout();
    session.getWorkspace().copy(TEST_PATH + "/source/node", TEST_PATH + "/target/copied");
    Node copy = testNode.getNode("target/copied");
    VersionHistory vh = copy.getVersionHistory();
    Version rootV = vh.getRootVersion();
    assertEquals(0, rootV.getSuccessors().length);
    VersionIterator vItr = vh.getAllVersions();
    while (vItr.hasNext()) {
        if (!rootV.isSame(vItr.nextVersion())) {
            fail("Unexpected version in version history of copied node.");
        }
    }
    try {
        vh.getVersion(v1.getName());
        fail("Unexpected version in version history of copied node.");
    } catch (VersionException e) {
    // success
    }
    try {
        vh.getVersion(v2.getName());
        fail("Unexpected version in version history of copied node.");
    } catch (VersionException e) {
    // success
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session) VersionException(javax.jcr.version.VersionException) Test(org.junit.Test)

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