Search in sources :

Example 1 with AlbumInfoParser

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

the class AlbumInfoService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    List<Album> albums = albumInfoDao.getAlbumsWithoutInfo();
    List<AlbumInfo> albumInfos = new ArrayList<>();
    setTotalOperations(albums.size());
    for (Album album : albums) {
        try {
            WSResponse wsResponse = albumInfoClient.getAlbumInfo(album);
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                AlbumInfoParser aiParser = new AlbumInfoParserImpl(stringUtil.getInputStream());
                albumInfos.add(aiParser.getAlbumInfo());
                if (albumInfos.size() == BATCH_SIZE) {
                    albumInfoDao.createAlbumInfo(albumInfos);
                    albumInfos.clear();
                }
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching album info for " + album.getName() + " failed.", e);
        }
        addFinishedOperation();
    }
    albumInfoDao.createAlbumInfo(albumInfos);
}
Also used : AlbumInfoParserImpl(com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParserImpl) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) ArrayList(java.util.ArrayList) AlbumInfoParser(com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParser) Album(com.github.hakko.musiccabinet.domain.model.music.Album) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Aggregations

Album (com.github.hakko.musiccabinet.domain.model.music.Album)1 AlbumInfo (com.github.hakko.musiccabinet.domain.model.music.AlbumInfo)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 AlbumInfoParser (com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParser)1 AlbumInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParserImpl)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 ArrayList (java.util.ArrayList)1