Search in sources :

Example 26 with VersionIterator

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

the class RestoreTest method testRestoreInvalidVersion2.

/**
     * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
     *
     * @throws RepositoryException
     */
@SuppressWarnings("deprecation")
public void testRestoreInvalidVersion2() throws RepositoryException {
    String invalidName;
    do {
        invalidName = createRandomString(3);
        for (VersionIterator it = versionableNode.getVersionHistory().getAllVersions(); it.hasNext(); ) {
            Version v = it.nextVersion();
            if (invalidName.equals(v.getName())) {
                invalidName = null;
                break;
            }
        }
    } while (invalidName == null);
    try {
        versionableNode.restore(invalidName, true);
        fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.");
    } catch (VersionException e) {
    // ok
    }
}
Also used : Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator) VersionException(javax.jcr.version.VersionException)

Example 27 with VersionIterator

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

the class RestoreTest method testRestoreInvalidVersion2.

/**
     * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
     *
     * @throws RepositoryException
     */
@SuppressWarnings("deprecation")
public void testRestoreInvalidVersion2() throws RepositoryException {
    String invalidName;
    do {
        invalidName = createRandomString(3);
        for (VersionIterator it = versionableNode.getVersionHistory().getAllVersions(); it.hasNext(); ) {
            Version v = it.nextVersion();
            if (invalidName.equals(v.getName())) {
                invalidName = null;
                break;
            }
        }
    } while (invalidName == null);
    try {
        versionableNode.restore(invalidName, true);
        fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.");
    } catch (VersionException e) {
    // ok
    }
}
Also used : Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator) VersionException(javax.jcr.version.VersionException)

Example 28 with VersionIterator

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

the class RestoreTest method testRestoreInvalidVersion2Jcr2.

/**
     * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
     *
     * @throws RepositoryException
     */
public void testRestoreInvalidVersion2Jcr2() throws RepositoryException {
    String invalidName;
    do {
        invalidName = createRandomString(3);
        for (VersionIterator it = versionManager.getVersionHistory(versionableNode.getPath()).getAllVersions(); it.hasNext(); ) {
            Version v = it.nextVersion();
            if (invalidName.equals(v.getName())) {
                invalidName = null;
                break;
            }
        }
    } while (invalidName == null);
    try {
        versionManager.restore(versionableNode.getPath(), invalidName, true);
        fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.");
    } catch (VersionException e) {
    // ok
    }
}
Also used : Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator) VersionException(javax.jcr.version.VersionException)

Example 29 with VersionIterator

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

the class VersionInfoServlet method getJsonObject.

private JsonObject getJsonObject(Resource resource) throws RepositoryException {
    final JsonObjectBuilder result = Json.createObjectBuilder();
    final Node node = resource.adaptTo(Node.class);
    if (node == null || !node.isNodeType(JcrConstants.MIX_VERSIONABLE)) {
        return result.build();
    }
    final VersionHistory history = node.getVersionHistory();
    final Version baseVersion = node.getBaseVersion();
    for (final VersionIterator it = history.getAllVersions(); it.hasNext(); ) {
        final Version v = it.nextVersion();
        final JsonObjectBuilder obj = Json.createObjectBuilder();
        obj.add("created", createdDate(v));
        obj.add("successors", getArrayBuilder(getNames(v.getSuccessors())));
        obj.add("predecessors", getArrayBuilder(getNames(v.getPredecessors())));
        obj.add("labels", getArrayBuilder(history.getVersionLabels(v)));
        obj.add("baseVersion", baseVersion.isSame(v));
        result.add(v.getName(), obj);
    }
    return Json.createObjectBuilder().add("versions", result).build();
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) JsonObjectBuilder(javax.json.JsonObjectBuilder) VersionHistory(javax.jcr.version.VersionHistory)

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