Search in sources :

Example 41 with VersionHistory

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

the class DavResourceFactoryImpl method createResourceForItem.

/**
     * Tries to retrieve the repository item defined by the locator's resource
     * path and build the corresponding WebDAV resource. The following distinction
     * is made between items: Version nodes, VersionHistory nodes, root node,
     * unspecified nodes and finally property items.
     *
     * @param locator
     * @param sessionImpl
     * @return DavResource representing a repository item.
     * @throws RepositoryException if {@link javax.jcr.Session#getItem(String)} fails.
     */
private DavResource createResourceForItem(DavResourceLocator locator, JcrDavSession sessionImpl) throws RepositoryException, DavException {
    DavResource resource;
    Item item = getItem(sessionImpl, locator);
    if (item.isNode()) {
        // create special resources for Version and VersionHistory
        if (item instanceof Version) {
            resource = new VersionItemCollection(locator, sessionImpl, this, item);
        } else if (item instanceof VersionHistory) {
            resource = new VersionHistoryItemCollection(locator, sessionImpl, this, item);
        } else {
            resource = new VersionControlledItemCollection(locator, sessionImpl, this, item);
        }
    } else {
        resource = new DefaultItemResource(locator, sessionImpl, this, item);
    }
    return resource;
}
Also used : Item(javax.jcr.Item) VersionHistoryItemCollection(org.apache.jackrabbit.webdav.jcr.version.VersionHistoryItemCollection) DavResource(org.apache.jackrabbit.webdav.DavResource) Version(javax.jcr.version.Version) VersionItemCollection(org.apache.jackrabbit.webdav.jcr.version.VersionItemCollection) VersionHistory(javax.jcr.version.VersionHistory)

Example 42 with VersionHistory

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

the class NodeImpl method restore.

/**
     * Common internal restore method for the various Node#restore calls.
     *
     * @param targetNode
     * @param relQPath
     * @param version
     * @param removeExisting
     * @throws PathNotFoundException
     * @throws ItemExistsException
     * @throws VersionException
     * @throws ConstraintViolationException
     * @throws UnsupportedRepositoryOperationException
     * @throws LockException
     * @throws InvalidItemStateException
     * @throws RepositoryException
     */
private void restore(NodeImpl targetNode, Path relQPath, Version version, boolean removeExisting) throws PathNotFoundException, ItemExistsException, VersionException, ConstraintViolationException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
    if (relQPath == null) {
        /* restore target already exists. */
        // target must be versionable
        targetNode.checkIsVersionable();
        VersionHistory vH = targetNode.getVersionHistory();
        // version must be a version of the target node
        if (!vH.isSame(version.getContainingHistory())) {
            throw new VersionException("Version " + version + " does not correspond to the restore target.");
        }
        // version must not be the root version
        if (vH.getRootVersion().isSame(version)) {
            throw new VersionException("Attempt to restore root version.");
        }
        targetNode.checkIsWritable();
        targetNode.checkIsLocked();
    } else {
        /* If no node exists at relPath then a VersionException is thrown if
               the parent node is not checked out. */
        if (!targetNode.isCheckedOut()) {
            throw new VersionException("Parent " + targetNode.safeGetJCRPath() + " for non-existing restore target '" + LogUtil.safeGetJCRPath(relQPath, session.getPathResolver()) + "' must be checked out.");
        }
        targetNode.checkIsLocked();
    // NOTE: check for nodetype constraint violation is left to the 'server'
    }
    NodeState versionState = session.getVersionState(version);
    session.getVersionStateManager().restore(targetNode.getNodeState(), relQPath, versionState, removeExisting);
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) VersionHistory(javax.jcr.version.VersionHistory) VersionException(javax.jcr.version.VersionException)

Example 43 with VersionHistory

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

the class RepositoryServiceImpl method removeVersionLabel.

/**
     * {@inheritDoc}
     */
public void removeVersionLabel(final SessionInfo sessionInfo, final NodeId versionHistoryId, final NodeId versionId, final Name label) throws VersionException, RepositoryException {
    final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    executeWithLocalEvents(new Callable() {

        public Object run() throws RepositoryException {
            String jcrLabel;
            jcrLabel = sInfo.getNamePathResolver().getJCRName((label));
            Node vHistory = getNode(versionHistoryId, sInfo);
            if (vHistory instanceof VersionHistory) {
                ((VersionHistory) vHistory).removeVersionLabel(jcrLabel);
            } else {
                throw new RepositoryException("versionHistoryId does not reference a VersionHistory node");
            }
            return null;
        }
    }, sInfo);
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory)

Example 44 with VersionHistory

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

the class RepositoryServiceImpl method addVersionLabel.

/**
     * {@inheritDoc}
     */
public void addVersionLabel(final SessionInfo sessionInfo, final NodeId versionHistoryId, final NodeId versionId, final Name label, final boolean moveLabel) throws VersionException, RepositoryException {
    final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    executeWithLocalEvents(new Callable() {

        public Object run() throws RepositoryException {
            String jcrLabel;
            jcrLabel = sInfo.getNamePathResolver().getJCRName(label);
            Node version = getNode(versionId, sInfo);
            Node vHistory = getNode(versionHistoryId, sInfo);
            if (vHistory instanceof VersionHistory) {
                ((VersionHistory) vHistory).addVersionLabel(version.getName(), jcrLabel, moveLabel);
            } else {
                throw new RepositoryException("versionHistoryId does not reference a VersionHistory node");
            }
            return null;
        }
    }, sInfo);
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory)

Example 45 with VersionHistory

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

the class AbstractRepositoryTest method createVersionable.

protected Node createVersionable(Node parent) throws RepositoryException {
    Node versionable = parent.addNode("versionable", "nt:myversionable");
    versionable.setProperty("foo", "A");
    parent.save();
    VersionHistory history = versionable.getVersionHistory();
    Version versionA = versionable.checkin();
    history.addVersionLabel(versionA.getName(), "labelA", false);
    versionable.checkout();
    versionable.setProperty("foo", "B");
    parent.save();
    Version versionB = versionable.checkin();
    history.addVersionLabel(versionB.getName(), "labelB", false);
    return versionable;
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory)

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