use of com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks in project musiccabinet by hakko.
the class JdbcUserLovedTracksDaoTest method deletesUnlovedTracksIdentifiedInImport.
@Test
public void deletesUnlovedTracksIdentifiedInImport() throws ApplicationException {
List<Track> lovedTracks = new UserLovedTracksParserImpl(new ResourceUtil(LOVED_TRACKS_FILE).getInputStream()).getLovedTracks();
dao.createLovedTracks(asList(new UserLovedTracks(USERNAME1, lovedTracks)));
lovedTracks.remove(0);
dao.createLovedTracks(asList(new UserLovedTracks(USERNAME1, lovedTracks)));
List<Track> dbLovedTracks = dao.getLovedTracks(USERNAME1);
Collections.sort(lovedTracks);
Collections.sort(dbLovedTracks);
assertEquals(lovedTracks, dbLovedTracks);
}
use of com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks in project musiccabinet by hakko.
the class JdbcUserLovedTracksDaoTest method createAndRetrievesUserLovedTracks.
@Test
public void createAndRetrievesUserLovedTracks() throws ApplicationException {
List<Track> lovedTracks = new UserLovedTracksParserImpl(new ResourceUtil(LOVED_TRACKS_FILE).getInputStream()).getLovedTracks();
dao.createLovedTracks(asList(new UserLovedTracks(USERNAME1, lovedTracks)));
List<Track> dbLovedTracks = dao.getLovedTracks(USERNAME1);
Collections.sort(lovedTracks);
Collections.sort(dbLovedTracks);
assertEquals(lovedTracks, dbLovedTracks);
}
use of com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks in project musiccabinet by hakko.
the class UserLovedTracksService method updateUserLovedTracks.
private void updateUserLovedTracks() throws ApplicationException {
List<LastFmUser> users = lastFmSettingsService.getLastFmUsers();
setTotalOperations(users.size());
List<UserLovedTracks> userLovedTracks = new ArrayList<>();
for (LastFmUser user : users) {
short page = 0, totalPages = 0;
List<Track> lovedTracks = new ArrayList<>();
do {
WSResponse wsResponse = userLovedTracksClient.getUserLovedTracks(user, page);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
UserLovedTracksParser parser = new UserLovedTracksParserImpl(stringUtil.getInputStream());
totalPages = parser.getTotalPages();
lovedTracks.addAll(parser.getLovedTracks());
}
} while (++page < totalPages);
addFinishedOperation();
userLovedTracks.add(new UserLovedTracks(user.getLastFmUsername(), lovedTracks));
}
userLovedTracksDao.createLovedTracks(userLovedTracks);
for (UserStarredTrack ust : userLovedTracksDao.getStarredButNotLovedTracks()) {
trackLoveClient.love(ust.getStarredTrack(), ust.getLastFmUser());
}
}
use of com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks in project musiccabinet by hakko.
the class JdbcUserLovedTracksDao method createLovedTracks.
@Override
public void createLovedTracks(List<UserLovedTracks> userLovedTracks) {
if (userLovedTracks.size() > 0) {
clearImportTable();
for (UserLovedTracks ult : userLovedTracks) {
batchInsert(ult.getLastFmUsername(), ult.getLovedTracks());
}
updateLibrary();
}
}
use of com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks in project musiccabinet by hakko.
the class JdbcUserLovedTracksDaoTest method onlyTracksFromEarliestAlbumsAreStarredWhenImportingLovedTracks.
@Test
public void onlyTracksFromEarliestAlbumsAreStarredWhenImportingLovedTracks() {
File f1, f2, f3, f4, f5;
deleteLovedAndStarredTracks();
additionDao.getJdbcTemplate().execute("truncate library.directory cascade");
submitFile(additionDao, asList(f1 = getFile(artistName1, albumName1, trackName1, (short) 2006), f2 = getFile(artistName1, albumName2, trackName1, (short) 1999), f3 = getFile(artistName2, albumName1, trackName2, (short) 2010), f4 = getFile(artistName2, albumName2, trackName2, (short) 2011), f5 = getFile(artistName2, albumName3, trackName2, (short) 2012)));
dao.createLovedTracks(asList(new UserLovedTracks(USERNAME1, asList(new Track(artistName1, trackName1))), new UserLovedTracks(USERNAME2, asList(new Track(artistName2, trackName2)))));
assertFalse(browserDao.getTrackId(f1) == browserDao.getTrackId(f2));
assertFalse(browserDao.getTrackId(f3) == browserDao.getTrackId(f4));
assertFalse(browserDao.getTrackId(f3) == browserDao.getTrackId(f5));
assertEquals(asList(browserDao.getTrackId(f2)), starDao.getStarredTrackIds(lastFmDao.getLastFmUser(USERNAME1)));
assertEquals(asList(browserDao.getTrackId(f3)), starDao.getStarredTrackIds(lastFmDao.getLastFmUser(USERNAME2)));
}
Aggregations