Package com.github.hakko.musiccabinet.domain.model.aggr

Examples of com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent


  @Test
  public void noChangesWhenListingFiles() throws ApplicationException {
    scannerService.add(set(media1));
    Directory dirMedia1 = getFirstRootDirectory();
   
    DirectoryContent found = browserService.getDirectoryDiff(dirMedia1.getId());
   
    Assert.assertTrue(found.getFiles().isEmpty());
    Assert.assertTrue(found.getSubDirectories().isEmpty());
  }
View Full Code Here


    newDir.mkdir();
    newDir.deleteOnExit();
   
    Directory dirMedia1 = getFirstRootDirectory();
   
    DirectoryContent found = browserService.getDirectoryDiff(dirMedia1.getId());
   
    Assert.assertTrue(found.getFiles().isEmpty());
    Assert.assertFalse(found.getSubDirectories().isEmpty());
    Assert.assertEquals(1, found.getSubDirectories().size());
    Assert.assertTrue(found.getSubDirectories().contains(newDir.getAbsolutePath()));
   
    newDir.delete();
  }
View Full Code Here

    newFile.createNewFile();
    newFile.deleteOnExit();
   
    Directory dirMedia1 = getFirstRootDirectory();
   
    DirectoryContent found = browserService.getDirectoryDiff(dirMedia1.getId());
   
    Assert.assertFalse(found.getFiles().isEmpty());
    Assert.assertTrue(found.getSubDirectories().isEmpty());
    Assert.assertEquals(1, found.getFiles().size());
    Assert.assertEquals(found.getFiles().iterator().next().getFilename(),
        newFile.getName());

    newFile.delete();
  }
View Full Code Here

      .setHeader(LibraryUtil.FINISHED, true).build();
 
  public static GenericMessage<DirectoryContent> msg(
      String directory, Set<String> subDirectories, Set<File> files) {
    return new GenericMessage<DirectoryContent>(
        new DirectoryContent(directory, subDirectories, files));
  }
View Full Code Here

    while (true) {
      message = (Message<DirectoryContent>) libraryAdditionChannel.receive();
      if (message == null || message.equals(FINISHED_MESSAGE)) {
        break;
      } else {
        DirectoryContent content = message.getPayload();
        String dir = content.getDirectory();
        libraryAdditionDao.addSubdirectories(dir, content.getSubDirectories());
        libraryAdditionDao.addFiles(dir, content.getFiles());
      }
    }
  }
View Full Code Here

    while (true) {
      message = (Message<DirectoryContent>) libraryDeletionChannel.receive();
      if (message == null || message.equals(FINISHED_MESSAGE)) {
        break;
      } else {
        DirectoryContent content = message.getPayload();
        String dir = content.getDirectory();
        libraryDeletionDao.deleteFiles(dir, content.getFiles());
        libraryDeletionDao.deleteSubdirectories(dir, content.getSubDirectories());
      }
    }
  }
View Full Code Here

  public DirectoryContent getDirectoryDiff(int directoryId) {
    Directory dir = dao.getDirectory(directoryId);

    Set<String> dbSubDirs = presenceDao.getSubdirectories(dir.getPath());
    Set<File> dbFiles = presenceDao.getFiles(dir.getPath());
    DirectoryContent found = getContent(dir);

    removeIntersection(dbSubDirs, found.getSubDirectories());
    removeIntersection(dbFiles, found.getFiles());
   
    return found;
  }
View Full Code Here

  }
 
  private DirectoryContent getContent(Directory dir) {
    Set<File> foundFiles = new HashSet<>();
    Set<String> foundSubDirs = new HashSet<>();
    DirectoryContent content = new DirectoryContent(dir.getPath(), foundSubDirs, foundFiles);
   
    Path path = Paths.get(dir.getPath());
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
        for (Path file: stream) {
          BasicFileAttributeView view = getFileAttributeView(file,
View Full Code Here

    this.libraryPresenceChannel = libraryPresenceChannel;
  }

  @Override
    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
      DirectoryContent parentContent = map.get(dir.getParent());
      if (parentContent != null) {
        parentContent.getSubDirectories().add(dir.toString());
      }
      map.put(dir, new DirectoryContent(dir.toString()));
     
      return CONTINUE;
    }
View Full Code Here

      return CONTINUE;
    }
 
    @Override
    public FileVisitResult visitFile(Path file, BasicFileAttributes attr) {
      DirectoryContent directoryContent = map.get(file.getParent());
      if (attr.size() > Integer.MAX_VALUE) {
        LOG.warn(file.getFileName() + " has actual file size " + attr.size());
      }
      directoryContent.getFiles().add(new File(file, attr));
     
      return CONTINUE;
    }
View Full Code Here

TOP

Related Classes of com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent

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.