Search in sources :

Example 1 with TagTopArtistsParser

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

the class TagTopArtistsService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    List<TagTopArtists> topArtists = new ArrayList<>();
    List<Tag> tags = tagDao.getTagsWithoutTopArtists();
    setTotalOperations(tags.size());
    for (Tag tag : tags) {
        try {
            WSResponse wsResponse = tagTopArtistsClient.getTopArtists(tag);
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                TagTopArtistsParser parser = new TagTopArtistsParserImpl(stringUtil.getInputStream());
                topArtists.add(new TagTopArtists(tag.getName(), parser.getArtists()));
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching top artist for " + tag.getName() + " failed.", e);
        }
        addFinishedOperation();
    }
    tagDao.createTopArtists(topArtists);
}
Also used : TagTopArtistsParser(com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParser) TagTopArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParserImpl) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArrayList(java.util.ArrayList) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) TagTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists)

Aggregations

TagTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists)1 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 TagTopArtistsParser (com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParser)1 TagTopArtistsParserImpl (com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParserImpl)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 ArrayList (java.util.ArrayList)1