Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.FolderIndex


    logger.trace("Start updating the user profile where adding the file '{}'.", file.getName());
    try {
      UserProfile userProfile = profileManager.getUserProfile(getID(), true);

      // 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("This directory is write protected (and we don't have the keys).");
      }

      // create a file tree node in the user profile
      parentKey = parentNode.getFilePublicKey();
      // use the file keys generated above is stored
      if (file.isDirectory()) {
        FolderIndex folderIndex = new FolderIndex(parentNode, metaKeys, file.getName());
        context.provideIndex(folderIndex);
      } else {
        FileIndex fileIndex = new FileIndex(parentNode, metaKeys, file.getName(), md5);
        context.provideIndex(fileIndex);
      }
View Full Code Here


      try {
        userProfile = profileManager.getUserProfile(getID(), true);
      } catch (GetFailedException e) {
        return;
      }
      FolderIndex parentNode = (FolderIndex) userProfile.getFileById(parentKey);
      Index childNode = parentNode.getChildByName(context.getFile().getName());
      parentNode.removeChild(childNode);
      try {
        profileManager.readyToPut(userProfile, getID());
        modified = false;
      } catch (PutFailedException e) {
        // ignore
View Full Code Here

    protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
      try {
        UserProfile userProfile = profileManager.getUserProfile(getID(), operation == Operation.PUT);

        if (operation == Operation.MODIFY) {
          new FolderIndex(userProfile.getRoot(), null, NetworkTestUtil.randomString());
        }

        if (operation == Operation.PUT) {
          profileManager.readyToPut(userProfile, getID());
        }
View Full Code Here

      UserProfile profile = profileManager.getUserProfile(pid, true);

      List<FolderIndex> indexes = getIndexList(profile.getRoot());

      if (isFolder) {
        new FolderIndex(indexes.get(random.nextInt(indexes.size())), null, NetworkTestUtil.randomString());
      } else {
        new FileIndex(indexes.get(random.nextInt(indexes.size())), keys, file.getName(), md5Hash);
      }

      profileManager.readyToPut(profile, pid);
View Full Code Here

    if (toDelete == null) {
      logger.warn("Could not delete the file because it does not exist anymore.");
      return null;
    }

    FolderIndex parent = toDelete.getParent();
    if (parent == null) {
      logger.error("Got task to delete the root, which is invalid.");
      return null;
    }

    // check write permision
    if (!parent.canWrite(sender)) {
      logger.error("User without WRITE permissions tried to delete a file.");
      return null;
    }

    parent.removeChild(toDelete);
    profileManager.readyToPut(userProfile, randomPID);
    logger.debug("Removed the dead link from the user profile.");
    return toDelete;
  }
View Full Code Here

    // the result set
    result.clear();

    // build the digest recursively
    FolderIndex root = profile.getRoot();
    List<Index> digest = Index.getIndexList(root);
    for (Index index : digest) {
      if (index.equals(root)) {
        // skip the root
        continue;
View Full Code Here

  private void processSharedWithOther() throws Hive2HiveException {
    /** Add the new user to the permission list of the folder index */
    UserProfileManager profileManager = networkManager.getSession().getProfileManager();
    String pid = UUID.randomUUID().toString();
    UserProfile userProfile = profileManager.getUserProfile(pid, true);
    FolderIndex index = (FolderIndex) userProfile.getFileById(sharedIndex.getFilePublicKey());
    if (index == null) {
      throw new Hive2HiveException("I'm not the newly shared user but don't have the shared folder");
    }

    index.addUserPermissions(addedFriend);
    profileManager.readyToPut(userProfile, pid);
  }
View Full Code Here

      throw new ProcessExecutionException("Not allowed to delete this file (read-only permissions)");
    }

    // check preconditions
    if (index.isFolder()) {
      FolderIndex folder = (FolderIndex) index;
      if (!folder.getChildren().isEmpty()) {
        throw new ProcessExecutionException("Cannot delete a directory that is not empty.");
      }
    }

    // remove the node from the tree
    FolderIndex parentIndex = index.getParent();
    parentIndex.removeChild(index);

    // store for later
    context.provideIndex(index);
    context.setParentNode(parentIndex);

    // store for rollback
    this.parentIndexKey = parentIndex.getFilePublicKey();

    try {
      profileManager.readyToPut(profile, getID());
    } catch (PutFailedException e) {
      throw new ProcessExecutionException("Could not put user profile.");
View Full Code Here

        return;
      }

      // TODO this is buggy! rather use list to check for containment instead of above if-statement
      // re-add file to user profile
      FolderIndex parent = (FolderIndex) profile.getFileById(parentIndexKey);
      parent.addChild(index);
      index.setParent(parent);

      try {
        profileManager.readyToPut(profile, getID());
      } catch (PutFailedException e) {
View Full Code Here

  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    Index index = context.consumeIndex();

    try {
      if (index.isFolder()) {
        FolderIndex folderIndex = (FolderIndex) index;
        initForFolder(folderIndex);
      } else {
        FileIndex fileIndex = (FileIndex) index;
        initForFile(fileIndex);
      }
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.