use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser 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));
}
use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser 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);
}
use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.
the class UserLovedTracksServiceTest method updatesStarredTracksWhenImportIsOnlyAllowedForOneUser.
/*
* User story: user1 has starred track2, user2 has starred track3 & track4.
* When importing loved tracks, user2 is unavailable and user1 has loved track1.
* Expected outcome: afterwards, user1 has starred track1 & 2 and user2 track3 & 4.
*/
@Test
public void updatesStarredTracksWhenImportIsOnlyAllowedForOneUser() throws ApplicationException {
lastFmDao.createOrUpdateLastFmUser(new LastFmUser(USER1));
lastFmDao.createOrUpdateLastFmUser(new LastFmUser(USER2));
LastFmUser user1 = lastFmDao.getLastFmUser(USER1), user2 = lastFmDao.getLastFmUser(USER2);
Track track1 = new Track("Frank Ocean", "Lost"), track2 = new Track("Kate Bush", "Cloudbusting"), track3 = new Track("Adele", "Skyfall"), track4 = new Track("Kath Bloom", "Fall Again");
File f1, f2, f3, f4;
deleteLovedAndStarredTracks();
submitFile(additionDao, asList(f1 = getFile(track1), f2 = getFile(track2), f3 = getFile(track3), f4 = getFile(track4)));
int track1Id = browserDao.getTrackId(f1), track2Id = browserDao.getTrackId(f2), track3Id = browserDao.getTrackId(f3), track4Id = browserDao.getTrackId(f4);
LastFmSettingsService lastFmSettingsService = mock(LastFmSettingsService.class);
when(lastFmSettingsService.getLastFmUsers()).thenReturn(asList(user1, user2));
when(lastFmSettingsService.isSyncStarredAndLovedTracks()).thenReturn(true);
UserLovedTracksClient userLovedTracksClient = mock(UserLovedTracksClient.class);
when(userLovedTracksClient.getUserLovedTracks(user1, (short) 0)).thenReturn(new WSResponse(new ResourceUtil(LOVED_TRACKS_FILE, UTF8).getContent()));
when(userLovedTracksClient.getUserLovedTracks(user2, (short) 0)).thenReturn(new WSResponse(false, 403, "Forbidden"));
UserLovedTracksService userLovedTracksService = new UserLovedTracksService();
userLovedTracksService.setLastFmSettingsService(lastFmSettingsService);
userLovedTracksService.setUserLovedTracksClient(userLovedTracksClient);
userLovedTracksService.setUserLovedTracksDao(userLovedTracksDao);
userLovedTracksService.setStarService(mock(StarService.class));
userLovedTracksService.setTrackLoveClient(mock(TrackLoveClient.class));
starDao.starTrack(user1, track2Id);
starDao.starTrack(user2, track3Id);
starDao.starTrack(user2, track4Id);
userLovedTracksService.updateSearchIndex();
assertEquals(sort(asList(track1Id, track2Id)), sort(starDao.getStarredTrackIds(user1)));
assertEquals(sort(asList(track3Id, track4Id)), sort(starDao.getStarredTrackIds(user2)));
}
use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.
the class TrackLoveClientTest method validateParameters.
@Test
public void validateParameters() throws ApplicationException {
final String method = TrackLoveClient.METHOD;
final String lastFmUser = "arnathalon";
final String sessionKey = "sessionkey";
final String artist = "artist";
final String track = "track";
new TrackLoveClient() {
@Override
protected WSResponse executeWSRequest(List<NameValuePair> params) throws ApplicationException {
assertHasParameter(params, PARAM_METHOD, method);
assertHasParameter(params, PARAM_TRACK, track);
assertHasParameter(params, PARAM_ARTIST, artist);
assertHasParameter(params, PARAM_SK, sessionKey);
return null;
}
}.love(new Track(artist, track), new LastFmUser(lastFmUser, sessionKey));
}
use of com.github.hakko.musiccabinet.domain.model.library.LastFmUser in project musiccabinet by hakko.
the class AuthSessionParserTest method resourceFileCorrectlyParsed.
@Test
public void resourceFileCorrectlyParsed() throws ApplicationException {
AuthSessionParser parser = new AuthSessionParserImpl(new ResourceUtil(AUTH_SESSION_FILE).getInputStream());
LastFmUser lastFmUser = parser.getLastFmUser();
assertNotNull(lastFmUser);
assertEquals(NAME, lastFmUser.getLastFmUsername());
assertEquals(KEY, lastFmUser.getSessionKey());
}
Aggregations