Search in sources :

Example 6 with LastFmUser

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

the class JdbcWebserviceHistoryDaoTest method differentUsersDontInterfere.

@Test
public void differentUsersDontInterfere() {
    Calltype TOP_ARTISTS = Calltype.USER_GET_TOP_ARTISTS;
    LastFmUser user1 = new LastFmUser("user1");
    LastFmUser user2 = new LastFmUser("user2");
    WebserviceInvocation topArtists1 = new WebserviceInvocation(TOP_ARTISTS, user1, OVERALL.getDays());
    WebserviceInvocation topArtists2 = new WebserviceInvocation(TOP_ARTISTS, user2, OVERALL.getDays());
    deleteWebserviceInvocations();
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists2));
    dao.logWebserviceInvocation(topArtists2);
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
}
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)

Example 7 with LastFmUser

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

the class JdbcWebserviceHistoryDaoTest method periodIsSignificantForAllowance.

@Test
public void periodIsSignificantForAllowance() {
    Calltype TOP_ARTISTS = Calltype.USER_GET_TOP_ARTISTS;
    LastFmUser user = new LastFmUser("arnathalon");
    WebserviceInvocation topArtists1 = new WebserviceInvocation(TOP_ARTISTS, user, OVERALL.getDays());
    WebserviceInvocation topArtists2 = new WebserviceInvocation(TOP_ARTISTS, user, SIX_MONTHS.getDays());
    deleteWebserviceInvocations();
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists2));
    dao.logWebserviceInvocation(topArtists1);
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists1));
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists2));
    dao.logWebserviceInvocation(topArtists2);
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists1));
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
}
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)

Example 8 with LastFmUser

use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser 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 9 with LastFmUser

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

the class UserTopArtistsService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    List<LastFmUser> users = lastFmSettingsService.getLastFmUsers();
    setTotalOperations(users.size() * Period.values().length);
    List<UserTopArtists> userTopArtists = new ArrayList<>();
    for (LastFmUser user : users) {
        for (Period period : Period.values()) {
            try {
                WSResponse wsResponse = userTopArtistsClient.getUserTopArtists(user, period);
                if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                    StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                    UserTopArtistsParser parser = new UserTopArtistsParserImpl(stringUtil.getInputStream());
                    userTopArtists.add(new UserTopArtists(user, period, parser.getArtists()));
                }
            } catch (ApplicationException e) {
                LOG.warn("Fetching top artist for " + user.getLastFmUsername() + ", " + period.getDescription() + " failed.", e);
            }
            addFinishedOperation();
        }
    }
    userTopArtistsDao.createUserTopArtists(userTopArtists);
}
Also used : UserTopArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParserImpl) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) UserTopArtistsParser(com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParser) ArrayList(java.util.ArrayList) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Period(com.github.hakko.musiccabinet.domain.model.library.Period) UserTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Example 10 with LastFmUser

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

the class UserRecommendedArtistsClient method getUserRecommendedArtists.

public WSResponse getUserRecommendedArtists(String lastFmUsername) throws ApplicationException {
    LastFmUser user = lastFmDao.getLastFmUser(lastFmUsername);
    WebserviceInvocation webserviceInvocation = new WebserviceInvocation(USER_GET_RECOMMENDED_ARTISTS, user);
    List<NameValuePair> params = getDefaultParameterList();
    params.add(new BasicNameValuePair(PARAM_METHOD, METHOD));
    params.add(new BasicNameValuePair(PARAM_LIMIT, "100"));
    params.add(new BasicNameValuePair(PARAM_SK, user.getSessionKey()));
    return executeWSRequest(webserviceInvocation, params);
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)

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