Search in sources :

Example 1 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class JdbcNameSearchDao method getArtists.

@Override
public NameSearchResult<Artist> getArtists(String userQuery, int offset, int limit) {
    String sql = "select ma.id, ma.artist_name_capitalization" + " from library.artist la" + " inner join music.artist ma on la.artist_id = ma.id" + " where la.artist_name_search like ?" + " order by la.hasalbums desc, ma.artist_name" + " offset ? limit ?";
    List<Artist> artists = jdbcTemplate.query(sql, new Object[] { getNameQuery(userQuery), offset, limit }, new ArtistRowMapper());
    return new NameSearchResult<>(artists, offset);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) NameSearchResult(com.github.hakko.musiccabinet.domain.model.aggr.NameSearchResult) ArtistRowMapper(com.github.hakko.musiccabinet.dao.jdbc.rowmapper.ArtistRowMapper)

Example 2 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class JdbcArtistInfoDao method getArtistInfo.

@Override
public ArtistInfo getArtistInfo(final int artistId) {
    String sql = "select a.artist_name_capitalization, ai.largeimageurl, ai.biosummary," + " exists(select 1 from library.artisttoptrackplaycount where artist_id = a.id)" + " from music.artist a" + " left outer join music.artistinfo ai on ai.artist_id = a.id" + " where a.id = " + artistId;
    List<ArtistInfo> artistInfos = jdbcTemplate.query(sql, new RowMapper<ArtistInfo>() {

        @Override
        public ArtistInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
            ArtistInfo ai = new ArtistInfo();
            ai.setArtist(new Artist(artistId, rs.getString(1)));
            ai.setLargeImageUrl(rs.getString(2));
            ai.setBioSummary(rs.getString(3));
            ai.setInSearchIndex(rs.getBoolean(4));
            return ai;
        }
    });
    return artistInfos.isEmpty() ? null : artistInfos.get(0);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)

Example 3 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class JdbcArtistInfoDao method getDetailedArtistInfo.

@Override
public ArtistInfo getDetailedArtistInfo(final int artistId) {
    String sql = "select a.artist_name_capitalization, ai.largeimageurl, ai.biocontent" + " from music.artist a" + " left outer join music.artistinfo ai on ai.artist_id = a.id" + " where a.id = " + artistId;
    List<ArtistInfo> artistInfos = jdbcTemplate.query(sql, new RowMapper<ArtistInfo>() {

        @Override
        public ArtistInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
            ArtistInfo ai = new ArtistInfo();
            ai.setArtist(new Artist(artistId, rs.getString(1)));
            ai.setLargeImageUrl(rs.getString(2));
            ai.setBioContent(rs.getString(3));
            return ai;
        }
    });
    return artistInfos.isEmpty() ? null : artistInfos.get(0);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)

Example 4 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class ArtistTopTracksServiceTest method artistTopTracksUpdateUpdatesAllArtists.

@Test
public void artistTopTracksUpdateUpdatesAllArtists() throws ApplicationException, IOException {
    clearLibraryAndAddCherTrack();
    WebserviceInvocation wi = new WebserviceInvocation(ARTIST_GET_TOP_TRACKS, new Artist(artistName));
    Assert.assertTrue(webserviceHistoryService.isWebserviceInvocationAllowed(wi));
    Set<String> artists = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_TOP_TRACKS);
    Assert.assertNotNull(artists);
    Assert.assertEquals(1, artists.size());
    Assert.assertTrue(artists.contains(artistName));
    ArtistTopTracksService artistTopTracksService = new ArtistTopTracksService();
    artistTopTracksService.setArtistTopTracksClient(getArtistTopTracksClient(webserviceHistoryService));
    artistTopTracksService.setArtistTopTracksDao(artistTopTracksDao);
    artistTopTracksService.setWebserviceHistoryService(webserviceHistoryService);
    artistTopTracksService.updateSearchIndex();
    Assert.assertFalse(webserviceHistoryService.isWebserviceInvocationAllowed(wi));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 5 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class UserTopArtistsServiceTest method updatesTopArtistsWhenImportIsOnlyAllowedForOneUser.

/*
	 * User story: user1 and user2 have (previously imported) top artists.
	 * During import, new data can only be fetched for user1.
	 * Expected: top artists for user1 are updated, while user2 keeps original artists.
	 */
@Test
public void updatesTopArtistsWhenImportIsOnlyAllowedForOneUser() throws Exception {
    PostgreSQLUtil.truncateTables(userTopArtistsDao);
    createArtistInfosAndLocalFiles();
    lastFmDao.createOrUpdateLastFmUser(new LastFmUser(USER1));
    lastFmDao.createOrUpdateLastFmUser(new LastFmUser(USER2));
    LastFmUser user1 = lastFmDao.getLastFmUser(USER1), user2 = lastFmDao.getLastFmUser(USER2);
    LastFmSettingsService lastFmSettingsService = mock(LastFmSettingsService.class);
    when(lastFmSettingsService.getLastFmUsers()).thenReturn(asList(user1, user2));
    UserTopArtistsClient userTopArtistsClient = mock(UserTopArtistsClient.class);
    for (Period period : Period.values()) {
        String fileName = format(TOP_ARTISTS_FILE, period.getDescription());
        when(userTopArtistsClient.getUserTopArtists(user1, period)).thenReturn(new WSResponse(new ResourceUtil(fileName, UTF8).getContent()));
        when(userTopArtistsClient.getUserTopArtists(user2, period)).thenReturn(new WSResponse(false, 403, "Forbidden"));
    }
    UserTopArtistsService userTopArtistsService = new UserTopArtistsService();
    userTopArtistsService.setLastFmSettingsService(lastFmSettingsService);
    userTopArtistsService.setUserTopArtistsClient(userTopArtistsClient);
    userTopArtistsService.setUserTopArtistsDao(userTopArtistsDao);
    userTopArtistsDao.createUserTopArtists(asList(new UserTopArtists(user1, OVERALL, asList(new Artist("M83"))), new UserTopArtists(user2, SIX_MONTHS, asList(new Artist("Zola Jesus")))));
    assertEquals("M83", userTopArtistsService.getUserTopArtists(user1, OVERALL, 0, 10).get(0).getArtistName());
    assertEquals("Zola Jesus", userTopArtistsService.getUserTopArtists(user2, SIX_MONTHS, 0, 10).get(0).getArtistName());
    userTopArtistsService.updateSearchIndex();
    assertEquals(1, userTopArtistsService.getUserTopArtists(user2, SIX_MONTHS, 0, 10).size());
    for (Period period : Period.values()) {
        assertEquals("Expected 50 artists for period " + period, 50, userTopArtistsService.getUserTopArtists(user1, period, 0, 50).size());
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) UserTopArtistsClient(com.github.hakko.musiccabinet.ws.lastfm.UserTopArtistsClient) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Period(com.github.hakko.musiccabinet.domain.model.library.Period) UserTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) Test(org.junit.Test)

Aggregations

Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)66 Test (org.junit.Test)33 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)19 ArrayList (java.util.ArrayList)13 Album (com.github.hakko.musiccabinet.domain.model.music.Album)11 ArtistInfo (com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)11 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)10 Track (com.github.hakko.musiccabinet.domain.model.music.Track)9 File (com.github.hakko.musiccabinet.domain.model.library.File)8 NameValuePair (org.apache.http.NameValuePair)8 Calltype (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype)7 Before (org.junit.Before)6 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)5 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)5 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)5 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)5 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)4 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)4 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)4 ResultSet (java.sql.ResultSet)4