@Override
public void restore(final String absPath,
final Version version,
final boolean removeExisting)
throws RepositoryException {
final SessionDelegate sessionDelegate = sessionContext.getSessionDelegate();
sessionDelegate.perform(new SessionOperation<Void>() {
@Override
public Void perform() 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.getRoot().commit();
success = true;
} catch (CommitFailedException e) {
throw new RepositoryException(e);
} finally {
if (!success) {
// refresh if one of the modifying operations fail
sessionDelegate.refresh(false);
}
}
return null;
}
});