use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class TrackSimilarityClientTest method validateParameters.
@Test
public void validateParameters() throws ApplicationException {
final String method = TrackSimilarityClient.METHOD;
final String artistName = "madonna";
final String trackName = "ray of light";
new TrackSimilarityClient() {
@Override
protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
assertEquals(Calltype.TRACK_GET_SIMILAR, wi.getCallType());
assertTrue(trackName.equals(wi.getTrack().getName()));
assertTrue(artistName.equals(wi.getTrack().getArtist().getName()));
assertHasParameter(params, PARAM_METHOD, method);
assertHasParameter(params, PARAM_ARTIST, artistName);
assertHasParameter(params, PARAM_TRACK, trackName);
return null;
}
@Override
protected WebserviceHistoryService getHistoryService() {
return Mockito.mock(WebserviceHistoryService.class);
}
}.getTrackSimilarity(new Track(new Artist(artistName), trackName));
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class LastFmService method identifyLastFmUser.
public LastFmUser identifyLastFmUser(String token) throws ApplicationException {
LOG.debug("identifyLastFmUser(" + token + ")");
WSResponse wsResponse = authSessionClient.getAuthSession(token);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
AuthSessionParser authSessionParser = new AuthSessionParserImpl(stringUtil.getInputStream());
return authSessionParser.getLastFmUser();
} else {
LOG.debug("wsResponse: " + wsResponse.getResponseBody());
throw new ApplicationException("Could not get session key for user! (code " + wsResponse.getErrorCode() + ", " + wsResponse.getErrorMessage() + ")");
}
}
use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.
the class MusicBrainzService method updateArtistDiscographies.
protected void updateArtistDiscographies() {
List<MBArtist> outdatedArtists = artistDao.getOutdatedArtists();
List<MBRelease> mbReleases = new ArrayList<>();
ReleaseParser parser;
discographies = outdatedArtists.size();
for (MBArtist artist : outdatedArtists) {
try {
int offset = 0;
do {
StringUtil response = new StringUtil(releaseClient.get(artist.getName(), artist.getMbid(), offset));
parser = new ReleaseParserImpl(response.getInputStream());
for (MBRelease album : parser.getReleases()) {
album.setArtistId(artist.getId());
}
mbReleases.addAll(parser.getReleases());
offset += 100;
} while (offset < parser.getTotalReleases());
++discography;
if (mbReleases.size() > 1000) {
albumDao.createAlbums(mbReleases);
mbReleases.clear();
}
} catch (ApplicationException e) {
LOG.warn("Couldn't read discography for " + artist.getName(), e);
}
}
albumDao.createAlbums(mbReleases);
}
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);
}
Aggregations