Search in sources :

Example 76 with VersionHistory

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

the class ResourceFactoryImpl method createResource.

/**
 * Tries to retrieve the repository item defined by the locator's resource
 * path and build the corresponding WebDAV resource. If the repository
 * supports the versioning option different resources are created for
 * version, versionhistory and common nodes.
 *
 * @param node
 * @param locator
 * @param session
 * @return
 * @throws DavException
 */
private DavResource createResource(Node node, DavResourceLocator locator, DavSession session) throws DavException {
    JcrDavSession.checkImplementation(session);
    JcrDavSession sessionImpl = (JcrDavSession) session;
    DavResource resource;
    if (versioningSupported(sessionImpl.getRepositorySession())) {
        // create special resources for Version and VersionHistory
        if (node instanceof Version) {
            resource = new VersionResourceImpl(locator, this, sessionImpl, resourceConfig, node);
        } else if (node instanceof VersionHistory) {
            resource = new VersionHistoryResourceImpl(locator, this, sessionImpl, resourceConfig, node);
        } else {
            resource = new VersionControlledResourceImpl(locator, this, sessionImpl, resourceConfig, node);
        }
    } else {
        resource = new DavResourceImpl(locator, this, session, resourceConfig, node);
    }
    return resource;
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) Version(javax.jcr.version.Version) JcrDavSession(org.apache.jackrabbit.webdav.jcr.JcrDavSession) VersionHistory(javax.jcr.version.VersionHistory)

Example 77 with VersionHistory

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

the class VersionControlledResourceImpl method getVersionHistory.

/**
 * Returns the {@link javax.jcr.version.VersionHistory} associated with the repository node.
 * If the node is not versionable an exception is thrown.
 *
 * @return the {@link VersionHistoryResource} associated with this resource.
 * @throws org.apache.jackrabbit.webdav.DavException
 * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#getVersionHistory()
 * @see javax.jcr.Node#getVersionHistory()
 */
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    if (!isVersionControlled()) {
        throw new DavException(DavServletResponse.SC_FORBIDDEN);
    }
    try {
        VersionHistory vh = getNode().getVersionHistory();
        DavResourceLocator loc = getLocatorFromNode(vh);
        DavResource vhr = createResourceFromLocator(loc);
        if (vhr instanceof VersionHistoryResource) {
            return (VersionHistoryResource) vhr;
        } else {
            // severe error since resource factory doesn't behave correctly.
            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } 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) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 78 with VersionHistory

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

the class VersionResourceImpl method getVersionHistory.

/**
 * Returns the {@link VersionHistory} associated with the repository version.
 * Note: in contrast to a versionable node, the version history of a version
 * item is always represented by its nearest ancestor.
 *
 * @return the {@link org.apache.jackrabbit.webdav.version.VersionHistoryResource} associated with this resource.
 * @throws org.apache.jackrabbit.webdav.DavException
 * @see org.apache.jackrabbit.webdav.version.VersionResource#getVersionHistory()
 * @see javax.jcr.Item#getParent()
 */
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    try {
        VersionHistory vh = getVersionHistoryItem();
        DavResourceLocator loc = getLocatorFromNode(vh);
        DavResource vhr = createResourceFromLocator(loc);
        if (vhr instanceof VersionHistoryResource) {
            return (VersionHistoryResource) vhr;
        } else {
            // severe error since resource factory doesn't behave correctly.
            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } 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) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 79 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:cersionable) must return true.", 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));
    // check if jcr:copiedFrom is set correctly
    assertTrue("Version history of desination must have a jcr:copiedFrom property", vh2.hasProperty(jcrCopiedFrom));
    Node ref = vh2.getProperty(jcrCopiedFrom).getNode();
    Version base = vMgr.getBaseVersion(srcPath);
    assertTrue("jcr:copiedFrom must point to the base version of the original.", ref.isSame(base));
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Workspace(javax.jcr.Workspace)

Example 80 with VersionHistory

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

the class RemoveVersionByLabel method execute.

/**
 * {@inheritDoc}
 */
public boolean execute(Context ctx) throws Exception {
    String path = (String) ctx.get(this.pathKey);
    String label = (String) ctx.get(this.labelKey);
    if (log.isDebugEnabled()) {
        log.debug("Remove version with label " + label + " from node " + path);
    }
    VersionHistory vh = CommandHelper.getNode(ctx, path).getVersionHistory();
    Version v = vh.getVersionByLabel(label);
    vh.removeVersion(v.getName());
    return false;
}
Also used : Version(javax.jcr.version.Version) VersionHistory(javax.jcr.version.VersionHistory)

Aggregations

VersionHistory (javax.jcr.version.VersionHistory)89 Node (javax.jcr.Node)59 Version (javax.jcr.version.Version)43 Test (org.junit.Test)30 VersionManager (javax.jcr.version.VersionManager)26 RepositoryException (javax.jcr.RepositoryException)25 VersionIterator (javax.jcr.version.VersionIterator)23 Session (javax.jcr.Session)19 Property (javax.jcr.Property)11 ArrayList (java.util.ArrayList)8 DavException (org.apache.jackrabbit.webdav.DavException)7 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)7 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 Workspace (javax.jcr.Workspace)6 DavResource (org.apache.jackrabbit.webdav.DavResource)6 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 Value (javax.jcr.Value)5 NodeIterator (javax.jcr.NodeIterator)4 PathNotFoundException (javax.jcr.PathNotFoundException)4 NodeType (javax.jcr.nodetype.NodeType)4