Search in sources :

Example 1 with UserLovedTracks

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);
}
Also used : UserLovedTracksParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParserImpl) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) UserLovedTracks(com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks) UserStarredTrack(com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Example 2 with UserLovedTracks

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);
}
Also used : UserLovedTracksParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParserImpl) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) UserLovedTracks(com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks) UserStarredTrack(com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Example 3 with UserLovedTracks

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());
    }
}
Also used : UserStarredTrack(com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack) ArrayList(java.util.ArrayList) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) UserLovedTracks(com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks) UserLovedTracksParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParserImpl) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) UserLovedTracksParser(com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParser) UserStarredTrack(com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack) Track(com.github.hakko.musiccabinet.domain.model.music.Track)

Example 4 with UserLovedTracks

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();
    }
}
Also used : UserLovedTracks(com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks)

Example 5 with UserLovedTracks

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)));
}
Also used : UnittestLibraryUtil.getFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile) File(com.github.hakko.musiccabinet.domain.model.library.File) UnittestLibraryUtil.submitFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.submitFile) UserLovedTracks(com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks) UserStarredTrack(com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Aggregations

UserLovedTracks (com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks)5 UserStarredTrack (com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack)4 Track (com.github.hakko.musiccabinet.domain.model.music.Track)4 UserLovedTracksParserImpl (com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParserImpl)3 Test (org.junit.Test)3 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)2 File (com.github.hakko.musiccabinet.domain.model.library.File)1 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)1 UserLovedTracksParser (com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParser)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)1 UnittestLibraryUtil.submitFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.submitFile)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 ArrayList (java.util.ArrayList)1