Search in sources :

Example 11 with VersionIterator

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

the class RestoreTest method testLinearVersionsJcr2.

/**
     * Tests if restore on simple versioning creates a new version that is
     * in the correct linear order.
     */
public void testLinearVersionsJcr2() throws Exception {
    // first get all linear versions
    VersionIterator iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
    StringBuffer expected = new StringBuffer();
    while (iter.hasNext()) {
        expected.append(iter.nextVersion().getName()).append(",");
    }
    // restore version
    versionManager.restore(version, true);
    // append new base version
    expected.append(versionManager.getBaseVersion(versionableNode.getPath()).getName()).append(",");
    // get the version names again
    iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
    StringBuffer actual = new StringBuffer();
    while (iter.hasNext()) {
        actual.append(iter.nextVersion().getName()).append(",");
    }
    assertEquals("Node.restore() on simple versioning must create a new version.", expected.toString(), actual.toString());
}
Also used : VersionIterator(javax.jcr.version.VersionIterator)

Example 12 with VersionIterator

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

the class RestoreTest method testLinearVersions.

/**
     * Tests if restore on simple versioning creates a new version that is
     * in the correct linear order.
     */
@SuppressWarnings("deprecation")
public void testLinearVersions() throws Exception {
    // first get all linear versions
    VersionIterator iter = versionableNode.getVersionHistory().getAllLinearVersions();
    StringBuffer expected = new StringBuffer();
    while (iter.hasNext()) {
        expected.append(iter.nextVersion().getName()).append(",");
    }
    // restore version
    versionableNode.restore(version, true);
    // append new base version
    expected.append(versionableNode.getBaseVersion().getName()).append(",");
    // get the version names again
    iter = versionableNode.getVersionHistory().getAllLinearVersions();
    StringBuffer actual = new StringBuffer();
    while (iter.hasNext()) {
        actual.append(iter.nextVersion().getName()).append(",");
    }
    assertEquals("Node.restore() on simple versioning must create a new version.", expected.toString(), actual.toString());
}
Also used : VersionIterator(javax.jcr.version.VersionIterator)

Example 13 with VersionIterator

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

the class RestoreTest method testLinearVersionsJcr2_4.

/**
     * Tests if restore on simple versioning creates a new version that is
     * in the correct linear order.
     */
public void testLinearVersionsJcr2_4() throws Exception {
    // first get all linear versions
    VersionIterator iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
    StringBuffer expected = new StringBuffer();
    while (iter.hasNext()) {
        expected.append(iter.nextVersion().getName()).append(",");
    }
    // restore version
    versionManager.restore(new Version[] { version }, true);
    // append new base version
    expected.append(versionManager.getBaseVersion(versionableNode.getPath()).getName()).append(",");
    // get the version names again
    iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
    StringBuffer actual = new StringBuffer();
    while (iter.hasNext()) {
        actual.append(iter.nextVersion().getName()).append(",");
    }
    assertEquals("Node.restore() on simple versioning must create a new version.", expected.toString(), actual.toString());
}
Also used : VersionIterator(javax.jcr.version.VersionIterator)

Example 14 with VersionIterator

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

the class RestoreTest method testLinearVersionsJcr2_2.

/**
     * Tests if restore on simple versioning creates a new version that is
     * in the correct linear order.
     */
public void testLinearVersionsJcr2_2() throws Exception {
    // first get all linear versions
    VersionIterator iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
    StringBuffer expected = new StringBuffer();
    while (iter.hasNext()) {
        expected.append(iter.nextVersion().getName()).append(",");
    }
    // restore version
    versionManager.restore(version, true);
    // append new base version
    expected.append(versionManager.getBaseVersion(versionableNode.getPath()).getName()).append(",");
    // get the version names again
    iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions();
    StringBuffer actual = new StringBuffer();
    while (iter.hasNext()) {
        actual.append(iter.nextVersion().getName()).append(",");
    }
    assertEquals("Node.restore() on simple versioning must create a new version.", expected.toString(), actual.toString());
}
Also used : VersionIterator(javax.jcr.version.VersionIterator)

Example 15 with VersionIterator

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

the class VersionOperation method getRandomVersion.

/**
     * Returns a randomly chosen version for the current node or
     * <code>null</code> if the current node only has a root version.
     *
     * @param excludeReferenced exclude versions that are still referenced.
     * @return randomly chosen version or <code>null</code>.
     * @throws RepositoryException if an error occurs while reading from the
     *                             repository.
     */
protected Version getRandomVersion(boolean excludeReferenced) throws RepositoryException {
    List allVersions = new ArrayList();
    Node n = getNode();
    for (VersionIterator it = n.getVersionHistory().getAllVersions(); it.hasNext(); ) {
        Version v = it.nextVersion();
        if (excludeReferenced) {
            // quick check if it is the base version
            if (n.getBaseVersion().isSame(v)) {
                continue;
            }
        }
        if (v.getPredecessors().length > 0) {
            if (!excludeReferenced || !v.getReferences().hasNext()) {
                allVersions.add(v);
            }
        }
    }
    if (allVersions.size() > 0) {
        return (Version) allVersions.get(getRandom().nextInt(allVersions.size()));
    } else {
        return null;
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

VersionIterator (javax.jcr.version.VersionIterator)29 Version (javax.jcr.version.Version)16 VersionHistory (javax.jcr.version.VersionHistory)12 Node (javax.jcr.Node)9 ArrayList (java.util.ArrayList)8 RepositoryException (javax.jcr.RepositoryException)6 VersionException (javax.jcr.version.VersionException)5 VersionManager (javax.jcr.version.VersionManager)4 Test (org.junit.Test)4 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)3 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)3 HashMap (java.util.HashMap)2 Session (javax.jcr.Session)2 DavException (org.apache.jackrabbit.webdav.DavException)2 DavResource (org.apache.jackrabbit.webdav.DavResource)2 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)2 VersionResource (org.apache.jackrabbit.webdav.version.VersionResource)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1