Search in sources :

Example 1 with LabelExistsVersionException

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

the class ReadWriteVersionManager method addVersionLabel.

public void addVersionLabel(@Nonnull VersionStorage versionStorage, @Nonnull String versionHistoryOakRelPath, @Nonnull String versionIdentifier, @Nonnull String oakVersionLabel, boolean moveLabel) throws RepositoryException {
    Tree versionHistory = TreeUtil.getTree(checkNotNull(versionStorage.getTree()), checkNotNull(versionHistoryOakRelPath));
    Tree labels = checkNotNull(versionHistory).getChild(JCR_VERSIONLABELS);
    PropertyState existing = labels.getProperty(checkNotNull(oakVersionLabel));
    if (existing != null) {
        if (moveLabel) {
            labels.removeProperty(existing.getName());
        } else {
            throw new LabelExistsVersionException("Version label '" + oakVersionLabel + "' already exists on this version history");
        }
    }
    labels.setProperty(oakVersionLabel, versionIdentifier, Type.REFERENCE);
    try {
        sessionDelegate.commit(versionStorage.getRoot());
        refresh();
    } catch (CommitFailedException e) {
        versionStorage.refresh();
        throw e.asRepositoryException();
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) LabelExistsVersionException(javax.jcr.version.LabelExistsVersionException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Aggregations

LabelExistsVersionException (javax.jcr.version.LabelExistsVersionException)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1 Tree (org.apache.jackrabbit.oak.api.Tree)1