// create a version selector to the set of versions
VersionSelector vsel = new VersionSelector() {
public Version select(VersionHistory versionHistory) throws RepositoryException {
// try to select version as specified
Version v = (Version) toRestore.get(versionHistory.getUUID());
if (v == null) {
// select latest one
v = DateVersionSelector.selectByDate(versionHistory, null);
}
return v;
}
};
// check for pending changes
if (session.hasPendingChanges()) {
String msg = "Unable to restore version. Session has pending changes.";
log.debug(msg);
throw new InvalidItemStateException(msg);
}
try {
// now restore all versions that have a node in the ws
int numRestored = 0;
while (toRestore.size() > 0) {
Version[] restored = null;
Iterator iter = toRestore.values().iterator();
while (iter.hasNext()) {
VersionImpl v = (VersionImpl) iter.next();
try {
NodeImpl node = (NodeImpl) session.getNodeByUUID(v.getFrozenNode().getFrozenUUID());
restored = node.internalRestore(v, vsel, removeExisting);
// remove restored versions from set
for (int i = 0; i < restored.length; i++) {
toRestore.remove(restored[i].getContainingHistory().getUUID());
}