Search in sources :

Example 1 with ArtistInfoParserImpl

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

the class WSResponseTest method illegalControlCharactersAreChomped1.

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

Example 2 with ArtistInfoParserImpl

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

the class JdbcArtistInfoDaoTest method loadFunctionDependency.

@Before
public void loadFunctionDependency() throws ApplicationException {
    PostgreSQLUtil.loadFunction(dao, UPDATE_ARTISTINFO);
    aiAbba = new ArtistInfoParserImpl(new ResourceUtil(AI_ABBA_FILE).getInputStream()).getArtistInfo();
    aiCher = new ArtistInfoParserImpl(new ResourceUtil(AI_CHER_FILE).getInputStream()).getArtistInfo();
    aiTina = new ArtistInfoParserImpl(new ResourceUtil(AI_TINA_FILE).getInputStream()).getArtistInfo();
    deleteArtists();
    // re-create artists
    for (ArtistInfo ai : new ArtistInfo[] { aiAbba, aiCher, aiTina }) {
        musicDao.getArtistId(ai.getArtist());
    }
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) ArtistInfoParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo) Before(org.junit.Before)

Example 3 with ArtistInfoParserImpl

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

the class ArtistInfoService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_INFO);
    List<ArtistInfo> artistInfos = new ArrayList<>(artistNames.size());
    setTotalOperations(artistNames.size());
    for (String artistName : artistNames) {
        try {
            WSResponse wsResponse = artistInfoClient.getArtistInfo(new Artist(artistName), lastFmSettingsService.getLang());
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                ArtistInfoParser aiParser = new ArtistInfoParserImpl(stringUtil.getInputStream());
                if (aiParser.getArtistInfo() != null) {
                    artistInfos.add(aiParser.getArtistInfo());
                } else {
                    LOG.warn("Artist info response for " + artistName + " not parsed correctly. Response was " + wsResponse.getResponseBody());
                }
                if (artistInfos.size() == BATCH_SIZE) {
                    artistInfoDao.createArtistInfo(artistInfos);
                    artistInfos.clear();
                }
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching artist info for " + artistName + " failed.", e);
        }
        addFinishedOperation();
    }
    artistInfoDao.createArtistInfo(artistInfos);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArtistInfoParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl) ArrayList(java.util.ArrayList) ArtistInfoParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParser) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)

Aggregations

ArtistInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl)3 ArtistInfo (com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)2 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)2 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)2 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)2 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)1 ArtistInfoParser (com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParser)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