Search in sources :

Example 41 with VersionException

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

the class WorkspaceMoveVersionableTest method testMoveNodesVersionableAndCheckedIn.

/**
     * A VersionException is thrown if the parent node of destAbsPath is
     * versionable and checked-in, or is non-versionable but its nearest
     * versionable ancestor is checked-in.
     */
public void testMoveNodesVersionableAndCheckedIn() throws RepositoryException, NotExecutableException {
    // prepare the test data
    // create a non-versionable node below a versionable node
    // required for having a nearest versionable ancestor to a nonversionable sub node
    String dstAbsPath = node1.getPath() + "/" + node2.getName();
    workspace.copy(node2.getPath(), dstAbsPath);
    try {
        // make parent node versionable and check-in
        addMixinVersionableToNode(testRootNode, node1);
        node1.checkin();
    } catch (ConstraintViolationException ex) {
        throw new NotExecutableException("server does not support making the parent versionable: " + ex.getMessage());
    }
    // 1. parent node of destAbsPath is non-versionable but its nearest versionable ancestor is checked-in
    try {
        workspace.move(node2.getPath(), dstAbsPath + "/" + node2.getName());
        fail("Copying a node to a node's versionable and checked-in nearest ancestor node of destAbsPath should throw VersionException.");
    } catch (VersionException e) {
    // successful
    }
    // 2. parent node of destAbsPath is versionable and checked-in
    try {
        workspace.move(node2.getPath(), node1.getPath() + "/" + node2.getName());
        fail("Copying a node to a versionable and checked-in parent node of destAbsPath should throw VersionException.");
    } catch (VersionException e) {
    // successful
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) VersionException(javax.jcr.version.VersionException)

Example 42 with VersionException

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

the class BatchedItemOperations method verifyCheckedOut.

//----------------------------------------------------< protected methods >
/**
     * Verifies that the node at <code>nodePath</code> is checked-out; throws a
     * <code>VersionException</code> if that's not the case.
     * <p>
     * A node is considered <i>checked-out</i> if it is versionable and
     * checked-out, or is non-versionable but its nearest versionable ancestor
     * is checked-out, or is non-versionable and there are no versionable
     * ancestors.
     *
     * @param nodePath
     * @throws PathNotFoundException
     * @throws VersionException
     * @throws RepositoryException
     */
protected void verifyCheckedOut(Path nodePath) throws PathNotFoundException, VersionException, RepositoryException {
    // search nearest ancestor that is versionable, start with node at nodePath
    /**
         * FIXME should not only rely on existence of jcr:isCheckedOut property
         * but also verify that node.isNodeType("mix:versionable")==true;
         * this would have a negative impact on performance though...
         */
    NodeState nodeState = getNodeState(nodePath);
    while (!nodeState.hasPropertyName(NameConstants.JCR_ISCHECKEDOUT)) {
        if (nodePath.denotesRoot()) {
            return;
        }
        nodePath = nodePath.getAncestor(1);
        nodeState = getNodeState(nodePath);
    }
    PropertyId propId = new PropertyId(nodeState.getNodeId(), NameConstants.JCR_ISCHECKEDOUT);
    PropertyState propState;
    try {
        propState = (PropertyState) stateMgr.getItemState(propId);
    } catch (ItemStateException ise) {
        String msg = "internal error: failed to retrieve state of " + safeGetJCRPath(propId);
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
    boolean checkedOut = propState.getValues()[0].getBoolean();
    if (!checkedOut) {
        throw new VersionException(safeGetJCRPath(nodePath) + " is checked-in");
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) VersionException(javax.jcr.version.VersionException)

Example 43 with VersionException

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

the class XATest method testSetVersionLabel.

/**
     * Test new version label becomes available to other sessions on commit.
     */
public void testSetVersionLabel() throws Exception {
    final String versionLabel = "myVersion";
    // get user transaction object
    UserTransaction utx = new UserTransactionImpl(superuser);
    // add node and save
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixVersionable);
    testRootNode.save();
    // reference node in other session
    Node nOther = otherSuperuser.getNodeByUUID(n.getUUID());
    // create another version
    Version v = n.checkin();
    // start transaction
    utx.begin();
    // add new version label
    n.getVersionHistory().addVersionLabel(v.getName(), versionLabel, false);
    // assert: version label unknown in other session
    try {
        nOther.getVersionHistory().getVersionByLabel(versionLabel);
        fail("Version label visible outside tx.");
    } catch (VersionException e) {
    // expected
    }
    // commit
    utx.commit();
    // assert: version label known in other session
    nOther.getVersionHistory().getVersionByLabel(versionLabel);
}
Also used : UserTransaction(javax.transaction.UserTransaction) Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionException(javax.jcr.version.VersionException)

Example 44 with VersionException

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

the class XATest method testCheckin.

//-----------------------------------------------------------< versioning >
/**
     * Checkin inside tx should not be visible to other users.
     */
public void testCheckin() throws Exception {
    // get user transaction object
    UserTransaction utx = new UserTransactionImpl(superuser);
    // add node and save
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixVersionable);
    testRootNode.save();
    // reference node in other session
    Node nOther = otherSuperuser.getNodeByUUID(n.getUUID());
    // start transaction
    utx.begin();
    // checkin node
    n.checkin();
    // assert: base versions must differ
    if (n.getBaseVersion().getName().equals(nOther.getBaseVersion().getName())) {
        fail("Base versions must differ");
    }
    // assert: version must not be visible to other session
    try {
        nOther.getVersionHistory().getVersion(n.getBaseVersion().getName());
        fail("Version must not be visible to other session.");
    } catch (VersionException e) {
    // expected.
    }
    // commit
    utx.commit();
    // assert: base versions must be equal
    assertEquals("Base versions must be equal", n.getBaseVersion().getName(), nOther.getBaseVersion().getName());
}
Also used : UserTransaction(javax.transaction.UserTransaction) Node(javax.jcr.Node) VersionException(javax.jcr.version.VersionException)

Example 45 with VersionException

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

the class SessionRemoveItemTest method testRemoveCheckedInItem.

public void testRemoveCheckedInItem() throws RepositoryException, NotExecutableException {
    // add a child property and a child node to test deep lock effect.
    Node childN = removeNode.addNode(nodeName2);
    Value v = getJcrValue(superuser, RepositoryStub.PROP_PROP_VALUE2, RepositoryStub.PROP_PROP_TYPE2, "propvalue2");
    Property childP = removeNode.setProperty(propertyName2, v);
    removeNode.save();
    ensureMixinType(removeNode, mixVersionable);
    removeNode.save();
    removeNode.checkin();
    try {
        adminSession.removeItem(childP.getPath());
        adminSession.save();
        fail("child property of a checked-in node cannot be removed.");
    } catch (VersionException e) {
    // success
    }
    try {
        adminSession.removeItem(childN.getPath());
        adminSession.save();
        fail("child node of a checked-in node cannot be removed.");
    } catch (VersionException e) {
    // success
    }
}
Also used : Node(javax.jcr.Node) Value(javax.jcr.Value) Property(javax.jcr.Property) 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