Search in sources :

Example 1 with UserRecommendedArtistsParserImpl

use of com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl in project musiccabinet by hakko.

the class JdbcUserRecommendedArtistsDaoTest method loadFunctionDependency.

@Before
public void loadFunctionDependency() throws ApplicationException {
    PostgreSQLUtil.loadFunction(dao, UPDATE_USER_RECOMMENDED_ARTISTS);
    joanRec = new UserRecommendedArtists(joan, new UserRecommendedArtistsParserImpl(new ResourceUtil(JOAN_FILE).getInputStream()).getArtists());
    rjRec = new UserRecommendedArtists(rj, new UserRecommendedArtistsParserImpl(new ResourceUtil(RJ_FILE).getInputStream()).getArtists());
    String body = new WSResponse(new ResourceUtil(FTPAREA_FILE).getContent()).getResponseBody();
    ftpareaRec = new UserRecommendedArtists(ftparea, new UserRecommendedArtistsParserImpl(new StringUtil(body).getInputStream()).getArtists());
    createArtistMetaData();
}
Also used : UserRecommendedArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) UserRecommendedArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) Before(org.junit.Before)

Example 2 with UserRecommendedArtistsParserImpl

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

Aggregations

UserRecommendedArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists)2 UserRecommendedArtistsParserImpl (com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl)2 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)2 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)2 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 UserRecommendedArtistsParser (com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParser)1 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1