Search in sources :

Example 36 with VersionException

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

the class VersionHistoryImpl method getVersionByLabel.

/**
     * @see javax.jcr.version.VersionHistory#getVersionByLabel(String)
     */
public javax.jcr.version.Version getVersionByLabel(String label) throws RepositoryException {
    try {
        Name qLabel = sessionContext.getQName(label);
        InternalVersion v = getInternalVersionHistory().getVersionByLabel(qLabel);
        if (v == null) {
            throw new VersionException("No version with label '" + label + "' exists in this version history.");
        }
        return (Version) sessionContext.getSessionImpl().getNodeById(v.getId());
    } catch (NameException e) {
        throw new VersionException(e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Version(javax.jcr.version.Version) Name(org.apache.jackrabbit.spi.Name) VersionException(javax.jcr.version.VersionException)

Example 37 with VersionException

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

the class VersionHistoryImpl method removeVersionLabel.

/**
     * @see javax.jcr.version.VersionHistory#removeVersionLabel(String)
     */
public void removeVersionLabel(String label) throws RepositoryException {
    try {
        // check permissions
        checkVersionManagementPermission();
        InternalVersion existing = sessionContext.getSessionImpl().getInternalVersionManager().setVersionLabel(getSession(), getInternalVersionHistory(), null, sessionContext.getQName(label), true);
        if (existing == null) {
            throw new VersionException("No version with label '" + label + "' exists in this version history.");
        }
    } catch (NameException e) {
        throw new VersionException(e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) VersionException(javax.jcr.version.VersionException)

Example 38 with VersionException

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

the class VersionHistoryImpl method getVersion.

/**
     * @see javax.jcr.version.VersionHistory#getVersion(String)
     */
public javax.jcr.version.Version getVersion(String versionName) throws VersionException, RepositoryException {
    try {
        Name name = sessionContext.getQName(versionName);
        InternalVersion v = getInternalVersionHistory().getVersion(name);
        if (v == null) {
            throw new VersionException("No version with name '" + versionName + "' exists in this version history.");
        }
        return (Version) sessionContext.getSessionImpl().getNodeById(v.getId());
    } catch (NameException e) {
        throw new VersionException(e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Version(javax.jcr.version.Version) Name(org.apache.jackrabbit.spi.Name) VersionException(javax.jcr.version.VersionException)

Example 39 with VersionException

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

the class VersionHistoryImpl method addVersionLabel.

/**
     * @see javax.jcr.version.VersionHistory#addVersionLabel(String, String, boolean)
     */
public void addVersionLabel(String versionName, String label, boolean move) throws VersionException, RepositoryException {
    try {
        // check permissions
        checkVersionManagementPermission();
        sessionContext.getSessionImpl().getInternalVersionManager().setVersionLabel(getSession(), getInternalVersionHistory(), sessionContext.getQName(versionName), sessionContext.getQName(label), move);
    } catch (NameException e) {
        throw new VersionException(e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) VersionException(javax.jcr.version.VersionException)

Example 40 with VersionException

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

the class NodeAddMixinTest method testCheckedIn.

/**
     * Tests if <code>Node.addMixin(String mixinName)</code> throws a
     * <code>VersionException</code> if <code>Node</code> is checked-in.
     * <p>
     * The test creates a node <code>nodeName1</code> of type
     * <code>testNodeType</code> under <code>testRoot</code> and checks it in.
     * Then the test tries to add a mixin to <code>nodeName1</code>.
     */
public void testCheckedIn() throws NotExecutableException, RepositoryException {
    Session session = testRootNode.getSession();
    if (!isSupported(Repository.OPTION_VERSIONING_SUPPORTED)) {
        throw new NotExecutableException("Versioning is not supported.");
    }
    // create a node that is versionable
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    // or try to make it versionable if it is not
    ensureMixinType(node, mixVersionable);
    testRootNode.getSession().save();
    String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
    if (mixinName == null || node.isNodeType(mixinName)) {
        throw new NotExecutableException("No testable mixin node type found");
    }
    node.checkin();
    try {
        node.addMixin(mixinName);
        fail("Node.addMixin(String mixinName) must throw a VersionException " + "if the node is checked-in.");
    } catch (VersionException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Session(javax.jcr.Session) 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