throw new ProcessExecutionException("Meta document not found.");
} else if (!metaFile.isSmall()) {
throw new ProcessExecutionException("Meta document is not a small meta file.");
}
MetaFileSmall metaFileSmall = (MetaFileSmall) metaFile;
// cast the versions to the public interface
List<IFileVersion> versions = new ArrayList<IFileVersion>();
for (FileVersion version : metaFileSmall.getVersions()) {
if (metaFileSmall.getNewestVersion().equals(version)) {
// skip newest version since it's not worth to restore it
continue;
}
versions.add(version);
}
logger.debug(
"Start with the selection of the version by the user. The user has choice between {} versions.",
versions.size());
IFileVersion selected = selector.selectVersion(versions);
if (selected == null) {
throw new ProcessExecutionException("Selected file version is null.");
}
// find the selected version
FileVersion selectedVersion = null;
for (FileVersion version : metaFileSmall.getVersions()) {
if (version.getIndex() == selected.getIndex()) {
selectedVersion = version;
break;
}
}
// check if the developer returned an invalid index
if (selectedVersion == null) {
throw new ProcessExecutionException("Invalid version index selected.");
}
logger.debug("Selected version {} where {} is newest.", selected.getIndex(), metaFileSmall
.getNewestVersion().getIndex());
// 1. download the file with new name <filename>_<date>
// 2. add the file with an AddFileProcess (which also notifies other clients)
try {
// find the node at the user profile
UserProfileManager profileManager = networkManager.getSession().getProfileManager();
UserProfile userProfile = profileManager.getUserProfile(getID(), false);
Index selectedNode = userProfile.getFileById(metaFileSmall.getId());
if (selectedNode == null) {
throw new Hive2HiveException("File node not found");
}
// ask the user for the new file name