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;
}
}
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);
}
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();
}
Aggregations