use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class VersionHistoryResourceImpl method getVersions.
//---------------------------------------------< VersionHistoryResource >---
/**
* Return an array of {@link org.apache.jackrabbit.webdav.version.VersionResource}s representing all versions
* present in the underlying JCR version history.
*
* @return array of {@link org.apache.jackrabbit.webdav.version.VersionResource}s representing all versions
* present in the underlying JCR version history.
* @throws org.apache.jackrabbit.webdav.DavException
* @see org.apache.jackrabbit.webdav.version.VersionHistoryResource#getVersions()
*/
public VersionResource[] getVersions() throws DavException {
try {
VersionIterator vIter = ((VersionHistory) getNode()).getAllVersions();
ArrayList<VersionResource> l = new ArrayList<VersionResource>();
while (vIter.hasNext()) {
DavResourceLocator versionLoc = getLocatorFromNode(vIter.nextVersion());
DavResource vr = createResourceFromLocator(versionLoc);
if (vr instanceof VersionResource) {
l.add((VersionResource) vr);
} else {
// severe error since resource factory doesn't behave correctly.
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
return l.toArray(new VersionResource[l.size()]);
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class CopyTest method testCopy.
public void testCopy() throws RepositoryException {
Workspace wsp = superuser.getWorkspace();
VersionManager vMgr = wsp.getVersionManager();
String srcPath = versionableNode.getPath();
String dstPath = getProperty("destination");
wsp.copy(srcPath, dstPath);
// check versionable
Node v = superuser.getNode(dstPath);
assertTrue("Copied Node.isNodeType(mix:simpleVersionable) must return true.", v.isNodeType(mixSimpleVersionable));
assertFalse("Copied Node.isNodeType(mix:versionable) must return false.", v.isNodeType(mixVersionable));
// check different version history
VersionHistory vh1 = vMgr.getVersionHistory(srcPath);
VersionHistory vh2 = vMgr.getVersionHistory(dstPath);
assertFalse("Copied node needs a new version history.", vh1.isSame(vh2));
// check if 1 version
assertEquals("Copied node must have 1 version.", 1, getNumberOfVersions(vh2));
}
use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class BackwardsCompatibilityIT method assertVersionable.
@SuppressWarnings("deprecation")
private Node assertVersionable(Node test) throws RepositoryException {
assertTrue(test.hasNode("versionable"));
Node versionable = test.getNode("versionable");
assertTrue(versionable.isNodeType("nt:myversionable"));
assertTrue(versionable.isNodeType("nt:unstructured"));
assertTrue(versionable.isNodeType("mix:versionable"));
assertFalse(versionable.isCheckedOut());
VersionHistory history = versionable.getVersionHistory();
Version versionB = versionable.getBaseVersion();
String[] labels = history.getVersionLabels(versionB);
assertEquals(1, labels.length);
assertEquals("labelB", labels[0]);
Version versionA = history.getVersionByLabel("labelA");
versionable.restore(versionA, true);
assertEquals("A", versionable.getProperty("foo").getString());
versionable.restore(versionB, true);
assertEquals("B", versionable.getProperty("foo").getString());
return versionable;
}
use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class RemoveVersionLabel method execute.
public NodeIterator execute() throws Exception {
Node n = getNode();
VersionHistory vh = n.getVersionHistory();
String[] labels = vh.getVersionLabels();
if (labels.length > 0) {
String label = labels[getRandom().nextInt(labels.length)];
log.info(n.getPath() + " -> " + label);
vh.removeVersionLabel(label);
}
return wrapWithIterator(n);
}
use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class ReadVersionsWhileModified method testVersionHistory.
public void testVersionHistory() throws RepositoryException {
final Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixVersionable);
testRootNode.save();
final Session s = getHelper().getSuperuserSession();
Thread t = new Thread(new Runnable() {
public void run() {
long end = System.currentTimeMillis() + RUN_NUM_SECONDS * 1000;
try {
Node vn = (Node) s.getItem(n.getPath());
while (end > System.currentTimeMillis()) {
vn.checkout();
vn.checkin();
}
} catch (RepositoryException e) {
e.printStackTrace();
} finally {
s.logout();
}
}
});
t.start();
VersionHistory vh = n.getVersionHistory();
while (t.isAlive()) {
// walk version history
Version v = vh.getRootVersion();
while (v.getSuccessors().length > 0) {
v = v.getSuccessors()[0];
}
}
}
Aggregations