Search in sources :

Example 21 with VersionException

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

the class WorkspaceCopyVersionableTest method testCopyNodesVersionableAndCheckedIn.

/**
     * 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 testCopyNodesVersionableAndCheckedIn() 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.copy(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.copy(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 22 with VersionException

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

the class MergeNodeTest method disable_testMergeNodeForceFailure.

/**
     * if mergeFailedProperty is present &gt; VersionException<br>
     */
@SuppressWarnings("deprecation")
public void disable_testMergeNodeForceFailure() throws RepositoryException {
    // create 2 independent versions for a node and its corresponding node
    // so merge fails for this node
    // default workspace
    Node originalNode = testRootNode.getNode(nodeName1);
    originalNode.checkout();
    originalNode.checkin();
    // second workspace
    nodeToMerge.checkin();
    // "merge" the clonedNode with the newNode from the default workspace
    // besteffort set to true to report all failures
    nodeToMerge.checkout();
    nodeToMerge.merge(workspace.getName(), true);
    try {
        nodeToMerge.merge(workspace.getName(), true);
        fail("Merge failed for node in earlier merge operations. Because the mergeFailedProperty is present, merge must throw a VersionException");
    } catch (VersionException e) {
    // success version exception expected
    }
}
Also used : Node(javax.jcr.Node) VersionException(javax.jcr.version.VersionException)

Example 23 with VersionException

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

the class MergeNodeTest method disable_testMergeNodeForceFailureJcr2.

/**
     * if mergeFailedProperty is present &gt; VersionException<br>
     */
public void disable_testMergeNodeForceFailureJcr2() throws RepositoryException {
    // create 2 independent versions for a node and its corresponding node
    // so merge fails for this node
    // default workspace
    Node originalNode = testRootNode.getNode(nodeName1);
    VersionManager vmWsp1 = originalNode.getSession().getWorkspace().getVersionManager();
    String originalPath = originalNode.getPath();
    vmWsp1.checkout(originalPath);
    vmWsp1.checkin(originalPath);
    // second workspace
    VersionManager vmWsp2 = nodeToMerge.getSession().getWorkspace().getVersionManager();
    String path = nodeToMerge.getPath();
    vmWsp2.checkin(path);
    // "merge" the clonedNode with the newNode from the default workspace
    // besteffort set to true to report all failures
    vmWsp2.checkout(path);
    vmWsp2.merge(path, workspace.getName(), true);
    try {
        vmWsp2.merge(path, workspace.getName(), true);
        fail("Merge failed for node in earlier merge operations. Because the mergeFailedProperty is present, merge must throw a VersionException");
    } catch (VersionException e) {
    // success version exception expected
    }
}
Also used : Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager) VersionException(javax.jcr.version.VersionException)

Example 24 with VersionException

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

the class NodeImpl method internalSetProperty.

private Property internalSetProperty(final String jcrName, final Value[] values, final int type, final boolean exactTypeMatch) throws RepositoryException {
    final String oakName = getOakPathOrThrow(checkNotNull(jcrName));
    final PropertyState state = createMultiState(oakName, compact(values), Type.fromTag(type, true));
    if (values.length > MV_PROPERTY_WARN_THRESHOLD) {
        LOG.warn("Large multi valued property [{}/{}] detected ({} values).", dlg.getPath(), jcrName, values.length);
    }
    return perform(new ItemWriteOperation<Property>("internalSetProperty") {

        @Override
        public void checkPreconditions() throws RepositoryException {
            super.checkPreconditions();
            if (!isCheckedOut() && getOPV(dlg.getTree(), state) != OnParentVersionAction.IGNORE) {
                throw new VersionException(format("Cannot set property. Node [%s] is checked in.", getNodePath()));
            }
        }

        @Nonnull
        @Override
        public Property perform() throws RepositoryException {
            return new PropertyImpl(dlg.setProperty(state, exactTypeMatch, false), sessionContext);
        }

        @Override
        public String toString() {
            return format("Setting property [%s/%s]", dlg.getPath(), jcrName);
        }
    });
}
Also used : Nonnull(javax.annotation.Nonnull) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) VersionException(javax.jcr.version.VersionException)

Example 25 with VersionException

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

the class CopyTest method testCopyVersionableNodeClearsVersions.

@Test
public void testCopyVersionableNodeClearsVersions() throws Exception {
    Session session = getAdminSession();
    Node toCopy = session.getNode(TEST_PATH + "/source/node");
    toCopy.addMixin(JcrConstants.MIX_VERSIONABLE);
    session.save();
    Version v1 = toCopy.checkin();
    toCopy.checkout();
    Version v2 = toCopy.checkin();
    toCopy.checkout();
    session.getWorkspace().copy(TEST_PATH + "/source/node", TEST_PATH + "/target/copied");
    Node copy = testNode.getNode("target/copied");
    VersionHistory vh = copy.getVersionHistory();
    Version rootV = vh.getRootVersion();
    assertEquals(0, rootV.getSuccessors().length);
    VersionIterator vItr = vh.getAllVersions();
    while (vItr.hasNext()) {
        if (!rootV.isSame(vItr.nextVersion())) {
            fail("Unexpected version in version history of copied node.");
        }
    }
    try {
        vh.getVersion(v1.getName());
        fail("Unexpected version in version history of copied node.");
    } catch (VersionException e) {
    // success
    }
    try {
        vh.getVersion(v2.getName());
        fail("Unexpected version in version history of copied node.");
    } catch (VersionException e) {
    // success
    }
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session) VersionException(javax.jcr.version.VersionException) Test(org.junit.Test)

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