use of com.github.hakko.musiccabinet.domain.model.library.File in project musiccabinet by hakko.
the class JdbcLibraryDaoTest method storesFiles.
@Test
public void storesFiles() {
String d1 = "/d1", d2 = "/d1/d2";
File f1 = getFile(d1, "f1");
File f2a = getFile(d2, "f2a");
File f2b = getFile(d2, "f2b");
additionDao.addSubdirectories(null, set(d1));
additionDao.addSubdirectories(d1, set(d2));
additionDao.addFiles(d1, set(f1));
additionDao.addFiles(d2, set(f2a, f2b));
additionDao.updateLibrary();
Assert.assertEquals(set(f1), presenceDao.getFiles(d1));
Assert.assertEquals(set(f2a, f2b), presenceDao.getFiles(d2));
}
use of com.github.hakko.musiccabinet.domain.model.library.File 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.library.File in project musiccabinet by hakko.
the class LibraryMetadataService method receive.
@SuppressWarnings("unchecked")
@Override
public void receive() {
Message<DirectoryContent> message;
progress.reset();
progress.setFinishedOperations(0);
while (true) {
message = (Message<DirectoryContent>) libraryMetadataChannel.receive();
if (message == null || message.equals(FINISHED_MESSAGE)) {
libraryAdditionChannel.send(message);
break;
} else {
for (File file : message.getPayload().getFiles()) {
audioTagService.updateMetadata(file);
progress.addFinishedOperation();
}
libraryAdditionChannel.send(message);
}
}
}
use of com.github.hakko.musiccabinet.domain.model.library.File in project musiccabinet by hakko.
the class ArtistTopTracksServiceTest method clearLibraryAndAddCherTrack.
private void clearLibraryAndAddCherTrack() throws ApplicationException {
PostgreSQLUtil.truncateTables(artistTopTracksDao);
File file = getFile(artistName, null, "Believe");
UnittestLibraryUtil.submitFile(additionDao, file);
}
use of com.github.hakko.musiccabinet.domain.model.library.File in project musiccabinet by hakko.
the class UserLovedTracksServiceTest method updatesStarredTracksWhenImportIsOnlyAllowedForOneUser.
/*
* User story: user1 has starred track2, user2 has starred track3 & track4.
* When importing loved tracks, user2 is unavailable and user1 has loved track1.
* Expected outcome: afterwards, user1 has starred track1 & 2 and user2 track3 & 4.
*/
@Test
public void updatesStarredTracksWhenImportIsOnlyAllowedForOneUser() throws ApplicationException {
lastFmDao.createOrUpdateLastFmUser(new LastFmUser(USER1));
lastFmDao.createOrUpdateLastFmUser(new LastFmUser(USER2));
LastFmUser user1 = lastFmDao.getLastFmUser(USER1), user2 = lastFmDao.getLastFmUser(USER2);
Track track1 = new Track("Frank Ocean", "Lost"), track2 = new Track("Kate Bush", "Cloudbusting"), track3 = new Track("Adele", "Skyfall"), track4 = new Track("Kath Bloom", "Fall Again");
File f1, f2, f3, f4;
deleteLovedAndStarredTracks();
submitFile(additionDao, asList(f1 = getFile(track1), f2 = getFile(track2), f3 = getFile(track3), f4 = getFile(track4)));
int track1Id = browserDao.getTrackId(f1), track2Id = browserDao.getTrackId(f2), track3Id = browserDao.getTrackId(f3), track4Id = browserDao.getTrackId(f4);
LastFmSettingsService lastFmSettingsService = mock(LastFmSettingsService.class);
when(lastFmSettingsService.getLastFmUsers()).thenReturn(asList(user1, user2));
when(lastFmSettingsService.isSyncStarredAndLovedTracks()).thenReturn(true);
UserLovedTracksClient userLovedTracksClient = mock(UserLovedTracksClient.class);
when(userLovedTracksClient.getUserLovedTracks(user1, (short) 0)).thenReturn(new WSResponse(new ResourceUtil(LOVED_TRACKS_FILE, UTF8).getContent()));
when(userLovedTracksClient.getUserLovedTracks(user2, (short) 0)).thenReturn(new WSResponse(false, 403, "Forbidden"));
UserLovedTracksService userLovedTracksService = new UserLovedTracksService();
userLovedTracksService.setLastFmSettingsService(lastFmSettingsService);
userLovedTracksService.setUserLovedTracksClient(userLovedTracksClient);
userLovedTracksService.setUserLovedTracksDao(userLovedTracksDao);
userLovedTracksService.setStarService(mock(StarService.class));
userLovedTracksService.setTrackLoveClient(mock(TrackLoveClient.class));
starDao.starTrack(user1, track2Id);
starDao.starTrack(user2, track3Id);
starDao.starTrack(user2, track4Id);
userLovedTracksService.updateSearchIndex();
assertEquals(sort(asList(track1Id, track2Id)), sort(starDao.getStarredTrackIds(user1)));
assertEquals(sort(asList(track3Id, track4Id)), sort(starDao.getStarredTrackIds(user2)));
}
Aggregations