Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.IFileVersion


    }

    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
      String originalFileName = context.getFile().getName();
      String noSuffix = FilenameUtils.removeExtension(originalFileName);
      String extension = FilenameUtils.getExtension(originalFileName);
      String recoveredFileName = selector.getRecoveredFileName(originalFileName, noSuffix, extension);
      if (recoveredFileName == null || originalFileName.equals(recoveredFileName)) {
        // generate a new file name indicating that the file is restored
        logger.warn("Replacing the given file name with a custom file name because it was invalid.");
        Date versionDate = new Date(selected.getDate());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss");
        recoveredFileName = noSuffix + "-" + sdf.format(versionDate) + "." + extension;
      }

      logger.debug("Starting to download the restored file under the name '{}'.", recoveredFileName);
      File destination = new File(context.getFile().getParentFile(), recoveredFileName);

      // add the process to download the file
      ProcessComponent downloadProcess = ProcessFactory.instance().createDownloadFileProcess(
          selectedNode.getFilePublicKey(), selected.getIndex(), destination, networkManager);
      getParent().add(downloadProcess);

      // add the process to upload the file
      ProcessComponent addProcess = ProcessFactory.instance().createNewFileProcess(destination,
          networkManager);
View Full Code Here

TOP

Related Classes of org.hive2hive.core.model.IFileVersion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.