use of com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack in project musiccabinet by hakko.
the class UserLovedTracksService method updateUserLovedTracks.
private void updateUserLovedTracks() throws ApplicationException {
List<LastFmUser> users = lastFmSettingsService.getLastFmUsers();
setTotalOperations(users.size());
List<UserLovedTracks> userLovedTracks = new ArrayList<>();
for (LastFmUser user : users) {
short page = 0, totalPages = 0;
List<Track> lovedTracks = new ArrayList<>();
do {
WSResponse wsResponse = userLovedTracksClient.getUserLovedTracks(user, page);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
UserLovedTracksParser parser = new UserLovedTracksParserImpl(stringUtil.getInputStream());
totalPages = parser.getTotalPages();
lovedTracks.addAll(parser.getLovedTracks());
}
} while (++page < totalPages);
addFinishedOperation();
userLovedTracks.add(new UserLovedTracks(user.getLastFmUsername(), lovedTracks));
}
userLovedTracksDao.createLovedTracks(userLovedTracks);
for (UserStarredTrack ust : userLovedTracksDao.getStarredButNotLovedTracks()) {
trackLoveClient.love(ust.getStarredTrack(), ust.getLastFmUser());
}
}
use of com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack in project musiccabinet by hakko.
the class UserStarredTrackRowMapper method mapRow.
@Override
public UserStarredTrack mapRow(ResultSet rs, int rowNum) throws SQLException {
String username = rs.getString(1);
String sessionKey = rs.getString(2);
String artistName = rs.getString(3);
String trackName = rs.getString(4);
return new UserStarredTrack(new LastFmUser(username, sessionKey), new Track(artistName, trackName));
}
Aggregations