Search in sources :

Example 1 with TagTopArtists

use of com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists in project musiccabinet by hakko.

the class TagTopArtistsService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    List<TagTopArtists> topArtists = new ArrayList<>();
    List<Tag> tags = tagDao.getTagsWithoutTopArtists();
    setTotalOperations(tags.size());
    for (Tag tag : tags) {
        try {
            WSResponse wsResponse = tagTopArtistsClient.getTopArtists(tag);
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                TagTopArtistsParser parser = new TagTopArtistsParserImpl(stringUtil.getInputStream());
                topArtists.add(new TagTopArtists(tag.getName(), parser.getArtists()));
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching top artist for " + tag.getName() + " failed.", e);
        }
        addFinishedOperation();
    }
    tagDao.createTopArtists(topArtists);
}
Also used : TagTopArtistsParser(com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParser) TagTopArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParserImpl) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArrayList(java.util.ArrayList) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) TagTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists)

Example 2 with TagTopArtists

use of com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists in project musiccabinet by hakko.

the class JdbcTagDao method createTopArtists.

@Override
public void createTopArtists(List<TagTopArtists> tagTopArtists) {
    if (tagTopArtists.size() > 0) {
        clearImportTable();
        for (TagTopArtists tta : tagTopArtists) {
            batchInsert(tta.getTagName(), tta.getArtists());
        }
        updateUserTopArtists();
    }
}
Also used : TagTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists)

Example 3 with TagTopArtists

use of com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists in project musiccabinet by hakko.

the class JdbcTagDaoTest method tagsWithTopArtistsAreNotPickedForUpdate.

@Test
public void tagsWithTopArtistsAreNotPickedForUpdate() {
    deleteTags();
    List<String> tagNames = Arrays.asList("disco", "sludge");
    dao.createTags(tagNames);
    dao.setTopTags(tagNames);
    List<TagTopArtists> topArtists = Arrays.asList(new TagTopArtists("disco", asList(new Artist("Madonna"))));
    dao.createTopArtists(topArtists);
    List<Tag> tags = dao.getTagsWithoutTopArtists();
    Assert.assertEquals(1, tags.size());
    Assert.assertEquals("sludge", tags.get(0).getName());
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) TagTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists) Test(org.junit.Test)

Example 4 with TagTopArtists

use of com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists 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)

Aggregations

TagTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists)4 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)2 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)2 ArrayList (java.util.ArrayList)2 File (com.github.hakko.musiccabinet.domain.model.library.File)1 ArtistInfo (com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)1 ArtistRelation (com.github.hakko.musiccabinet.domain.model.music.ArtistRelation)1 Track (com.github.hakko.musiccabinet.domain.model.music.Track)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 TagTopArtistsParser (com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParser)1 TagTopArtistsParserImpl (com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParserImpl)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 Before (org.junit.Before)1 Test (org.junit.Test)1