use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.
the class VersionHistoryTest method testGetVersionHistoryAfterMove.
public void testGetVersionHistoryAfterMove() throws Exception {
Node node1 = testRootNode.addNode(nodeName1);
node1.addMixin(JcrConstants.MIX_VERSIONABLE);
superuser.save();
Node node2 = testRootNode.addNode(nodeName2);
String destPath = node2.getPath() + "/" + nodeName3;
superuser.move(node1.getPath(), destPath);
superuser.save();
assertTrue(superuser.nodeExists(destPath));
VersionHistory vh = versionManager.getVersionHistory(destPath);
}
use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.
the class VersionableTest method testSuccessorsPredecessorsMergedOnRemove.
// OAK-5193
public void testSuccessorsPredecessorsMergedOnRemove() throws Exception {
Node node = testRootNode.addNode(nodeName1, ntUnstructured);
node.addMixin(mixVersionable);
superuser.save();
VersionManager vm = superuser.getWorkspace().getVersionManager();
VersionHistory history = vm.getVersionHistory(node.getPath());
// 1.0
vm.checkpoint(node.getPath());
Version v11 = vm.checkpoint(node.getPath());
// 1.2
vm.checkpoint(node.getPath());
// 1.3
vm.checkpoint(node.getPath());
vm.restore(v11, true);
// 1.1
vm.checkpoint(node.getPath());
// 1.1.0
vm.checkpoint(node.getPath());
assertSuccessors(history, of("1.1.0", "1.2"), "1.1");
// 1.1.1
vm.checkpoint(node.getPath());
history.removeVersion("1.2");
assertSuccessors(history, of("1.1.0", "1.3"), "1.1");
}
use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.
the class ReferencesTest method testVersionReferencesVH.
public void testVersionReferencesVH() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1, testNodeType);
n.addMixin(mixVersionable);
superuser.save();
String p = n.getPath();
VersionManager vMgr = superuser.getWorkspace().getVersionManager();
VersionHistory vh = vMgr.getVersionHistory(p);
// check if versionable node has references to root version
assertEquals("Version History", vh.getIdentifier(), n.getProperty(Property.JCR_VERSION_HISTORY).getString());
checkReferences("Version History", vh.getReferences(), p + "/jcr:versionHistory");
}
use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.
the class VersionManagerImpl method restore.
@Override
public void restore(final Version[] versions, final boolean removeExisting) throws ItemExistsException, UnsupportedRepositoryOperationException, VersionException, LockException, InvalidItemStateException, RepositoryException {
if (versions.length > 1) {
throw new UnsupportedRepositoryOperationException("OAK-168: Restore of multiple versions not implemented.");
}
final Version version = versions[0];
VersionHistory history = (VersionHistory) version.getParent();
final String versionableId = history.getVersionableIdentifier();
if (history.getRootVersion().isSame(version)) {
throw new VersionException("Restore of root version not possible");
}
final SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
sessionDelegate.performVoid(new SessionOperation<Void>("restore", true) {
@Override
public void performVoid() throws RepositoryException {
// check for pending changes
checkPendingChangesForRestore(sessionDelegate);
NodeDelegate n = sessionDelegate.getNodeByIdentifier(versionableId);
if (n == null) {
throw new VersionException("Unable to restore version. " + "No versionable node with identifier: " + versionableId);
}
// check lock status
checkNotLocked(n.getPath());
// check for existing nodes
List<NodeDelegate> existing = getExisting(version, Collections.singleton(n.getPath()));
boolean success = false;
try {
if (!existing.isEmpty()) {
if (removeExisting) {
removeExistingNodes(existing);
} else {
List<String> paths = new ArrayList<String>();
for (NodeDelegate nd : existing) {
paths.add(nd.getPath());
}
throw new ItemExistsException("Unable to restore with " + "removeExisting=false. Existing nodes in " + "workspace: " + paths);
}
}
// ready for restore
VersionDelegate vd = versionManagerDelegate.getVersionByIdentifier(version.getIdentifier());
versionManagerDelegate.restore(n.getParent(), n.getName(), vd);
sessionDelegate.commit();
success = true;
} catch (CommitFailedException e) {
throw new RepositoryException(e);
} finally {
if (!success) {
// refresh if one of the modifying operations fail
sessionDelegate.refresh(false);
}
}
}
});
}
use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.
the class VersionManagementTest method testAccessVersionHistory.
/**
* @since oak (DIFF: jr required jcr:versionManagement privilege on the version store)
*/
@Test
public void testAccessVersionHistory() throws Exception {
Node n = createVersionableNode(superuser.getNode(path));
allow(n.getPath(), versionPrivileges);
Node testNode = testSession.getNode(n.getPath());
testNode.checkin();
testNode.checkout();
// accessing the version history must be allowed if the versionable node
// is readable to the editing test session.
VersionHistory vh = testNode.getVersionHistory();
String vhPath = vh.getPath();
String vhUUID = vh.getIdentifier();
assertTrue(vh.isSame(testNode.getSession().getNode(vhPath)));
assertTrue(vh.isSame(testNode.getSession().getNodeByIdentifier(vhUUID)));
assertTrue(vh.isSame(testNode.getSession().getNodeByUUID(vhUUID)));
}
Aggregations