Search in sources :

Example 11 with VersionException

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

the class RestoreTest method testRestoreInvalidVersionJcr2.

/**
     * VersionException expected on Node.restore(Version, boolean) if the
     * specified version is not part of this node's version history.
     *
     * @throws RepositoryException
     */
public void testRestoreInvalidVersionJcr2() throws RepositoryException {
    Version vNode2 = versionManager.checkin(versionableNode2.getPath());
    try {
        versionManager.restore(versionableNode.getPath(), 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 12 with VersionException

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

the class InternalFrozenNodeImpl method checkin.

/**
     * Checks-in a <code>src</code> node. It creates a new child node of
     * <code>parent</code> with the given <code>name</code> and adds the
     * source nodes properties according to their OPV value to the
     * list of frozen properties. It creates frozen child nodes for each child
     * node of <code>src</code> according to its OPV value.
     *
     * @param parent destination parent
     * @param name new node name
     * @param src source node state
     * @param forceCopy if <code>true</code> the OPV is ignored and a COPY is performed
     * @return the nde node state
     * @throws RepositoryException if an error occurs
     * @throws ItemStateException if an error during reading the items occurs
     */
private static NodeStateEx checkin(NodeStateEx parent, Name name, NodeStateEx src, boolean forceCopy) throws RepositoryException, ItemStateException {
    // create new node
    NodeStateEx node = parent.addNode(name, NameConstants.NT_FROZENNODE, null, true);
    // initialize the internal properties
    node.setPropertyValue(NameConstants.JCR_FROZENUUID, InternalValue.create(src.getNodeId().toString()));
    node.setPropertyValue(NameConstants.JCR_FROZENPRIMARYTYPE, InternalValue.create(src.getState().getNodeTypeName()));
    if (src.hasProperty(NameConstants.JCR_MIXINTYPES)) {
        node.setPropertyValues(NameConstants.JCR_FROZENMIXINTYPES, PropertyType.NAME, src.getPropertyValues(NameConstants.JCR_MIXINTYPES));
    }
    // add the properties
    for (PropertyState prop : src.getProperties()) {
        int opv;
        if (forceCopy) {
            opv = OnParentVersionAction.COPY;
        } else {
            opv = src.getDefinition(prop).getOnParentVersion();
        }
        Name propName = prop.getName();
        if (opv == OnParentVersionAction.ABORT) {
            parent.reload();
            throw new VersionException("Checkin aborted due to OPV abort in " + propName);
        } else if (opv == OnParentVersionAction.VERSION || opv == OnParentVersionAction.COPY) {
            // ignore frozen properties
            if (!propName.equals(NameConstants.JCR_PRIMARYTYPE) && !propName.equals(NameConstants.JCR_MIXINTYPES) && !propName.equals(NameConstants.JCR_UUID) && // JCR-3635: should never occur in normal content...
            !propName.equals(NameConstants.JCR_FROZENPRIMARYTYPE) && !propName.equals(NameConstants.JCR_FROZENMIXINTYPES) && !propName.equals(NameConstants.JCR_FROZENUUID)) {
                node.copyFrom(prop);
            }
        }
    }
    // add the frozen children and histories
    boolean isFull = src.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE);
    for (NodeStateEx child : src.getChildNodes()) {
        int opv;
        if (forceCopy) {
            opv = OnParentVersionAction.COPY;
        } else {
            opv = child.getDefinition().getOnParentVersion();
        }
        if (opv == OnParentVersionAction.ABORT) {
            throw new VersionException("Checkin aborted due to OPV in " + child);
        } else if (opv == OnParentVersionAction.VERSION) {
            if (isFull && child.getEffectiveNodeType().includesNodeType(NameConstants.MIX_VERSIONABLE)) {
                // create frozen versionable child
                NodeId histId = child.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
                NodeStateEx newChild = node.addNode(child.getName(), NameConstants.NT_VERSIONEDCHILD, null, false);
                newChild.setPropertyValue(NameConstants.JCR_CHILDVERSIONHISTORY, InternalValue.create(histId));
            } else {
                // else copy
                checkin(node, child.getName(), child, true);
            }
        } else if (opv == OnParentVersionAction.COPY) {
            checkin(node, child.getName(), child, true);
        }
    }
    return node;
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Name(org.apache.jackrabbit.spi.Name) VersionException(javax.jcr.version.VersionException)

Example 13 with VersionException

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

the class NodeSetPrimaryTypeTest method testCheckedIn.

/**
     * Tests if <code>Node.setPrimaryType(String)</code> throws a
     * <code>VersionException</code> if <code>Node</code> is checked-in.
     */
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);
    superuser.save();
    String primaryTypeName = getPrimaryTypeName(session, node);
    if (primaryTypeName == null) {
        throw new NotExecutableException("No testable node type found");
    }
    node.checkin();
    try {
        node.setPrimaryType(primaryTypeName);
        fail("Node.setPrimaryType(String) 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)

Example 14 with VersionException

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

the class NodeImpl method restoreByLabel.

/**
     * @see Node#restoreByLabel(String, boolean)
     */
public void restoreByLabel(String versionLabel, boolean removeExisting) throws VersionException, ItemExistsException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
    checkSessionHasPendingChanges();
    // check for version-enabled and lock are performed with subsequent calls.
    Version v = getVersionHistory().getVersionByLabel(versionLabel);
    if (v == null) {
        throw new VersionException("No version for label " + versionLabel + " found.");
    }
    restore(this, null, v, removeExisting);
}
Also used : Version(javax.jcr.version.Version) VersionException(javax.jcr.version.VersionException)

Example 15 with VersionException

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

the class WorkspaceMoveVersionExceptionTest method testWorkspaceMoveSourceCheckedInVersionException.

/**
     * Tries to move a node using {@link javax.jcr.Workspace#move(String, String)}
     * where the source parent is checked in. This should throw an
     * {@link javax.jcr.version.VersionException}.
     */
public void testWorkspaceMoveSourceCheckedInVersionException() throws RepositoryException {
    // add a node under a versionable node
    Node movingNode = versionableNode.addNode(nodeName1, nonVersionableNodeType.getName());
    versionableNode.save();
    // check the parent node in
    versionableNode.checkin();
    try {
        // try to move the sub node this should throw an VersionException
        superuser.getWorkspace().move(movingNode.getPath(), nonVersionableNode.getPath() + "/" + nodeName1);
        fail("Moving a node using Workspace.move() where parent node is " + "versionable and checked in should throw a VersionException!");
    } catch (VersionException e) {
    // ok, works as expected
    }
}
Also used : Node(javax.jcr.Node) 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