Search in sources :

Example 71 with VersionHistory

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

the class JcrItemResourceFactory method getFrozenNode.

private Node getFrozenNode(Node node, String versionSpecifier) throws RepositoryException {
    final VersionManager versionManager = session.getWorkspace().getVersionManager();
    final VersionHistory history = versionManager.getVersionHistory(node.getPath());
    if (history.hasVersionLabel(versionSpecifier)) {
        return history.getVersionByLabel(versionSpecifier).getFrozenNode();
    } else if (history.hasNode(versionSpecifier)) {
        return history.getVersion(versionSpecifier).getFrozenNode();
    } else {
        return null;
    }
}
Also used : VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory)

Example 72 with VersionHistory

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

the class RestoreOperation method restore.

private void restore(Node node, String versionSpecifier, boolean removeExisting) throws RepositoryException {
    final VersionManager vm = node.getSession().getWorkspace().getVersionManager();
    final VersionHistory history = vm.getVersionHistory(node.getPath());
    final Version version;
    if (history.hasVersionLabel(versionSpecifier)) {
        version = history.getVersionByLabel(versionSpecifier);
    } else if (history.hasNode(versionSpecifier)) {
        version = history.getVersion(versionSpecifier);
    } else {
        throw new IllegalArgumentException("Unable to process restore. Invalid version: " + versionSpecifier);
    }
    vm.restore(version, removeExisting);
}
Also used : Version(javax.jcr.version.Version) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory)

Example 73 with VersionHistory

use of javax.jcr.version.VersionHistory 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

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