Esempio n. 1
0
  @Test
  public void testFileHistoryInitEmpty() {
    PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));

    assertEquals(FileHistoryId.parseFileId("1234"), fileHistory.getFileHistoryId());
    assertNotSame(FileHistoryId.parseFileId("9999"), fileHistory.getFileHistoryId());
    assertNull(fileHistory.getLastVersion());
    assertNotNull(fileHistory.toString());
    assertTrue(fileHistory.toString().contains("1234"));
    assertNotNull(fileHistory.getFileVersions());
    assertEquals(0, fileHistory.getFileVersions().size());
  }
Esempio n. 2
0
  @Test
  public void testFileHistoryClone() {
    FileVersion fileVersion1 = new FileVersion();
    fileVersion1.setVersion(1L);
    fileVersion1.setPath("/somepath");

    FileVersion fileVersion2 = new FileVersion();
    fileVersion2.setVersion(2L);
    fileVersion2.setPath("/somepath");

    PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
    fileHistory.addFileVersion(fileVersion1);
    fileHistory.addFileVersion(fileVersion2);

    PartialFileHistory fileHistoryClone = fileHistory.clone();

    assertEquals(fileHistory, fileHistoryClone);
    assertEquals(fileHistory.getFileVersions().size(), fileHistoryClone.getFileVersions().size());
    assertEquals(fileHistory.getFileVersions(), fileHistoryClone.getFileVersions());

    FileVersion fileVersion3 = new FileVersion();
    fileVersion3.setVersion(3L);
    fileVersion3.setPath("/somepath");

    fileHistoryClone.addFileVersion(fileVersion3);
    assertEquals(
        fileHistory.getFileVersions().size() + 1, fileHistoryClone.getFileVersions().size());
  }
Esempio n. 3
0
  private void handleGetFileRequest(GetFileRequest fileRequest) {
    try {
      FileHistoryId fileHistoryId = FileHistoryId.parseFileId(fileRequest.getFileHistoryId());
      long version = fileRequest.getVersion();

      FileVersion fileVersion = localDatabase.getFileVersion(fileHistoryId, version);
      FileContent fileContent = localDatabase.getFileContent(fileVersion.getChecksum(), true);
      Map<ChunkChecksum, MultiChunkId> multiChunks =
          localDatabase.getMultiChunkIdsByChecksums(fileContent.getChunks());

      TransferManager transferManager =
          config.getTransferPlugin().createTransferManager(config.getConnection());
      Downloader downloader = new Downloader(config, transferManager);
      Assembler assembler = new Assembler(config, localDatabase);

      downloader.downloadAndDecryptMultiChunks(new HashSet<MultiChunkId>(multiChunks.values()));

      File tempFile = assembler.assembleToCache(fileVersion);
      String tempFileToken = StringUtil.toHex(ObjectId.secureRandomBytes(40));

      GetFileResponse fileResponse =
          new GetFileResponse(fileRequest.getId(), fileRequest.getRoot(), tempFileToken);
      GetFileResponseInternal fileResponseInternal =
          new GetFileResponseInternal(fileResponse, tempFile);

      eventBus.post(fileResponseInternal);
    } catch (Exception e) {
      logger.log(Level.WARNING, "Cannot reassemble file.", e);
      eventBus.post(new BadRequestResponse(fileRequest.getId(), "Cannot reassemble file."));
    }
  }
Esempio n. 4
0
 private PartialFileHistory createNewFileHistory(PartialFileHistory lastFileHistory) {
   if (lastFileHistory == null) {
     FileHistoryId newFileHistoryId = FileHistoryId.secureRandomFileId();
     return new PartialFileHistory(newFileHistoryId);
   } else {
     return new PartialFileHistory(lastFileHistory.getFileHistoryId());
   }
 }
Esempio n. 5
0
  private void handleGetFileHistoryRequest(GetFileHistoryRequest fileHistoryRequest) {
    FileHistoryId fileHistoryId = FileHistoryId.parseFileId(fileHistoryRequest.getFileHistoryId());
    List<FileVersion> fileHistory = localDatabase.getFileHistory(fileHistoryId);
    GetFileHistoryResponse fileHistoryRespose =
        new GetFileHistoryResponse(
            fileHistoryRequest.getId(), fileHistoryRequest.getRoot(), fileHistory);

    eventBus.post(fileHistoryRespose);
  }
Esempio n. 6
0
  private void handleRestoreRequest(RestoreRequest restoreRequest) {
    RestoreOperationOptions restoreOptions = new RestoreOperationOptions();

    restoreOptions.setFileHistoryId(FileHistoryId.parseFileId(restoreRequest.getFileHistoryId()));
    restoreOptions.setFileVersion(restoreRequest.getVersion());

    try {
      RestoreOperationResult restoreResult = new RestoreOperation(config, restoreOptions).execute();

      RestoreResponse restoreResponse =
          new RestoreResponse(restoreRequest.getId(), restoreResult.getTargetFile());
      eventBus.post(restoreResponse);
    } catch (Exception e) {
      logger.log(Level.WARNING, "BadRequestResponse: Cannot restore file.");
      eventBus.post(new BadRequestResponse(restoreRequest.getId(), "Cannot restore file."));
    }
  }
Esempio n. 7
0
  @Test
  public void testFileHistoryIdRandom() {
    FileHistoryId secureRandomFileId1 = FileHistoryId.secureRandomFileId();
    FileHistoryId secureRandomFileId2 = FileHistoryId.secureRandomFileId();

    assertNotNull(secureRandomFileId1);
    assertEquals(20 * 2, secureRandomFileId1.toString().length());

    assertNotSame(secureRandomFileId1, secureRandomFileId2);
    assertNotNull(secureRandomFileId2);
    assertEquals(20 * 2, secureRandomFileId2.toString().length());
  }
Esempio n. 8
0
  @Test
  public void testFileHistoryGetVersionsNonEmpty() {
    FileVersion fileVersion = new FileVersion();
    fileVersion.setVersion(5L);
    fileVersion.setPath("/somepath");

    PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
    fileHistory.addFileVersion(fileVersion);

    assertNotNull(fileHistory.getLastVersion());
    assertNotNull(fileHistory.getFileVersions());
    assertEquals(1, fileHistory.getFileVersions().size());
    assertEquals(fileVersion, fileHistory.getLastVersion());
    assertNull(fileHistory.getFileVersions().get(1L));
    assertNull(fileHistory.getFileVersion(1L));
    assertEquals(fileVersion, fileHistory.getFileVersions().get(5L));
    assertEquals(fileVersion, fileHistory.getFileVersion(5L));
  }
  private void sendLsFolderRequest(String root, FileHistoryId fileHistoryId) {
    // Create list request
    LsOperationOptions lsOptions = new LsOperationOptions();

    lsOptions.setPathExpression(fileHistoryId.toString());
    lsOptions.setFileHistoryId(true);
    lsOptions.setRecursive(false);
    lsOptions.setDeleted(true);
    lsOptions.setFetchHistories(true);
    lsOptions.setFileTypes(Sets.newHashSet(FileType.FILE, FileType.SYMLINK));

    LsFolderRequest lsRequest = new LsFolderRequest();

    lsRequest.setRoot(root);
    lsRequest.setOptions(lsOptions);

    logger.log(
        Level.INFO,
        "Detail panel: Sending LsRequest with ID #" + lsRequest.getId() + " for " + root + " ...");

    // Send request
    pendingLsFolderRequests.put(lsRequest.getId(), lsRequest);
    eventBus.post(lsRequest);
  }
Esempio n. 10
0
 @Test(expected = IllegalArgumentException.class)
 public void testFileHistoryAddFileVersionInvalidVersionNull() {
   PartialFileHistory fileHistory = new PartialFileHistory(FileHistoryId.parseFileId("1234"));
   fileHistory.addFileVersion(new FileVersion());
 }
Esempio n. 11
0
 @Test(expected = IllegalArgumentException.class)
 public void testFileHistoryIdInvalidNull() {
   FileHistoryId.parseFileId(null);
 }
Esempio n. 12
0
 @Test
 public void testFileHistoryIdParsedOk() {
   assertEquals("12", FileHistoryId.parseFileId("12").toString());
 }