Package org.hive2hive.core.processes.framework.exceptions

Examples of org.hive2hive.core.processes.framework.exceptions.ProcessExecutionException


    try {
      UserProfile userProfile = profileManager.getUserProfile(getID(), true);
      FolderIndex folderIndex = (FolderIndex) userProfile.getFileByPath(context.getFolder(), root);

      if (!folderIndex.canWrite()) {
        throw new ProcessExecutionException(String.format(
            "Cannot share folder '%s' with read-only access.", folderIndex.getName()));
      } else if (!folderIndex.getSharedFlag() && folderIndex.isSharedOrHasSharedChildren()) {
        // restriction that disallows sharing folders within other shared folders
        throw new ProcessExecutionException(String.format(
            "Folder '%s' is already shared or contains an shared folder.", folderIndex.getName()));
      }

      // check if the folder is already shared with this user
      if (folderIndex.getCalculatedUserList().contains(context.getFriendId())) {
        throw new ProcessExecutionException(String.format(
            "Friend '%s' already has access to folder '%s'.", context.getFriendId(),
            folderIndex.getName()));
      }

      // store for the notification
      context.provideIndex(folderIndex);

      if (folderIndex.getSharedFlag()) {
        // this if-clause allows sharing with multiple users and omits the next if-clause
        logger.debug("Sharing an already shared folder '{}' with friend '{}'.",
            folderIndex.getName(), context.getFriendId());
        folderIndex.addUserPermissions(context.getUserPermission());
      } else {
        // make the node shared with the new protection keys
        folderIndex.share(context.consumeNewProtectionKeys());
        // add read/write user permission of friend
        folderIndex.addUserPermissions(context.getUserPermission());
        // add write user permission of user itself
        folderIndex.addUserPermissions(new UserPermission(userId, PermissionType.WRITE));
      }

      // upload modified profile
      profileManager.readyToPut(userProfile, getID());

      // set modification flag needed for roll backs
      modified = true;
    } catch (GetFailedException | PutFailedException e) {
      throw new ProcessExecutionException(e);
    }
  }
View Full Code Here


    PublicKey receiverPublicKey;
    try {
      receiverPublicKey = keyManager.getPublicKey(context.getUserName());
    } catch (GetFailedException e) {
      throw new ProcessExecutionException("Cannot get public key of user " + context.getUserName());
    }

    MetaChunk metaChunk = context.getMetaChunk();
    RequestChunkMessage request = new RequestChunkMessage(context.getSelectedPeer(), context.getTask()
        .getFileKey(), metaChunk.getIndex(), config.getChunkSize(), metaChunk.getChunkHash());
View Full Code Here

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    MetaFile metaFile = context.consumeMetaFile();
    if (metaFile == null) {
      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
      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);
      getParent().add(addProcess);
    } catch (Hive2HiveException e) {
      throw new ProcessExecutionException(e);
    }

  }
View Full Code Here

      PublicKey publicKey = keyManager.getPublicKey(friendId);
      if (publicKey == null)
        throw new GetFailedException(String.format("The friend '%s' does not seem to exist.",
            friendId));
    } catch (GetFailedException e) {
      throw new ProcessExecutionException(String.format(
          "The friend '%s' does not seem to exist. reason = '%s'", friendId, e.getMessage()));
    }
  }
View Full Code Here

      Chunk chunk;

      try {
        chunk = FileChunkUtil.getChunk(file, config.getChunkSize(), i, chunkId);
      } catch (IOException e) {
        throw new ProcessExecutionException("Cannot read the large file", e);
      }

      byte[] md5Hash = EncryptionUtil.generateMD5Hash(chunk.getData());
      context.getMetaChunks().add(new MetaChunk(chunkId, md5Hash, i));
    }
View Full Code Here

TOP

Related Classes of org.hive2hive.core.processes.framework.exceptions.ProcessExecutionException

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.