Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.FolderIndex


      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.");
        return;
      }

      // rearrange
      oldParent.removeChild(child);
      newParent.addChild(child);
      child.setParent(newParent);

      // change the child's name
      child.setName(destFileName);
View Full Code Here


    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");
    node2f = new FileIndex(node1d, keys, "2f", EncryptionUtil.generateMD5Hash(file2f));
    node2d = new FolderIndex(node1d, keys, "2d");

    // write the meta data now. Before creating the synchronizer, modify the file system as desired first.
    FileUtil.writePersistentMetaData(rootPath, null, null);
  }
View Full Code Here

  @Test
  public void testAddedRemotely() throws IOException, ClassNotFoundException {
    KeyPair keys = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_META_FILE);
    Index node1f3 = new FileIndex(root, keys, "1f3", null);
    Index node2d2 = new FolderIndex(node1d, keys, "2d2");

    FileSynchronizer fileSynchronizer = new FileSynchronizer(rootPath, userProfile);
    List<Index> addedRemotely = fileSynchronizer.getAddedRemotely();
    Assert.assertEquals(2, addedRemotely.size());
    Assert.assertTrue(addedRemotely.contains(node1f3));
View Full Code Here

    UserProfile userProfile = profileManager.getUserProfile("abc", true);

    // modify the version key to trigger a version conflict (wrong based on key)
    userProfile.generateVersionKey();

    new FolderIndex(userProfile.getRoot(), null, NetworkTestUtil.randomString());

    try {
      profileManager.readyToPut(userProfile, "abc");
      Assert.fail();
    } catch (PutFailedException e) {
View Full Code Here

  protected void doExecute() throws InvalidProcessStateException {
    logger.debug(
        "Preparing a notification message to the friend '{}' and all other sharers of the shared folder '{}'.",
        context.getFriendId(), context.getFolder().getName());

    FolderIndex fileNode = (FolderIndex) context.consumeIndex();

    // create a subtree containing all children
    FolderIndex sharedNode = new FolderIndex(fileNode.getParent(), fileNode.getFileKeys(),
        fileNode.getName());
    for (Index child : fileNode.getChildren()) {
      sharedNode.addChild(child);
      child.setParent(sharedNode);
    }

    // copy all user permissions
    for (UserPermission userPermission : fileNode.getUserPermissions()) {
      sharedNode.addUserPermissions(userPermission);
    }

    // if the friend receives write access, he gets the protection key
    if (context.getPermissionType() == PermissionType.WRITE) {
      logger.debug("Friend '{}' gets WRITE access to the shared folder '{}'.", context.getFriendId(),
          context.getFolder().getName());
      sharedNode.share(context.consumeNewProtectionKeys());
    } else {
      logger.debug("Friend '{}' gets READ access to the shared folder '{}'.",
          context.getFriendId(), context.getFolder().getName());
      sharedNode.share(null);
    }

    // remove the parent and only send the sub-tree
    sharedNode.setParent(null);

    // notify all users of the shared node
    Set<String> friends = new HashSet<String>();
    friends.addAll(fileNode.getCalculatedUserList());
    friends.remove(userId); // skip to notify myself
View Full Code Here

    } catch (GetFailedException e) {
      throw new ProcessExecutionException(e);
    }

    // find the parent node using the relative path to navigate there
    FolderIndex parentNode = (FolderIndex) userProfile.getFileByPath(file.getParentFile(), root);

    // validate the write protection
    if (!parentNode.canWrite()) {
      throw new ProcessExecutionException(String.format(
          "This directory '%s' is write protected (and we don't have the keys).", file
              .getParentFile().getName()));
    }
   
    // provide the content protection keys
    context.provideProtectionKeys(parentNode.getProtectionKeys());
  }
View Full Code Here

      Index movedNode = userProfile.getFileById(context.getFileNodeKeys().getPublic());

      // consider renaming
      movedNode.setName(context.getDestination().getName());

      FolderIndex oldParent = movedNode.getParent();
      oldParentKey = oldParent.getFileKeys().getPublic();

      // source's parent needs to be updated, no matter if it's root or not
      oldParent.removeChild(movedNode);

      // add to the new parent
      FolderIndex newParent = (FolderIndex) userProfile.getFileByPath(context.getDestination()
          .getParentFile(), networkManager.getSession().getRoot());
      movedNode.setParent(newParent);
      newParent.addChild(movedNode);

      // validate
      if (!oldParent.canWrite()) {
        throw new ProcessExecutionException("No write access to the source directory");
      } else if (!newParent.canWrite()) {
        throw new ProcessExecutionException("No write access to the destination directory");
      }

      // update in DHT
      profileManager.readyToPut(userProfile, getID());
      profileUpdated = true;
      logger.debug("Successfully relinked the moved file in the user profile.");

      // check if the protection key needs to be updated
      if (!H2HEncryptionUtil.compare(oldParent.getProtectionKeys(), newParent.getProtectionKeys())) {
        // update the protection key of the meta file and eventually all chunks
        logger.info("Required to update the protection key of the moved file(s)/folder(s).");
        initPKUpdateStep(movedNode, oldParent.getProtectionKeys(), newParent.getProtectionKeys());
      }

      // notify other users
      initNotificationParameters(oldParent.getCalculatedUserList(), movedNode);
View Full Code Here

  public void run() {
    logger.debug("Notification message received.");
    if (index.isFile()) {
      downloadSingle();
    } else {
      FolderIndex folder = (FolderIndex) index;
      if (folder.getChildren().isEmpty()) {
        downloadSingle();
      } else {
        downloadTree(folder);
      }
    }
View Full Code Here

        UserProfile userProfile = profileManager.getUserProfile(getID(), true);

        // relink them
        Index movedNode = userProfile.getFileById(context.getFileNodeKeys().getPublic());
        userProfile.getRoot().removeChild(movedNode);
        FolderIndex oldParent = (FolderIndex) userProfile.getFileById(oldParentKey);
        movedNode.setParent(oldParent);
        oldParent.addChild(movedNode);

        // update in DHT
        profileManager.readyToPut(userProfile, getID());
      } catch (NoSessionException | GetFailedException | PutFailedException e) {
        // ignore
View Full Code Here

    try {
      // get the user profile first
      String randomPID = UUID.randomUUID().toString();
      UserProfileManager profileManager = networkManager.getSession().getProfileManager();
      UserProfile userProfile = profileManager.getUserProfile(randomPID, true);
      FolderIndex parentNode = (FolderIndex) userProfile.getFileById(parentKey);
      if (parentNode == null) {
        logger.error("Could not process the task because the parent node has not been found.");
        return;
      }

      // validate if the other sharer has the right to share
      if (parentNode.canWrite(sender)) {
        logger.debug("Rights of user '{}' checked. User is allowed to modify.", sender);
      } else {
        logger.error("Permission of user '{}' not found. Deny to apply this user's changes.", sender);
        return;
      }

      // this task is sent when the file has been added or updated, make the difference between them.
      // When it's been added, add the index to the user profile, else, simply upldate it's md5 hash
      // there.
      if (parentNode.getChildByName(index.getName()) == null) {
        logger.debug("Newly shared file '{}' received.", index.getName());
        // file is new, link parent and new child
        parentNode.addChild(index);
        index.setParent(parentNode);
      } else {
        // copy the md5 parameter of the received file
        Index existing = parentNode.getChildByName(index.getName());
        if (existing.isFile() && index.isFile()) {
          logger.debug("File update in a shared folder received: '{}'.", index.getName());
          FileIndex existingFile = (FileIndex) existing;
          FileIndex newFile = (FileIndex) index;
          existingFile.setMD5(newFile.getMD5());
View Full Code Here

TOP

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

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.