Search in sources :

Example 26 with LastFmUser

use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.

the class UserStarredTrackRowMapper method mapRow.

@Override
public UserStarredTrack mapRow(ResultSet rs, int rowNum) throws SQLException {
    String username = rs.getString(1);
    String sessionKey = rs.getString(2);
    String artistName = rs.getString(3);
    String trackName = rs.getString(4);
    return new UserStarredTrack(new LastFmUser(username, sessionKey), new Track(artistName, trackName));
}
Also used : UserStarredTrack(com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Track(com.github.hakko.musiccabinet.domain.model.music.Track) UserStarredTrack(com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack)

Example 27 with LastFmUser

use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.

the class UserRecommendedArtistsService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    List<LastFmUser> users = lastFmSettingsService.getLastFmUsers();
    setTotalOperations(users.size());
    List<UserRecommendedArtists> artists = new ArrayList<>();
    for (LastFmUser user : users) {
        try {
            WSResponse wsResponse = userRecommendedArtistsClient.getUserRecommendedArtists(user.getLastFmUsername());
            LOG.debug(wsResponse);
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                UserRecommendedArtistsParser parser = new UserRecommendedArtistsParserImpl(stringUtil.getInputStream());
                artists.add(new UserRecommendedArtists(user, parser.getArtists()));
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching top artist for " + user.getLastFmUsername() + " failed.", e);
        }
        addFinishedOperation();
    }
    dao.createUserRecommendedArtists(artists);
}
Also used : UserRecommendedArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) UserRecommendedArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl) UserRecommendedArtistsParser(com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParser) ArrayList(java.util.ArrayList) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Example 28 with LastFmUser

use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.

the class JdbcMusicBrainzAlbumDaoTest method findsAlbumsMissingFromLibraryWithRecentlyPlayedFilter.

@Test
public void findsAlbumsMissingFromLibraryWithRecentlyPlayedFilter() {
    List<MBAlbum> albums = albumDao.getMissingAlbums(null, null, USER, 10, 0);
    assertEquals(0, albums.size());
    LastFmUser lastFmUser = new LastFmUser(USER);
    lastFmDao.createOrUpdateLastFmUser(lastFmUser);
    submitFile(additionDao, getFile(artist.getName(), UNKNOWN, UNKNOWN));
    Track track = browserDao.getTracks(browserDao.getRandomTrackIds(1)).get(0);
    playCountDao.addPlayCount(lastFmUser, track);
    albums = albumDao.getMissingAlbums(null, null, USER, 10, 0);
    assertEquals(2, albums.size());
}
Also used : LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) MBAlbum(com.github.hakko.musiccabinet.domain.model.music.MBAlbum) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Test(org.junit.Test)

Example 29 with LastFmUser

use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.

the class JdbcPlayCountDaoTest method prepareTestData.

@Before
public void prepareTestData() throws ApplicationException {
    dao.getJdbcTemplate().execute("truncate music.lastfmuser cascade");
    dao.getJdbcTemplate().execute("truncate library.file cascade");
    dao.getJdbcTemplate().execute("truncate music.artist cascade");
    user1 = new LastFmUser(username1 = "user1");
    user2 = new LastFmUser(username2 = "user2");
    lastFmDao.createOrUpdateLastFmUser(user1);
    lastFmDao.createOrUpdateLastFmUser(user2);
    File file1 = UnittestLibraryUtil.getFile("artist1", "album1", "title1");
    File file2 = UnittestLibraryUtil.getFile("artist1", "album1", "title2");
    File file3 = UnittestLibraryUtil.getFile("artist2", "album2", "title3");
    submitFile(additionDao, Arrays.asList(file1, file2, file3));
    List<Artist> artists = browserDao.getArtists();
    assertEquals(2, artists.size());
    artist1 = artists.get(0);
    artist2 = artists.get(1);
    List<Album> albums1 = browserDao.getAlbums(artist1.getId(), true);
    assertEquals(1, albums1.size());
    album1 = albums1.get(0);
    List<Album> albums2 = browserDao.getAlbums(artist2.getId(), true);
    assertEquals(1, albums2.size());
    album2 = albums2.get(0);
    List<Track> tracks1 = browserDao.getTracks(album1.getTrackIds());
    Collections.sort(tracks1, trackComparator);
    assertEquals(2, tracks1.size());
    track1a = tracks1.get(0);
    track1b = tracks1.get(1);
    List<Track> tracks2 = browserDao.getTracks(album2.getTrackIds());
    assertEquals(1, tracks2.size());
    track2 = tracks2.get(0);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Album(com.github.hakko.musiccabinet.domain.model.music.Album) File(com.github.hakko.musiccabinet.domain.model.library.File) UnittestLibraryUtil.submitFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.submitFile) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Before(org.junit.Before)

Example 30 with LastFmUser

use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.

the class JdbcWebserviceHistoryDaoTest method importUserRelatedDataNotPossibleTwice.

@Test
public void importUserRelatedDataNotPossibleTwice() {
    Calltype TOP_ARTISTS = Calltype.USER_GET_TOP_ARTISTS;
    LastFmUser user = new LastFmUser("arnathalon");
    WebserviceInvocation topArtists = new WebserviceInvocation(TOP_ARTISTS, user, OVERALL.getDays());
    deleteWebserviceInvocations();
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists));
    dao.logWebserviceInvocation(topArtists);
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists));
}
Also used : Calltype(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Aggregations

LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)35 Test (org.junit.Test)14 Track (com.github.hakko.musiccabinet.domain.model.music.Track)9 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)7 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)7 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)7 NameValuePair (org.apache.http.NameValuePair)6 Scrobble (com.github.hakko.musiccabinet.domain.model.aggr.Scrobble)4 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)4 Before (org.junit.Before)4 Period (com.github.hakko.musiccabinet.domain.model.library.Period)3 Calltype (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype)3 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)3 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)3 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)3 ArrayList (java.util.ArrayList)3 UserStarredTrack (com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack)2 UserTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists)2 File (com.github.hakko.musiccabinet.domain.model.library.File)2 Album (com.github.hakko.musiccabinet.domain.model.music.Album)2