Search in sources :

Example 11 with VersionHistory

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);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) VersionResource(org.apache.jackrabbit.webdav.version.VersionResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 12 with VersionHistory

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));
}
Also used : Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Workspace(javax.jcr.Workspace)

Example 13 with VersionHistory

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;
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory)

Example 14 with VersionHistory

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);
}
Also used : Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory)

Example 15 with VersionHistory

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];
        }
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session)

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