Search in sources :

Example 76 with VersionManager

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

the class RepositorySidegradeTest method verifyVersionHistory.

@Test
public void verifyVersionHistory() throws RepositoryException {
    Session session = createAdminSession();
    try {
        assertTrue(session.nodeExists("/versionable"));
        Node versionable = session.getNode("/versionable");
        assertTrue(versionable.hasNode("child"));
        Node child = versionable.getNode("child");
        assertTrue(child.hasNode("child2"));
        Node child2 = child.getNode("child2");
        assertFalse(versionable.isCheckedOut());
        assertTrue(versionable.hasProperty(JCR_UUID));
        assertFalse(child.isCheckedOut());
        assertTrue(child.hasProperty(JCR_UUID));
        assertFalse(child2.isCheckedOut());
        assertFalse(child2.hasProperty(JCR_UUID));
        VersionManager manager = session.getWorkspace().getVersionManager();
        Version version = manager.getBaseVersion("/versionable");
        Node frozen = version.getFrozenNode();
        assertEquals(versionable.getPrimaryNodeType().getName(), frozen.getProperty(JCR_FROZENPRIMARYTYPE).getString());
        assertEquals(versionable.getMixinNodeTypes()[0].getName(), frozen.getProperty(JCR_FROZENMIXINTYPES).getValues()[0].getString());
        assertEquals(versionable.getIdentifier(), frozen.getProperty(JCR_FROZENUUID).getString());
        Node frozenChild = frozen.getNode("child");
        assertEquals(child.getPrimaryNodeType().getName(), frozenChild.getProperty(JCR_FROZENPRIMARYTYPE).getString());
        assertFalse(frozenChild.hasProperty(JCR_FROZENMIXINTYPES));
        assertEquals("OAK-1789", child.getIdentifier(), frozenChild.getProperty(JCR_FROZENUUID).getString());
        Node frozenChild2 = frozenChild.getNode("child2");
        assertEquals(child2.getPrimaryNodeType().getName(), frozenChild2.getProperty(JCR_FROZENPRIMARYTYPE).getString());
        assertFalse(frozenChild2.hasProperty(JCR_FROZENMIXINTYPES));
        assertEquals("OAK-1789", child2.getIdentifier(), frozenChild2.getProperty(JCR_FROZENUUID).getString());
        VersionHistory history = manager.getVersionHistory("/versionable");
        assertTrue(history.isNodeType("rep:VersionablePaths"));
        Property versionablePath = history.getProperty("default");
        assertEquals("/versionable", versionablePath.getString());
    } finally {
        session.logout();
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 77 with VersionManager

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

the class RepositoryUpgradeTest method verifyVersionHistory.

@Test
public void verifyVersionHistory() throws RepositoryException {
    Session session = createAdminSession();
    try {
        assertTrue(session.nodeExists("/versionable"));
        Node versionable = session.getNode("/versionable");
        assertTrue(versionable.hasNode("child"));
        Node child = versionable.getNode("child");
        assertTrue(child.hasNode("child2"));
        Node child2 = child.getNode("child2");
        assertFalse(versionable.isCheckedOut());
        assertTrue(versionable.hasProperty(JCR_UUID));
        assertFalse(child.isCheckedOut());
        assertTrue(child.hasProperty(JCR_UUID));
        assertFalse(child2.isCheckedOut());
        assertFalse(child2.hasProperty(JCR_UUID));
        VersionManager manager = session.getWorkspace().getVersionManager();
        Version version = manager.getBaseVersion("/versionable");
        Node frozen = version.getFrozenNode();
        assertEquals(versionable.getPrimaryNodeType().getName(), frozen.getProperty(JCR_FROZENPRIMARYTYPE).getString());
        assertEquals(versionable.getMixinNodeTypes()[0].getName(), frozen.getProperty(JCR_FROZENMIXINTYPES).getValues()[0].getString());
        assertEquals(versionable.getIdentifier(), frozen.getProperty(JCR_FROZENUUID).getString());
        Node frozenChild = frozen.getNode("child");
        assertEquals(child.getPrimaryNodeType().getName(), frozenChild.getProperty(JCR_FROZENPRIMARYTYPE).getString());
        assertFalse(frozenChild.hasProperty(JCR_FROZENMIXINTYPES));
        assertEquals("OAK-1789", child.getIdentifier(), frozenChild.getProperty(JCR_FROZENUUID).getString());
        Node frozenChild2 = frozenChild.getNode("child2");
        assertEquals(child2.getPrimaryNodeType().getName(), frozenChild2.getProperty(JCR_FROZENPRIMARYTYPE).getString());
        assertFalse(frozenChild2.hasProperty(JCR_FROZENMIXINTYPES));
        assertEquals("OAK-1789", child2.getIdentifier(), frozenChild2.getProperty(JCR_FROZENUUID).getString());
        VersionHistory history = manager.getVersionHistory("/versionable");
        assertTrue(history.isNodeType("rep:VersionablePaths"));
        Property versionablePath = history.getProperty("default");
        assertEquals("/versionable", versionablePath.getString());
    } finally {
        session.logout();
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) Session(javax.jcr.Session) Test(org.junit.Test)

Example 78 with VersionManager

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

the class BrokenVersionableTest method verifyNoVersionable.

@Test
public void verifyNoVersionable() throws RepositoryException {
    Session session = createAdminSession();
    VersionManager vMgr = session.getWorkspace().getVersionManager();
    try {
        assertFalse(session.getNode("/versionable1").isNodeType(MIX_VERSIONABLE));
        Node versionable2 = session.getNode("/versionable2");
        assertTrue(versionable2.isNodeType(MIX_VERSIONABLE));
        VersionHistory history = vMgr.getVersionHistory(versionable2.getPath());
        VersionIterator versions = history.getAllVersions();
        assertEquals("jcr:rootVersion", versions.nextVersion().getName());
        assertFalse(versions.hasNext());
    } finally {
        session.logout();
    }
}
Also used : Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Example 79 with VersionManager

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

the class CopyVersionHistoryTest method assertVersionsCanBeRestored.

private static void assertVersionsCanBeRestored(final Session session, final String... names) throws RepositoryException {
    VersionManager vMgr = session.getWorkspace().getVersionManager();
    for (final String mixin : MIXINS) {
        final String pathPrefix = VERSIONABLES_PATH_PREFIX + mixin + "/";
        for (final String name : names) {
            final String path = pathPrefix + name;
            VersionHistory history = vMgr.getVersionHistory(path);
            assertEquals("1.2", session.getNode(path).getProperty("version").getString());
            vMgr.restore(history.getVersion("1.0"), false);
            Node versionable = session.getNode(path);
            assertEquals("1.0", versionable.getProperty("version").getString());
            // restored node should have correct properties
            String versionHistoryUuid = versionable.getProperty(JCR_VERSIONHISTORY).getString();
            assertEquals(history.getIdentifier(), versionHistoryUuid);
            final Version baseVersion = vMgr.getBaseVersion(path);
            assertEquals("1.0", baseVersion.getName());
            final Value[] predecessors = versionable.getProperty(JCR_PREDECESSORS).getValues();
            assertEquals(0, predecessors.length);
            assertFalse(vMgr.isCheckedOut(path));
        }
    }
    // after restoring, the paths should be still versionable
    assertVersionablePaths(session, names);
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) Value(javax.jcr.Value) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory)

Example 80 with VersionManager

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

the class VersionCopyTestUtils method createLabeledVersions.

public static String createLabeledVersions(Node node) throws RepositoryException, InterruptedException {
    final Session session = node.getSession();
    final VersionManager versionManager = session.getWorkspace().getVersionManager();
    node.setProperty("version", "root");
    session.save();
    final String path = node.getPath();
    final List<String> versionNames = new ArrayList<String>();
    for (final String label : LABELS) {
        node.setProperty("version", label);
        session.save();
        final Version v = versionManager.checkpoint(path);
        versionNames.add(v.getName());
    }
    final VersionHistory history = versionManager.getVersionHistory(path);
    for (final String versionName : versionNames) {
        history.addVersionLabel(versionName, String.format("version %s", versionName), false);
    }
    return history.getPath();
}
Also used : Version(javax.jcr.version.Version) ArrayList(java.util.ArrayList) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session)

Aggregations

VersionManager (javax.jcr.version.VersionManager)154 Node (javax.jcr.Node)97 Version (javax.jcr.version.Version)65 VersionHistory (javax.jcr.version.VersionHistory)17 RepositoryException (javax.jcr.RepositoryException)11 Value (javax.jcr.Value)10 Test (org.junit.Test)9 Property (javax.jcr.Property)8 Session (javax.jcr.Session)8 NodeIterator (javax.jcr.NodeIterator)7 VersionException (javax.jcr.version.VersionException)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)4 MergeException (javax.jcr.MergeException)4 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)4 VersionIterator (javax.jcr.version.VersionIterator)4 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)3 InvalidItemStateException (javax.jcr.InvalidItemStateException)2