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) {
}
}
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());
}
}
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);
}
Aggregations