use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.
the class JdbcWebserviceHistoryDaoTest method differentUsersDontInterfere.
@Test
public void differentUsersDontInterfere() {
Calltype TOP_ARTISTS = Calltype.USER_GET_TOP_ARTISTS;
LastFmUser user1 = new LastFmUser("user1");
LastFmUser user2 = new LastFmUser("user2");
WebserviceInvocation topArtists1 = new WebserviceInvocation(TOP_ARTISTS, user1, OVERALL.getDays());
WebserviceInvocation topArtists2 = new WebserviceInvocation(TOP_ARTISTS, user2, OVERALL.getDays());
deleteWebserviceInvocations();
assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
assertTrue(dao.isWebserviceInvocationAllowed(topArtists2));
dao.logWebserviceInvocation(topArtists2);
assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
}
use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.
the class JdbcWebserviceHistoryDaoTest method periodIsSignificantForAllowance.
@Test
public void periodIsSignificantForAllowance() {
Calltype TOP_ARTISTS = Calltype.USER_GET_TOP_ARTISTS;
LastFmUser user = new LastFmUser("arnathalon");
WebserviceInvocation topArtists1 = new WebserviceInvocation(TOP_ARTISTS, user, OVERALL.getDays());
WebserviceInvocation topArtists2 = new WebserviceInvocation(TOP_ARTISTS, user, SIX_MONTHS.getDays());
deleteWebserviceInvocations();
assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
assertTrue(dao.isWebserviceInvocationAllowed(topArtists2));
dao.logWebserviceInvocation(topArtists1);
assertFalse(dao.isWebserviceInvocationAllowed(topArtists1));
assertTrue(dao.isWebserviceInvocationAllowed(topArtists2));
dao.logWebserviceInvocation(topArtists2);
assertFalse(dao.isWebserviceInvocationAllowed(topArtists1));
assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
}
use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser 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.library.LastFmUser 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);
}
use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.
the class UserRecommendedArtistsClient method getUserRecommendedArtists.
public WSResponse getUserRecommendedArtists(String lastFmUsername) throws ApplicationException {
LastFmUser user = lastFmDao.getLastFmUser(lastFmUsername);
WebserviceInvocation webserviceInvocation = new WebserviceInvocation(USER_GET_RECOMMENDED_ARTISTS, user);
List<NameValuePair> params = getDefaultParameterList();
params.add(new BasicNameValuePair(PARAM_METHOD, METHOD));
params.add(new BasicNameValuePair(PARAM_LIMIT, "100"));
params.add(new BasicNameValuePair(PARAM_SK, user.getSessionKey()));
return executeWSRequest(webserviceInvocation, params);
}
Aggregations