use of com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParser in project musiccabinet by hakko.
the class UserTopArtistsService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
List<LastFmUser> users = lastFmSettingsService.getLastFmUsers();
setTotalOperations(users.size() * Period.values().length);
List<UserTopArtists> userTopArtists = new ArrayList<>();
for (LastFmUser user : users) {
for (Period period : Period.values()) {
try {
WSResponse wsResponse = userTopArtistsClient.getUserTopArtists(user, period);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
UserTopArtistsParser parser = new UserTopArtistsParserImpl(stringUtil.getInputStream());
userTopArtists.add(new UserTopArtists(user, period, parser.getArtists()));
}
} catch (ApplicationException e) {
LOG.warn("Fetching top artist for " + user.getLastFmUsername() + ", " + period.getDescription() + " failed.", e);
}
addFinishedOperation();
}
}
userTopArtistsDao.createUserTopArtists(userTopArtists);
}
Aggregations