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();
}
}
Aggregations