Search in sources :

Example 26 with VersionHistory

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

the class VersionHistoryTest method testGetVersionHistoryAfterMove.

public void testGetVersionHistoryAfterMove() throws Exception {
    Node node1 = testRootNode.addNode(nodeName1);
    node1.addMixin(JcrConstants.MIX_VERSIONABLE);
    superuser.save();
    Node node2 = testRootNode.addNode(nodeName2);
    String destPath = node2.getPath() + "/" + nodeName3;
    superuser.move(node1.getPath(), destPath);
    superuser.save();
    assertTrue(superuser.nodeExists(destPath));
    VersionHistory vh = versionManager.getVersionHistory(destPath);
}
Also used : Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory)

Example 27 with VersionHistory

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

the class VersionableTest method testSuccessorsPredecessorsMergedOnRemove.

// OAK-5193
public void testSuccessorsPredecessorsMergedOnRemove() throws Exception {
    Node node = testRootNode.addNode(nodeName1, ntUnstructured);
    node.addMixin(mixVersionable);
    superuser.save();
    VersionManager vm = superuser.getWorkspace().getVersionManager();
    VersionHistory history = vm.getVersionHistory(node.getPath());
    // 1.0
    vm.checkpoint(node.getPath());
    Version v11 = vm.checkpoint(node.getPath());
    // 1.2
    vm.checkpoint(node.getPath());
    // 1.3
    vm.checkpoint(node.getPath());
    vm.restore(v11, true);
    // 1.1
    vm.checkpoint(node.getPath());
    // 1.1.0
    vm.checkpoint(node.getPath());
    assertSuccessors(history, of("1.1.0", "1.2"), "1.1");
    // 1.1.1
    vm.checkpoint(node.getPath());
    history.removeVersion("1.2");
    assertSuccessors(history, of("1.1.0", "1.3"), "1.1");
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory)

Example 28 with VersionHistory

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

the class ReferencesTest method testVersionReferencesVH.

public void testVersionReferencesVH() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixVersionable);
    superuser.save();
    String p = n.getPath();
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    VersionHistory vh = vMgr.getVersionHistory(p);
    // check if versionable node has references to root version
    assertEquals("Version History", vh.getIdentifier(), n.getProperty(Property.JCR_VERSION_HISTORY).getString());
    checkReferences("Version History", vh.getReferences(), p + "/jcr:versionHistory");
}
Also used : Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory)

Example 29 with VersionHistory

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

the class VersionManagerImpl method restore.

@Override
public void restore(final Version[] versions, final boolean removeExisting) throws ItemExistsException, UnsupportedRepositoryOperationException, VersionException, LockException, InvalidItemStateException, RepositoryException {
    if (versions.length > 1) {
        throw new UnsupportedRepositoryOperationException("OAK-168: Restore of multiple versions not implemented.");
    }
    final Version version = versions[0];
    VersionHistory history = (VersionHistory) version.getParent();
    final String versionableId = history.getVersionableIdentifier();
    if (history.getRootVersion().isSame(version)) {
        throw new VersionException("Restore of root version not possible");
    }
    final SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
    sessionDelegate.performVoid(new SessionOperation<Void>("restore", true) {

        @Override
        public void performVoid() throws RepositoryException {
            // check for pending changes
            checkPendingChangesForRestore(sessionDelegate);
            NodeDelegate n = sessionDelegate.getNodeByIdentifier(versionableId);
            if (n == null) {
                throw new VersionException("Unable to restore version. " + "No versionable node with identifier: " + versionableId);
            }
            // check lock status
            checkNotLocked(n.getPath());
            // check for existing nodes
            List<NodeDelegate> existing = getExisting(version, Collections.singleton(n.getPath()));
            boolean success = false;
            try {
                if (!existing.isEmpty()) {
                    if (removeExisting) {
                        removeExistingNodes(existing);
                    } else {
                        List<String> paths = new ArrayList<String>();
                        for (NodeDelegate nd : existing) {
                            paths.add(nd.getPath());
                        }
                        throw new ItemExistsException("Unable to restore with " + "removeExisting=false. Existing nodes in " + "workspace: " + paths);
                    }
                }
                // ready for restore
                VersionDelegate vd = versionManagerDelegate.getVersionByIdentifier(version.getIdentifier());
                versionManagerDelegate.restore(n.getParent(), n.getName(), vd);
                sessionDelegate.commit();
                success = true;
            } catch (CommitFailedException e) {
                throw new RepositoryException(e);
            } finally {
                if (!success) {
                    // refresh if one of the modifying operations fail
                    sessionDelegate.refresh(false);
                }
            }
        }
    });
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) VersionDelegate(org.apache.jackrabbit.oak.jcr.delegate.VersionDelegate) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) SessionDelegate(org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate) Version(javax.jcr.version.Version) ItemExistsException(javax.jcr.ItemExistsException) ArrayList(java.util.ArrayList) List(java.util.List) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) VersionException(javax.jcr.version.VersionException)

Example 30 with VersionHistory

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

the class VersionManagementTest method testAccessVersionHistory.

/**
     * @since oak (DIFF: jr required jcr:versionManagement privilege on the version store)
     */
@Test
public void testAccessVersionHistory() throws Exception {
    Node n = createVersionableNode(superuser.getNode(path));
    allow(n.getPath(), versionPrivileges);
    Node testNode = testSession.getNode(n.getPath());
    testNode.checkin();
    testNode.checkout();
    // accessing the version history must be allowed if the versionable node
    // is readable to the editing test session.
    VersionHistory vh = testNode.getVersionHistory();
    String vhPath = vh.getPath();
    String vhUUID = vh.getIdentifier();
    assertTrue(vh.isSame(testNode.getSession().getNode(vhPath)));
    assertTrue(vh.isSame(testNode.getSession().getNodeByIdentifier(vhUUID)));
    assertTrue(vh.isSame(testNode.getSession().getNodeByUUID(vhUUID)));
}
Also used : Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) 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