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);
}
Aggregations