use of com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent in project musiccabinet by hakko.
the class DirectoryBrowserService method getContent.
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, BasicFileAttributeView.class);
BasicFileAttributes attr = view.readAttributes();
if (attr.isDirectory()) {
foundSubDirs.add(file.toAbsolutePath().toString());
} else if (attr.isRegularFile()) {
foundFiles.add(new File(file, attr));
}
}
} catch (IOException | DirectoryIteratorException e) {
throw new ApplicationContextException("Couldn't read " + dir.getPath(), e);
}
return content;
}
use of com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent in project musiccabinet by hakko.
the class LibraryScanner method postVisitDirectory.
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e) {
DirectoryContent content = map.get(dir);
libraryPresenceChannel.send(new GenericMessage<DirectoryContent>(content));
map.remove(dir);
return CONTINUE;
}
use of com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent in project musiccabinet by hakko.
the class LibraryScanner method visitFile.
@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;
}
use of com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent in project musiccabinet by hakko.
the class LibraryPresenceServiceTest method delegatesHandlingOfAddedAndDeletedResources.
@Test
public void delegatesHandlingOfAddedAndDeletedResources() {
LibraryPresenceDao presenceDao = mock(LibraryPresenceDao.class);
when(presenceDao.getFiles(dir1)).thenReturn(set(file1, file2, file3));
when(presenceDao.getSubdirectories(dir1)).thenReturn(set(dir2));
presenceService.setLibraryPresenceDao(presenceDao);
file2b.setSize(file2.getSize() + 1);
PollableChannel presenceChannel = presenceService.libraryPresenceChannel;
presenceChannel.send(LibraryUtil.msg(dir1, set(dir2), set(file1, file2b)));
presenceChannel.send(FINISHED_MESSAGE);
presenceService.receive();
Message<?> additionMessage, deletionMessage;
assertNotNull(additionMessage = presenceService.libraryMetadataChannel.receive());
assertNotNull(deletionMessage = presenceService.libraryDeletionChannel.receive());
assertEquals(FINISHED_MESSAGE, presenceService.libraryMetadataChannel.receive());
assertEquals(FINISHED_MESSAGE, presenceService.libraryDeletionChannel.receive());
Set<File> addedFiles = ((DirectoryContent) additionMessage.getPayload()).getFiles();
Set<File> deletedFiles = ((DirectoryContent) deletionMessage.getPayload()).getFiles();
assertEquals(set(file2b), addedFiles);
assertEquals(set(file2, file3), deletedFiles);
}
use of com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent in project musiccabinet by hakko.
the class DirectoryBrowserServiceTest method addedSubdirectoryDetectedWhenListingFiles.
@Test
public void addedSubdirectoryDetectedWhenListingFiles() throws ApplicationException, IOException {
scannerService.add(set(media1));
File newDir = new File(media1 + separatorChar + "newdir");
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();
}
Aggregations