use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class AbstractSAXParserImpl method parseFromStream.
protected void parseFromStream(InputStream source, DefaultHandler handler) throws ApplicationException {
try (InputStream autoClosingStream = source) {
SAXParser saxParser = getSAXParser();
saxParser.parse(source, handler);
} catch (IOException e) {
throw new ApplicationException("Could not read data from stream!", e);
} catch (SAXException e) {
throw new ApplicationException("Could not parse data from stream!", e);
} catch (ParserConfigurationException e) {
throw new ApplicationException("Could not set up SAX parser!", e);
}
}
use of com.github.hakko.musiccabinet.exception.ApplicationException 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);
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class ArtistRelationService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_SIMILAR);
setTotalOperations(artistNames.size());
for (String artistName : artistNames) {
try {
WSResponse wsResponse = artistSimilarityClient.getArtistSimilarity(new Artist(artistName));
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
ArtistSimilarityParser asParser = new ArtistSimilarityParserImpl(stringUtil.getInputStream());
artistRelationDao.createArtistRelations(asParser.getArtist(), asParser.getArtistRelations());
}
} catch (ApplicationException e) {
LOG.warn("Fetching artist relations for " + artistName + " failed.", e);
}
addFinishedOperation();
}
}
use of com.github.hakko.musiccabinet.exception.ApplicationException 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();
}
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class UserRecommendedArtistsService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
List<LastFmUser> users = lastFmSettingsService.getLastFmUsers();
setTotalOperations(users.size());
List<UserRecommendedArtists> artists = new ArrayList<>();
for (LastFmUser user : users) {
try {
WSResponse wsResponse = userRecommendedArtistsClient.getUserRecommendedArtists(user.getLastFmUsername());
LOG.debug(wsResponse);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
UserRecommendedArtistsParser parser = new UserRecommendedArtistsParserImpl(stringUtil.getInputStream());
artists.add(new UserRecommendedArtists(user, parser.getArtists()));
}
} catch (ApplicationException e) {
LOG.warn("Fetching top artist for " + user.getLastFmUsername() + " failed.", e);
}
addFinishedOperation();
}
dao.createUserRecommendedArtists(artists);
}
Aggregations