Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.UserProfile


          FileUtils.readFileToString(synchronizedFile));
    }
  }

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


      NoSessionException, NoPeerConnectionException, InvalidProcessStateException {
    // pick new client to test
    NetworkManager client = network.get(1);

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

    UserCredentials credentials = NetworkTestUtil.generateRandomCredentials();
    UseCaseTestUtil.register(credentials, client);

    // verify put user profile
    UserProfile getUserProfile = UseCaseTestUtil.getUserProfile(otherClient, credentials);

    assertNotNull(getUserProfile);
    assertEquals(credentials.getUserId(), getUserProfile.getUserId());

    // verify put locations
    FutureGet getLocations = otherClient.getDataManager().getUnblocked(
        new Parameters().setLocationKey(credentials.getUserId()).setContentKey(
            H2HConstants.USER_LOCATIONS));
View Full Code Here

  @Test
  public void testPutException() throws GetFailedException, IOException, NoPeerConnectionException {
    UseCaseTestUtil.register(userCredentials, client);
    UserProfileManager profileManager = new UserProfileManager(client.getDataManager(), userCredentials);
    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

    File file = context.getFile();

    logger.trace("Check write access in folder '{}' to add file '{}'.", file
        .getParentFile().getName(), file.getName());

    UserProfile userProfile = null;
    try {
      // fetch user profile (only read)
      userProfile = profileManager.getUserProfile(getID(), false);
    } 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
View Full Code Here

      logger.error("Cannot answer because session is invalid");
      sendDirectResponse(createResponse(null));
      return;
    }

    UserProfile userProfile;
    try {
      UserProfileManager profileManager = session.getProfileManager();
      userProfile = profileManager.getUserProfile(messageID, false);
    } catch (GetFailedException e) {
      logger.error("Cannot get the user profile", e);
      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

      profileManager = networkManager.getSession().getProfileManager();
    } catch (NoSessionException e) {
      throw new ProcessExecutionException(e);
    }

    UserProfile profile = null;
    try {
      profile = profileManager.getUserProfile(getID(), false);
    } catch (GetFailedException e) {
      throw new ProcessExecutionException("User profile could not be loaded.");
    }
View Full Code Here

    this.networkManager = networkManager;
  }

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    UserProfile userProfile = context.consumeUserProfile();

    H2HSession session;
    try {
      // get the persistently cached items
      PersistentMetaData metaData = FileUtil.readPersistentMetaData(params.getRoot());

      // create the key manager
      PublicKeyManager keyManager = new PublicKeyManager(userProfile.getUserId(),
          userProfile.getEncryptionKeys(), networkManager.getDataManager());

      // read eventually cached keys and add them to the key manager
      Map<String, PublicKey> publicKeyCache = metaData.getPublicKeyCache();
      for (String userId : publicKeyCache.keySet()) {
        keyManager.putPublicKey(userId, publicKeyCache.get(userId));
View Full Code Here

    // - file moved from other source to root
    // - file moved from other source to other destination
    // Additionally, the file can be renamed (within any directory)
    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
View Full Code Here

  protected void doRollback(RollbackReason reason) throws InvalidProcessStateException {
    // only when user profile has been updated
    if (profileUpdated) {
      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());
View Full Code Here

TOP

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

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.