Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.UserProfile


  public static File downloadFile(NetworkManager networkManager, PublicKey fileKey) throws NoSessionException,
      GetFailedException, NoPeerConnectionException {
    IProcessComponent process = ProcessFactory.instance().createDownloadFileProcess(fileKey, networkManager);
    executeProcess(process);
    UserProfile userProfile = getUserProfile(networkManager, networkManager.getSession().getCredentials());
    return FileUtil.getPath(networkManager.getSession().getRoot(), userProfile.getFileById(fileKey)).toFile();
  }
View Full Code Here


  public void start() {
    try {
      H2HSession session = networkManager.getSession();
      String randomPID = UUID.randomUUID().toString();
      UserProfileManager profileManager = session.getProfileManager();
      UserProfile userProfile = profileManager.getUserProfile(randomPID, true);

      // get and check the file nodes to be rearranged
      FolderIndex oldParent = (FolderIndex) userProfile.getFileById(oldParentKey);
      if (oldParent == null) {
        logger.error("Could not find the old parent.");
        return;
      } else if (!oldParent.canWrite(sender)) {
        logger.error("User was not allowed to change the source directory.");
        return;
      }

      Index child = oldParent.getChildByName(sourceFileName);
      if (child == null) {
        logger.error("File node that should be moved not found.");
        return;
      }

      FolderIndex newParent = (FolderIndex) userProfile.getFileById(newParentKey);
      if (newParent == null) {
        logger.error("Could not find the new parent.");
        return;
      } else if (!newParent.canWrite(sender)) {
        logger.error("User was not allowed to change the destination directory.");
View Full Code Here

  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    // file node can be null or already present
    logger.info("Getting the corresponding file node for file '{}'.", file.getName());

    // file node is null, first look it up in the user profile
    UserProfile profile = null;
    try {
      profile = session.getProfileManager().getUserProfile(getID(), false);
    } catch (GetFailedException e) {
      throw new ProcessExecutionException(e);
    }

    Index fileNode = profile.getFileByPath(file, session.getRoot());
    if (fileNode == null) {
      throw new ProcessExecutionException(
          "File does not exist in user profile. Consider uploading a new file.");
    }
View Full Code Here

    file2f = new File(file1d, "2f");
    FileUtils.writeStringToFile(file2f, NetworkTestUtil.randomString());
    file2d = new File(file1d, "2d");
    file2d.mkdir();

    userProfile = new UserProfile("test-user");
    root = userProfile.getRoot();
    KeyPair keys = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_META_FILE);
    node1f1 = new FileIndex(root, keys, "1f1", EncryptionUtil.generateMD5Hash(file1f1));
    node1f2 = new FileIndex(root, keys, "1f2", EncryptionUtil.generateMD5Hash(file1f2));
    node1d = new FolderIndex(root, keys, "1d");
View Full Code Here

      throw new ProcessExecutionException(
          "The new MD5 hash for the user profile could not be generated.", e);
    }

    try {
      UserProfile userProfile = profileManager.getUserProfile(getID(), true);
      FileIndex index = (FileIndex) userProfile.getFileById(metaFileSmall.getId());

      // store hash of meta file
      index.setMetaFileHash(context.consumeHash());

      // store for backup
View Full Code Here

  protected void doRollback(RollbackReason reason) throws InvalidProcessStateException {
    MetaFileSmall metaFileSmall = (MetaFileSmall) context.consumeMetaFile();
    if (metaFileSmall != null) {
      try {
        // return to original MD5 and put the userProfile
        UserProfile userProfile = profileManager.getUserProfile(getID(), true);
        FileIndex fileNode = (FileIndex) userProfile.getFileById(metaFileSmall.getId());
        fileNode.setMD5(originalMD5);
        profileManager.readyToPut(userProfile, getID());
      } catch (Exception e) {
        // ignore
      }
View Full Code Here

      } catch (DataLengthException | IllegalStateException | InvalidCipherTextException
          | ClassNotFoundException | IOException e) {
        throw new ProcessExecutionException("User profile could not be decrypted.");
      }

      UserProfile profile = (UserProfile) decryptedContent;
      profile.setVersionKey(loadedContent.getVersionKey());
      profile.setBasedOnKey(loadedContent.getBasedOnKey());

      context.provideUserProfile(profile);
    }
  }
View Full Code Here

  }

  private void getFileKeys() throws GetFailedException, InvalidProcessStateException, NoSessionException,
      IllegalStateException {
    UserProfileManager profileManager = networkManager.getSession().getProfileManager();
    UserProfile userProfile = profileManager.getUserProfile(getID(), false);

    // get the keys for the file to move
    Index fileNode = userProfile
        .getFileByPath(context.getSource(), networkManager.getSession().getRoot());
    if (fileNode == null) {
      throw new IllegalStateException("File to move is not in user profile");
    }
    context.setFileNodeKeys(fileNode.getFileKeys());
View Full Code Here

      if (intendsToPut)
        stopModification(pid);
      throw e;
    }

    UserProfile profile = entry.getUserProfile();
    if (profile == null)
      throw new GetFailedException("User Profile not found");
    return profile;
  }
View Full Code Here

   * @return the default content protection keys
   * @throws GetFailedException
   */
  public KeyPair getDefaultProtectionKey() throws GetFailedException {
    if (defaultProtectionKey == null) {
      UserProfile userProfile = getUserProfile(UUID.randomUUID().toString(), false);
      defaultProtectionKey = userProfile.getProtectionKeys();
    }
    return defaultProtectionKey;
  }
View Full Code Here

TOP

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

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.