Search in sources :

Example 1 with UserTopArtistsParserImpl

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

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

the class UserTopArtistsServiceTest method createArtistInfosAndLocalFiles.

private void createArtistInfosAndLocalFiles() throws ApplicationException {
    Map<Artist, ArtistInfo> artistInfos = new HashMap<>();
    List<File> files = new ArrayList<>();
    for (Period period : Period.values()) {
        String fileName = format(TOP_ARTISTS_FILE, period.getDescription());
        for (Artist artist : new UserTopArtistsParserImpl(new ResourceUtil(fileName, UTF8).getInputStream()).getArtists()) {
            artistInfos.put(artist, new ArtistInfo(artist));
            files.add(UnittestLibraryUtil.getFile(artist.getName(), "A", "T"));
        }
    }
    artistInfoDao.createArtistInfo(new ArrayList<ArtistInfo>(artistInfos.values()));
    submitFile(additionDao, files);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) UserTopArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParserImpl) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Period(com.github.hakko.musiccabinet.domain.model.library.Period) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo) File(com.github.hakko.musiccabinet.domain.model.library.File) UnittestLibraryUtil.submitFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.submitFile)

Example 3 with UserTopArtistsParserImpl

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

the class JdbcUserTopArtistsDaoTest method loadFunctionDependency.

@Before
public void loadFunctionDependency() throws ApplicationException {
    PostgreSQLUtil.loadFunction(dao, UPDATE_USER_TOP_ARTISTS);
    arnOverall = new UserTopArtists(arn, Period.OVERALL, new UserTopArtistsParserImpl(new ResourceUtil(ARN_OVERALL_FILE).getInputStream()).getArtists());
    arn6month = new UserTopArtists(arn, Period.SIX_MONTHS, new UserTopArtistsParserImpl(new ResourceUtil(ARN_6MONTH_FILE).getInputStream()).getArtists());
    sys3month = new UserTopArtists(sys, Period.THREE_MONTHS, new UserTopArtistsParserImpl(new ResourceUtil(SYS_3MONTH_FILE).getInputStream()).getArtists());
    createArtistMetaData();
}
Also used : UserTopArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParserImpl) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) UserTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists) Before(org.junit.Before)

Aggregations

UserTopArtistsParserImpl (com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParserImpl)3 UserTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists)2 Period (com.github.hakko.musiccabinet.domain.model.library.Period)2 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)2 ArrayList (java.util.ArrayList)2 File (com.github.hakko.musiccabinet.domain.model.library.File)1 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)1 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)1 ArtistInfo (com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 UserTopArtistsParser (com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParser)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 UnittestLibraryUtil.submitFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.submitFile)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1