Search in sources :

Example 16 with ArtistInfo

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

the class ArtistInfoService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_INFO);
    List<ArtistInfo> artistInfos = new ArrayList<>(artistNames.size());
    setTotalOperations(artistNames.size());
    for (String artistName : artistNames) {
        try {
            WSResponse wsResponse = artistInfoClient.getArtistInfo(new Artist(artistName), lastFmSettingsService.getLang());
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                ArtistInfoParser aiParser = new ArtistInfoParserImpl(stringUtil.getInputStream());
                if (aiParser.getArtistInfo() != null) {
                    artistInfos.add(aiParser.getArtistInfo());
                } else {
                    LOG.warn("Artist info response for " + artistName + " not parsed correctly. Response was " + wsResponse.getResponseBody());
                }
                if (artistInfos.size() == BATCH_SIZE) {
                    artistInfoDao.createArtistInfo(artistInfos);
                    artistInfos.clear();
                }
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching artist info for " + artistName + " failed.", e);
        }
        addFinishedOperation();
    }
    artistInfoDao.createArtistInfo(artistInfos);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArtistInfoParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl) ArrayList(java.util.ArrayList) ArtistInfoParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParser) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)

Example 17 with ArtistInfo

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

the class JdbcArtistInfoDaoTest method unknownArtistInfoReturnsNull.

@Test
public void unknownArtistInfoReturnsNull() throws ApplicationException {
    int unknownId = -1;
    ArtistInfo artistInfo = dao.getArtistInfo(unknownId);
    assertNull(artistInfo);
}
Also used : ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo) Test(org.junit.Test)

Example 18 with ArtistInfo

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

the class JdbcArtistRecommendationDaoTest method createTestData.

@Before
public void createTestData() throws ApplicationException {
    PostgreSQLUtil.truncateTables(artistRecommendationDao);
    List<ArtistRelation> artistRelations = new ArrayList<>();
    for (Artist targetArtist : asList(madonna, cyndi, celine, kylie)) {
        artistRelations.add(new ArtistRelation(targetArtist, 0.33f));
    }
    artistRelationDao.createArtistRelations(cher, artistRelations);
    tagDao.createTags(asList("disco"));
    tagDao.createTopArtists(Arrays.asList(new TagTopArtists("disco", Arrays.asList(cher, madonna, cyndi, celine, kylie))));
    Track track1, track2, track3;
    artistTopTracksDao.createTopTracks(madonna, Arrays.asList(track1 = new Track(madonna, "Like A Prayer"), track2 = new Track(madonna, "Hung Up"), new Track(madonna, "Frozen")));
    artistTopTracksDao.createTopTracks(cyndi, Arrays.asList(track3 = new Track(cyndi, "Time After Time"), new Track(cyndi, "Girls Just Wanna Have Fun")));
    artistTopTracksDao.createTopTracks(celine, Arrays.asList(new Track(celine, "My Heart Will Go On")));
    artistTopTracksDao.createTopTracks(kylie, Arrays.asList(new Track(kylie, "Love At First Sight")));
    List<File> files = new ArrayList<>();
    for (Track track : Arrays.asList(track1, track2, track3)) {
        files.add(getFile(track));
    }
    UnittestLibraryUtil.submitFile(additionDao, files);
    playlistGeneratorService.updateSearchIndex();
    cherId = musicDao.getArtistId(cher);
    List<ArtistInfo> artistInfos = new ArrayList<>();
    for (Artist artist : Arrays.asList(madonna, cyndi, celine, kylie)) {
        artistInfos.add(new ArtistInfo(artist, "/image/for/" + artist.getName()));
    }
    artistInfoDao.createArtistInfo(artistInfos);
}
Also used : ArtistRelation(com.github.hakko.musiccabinet.domain.model.music.ArtistRelation) Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ArrayList(java.util.ArrayList) TagTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists) UnittestLibraryUtil.getFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile) File(com.github.hakko.musiccabinet.domain.model.library.File) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo) Track(com.github.hakko.musiccabinet.domain.model.music.Track) Before(org.junit.Before)

Example 19 with ArtistInfo

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

the class JdbcUserTopArtistsDaoTest method createArtistMetaData.

private void createArtistMetaData() {
    Set<Artist> artists = new HashSet<>();
    for (UserTopArtists uta : Arrays.asList(arnOverall, arn6month, sys3month)) {
        for (Artist artist : uta.getArtists()) {
            artists.add(artist);
        }
    }
    List<File> files = new ArrayList<>();
    for (Artist artist : artists) {
        files.add(getFile(artist.getName(), null, null));
    }
    List<ArtistInfo> artistInfos = new ArrayList<>();
    for (Artist artist : artists) {
        artistInfos.add(new ArtistInfo(artist, "/url/to/" + artist.getName()));
    }
    additionDao.getJdbcTemplate().execute("truncate library.file cascade");
    UnittestLibraryUtil.submitFile(additionDao, files);
    artistInfoDao.createArtistInfo(artistInfos);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ArrayList(java.util.ArrayList) UserTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists) UnittestLibraryUtil.getFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile) File(com.github.hakko.musiccabinet.domain.model.library.File) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo) HashSet(java.util.HashSet)

Example 20 with ArtistInfo

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

the class JdbcArtistInfoDaoTest method createAndValidateUpdatedArtistInfos.

@Test
public void createAndValidateUpdatedArtistInfos() throws ApplicationException {
    deleteArtistInfos();
    String newBio = "Abba was a pop group.";
    String newContent = "Abba was a pop group. They sold many records.";
    dao.createArtistInfo(Arrays.asList(aiAbba, aiTina));
    aiAbba.setBioSummary(newBio);
    aiAbba.setBioContent(newContent);
    dao.createArtistInfo(Arrays.asList(aiAbba, aiCher));
    ArtistInfo dbAbba = dao.getArtistInfo(aiAbba.getArtist());
    Assert.assertEquals(newBio, dbAbba.getBioSummary());
    Assert.assertEquals(newContent, dbAbba.getBioContent());
}
Also used : ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo) Test(org.junit.Test)

Aggregations

ArtistInfo (com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)22 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)11 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)7 File (com.github.hakko.musiccabinet.domain.model.library.File)5 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)4 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)4 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 HashSet (java.util.HashSet)3 Before (org.junit.Before)3 ArtistInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl)2 TagTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists)1 UserRecommendedArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists)1 RecommendedArtist (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist)1 UserTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists)1 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)1 Period (com.github.hakko.musiccabinet.domain.model.library.Period)1 Album (com.github.hakko.musiccabinet.domain.model.music.Album)1 ArtistRelation (com.github.hakko.musiccabinet.domain.model.music.ArtistRelation)1