Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.Index


    // assert that the file is moved
    Assert.assertTrue(destination.exists());

    // check that the user profile has a correct entry
    UserProfile userProfile = UseCaseTestUtil.getUserProfile(client, userCredentials);
    Index fileNode = userProfile.getFileByPath(destination, root.toPath());
    Assert.assertNotNull(fileNode);
    Assert.assertEquals(fileNode.getName(), destination.getName());
  }
View Full Code Here


  private static void checkIndex(File fileAtA, File fileAtB) throws GetFailedException, NoSessionException {
    UserProfile userProfileA = network.get(0).getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Path relativePathA = rootA.toPath().relativize(fileAtA.toPath());
    Index indexA = userProfileA.getFileByPath(relativePathA);

    UserProfile userProfileB = network.get(1).getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Path relativePathB = rootB.toPath().relativize(fileAtB.toPath());
    Index indexB = userProfileB.getFileByPath(relativePathB);

    // check if content protection keys are the same
    Assert.assertTrue(indexA.getProtectionKeys().getPrivate()
        .equals(indexB.getProtectionKeys().getPrivate()));
    Assert.assertTrue(indexA.getProtectionKeys().getPublic()
        .equals(indexB.getProtectionKeys().getPublic()));

    // check if isShared flag is set
    Assert.assertTrue(indexA.isShared());
    Assert.assertTrue(indexB.isShared());

    // check write access
    Assert.assertTrue(indexA.canWrite());
    Assert.assertTrue(indexB.canWrite());

    // check user permissions at A
    Set<String> usersA = indexA.getCalculatedUserList();
    Assert.assertEquals(2, usersA.size());
    Assert.assertTrue(usersA.contains(userA.getUserId()));
    Assert.assertTrue(usersA.contains(userB.getUserId()));

    // check user permissions at A
    Set<String> usersB = indexB.getCalculatedUserList();
    Assert.assertEquals(2, usersB.size());
    Assert.assertTrue(usersB.contains(userA.getUserId()));
    Assert.assertTrue(usersB.contains(userB.getUserId()));

    // check user permissions in case of a folder at A
    if (fileAtA.isDirectory()) {
      Assert.assertTrue(indexA.isFolder());
      Set<UserPermission> permissions = ((FolderIndex) indexA).getCalculatedUserPermissions();
      Assert.assertEquals(2, permissions.size());
      Assert.assertTrue(permissions.contains(new UserPermission(userA.getUserId(), PermissionType.WRITE)));
      Assert.assertTrue(permissions.contains(new UserPermission(userB.getUserId(), PermissionType.WRITE)));
    } else {
      Assert.assertTrue(indexA.isFile());
    }

    // check user permissions in case of a folder at B
    if (fileAtB.isDirectory()) {
      Assert.assertTrue(indexB.isFolder());
      Set<UserPermission> permissions = ((FolderIndex) indexB).getCalculatedUserPermissions();
      Assert.assertEquals(2, permissions.size());
      Assert.assertTrue(permissions.contains(new UserPermission(userA.getUserId(), PermissionType.WRITE)));
      Assert.assertTrue(permissions.contains(new UserPermission(userB.getUserId(), PermissionType.WRITE)));
    } else {
      Assert.assertTrue(indexB.isFile());
    }
  }
View Full Code Here

    // test if there is something in the user profile
    UserProfile gotProfile = UseCaseTestUtil.getUserProfile(client, userCredentials);
    Assert.assertNotNull(gotProfile);

    Index node = gotProfile.getFileByPath(originalFile, uploaderRoot.toPath());
    Assert.assertNotNull(node);

    // verify the meta document
    KeyPair metaFileKeys = node.getFileKeys();
    if (originalFile.isFile()) {
      MetaFile metaFile = UseCaseTestUtil.getMetaFile(client, metaFileKeys);
      Assert.assertNotNull(metaFile);
      Assert.assertTrue(metaFile instanceof MetaFileSmall);
      MetaFileSmall metaFileSmall = (MetaFileSmall) metaFile;
View Full Code Here

    // find children with same parents and make them run in parallel
    // idea: iterate through all children and search for parent in other map. If not there, they can be
    // added to the root process anyway
    for (FileIndex file : fileMap.keySet()) {
      AsyncComponent fileProcess = fileMap.get(file);
      Index parent = file.getParent();
      if (parent == null) {
        // file is in root, thus we can add it to the root process
        rootProcess.add(fileProcess);
      } else if (folderMap.containsKey(parent)) {
        // the parent exists here
        SequentialProcess parentProcess = folderMap.get(parent);
        parentProcess.add(fileProcess);
      } else {
        // file is not in root and parent is not here, thus we simply add it to the root process
        rootProcess.add(fileProcess);
      }
    }

    // files and folder are linked. We now link the folders with other folders
    for (FolderIndex folder : folderMap.keySet()) {
      SequentialProcess folderProcess = folderMap.get(folder);
      // In addition, we can make this process run asynchronous because it does not affect the siblings
      AsyncComponent asyncFolderProcess = new AsyncComponent(folderProcess);
      Index parent = folder.getParent();
      if (parent == null) {
        // file is in root, thus we can add it to the root process.
        rootProcess.add(asyncFolderProcess);
      } else if (folderMap.containsKey(parent)) {
        // this folder has a parent
View Full Code Here

  }

  @Override
  protected void doExecute() throws InvalidProcessStateException {
    // prepare the file tree node for sending to other users
    Index fileNode = context.consumeIndex();
    PublicKey parentKey = fileNode.getParent().getFilePublicKey();

    // provide the message factory
    context.provideMessageFactory(new DeleteNotifyMessageFactory(fileNode.getFilePublicKey(), parentKey,
        fileNode.getName()));

    HashSet<String> users = new HashSet<String>();
    users.addAll(fileNode.getCalculatedUserList());

    // provide the user list
    context.provideUsersToNotify(users);
  }
View Full Code Here

      if (now.containsKey(path)) {
        // skip, this file is still here
        continue;
      } else {
        // test whether it is in the user profile
        Index node = userProfile.getFileByPath(Paths.get(path));
        if (node != null) {
          // file is still in user profile
          if (node.isFolder()) {
            deletedLocally.add(node);
          } else {
            // check the MD5 value to not delete a modified file
            FileIndex fileNode = (FileIndex) node;
            if (H2HEncryptionUtil.compareMD5(fileNode.getMD5(), before.get(path))) {
View Full Code Here

    List<Path> addedLocally = new ArrayList<Path>();

    for (String p : now.keySet()) {
      Path path = Paths.get(p);
      // test whether it is in the user profile
      Index node = userProfile.getFileByPath(path);
      if (node == null) {
        // not in profile --> it has been added locally
        logger.debug("File '{}' has been added locally during absence.", p);
        addedLocally.add(Paths.get(root.toString(), path.toString()));
      }
View Full Code Here

      if (H2HEncryptionUtil.compareMD5(before.get(path), now.get(path))) {
        // md5 before and after match --> nothing changed
        continue;
      }

      Index index = userProfile.getFileByPath(Paths.get(path));
      if (index == null || index.isFolder()) {
        // file not found --> skip, this is not the task of this method
        // file node is a folder --> cannot compare the modification
        continue;
      }
View Full Code Here

      sendDirectResponse(createResponse(null));
      return;
    }

    // find file in user profile
    Index index = userProfile.getFileById(fileKey);
    if (index == null || index.isFolder()) {
      logger.info("File not found in the user profile, cannot return a chunk");
      sendDirectResponse(createResponse(null));
      return;
    }
View Full Code Here

    try {
      UserProfileManager profileManager = networkManager.getSession().getProfileManager();
      UserProfile userProfile = profileManager.getUserProfile(getID(), true);

      logger.debug("Start relinking the moved file in the user profile.");
      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");
View Full Code Here

TOP

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

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.