Search in sources :

Example 86 with Version

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

the class AbstractVersionManagementTest method testRemoveVersion.

public void testRemoveVersion() throws RepositoryException, NotExecutableException {
    Node trn = getTestNode();
    Node n = createVersionableNode(testRootNode);
    modifyPrivileges(trn.getPath(), Privilege.JCR_VERSION_MANAGEMENT, true);
    // test session should now be able to create versionable nodes, checkout
    // and checkin them, read the version/v-histories.
    Node testNode = trn.getNode(nodeName1);
    Version v = testNode.checkin();
    testNode.checkout();
    testNode.checkin();
    // remove ability to edit version information
    // -> VersionHistory.removeVersion must not be allowed.
    modifyPrivileges(trn.getPath(), Privilege.JCR_VERSION_MANAGEMENT, false);
    try {
        testNode.getVersionHistory().removeVersion(v.getName());
        fail("TestSession without remove privilege on the v-storage must not be able to remove a version.");
    } catch (AccessDeniedException e) {
        // success
        log.debug(e.getMessage());
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) Version(javax.jcr.version.Version) Node(javax.jcr.Node)

Example 87 with Version

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

the class VersionHistoryImpl method getVersionByLabel.

/**
     *
     * @param qLabel
     * @return
     * @throws VersionException
     * @throws RepositoryException
     */
private Version getVersionByLabel(Name qLabel) throws VersionException, RepositoryException {
    refreshEntry(labelNodeEntry);
    // retrieve reference property value -> and retrieve referenced node
    PropertyEntry pEntry = labelNodeEntry.getPropertyEntry(qLabel, true);
    if (pEntry == null) {
        throw new VersionException("Version with label '" + qLabel + "' does not exist.");
    }
    Node version = ((Property) getItemManager().getItem(pEntry)).getNode();
    return (Version) version;
}
Also used : Version(javax.jcr.version.Version) PropertyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry) Node(javax.jcr.Node) Property(javax.jcr.Property) VersionException(javax.jcr.version.VersionException)

Example 88 with Version

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

the class VersionHistoryImpl method getVersion.

/**
     * @see VersionHistory#getVersion(String)
     */
public Version getVersion(String versionName) throws VersionException, RepositoryException {
    checkStatus();
    NodeState vState = getVersionState(versionName);
    return (Version) getItemManager().getItem(vState.getHierarchyEntry());
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) Version(javax.jcr.version.Version)

Example 89 with Version

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

the class VersionHistoryImpl method removeVersionLabel.

/**
     * @see VersionHistory#removeVersionLabel(String)
     */
public void removeVersionLabel(String label) throws VersionException, RepositoryException {
    checkStatus();
    Name qLabel = getQLabel(label);
    Version version = getVersionByLabel(qLabel);
    NodeState vState = getVersionState(version.getName());
    // delegate to version manager that operates on workspace directly
    session.getVersionStateManager().removeVersionLabel((NodeState) getItemState(), vState, qLabel);
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) Version(javax.jcr.version.Version) Name(org.apache.jackrabbit.spi.Name)

Example 90 with Version

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

the class RepositoryServiceImpl method restore.

/**
     * {@inheritDoc}
     */
public void restore(final SessionInfo sessionInfo, final NodeId[] versionIds, final boolean removeExisting) throws ItemExistsException, UnsupportedRepositoryOperationException, VersionException, LockException, InvalidItemStateException, RepositoryException {
    final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    executeWithLocalEvents(new Callable() {

        public Object run() throws RepositoryException {
            Version[] versions = new Version[versionIds.length];
            for (int i = 0; i < versions.length; i++) {
                Node n = getNode(versionIds[i], sInfo);
                if (n instanceof Version) {
                    versions[i] = (Version) n;
                } else {
                    throw new RepositoryException(n.getPath() + " does not reference a Version node");
                }
            }
            sInfo.getSession().getWorkspace().restore(versions, removeExisting);
            return null;
        }
    }, sInfo);
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Aggregations

Version (javax.jcr.version.Version)265 Node (javax.jcr.Node)155 VersionManager (javax.jcr.version.VersionManager)65 RepositoryException (javax.jcr.RepositoryException)45 VersionHistory (javax.jcr.version.VersionHistory)29 VersionException (javax.jcr.version.VersionException)25 NodeIterator (javax.jcr.NodeIterator)23 Session (javax.jcr.Session)19 Test (org.junit.Test)19 Property (javax.jcr.Property)16 VersionIterator (javax.jcr.version.VersionIterator)16 Value (javax.jcr.Value)14 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)14 ItemExistsException (javax.jcr.ItemExistsException)13 HashSet (java.util.HashSet)12 NodeDefinition (javax.jcr.nodetype.NodeDefinition)12 ArrayList (java.util.ArrayList)11 Set (java.util.Set)7 DavException (org.apache.jackrabbit.webdav.DavException)7 UserTransaction (javax.transaction.UserTransaction)6