Search in sources :

Example 1 with ArtistTopTracksParserImpl

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

the class WSResponseTest method illegalControlCharactersAreChomped2.

/*
	 * Use an authentic response from last.fm, and assert that WSResponse
	 * silently replaces illegal XML characters in it.
	 */
@Test
public void illegalControlCharactersAreChomped2() throws ApplicationException {
    String ctrlCharResponse = new ResourceUtil(CTRL_CHAR_RESPONSE_2).getContent();
    WSResponse response = new WSResponse(ctrlCharResponse);
    // supposed to work, as WSResponse chomps illegal control characters
    new ArtistTopTracksParserImpl(new StringUtil(response.getResponseBody()).getInputStream());
    try {
        // supposed to fail, as it hasn't passed WSResponse
        new ArtistTopTracksParserImpl(new ResourceUtil(CTRL_CHAR_RESPONSE_2).getInputStream());
        Assert.fail();
    } catch (ApplicationException e) {
    }
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ArtistTopTracksParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParserImpl) Test(org.junit.Test)

Example 2 with ArtistTopTracksParserImpl

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

the class ArtistTopTracksService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_TOP_TRACKS);
    setTotalOperations(artistNames.size());
    for (String artistName : artistNames) {
        try {
            WSResponse wsResponse = artistTopTracksClient.getTopTracks(new Artist(artistName));
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                ArtistTopTracksParser attParser = new ArtistTopTracksParserImpl(stringUtil.getInputStream());
                artistTopTracksDao.createTopTracks(attParser.getArtist(), attParser.getTopTracks());
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching top tracks for " + artistName + " failed.", e);
        }
        addFinishedOperation();
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArtistTopTracksParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParser) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ArtistTopTracksParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParserImpl)

Example 3 with ArtistTopTracksParserImpl

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

the class JdbcArtistTopTracksDaoTest method loadFunctionDependencyAndTestdata.

@Before
public void loadFunctionDependencyAndTestdata() throws ApplicationException {
    PostgreSQLUtil.loadFunction(dao, UPDATE_ARTISTTOPTRACK);
    ArtistTopTracksParser cherParser = new ArtistTopTracksParserImpl(new ResourceUtil(CHER_TOP_TRACKS).getInputStream());
    ArtistTopTracksParser rihannaParser = new ArtistTopTracksParserImpl(new ResourceUtil(RIHANNA_TOP_TRACKS).getInputStream());
    cherArtist = cherParser.getArtist();
    rihannaArtist = rihannaParser.getArtist();
    cherTopTracks = cherParser.getTopTracks();
    rihannaTopTracks = rihannaParser.getTopTracks();
    PostgreSQLUtil.truncateTables(dao);
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) ArtistTopTracksParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParser) ArtistTopTracksParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParserImpl) Before(org.junit.Before)

Example 4 with ArtistTopTracksParserImpl

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

the class JdbcPlaylistGeneratorDaoTest method prepareTestdataForArtist.

private int prepareTestdataForArtist() throws ApplicationException {
    ArtistSimilarityParser asParser = new ArtistSimilarityParserImpl(new ResourceUtil(CHER_SIMILAR_ARTISTS).getInputStream());
    artistRelationDao.createArtistRelations(asParser.getArtist(), asParser.getArtistRelations());
    ArtistTopTracksParser attParser = new ArtistTopTracksParserImpl(new ResourceUtil(CHER_TOP_TRACKS).getInputStream());
    artistTopTracksDao.createTopTracks(attParser.getArtist(), attParser.getTopTracks());
    List<File> files = new ArrayList<>();
    for (Track topTrack : attParser.getTopTracks()) {
        files.add(UnittestLibraryUtil.getFile(topTrack));
    }
    UnittestLibraryUtil.submitFile(additionDao, files);
    int artistId = musicDao.getArtistId(asParser.getArtist());
    playlistGeneratorDao.updateSearchIndex();
    return artistId;
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) ArtistSimilarityParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParser) ArtistSimilarityParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParserImpl) ArrayList(java.util.ArrayList) ArtistTopTracksParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParser) ArtistTopTracksParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParserImpl) UnittestLibraryUtil.getFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile) File(com.github.hakko.musiccabinet.domain.model.library.File) Track(com.github.hakko.musiccabinet.domain.model.music.Track)

Aggregations

ArtistTopTracksParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParserImpl)4 ArtistTopTracksParser (com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParser)3 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)3 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)2 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)2 File (com.github.hakko.musiccabinet.domain.model.library.File)1 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)1 Track (com.github.hakko.musiccabinet.domain.model.music.Track)1 ArtistSimilarityParser (com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParser)1 ArtistSimilarityParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParserImpl)1 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1