Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.Index


      try {
        UserProfileManager profileManager = networkManager.getSession().getProfileManager();
        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) {
View Full Code Here


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

        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) {
View Full Code Here

    try {
      H2HSession session = networkManager.getSession();
      UserProfileManager profileManager = session.getProfileManager();
      UserProfile userProfile = profileManager.getUserProfile(UUID.randomUUID().toString(), false);

      Index oldParent = userProfile.getFileById(oldParentKey);
      Index newParent = userProfile.getFileById(newParentKey);
      FileUtil.moveFile(session.getRoot(), sourceFileName, destFileName, oldParent, newParent);
    } catch (NoSessionException | GetFailedException | IOException e) {
      logger.error("Could not process the notification message.", e);
    }
View Full Code Here

    this.networkManager = networkManager;
  }

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    Index file = context.consumeIndex();
    logger.debug("Try creating a new folder '{}' on disk.", file.getName());
    try {
      // create the folder on disk
      File folder = FileUtil.getPath(networkManager.getSession().getRoot(), file).toFile();
      if (folder.exists()) {
        throw new FileAlreadyExistsException("Folder already exists");
      } else if (!folder.mkdir()) {
        existedBefore = true;
        throw new IOException("Folder could not be created");
      }
    } catch (IOException | NoSessionException e) {
      throw new ProcessExecutionException(e);
    }

    // done with 'downloading' the file
    logger.debug("New folder '{}' has successfuly been created on disk.", file.getName());
  }
View Full Code Here

  public void start() {
    try {
      H2HSession session = networkManager.getSession();

      // remove dead link from user profile
      Index toDelete = updateUserProfile(session.getProfileManager());

      if (toDelete == null)
        return;

      // remove the file on disk
View Full Code Here

  private Index updateUserProfile(UserProfileManager profileManager) throws GetFailedException,
      PutFailedException {
    String randomPID = UUID.randomUUID().toString();

    UserProfile userProfile = profileManager.getUserProfile(randomPID, true);
    Index toDelete = userProfile.getFileById(fileKey);
    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;
    }
View Full Code Here

      userProfile = profileManager.getUserProfile(getID(), false);
    } catch (GetFailedException | NoSessionException e) {
      throw new ProcessExecutionException(e);
    }

    Index index = userProfile.getFileById(context.getFileKey());
    if (index == null) {
      throw new ProcessExecutionException("File key not found in user profile.");
    }

    context.provideIndex(index);

    // add the next steps here
    if (index.isFolder()) {
      logger.info("No download of the file needed since '{}' is a folder.", index.getFullPath());
      getParent().add(new CreateFolderStep(context, networkManager));
    } else {
      logger.info("Initalize the process for downloading file '{}'.", index.getFullPath());
      try {
        IDataManager dataManager = networkManager.getDataManager();
        getParent().add(new GetMetaFileStep(context, context, dataManager));
        PeerAddress ownPeerAddress = networkManager.getConnection().getPeer().getPeerAddress();
        getParent().add(
View Full Code Here

    this.dataManager = dataManager;
  }

  @Override
  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

      H2HSession session = networkManager.getSession();
      String pid = UUID.randomUUID().toString();

      Path root = session.getRoot();
      UserProfile userProfile = session.getProfileManager().getUserProfile(pid, false);
      Index parentNode = userProfile.getFileById(parentFileKey);

      if (parentNode == null) {
        throw new FileNotFoundException("Got notified about a file we don't know the parent of.");
      } else {
        boolean deleted = new File(FileUtil.getPath(root, parentNode).toFile(), fileName).delete();
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.