use of javax.jcr.version.VersionException in project jackrabbit-oak by apache.
the class NodeImpl method setMixins.
/**
* Simplified implementation of the {@link org.apache.jackrabbit.api.JackrabbitNode#setMixins(String[])}
* method that adds all mixin types that are not yet present on this node
* and removes all mixins that are no longer contained in the specified
* array. Note, that this implementation will not work exactly like the
* variant in Jackrabbit 2.x which first created the effective node type
* and adjusted the set of child items accordingly.
*
* @param mixinNames
* @throws RepositoryException
*/
@Override
public void setMixins(String[] mixinNames) throws RepositoryException {
final Set<String> oakTypeNames = newLinkedHashSet();
for (String mixinName : mixinNames) {
oakTypeNames.add(getOakName(checkNotNull(mixinName)));
}
sessionDelegate.performVoid(new ItemWriteOperation<Void>("setMixins") {
@Override
public void checkPreconditions() throws RepositoryException {
super.checkPreconditions();
if (!isCheckedOut()) {
throw new VersionException(format("Cannot set mixin types. Node [%s] is checked in.", getNodePath()));
}
// check for NODE_TYPE_MANAGEMENT permission here as we cannot
// distinguish between a combination of removeMixin and addMixin
// and Node#remove plus subsequent addNode when it comes to
// autocreated properties like jcr:create, jcr:uuid and so forth.
PropertyDelegate mixinProp = dlg.getPropertyOrNull(JCR_MIXINTYPES);
if (mixinProp != null) {
sessionContext.getAccessManager().checkPermissions(dlg.getTree(), mixinProp.getPropertyState(), Permissions.NODE_TYPE_MANAGEMENT);
}
}
@Override
public void performVoid() throws RepositoryException {
dlg.setMixins(oakTypeNames);
}
});
}
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 value, final boolean exactTypeMatch) throws RepositoryException {
final String oakName = getOakPathOrThrow(checkNotNull(jcrName));
final PropertyState state = createSingleState(oakName, value, Type.fromTag(value.getType(), false));
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);
}
});
}
use of javax.jcr.version.VersionException in project jackrabbit-oak by apache.
the class ReadWriteVersionManager method removeVersion.
public void removeVersion(@Nonnull VersionStorage versionStorage, @Nonnull String versionHistoryOakRelPath, @Nonnull String oakVersionName) throws RepositoryException {
Tree versionHistory = TreeUtil.getTree(versionStorage.getTree(), versionHistoryOakRelPath);
if (versionHistory == null || !versionHistory.exists()) {
throw new VersionException("Version history " + versionHistoryOakRelPath + " does not exist on this version storage");
}
Tree version = versionHistory.getChild(oakVersionName);
if (!version.exists()) {
throw new VersionException("Version " + oakVersionName + " does not exist on this version history");
}
version.remove();
try {
sessionDelegate.commit(versionStorage.getRoot());
refresh();
} catch (CommitFailedException e) {
versionStorage.refresh();
throw e.asRepositoryException();
}
}
use of javax.jcr.version.VersionException in project jackrabbit-oak by apache.
the class ReadWriteVersionManager method removeVersionLabel.
public void removeVersionLabel(@Nonnull VersionStorage versionStorage, @Nonnull String versionHistoryOakRelPath, @Nonnull String oakVersionLabel) throws RepositoryException {
Tree versionHistory = TreeUtil.getTree(checkNotNull(versionStorage.getTree()), checkNotNull(versionHistoryOakRelPath));
Tree labels = checkNotNull(versionHistory).getChild(JCR_VERSIONLABELS);
if (!labels.hasProperty(oakVersionLabel)) {
throw new VersionException("Version label " + oakVersionLabel + " does not exist on this version history");
}
labels.removeProperty(oakVersionLabel);
try {
sessionDelegate.commit(versionStorage.getRoot());
refresh();
} catch (CommitFailedException e) {
versionStorage.refresh();
throw e.asRepositoryException();
}
}
use of javax.jcr.version.VersionException in project jackrabbit-oak by apache.
the class NodeImpl method addMixin.
@Override
public void addMixin(String mixinName) throws RepositoryException {
final String oakTypeName = getOakName(checkNotNull(mixinName));
sessionDelegate.performVoid(new ItemWriteOperation<Void>("addMixin") {
@Override
public void checkPreconditions() throws RepositoryException {
super.checkPreconditions();
if (!isCheckedOut()) {
throw new VersionException(format("Cannot add mixin type. Node [%s] is checked in.", getNodePath()));
}
}
@Override
public void performVoid() throws RepositoryException {
dlg.addMixin(oakTypeName);
}
});
}
Aggregations