use of javax.jcr.version.VersionException in project jackrabbit-oak by apache.
the class OpvAbortTest method testChildInSubTree.
public void testChildInSubTree() throws Exception {
Node n = testRootNode.addNode(nodeName1).addNode(nodeName2);
n.addMixin("OpvAbortTest");
Node child = n.addNode("child", NodeTypeConstants.NT_OAK_UNSTRUCTURED);
superuser.save();
assertEquals(OnParentVersionAction.ABORT, child.getDefinition().getOnParentVersion());
try {
vMgr.checkpoint(testRootNode.getPath());
fail();
} catch (VersionException e) {
// success
} finally {
superuser.refresh(false);
}
}
use of javax.jcr.version.VersionException in project jackrabbit-oak by apache.
the class VersionManagerImpl method restore.
@Override
public void restore(final String absPath, final Version version, final boolean removeExisting) throws RepositoryException {
final SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
sessionDelegate.performVoid(new SessionOperation<Void>("restore", true) {
@Override
public void performVoid() throws RepositoryException {
String oakPath = getOakPathOrThrowNotFound(absPath);
NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
if (nodeDelegate != null) {
throw new VersionException("VersionManager.restore(String, Version, boolean)" + " not allowed on existing nodes; use" + " VersionManager.restore(Version, boolean) instead: " + absPath);
}
// check if parent exists
NodeDelegate parent = ensureParentExists(sessionDelegate, absPath);
// check for pending changes
checkPendingChangesForRestore(sessionDelegate);
// check lock status
checkNotLocked(parent.getPath());
// check for existing nodes
List<NodeDelegate> existing = getExisting(version, Collections.<String>emptySet());
boolean success = false;
try {
if (!existing.isEmpty()) {
if (removeExisting) {
removeExistingNodes(existing);
} else {
List<String> paths = new ArrayList<String>();
for (NodeDelegate nd : existing) {
paths.add(nd.getPath());
}
throw new ItemExistsException("Unable to restore with " + "removeExisting=false. Existing nodes in " + "workspace: " + paths);
}
}
// ready for restore
VersionDelegate vd = versionManagerDelegate.getVersionByIdentifier(version.getIdentifier());
versionManagerDelegate.restore(parent, PathUtils.getName(oakPath), vd);
sessionDelegate.commit();
success = true;
} catch (CommitFailedException e) {
throw e.asRepositoryException();
} finally {
if (!success) {
// refresh if one of the modifying operations fail
sessionDelegate.refresh(false);
}
}
}
});
}
use of javax.jcr.version.VersionException in project jackrabbit-oak by apache.
the class VersionManagerImpl method restore.
@Override
public void restore(final Version[] versions, final boolean removeExisting) throws ItemExistsException, UnsupportedRepositoryOperationException, VersionException, LockException, InvalidItemStateException, RepositoryException {
if (versions.length > 1) {
throw new UnsupportedRepositoryOperationException("OAK-168: Restore of multiple versions not implemented.");
}
final Version version = versions[0];
VersionHistory history = (VersionHistory) version.getParent();
final String versionableId = history.getVersionableIdentifier();
if (history.getRootVersion().isSame(version)) {
throw new VersionException("Restore of root version not possible");
}
final SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
sessionDelegate.performVoid(new SessionOperation<Void>("restore", true) {
@Override
public void performVoid() throws RepositoryException {
// check for pending changes
checkPendingChangesForRestore(sessionDelegate);
NodeDelegate n = sessionDelegate.getNodeByIdentifier(versionableId);
if (n == null) {
throw new VersionException("Unable to restore version. " + "No versionable node with identifier: " + versionableId);
}
// check lock status
checkNotLocked(n.getPath());
// check for existing nodes
List<NodeDelegate> existing = getExisting(version, Collections.singleton(n.getPath()));
boolean success = false;
try {
if (!existing.isEmpty()) {
if (removeExisting) {
removeExistingNodes(existing);
} else {
List<String> paths = new ArrayList<String>();
for (NodeDelegate nd : existing) {
paths.add(nd.getPath());
}
throw new ItemExistsException("Unable to restore with " + "removeExisting=false. Existing nodes in " + "workspace: " + paths);
}
}
// ready for restore
VersionDelegate vd = versionManagerDelegate.getVersionByIdentifier(version.getIdentifier());
versionManagerDelegate.restore(n.getParent(), n.getName(), vd);
sessionDelegate.commit();
success = true;
} catch (CommitFailedException e) {
throw new RepositoryException(e);
} finally {
if (!success) {
// refresh if one of the modifying operations fail
sessionDelegate.refresh(false);
}
}
}
});
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class ItemValidator method checkCondition.
private void checkCondition(ItemImpl item, int options, int permissions, boolean isRemoval) throws RepositoryException {
if ((options & CHECK_PENDING_CHANGES) == CHECK_PENDING_CHANGES) {
if (item.getSession().hasPendingChanges()) {
String msg = "Unable to perform operation. Session has pending changes.";
log.debug(msg);
throw new InvalidItemStateException(msg);
}
}
if ((options & CHECK_PENDING_CHANGES_ON_NODE) == CHECK_PENDING_CHANGES_ON_NODE) {
if (item.isNode() && ((NodeImpl) item).hasPendingChanges()) {
String msg = "Unable to perform operation. Session has pending changes.";
log.debug(msg);
throw new InvalidItemStateException(msg);
}
}
if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
if (isProtected(item)) {
String msg = "Unable to perform operation. Node is protected.";
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
if ((options & CHECK_CHECKED_OUT) == CHECK_CHECKED_OUT) {
NodeImpl node = (item.isNode()) ? (NodeImpl) item : (NodeImpl) item.getParent();
if (!node.isCheckedOut()) {
String msg = "Unable to perform operation. Node is checked-in.";
log.debug(msg);
throw new VersionException(msg);
}
}
if ((options & CHECK_LOCK) == CHECK_LOCK) {
checkLock(item);
}
if (permissions > Permission.NONE) {
Path path = item.getPrimaryPath();
context.getAccessManager().checkPermission(path, permissions);
}
if ((options & CHECK_HOLD) == CHECK_HOLD) {
if (hasHold(item, isRemoval)) {
throw new RepositoryException("Unable to perform operation. Node is affected by a hold.");
}
}
if ((options & CHECK_RETENTION) == CHECK_RETENTION) {
if (hasRetention(item, isRemoval)) {
throw new RepositoryException("Unable to perform operation. Node is affected by a retention.");
}
}
}
use of javax.jcr.version.VersionException in project jackrabbit by apache.
the class InternalVersionHistoryImpl method setVersionLabel.
/**
* Sets the version <code>label</code> to the given <code>version</code>.
* If the label is already assigned to another version, a VersionException is
* thrown unless <code>move</code> is <code>true</code>. If <code>version</code>
* is <code>null</code>, the label is removed from the respective version.
* In either case, the version the label was previously assigned to is returned,
* or <code>null</code> of the label was not moved.
*
* @param versionName the name of the version
* @param label the label to assign
* @param move flag what to do by collisions
* @return the version that was previously assigned by this label or <code>null</code>.
* @throws VersionException if the version does not exist or if the label is already defined.
*/
synchronized InternalVersion setVersionLabel(Name versionName, Name label, boolean move) throws VersionException {
InternalVersion version = (versionName != null) ? getVersion(versionName) : null;
if (versionName != null && version == null) {
throw new VersionException("Version " + versionName + " does not exist in this version history.");
}
Name prevName = labelCache.get(label);
InternalVersionImpl prev = null;
if (prevName == null) {
if (version == null) {
return null;
}
} else {
prev = (InternalVersionImpl) getVersion(prevName);
if (prev.equals(version)) {
return version;
} else if (!move) {
// already defined elsewhere, throw
throw new VersionException("Version label " + label + " already defined for version " + prev.getName());
}
}
// update persistence
try {
if (version == null) {
labelNode.removeProperty(label);
} else {
labelNode.setPropertyValue(label, InternalValue.create(version.getId()));
}
labelNode.store();
} catch (RepositoryException e) {
throw new VersionException(e);
}
// update internal structures
if (prev != null) {
prev.internalRemoveLabel(label);
labelCache.remove(label);
}
if (version != null) {
labelCache.put(label, version.getName());
((InternalVersionImpl) version).internalAddLabel(label);
}
return prev;
}
Aggregations