use of com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParserImpl 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);
}
use of com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParserImpl in project musiccabinet by hakko.
the class JdbcAlbumInfoDaoTest method loadFunctionDependency.
@Before
public void loadFunctionDependency() throws ApplicationException {
PostgreSQLUtil.loadFunction(dao, UPDATE_ALBUMINFO);
aiNirvana = new AlbumInfoParserImpl(new ResourceUtil(AI_NIRVANA_FILE).getInputStream()).getAlbumInfo();
aiHurts = new AlbumInfoParserImpl(new ResourceUtil(AI_HURTS_FILE).getInputStream()).getAlbumInfo();
aiSchuller = new AlbumInfoParserImpl(new ResourceUtil(AI_SCHULLER_FILE).getInputStream()).getAlbumInfo();
aiNirvana2 = new AlbumInfoParserImpl(new ResourceUtil(AI_NIRVANA2_FILE).getInputStream()).getAlbumInfo();
aiNirvana3 = new AlbumInfoParserImpl(new ResourceUtil(AI_NIRVANA3_FILE).getInputStream()).getAlbumInfo();
deleteArtists();
deleteLibraryTracks();
createLibraryTracks(aiNirvana, aiNirvana2, aiNirvana3, aiHurts, aiSchuller);
for (AlbumInfo ai : asList(aiNirvana, aiHurts, aiSchuller)) {
ai.getAlbum().getArtist().setId(musicDao.getArtistId(ai.getAlbum().getArtist()));
}
}
Aggregations