Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.Index


      } 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);

      profileManager.readyToPut(userProfile, randomPID);

      // move the file on disk
      FileUtil.moveFile(session.getRoot(), sourceFileName, destFileName, oldParent, newParent);
View Full Code Here


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

    // set the corresponding content protection keys
    protectionContext.provideProtectionKeys(fileNode.getProtectionKeys());
    keyPairContext.provideKeyPair(fileNode.getFileKeys());
  }
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

      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());

    logger.debug("Successfully fetched file keys for the file to move, its old parent and its new parent.");
  }
View Full Code Here

  private static void checkIndexesAfterMoving(Path oldPath, Path newPath) throws GetFailedException,
      NoSessionException {
    UserProfile userProfileA = nodeA.getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Index indexOldA = userProfileA.getFileByPath(oldPath);
    // should have been deleted
    Assert.assertNull(indexOldA);

    UserProfile userProfileB = nodeB.getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Index indexOldB = userProfileB.getFileByPath(oldPath);
    // should have been deleted
    Assert.assertNull(indexOldB);

    Index indexNew = userProfileA.getFileByPath(newPath);
    // should have been created
    Assert.assertNotNull(indexNew);
    // check isShared flag
    Assert.assertFalse(indexNew.isShared());
    // check if content protection keys are the default content protection key
    Assert.assertTrue(indexNew.getProtectionKeys().getPrivate()
        .equals(userProfileA.getProtectionKeys().getPrivate()));
    Assert.assertTrue(indexNew.getProtectionKeys().getPublic()
        .equals(userProfileA.getProtectionKeys().getPublic()));
    // check write access
    Assert.assertTrue(indexNew.canWrite());
    // check user permissions
    Set<String> users = indexNew.getCalculatedUserList();
    Assert.assertEquals(1, users.size());
    Assert.assertTrue(users.contains(userProfileA.getUserId()));
    // check user permissions in case of a folder
    if (indexNew.isFolder()) {
      Set<UserPermission> permissions = ((FolderIndex) indexNew).getCalculatedUserPermissions();
      Assert.assertEquals(1, permissions.size());
      Assert.assertTrue(permissions.contains(new UserPermission(userProfileA.getUserId(),
          PermissionType.WRITE)));
    }
View Full Code Here

  private static void checkIndexAfterTryingMoving(Path relativePath) throws GetFailedException,
      NoSessionException {
    UserProfile userProfileA = nodeA.getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Index indexA = userProfileA.getFileByPath(relativePath);

    UserProfile userProfileB = nodeB.getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Index indexB = userProfileB.getFileByPath(relativePath);

    // check if userA's content protection keys are other ones
    Assert.assertFalse(indexA.getProtectionKeys().getPrivate()
        .equals(userProfileA.getProtectionKeys().getPrivate()));
    Assert.assertFalse(indexA.getProtectionKeys().getPublic()
        .equals(userProfileA.getProtectionKeys().getPublic()));
    // check if user B has no content protection keys
    Assert.assertNull(indexB.getProtectionKeys());

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

    // check write access
    Assert.assertTrue(indexA.canWrite());
    // user B has no write access
    Assert.assertFalse(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 (indexA.isFolder()) {
      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.READ)));
    }

    // check user permissions in case of a folder at B
    if (indexB.isFolder()) {
      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.READ)));
    }
View Full Code Here

  private static void checkIndexAfterMoving(Path relativePathOld, Path relativePathNew)
      throws GetFailedException, NoSessionException {
    UserProfile userProfileA = nodeA.getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Index oldIndexAtA = userProfileA.getFileByPath(relativePathOld);
    Index newIndexAtA = userProfileA.getFileByPath(relativePathNew);

    UserProfile userProfileB = nodeB.getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Index oldIndexAtB = userProfileB.getFileByPath(relativePathOld);
    Index newIndexAtB = userProfileB.getFileByPath(relativePathNew);

    // check if old indexes have been removed
    Assert.assertNull(oldIndexAtA);
    Assert.assertNull(oldIndexAtB);

    // check if userA's content protection keys are other ones
    Assert.assertFalse(newIndexAtA.getProtectionKeys().getPrivate()
        .equals(userProfileA.getProtectionKeys().getPrivate()));
    Assert.assertFalse(newIndexAtA.getProtectionKeys().getPublic()
        .equals(userProfileA.getProtectionKeys().getPublic()));
    // check if user B has no content protection keys
    Assert.assertNull(newIndexAtB.getProtectionKeys());

    // check if isShared flag is set
    Assert.assertTrue(newIndexAtA.isShared());
    Assert.assertTrue(newIndexAtB.isShared());

    // check write access
    Assert.assertTrue(newIndexAtA.canWrite());
    // user B has no write access
    Assert.assertFalse(newIndexAtB.canWrite());

    // check user permissions at A
    Set<String> usersA = newIndexAtA.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 = newIndexAtB.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 (newIndexAtA.isFolder()) {
      Set<UserPermission> permissions = ((FolderIndex) newIndexAtA).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.READ)));
    }

    // check user permissions in case of a folder at B
    if (newIndexAtB.isFolder()) {
      Set<UserPermission> permissions = ((FolderIndex) newIndexAtB).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.READ)));
    }
View Full Code Here

  private static void checkIndexAfterTryingToMove(Path relativePath) throws GetFailedException,
      NoSessionException {
    UserProfile userProfileA = nodeA.getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Index indexAtA = userProfileA.getFileByPath(relativePath);

    UserProfile userProfileB = nodeB.getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Index indexAtB = userProfileB.getFileByPath(relativePath);

    // check if userA's content protection keys are other ones
    Assert.assertFalse(indexAtA.getProtectionKeys().getPrivate()
        .equals(userProfileA.getProtectionKeys().getPrivate()));
    Assert.assertFalse(indexAtA.getProtectionKeys().getPublic()
        .equals(userProfileA.getProtectionKeys().getPublic()));
    // check if user B has no content protection keys
    Assert.assertNull(indexAtB.getProtectionKeys());

    // check if isShared flag is set
    Assert.assertTrue(indexAtA.isShared());
    Assert.assertTrue(indexAtB.isShared());

    // check write access
    Assert.assertTrue(indexAtA.canWrite());
    // user B has no write access
    Assert.assertFalse(indexAtB.canWrite());

    // check user permissions at A
    Set<String> usersA = indexAtA.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 = indexAtB.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 (indexAtA.isFolder()) {
      Set<UserPermission> permissions = ((FolderIndex) indexAtA).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.READ)));
    }

    // check user permissions in case of a folder at B
    if (indexAtB.isFolder()) {
      Set<UserPermission> permissions = ((FolderIndex) indexAtB).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.READ)));
    }
View Full Code Here

  private static void checkIndex(File fileAtA, File fileAtB, boolean deleted) 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);

    // in case of deletion verify removed index nodes
    if (deleted) {
      Assert.assertNull(indexA);
      Assert.assertNull(indexB);
      return;
    }

    // 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

  private static void checkIndex(Path relativePath, boolean deleted) throws GetFailedException,
      NoSessionException {
    UserProfile userProfileA = nodeA.getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Index indexA = userProfileA.getFileByPath(relativePath);

    UserProfile userProfileB = nodeB.getSession().getProfileManager()
        .getUserProfile(UUID.randomUUID().toString(), false);
    Index indexB = userProfileB.getFileByPath(relativePath);

    // in case of deletion verify removed index nodes
    if (deleted) {
      Assert.assertNull(indexA);
      Assert.assertNull(indexB);
      return;
    }

    // check if userA's content protection keys are other ones
    Assert.assertFalse(indexA.getProtectionKeys().getPrivate()
        .equals(userProfileA.getProtectionKeys().getPrivate()));
    Assert.assertFalse(indexA.getProtectionKeys().getPublic()
        .equals(userProfileA.getProtectionKeys().getPublic()));
    // check if user B has no content protection keys
    Assert.assertNull(indexB.getProtectionKeys());

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

    // check write access
    Assert.assertTrue(indexA.canWrite());
    // user B has no write access
    Assert.assertFalse(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 (indexA.isFolder()) {
      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.READ)));
    }

    // check user permissions in case of a folder at B
    if (indexB.isFolder()) {
      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.READ)));
    }
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.