Search in sources :

Example 51 with VersionException

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

the class RestoreTest method testRestoreWithInvalidVersionJcr2.

/**
     * Test if restoring a node with an invalid Version throws a VersionException
     *
     * @throws RepositoryException
     */
public void testRestoreWithInvalidVersionJcr2() throws RepositoryException {
    Version invalidVersion = versionManager.checkin(versionableNode2.getPath());
    try {
        versionManager.restore(versionableNode.getPath(), invalidVersion, true);
        fail("Node.restore(Version, boolean): A VersionException must be thrown if the specified version does not exists in this node's version history.");
    } catch (VersionException e) {
    // success
    }
}
Also used : Version(javax.jcr.version.Version) VersionException(javax.jcr.version.VersionException)

Example 52 with VersionException

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

the class RestoreTest method testRestoreInvalidVersion2.

/**
     * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
     *
     * @throws RepositoryException
     */
@SuppressWarnings("deprecation")
public void testRestoreInvalidVersion2() throws RepositoryException {
    String invalidName;
    do {
        invalidName = createRandomString(3);
        for (VersionIterator it = versionableNode.getVersionHistory().getAllVersions(); it.hasNext(); ) {
            Version v = it.nextVersion();
            if (invalidName.equals(v.getName())) {
                invalidName = null;
                break;
            }
        }
    } while (invalidName == null);
    try {
        versionableNode.restore(invalidName, true);
        fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.");
    } catch (VersionException e) {
    // ok
    }
}
Also used : Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator) VersionException(javax.jcr.version.VersionException)

Example 53 with VersionException

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

the class RestoreTest method testRestoreWithInvalidVersion.

/**
     * Test if restoring a node with an invalid Version throws a VersionException
     *
     * @throws RepositoryException
     */
@SuppressWarnings("deprecation")
public void testRestoreWithInvalidVersion() throws RepositoryException {
    Version invalidVersion = versionableNode2.checkin();
    try {
        versionableNode.restore(invalidVersion, true);
        fail("Node.restore(Version, boolean): A VersionException must be thrown if the specified version does not exists in this node's version history.");
    } catch (VersionException e) {
    // success
    }
}
Also used : Version(javax.jcr.version.Version) VersionException(javax.jcr.version.VersionException)

Example 54 with VersionException

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

the class RestoreTest method testRestoreInvalidVersion.

/**
     * VersionException expected on Node.restore(Version, boolean) if the
     * specified version is not part of this node's version history.
     *
     * @throws RepositoryException
     */
@SuppressWarnings("deprecation")
public void testRestoreInvalidVersion() throws RepositoryException {
    Version vNode2 = versionableNode2.checkin();
    try {
        versionableNode.restore(vNode2, true);
        fail("VersionException expected on Node.restore(Version, boolean) if the specified version is not part of this node's version history.");
    } catch (VersionException e) {
    // ok
    }
}
Also used : Version(javax.jcr.version.Version) VersionException(javax.jcr.version.VersionException)

Example 55 with VersionException

use of javax.jcr.version.VersionException 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)

Aggregations

VersionException (javax.jcr.version.VersionException)78 Node (javax.jcr.Node)25 Version (javax.jcr.version.Version)25 RepositoryException (javax.jcr.RepositoryException)19 Name (org.apache.jackrabbit.spi.Name)8 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)7 Property (javax.jcr.Property)6 Session (javax.jcr.Session)6 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)6 VersionIterator (javax.jcr.version.VersionIterator)5 VersionManager (javax.jcr.version.VersionManager)5 NodeId (org.apache.jackrabbit.core.id.NodeId)5 Nonnull (javax.annotation.Nonnull)4 ItemExistsException (javax.jcr.ItemExistsException)4 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)4 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)4 RetentionManager (javax.jcr.retention.RetentionManager)4 LabelExistsVersionException (javax.jcr.version.LabelExistsVersionException)4 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)4 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4