use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo 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.domain.model.music.AlbumInfo in project musiccabinet by hakko.
the class JdbcAlbumInfoDaoTest method createAndValidateUpdatedArtistInfos.
@Test
public void createAndValidateUpdatedArtistInfos() throws ApplicationException {
deleteAlbumInfos();
String newSmallUrl = "http://userserve-ak.last.fm/serve/34s/1234567.png";
int newListeners = 1234567;
dao.createAlbumInfo(Arrays.asList(aiNirvana, aiSchuller));
aiNirvana.setSmallImageUrl(newSmallUrl);
aiNirvana.setListeners(newListeners);
dao.createAlbumInfo(Arrays.asList(aiNirvana, aiSchuller));
AlbumInfo dbNirvana = dao.getAlbumInfo(aiNirvana.getAlbum());
Assert.assertEquals(newSmallUrl, dbNirvana.getSmallImageUrl());
Assert.assertEquals(newListeners, dbNirvana.getListeners());
}
use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo 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()));
}
}
use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo in project musiccabinet by hakko.
the class JdbcAlbumInfoDaoTest method createAndValidateArtistInfos.
@Test
public void createAndValidateArtistInfos() throws ApplicationException {
deleteAlbumInfos();
List<AlbumInfo> albumInfos = new ArrayList<>();
albumInfos.add(aiNirvana);
albumInfos.add(aiHurts);
dao.createAlbumInfo(albumInfos);
AlbumInfo dbNirvana = dao.getAlbumInfo(aiNirvana.getAlbum());
AlbumInfo dbHurts = dao.getAlbumInfo(aiHurts.getAlbum());
Assert.assertEquals(aiNirvana, dbNirvana);
Assert.assertEquals(aiHurts, dbHurts);
}
use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo in project musiccabinet by hakko.
the class JdbcAlbumInfoDao method getAlbumInfosForIds.
@Override
public Map<Integer, AlbumInfo> getAlbumInfosForIds(List<Integer> paths) {
String sql = "select alb.album_name_capitalization, ai.mediumimageurl," + " ai.largeimageurl, ai.extralargeimageurl, alb.id from music.albuminfo ai" + " inner join music.album alb on ai.album_id = alb.id" + " where alb.id in (" + getParameters(paths.size()) + ")";
final Map<Integer, AlbumInfo> albumInfos = new HashMap<>();
try {
jdbcTemplate.query(sql, paths.toArray(), new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
AlbumInfo ai = new AlbumInfo();
String albumName = rs.getString(1);
ai.setMediumImageUrl(rs.getString(2));
ai.setLargeImageUrl(rs.getString(3));
ai.setExtraLargeImageUrl(rs.getString(4));
int albumId = rs.getInt(5);
ai.setAlbum(new Album(albumName));
albumInfos.put(albumId, ai);
}
});
} catch (DataAccessException e) {
LOG.warn("Could not fetch album infos for paths " + paths + "!", e);
}
return albumInfos;
}
Aggregations