Search in sources :

Example 56 with VersionException

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

the class NodeImpl method resolveMergeConflict.

/**
     * Internal method covering both {@link #doneMerge(Version)} and {@link #cancelMerge(Version)}.
     *
     * @param version
     * @param done
     * @throws VersionException
     * @throws InvalidItemStateException
     * @throws UnsupportedRepositoryOperationException
     * @throws RepositoryException
     */
private void resolveMergeConflict(Version version, boolean done) throws VersionException, InvalidItemStateException, UnsupportedRepositoryOperationException, RepositoryException {
    checkIsVersionable();
    checkHasPendingChanges();
    checkIsLocked();
    // check if checked out
    if (!isCheckedOut()) {
        String msg = "Unable to resolve merge conflict. Node is checked-in: " + safeGetJCRPath();
        log.error(msg);
        throw new VersionException(msg);
    }
    // check if version is in mergeFailed list
    boolean isConflicting = false;
    if (hasProperty(NameConstants.JCR_MERGEFAILED)) {
        Value[] vals = getProperty(NameConstants.JCR_MERGEFAILED).getValues();
        for (int i = 0; i < vals.length && !isConflicting; i++) {
            isConflicting = vals[i].getString().equals(version.getUUID());
        }
    }
    if (!isConflicting) {
        String msg = "Unable to resolve merge conflict. Specified version is not in jcr:mergeFailed property: " + safeGetJCRPath();
        log.error(msg);
        throw new VersionException(msg);
    }
    NodeState versionState = session.getVersionState(version);
    session.getVersionStateManager().resolveMergeConflict(getNodeState(), versionState, done);
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) VersionException(javax.jcr.version.VersionException)

Example 57 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 58 with VersionException

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

the class RestoreTest method testRestoreInvalidVersionJcr2.

/**
     * VersionException expected on restore 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 59 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 60 with VersionException

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

the class RestoreTest method testRestoreInvalidVersion2Jcr2.

/**
     * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
     *
     * @throws RepositoryException
     */
public void testRestoreInvalidVersion2Jcr2() throws RepositoryException {
    String invalidName;
    do {
        invalidName = createRandomString(3);
        for (VersionIterator it = versionManager.getVersionHistory(versionableNode.getPath()).getAllVersions(); it.hasNext(); ) {
            Version v = it.nextVersion();
            if (invalidName.equals(v.getName())) {
                invalidName = null;
                break;
            }
        }
    } while (invalidName == null);
    try {
        versionManager.restore(versionableNode.getPath(), 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)

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