Search in sources :

Example 1 with UserTopArtistsParser

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

Aggregations

UserTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists)1 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)1 Period (com.github.hakko.musiccabinet.domain.model.library.Period)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 UserTopArtistsParser (com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParser)1 UserTopArtistsParserImpl (com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParserImpl)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 ArrayList (java.util.ArrayList)1