Search in sources :

Example 1 with ArtistInfoParser

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

the class ArtistInfoService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_INFO);
    List<ArtistInfo> artistInfos = new ArrayList<>(artistNames.size());
    setTotalOperations(artistNames.size());
    for (String artistName : artistNames) {
        try {
            WSResponse wsResponse = artistInfoClient.getArtistInfo(new Artist(artistName), lastFmSettingsService.getLang());
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                ArtistInfoParser aiParser = new ArtistInfoParserImpl(stringUtil.getInputStream());
                if (aiParser.getArtistInfo() != null) {
                    artistInfos.add(aiParser.getArtistInfo());
                } else {
                    LOG.warn("Artist info response for " + artistName + " not parsed correctly. Response was " + wsResponse.getResponseBody());
                }
                if (artistInfos.size() == BATCH_SIZE) {
                    artistInfoDao.createArtistInfo(artistInfos);
                    artistInfos.clear();
                }
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching artist info for " + artistName + " failed.", e);
        }
        addFinishedOperation();
    }
    artistInfoDao.createArtistInfo(artistInfos);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArtistInfoParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl) ArrayList(java.util.ArrayList) ArtistInfoParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParser) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)

Aggregations

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 ArtistInfoParser (com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParser)1 ArtistInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 ArrayList (java.util.ArrayList)1