Search in sources :

Example 1 with UserLovedTracksParserImpl

use of com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParserImpl 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 UserLovedTracksParserImpl

use of com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParserImpl 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 UserLovedTracksParserImpl

use of com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParserImpl 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)

Aggregations

UserLovedTracks (com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks)3 UserStarredTrack (com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack)3 Track (com.github.hakko.musiccabinet.domain.model.music.Track)3 UserLovedTracksParserImpl (com.github.hakko.musiccabinet.parser.lastfm.UserLovedTracksParserImpl)3 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)2 Test (org.junit.Test)2 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 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 ArrayList (java.util.ArrayList)1