Search in sources :

Example 1 with AlbumInfoParserImpl

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

Example 2 with AlbumInfoParserImpl

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()));
    }
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) AlbumInfoParserImpl(com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParserImpl) AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) Before(org.junit.Before)

Aggregations

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