Search in sources :

Example 1 with ArtistTopTagsParser

use of com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTagsParser in project musiccabinet by hakko.

the class JdbcArtistTopTagsDaoTest method loadFunctionDependencyAndTestdata.

@Before
public void loadFunctionDependencyAndTestdata() throws ApplicationException {
    PostgreSQLUtil.loadFunction(dao, UPDATE_ARTISTTOPTAG);
    ArtistTopTagsParser cherParser = new ArtistTopTagsParserImpl(new ResourceUtil(CHER_TOP_TAGS).getInputStream());
    ArtistTopTagsParser rihannaParser = new ArtistTopTagsParserImpl(new ResourceUtil(RIHANNA_TOP_TAGS).getInputStream());
    cherArtist = cherParser.getArtist();
    cherTopTags = cherParser.getTopTags();
    rihannaArtist = rihannaParser.getArtist();
    rihannaTopTags = rihannaParser.getTopTags();
    PostgreSQLUtil.truncateTables(dao);
    musicDao.setArtistId(cherArtist);
    musicDao.setArtistId(rihannaArtist);
}
Also used : ArtistTopTagsParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTagsParser) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) ArtistTopTagsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTagsParserImpl) Before(org.junit.Before)

Example 2 with ArtistTopTagsParser

use of com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTagsParser in project musiccabinet by hakko.

the class ArtistTopTagsService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_TOP_TAGS);
    setTotalOperations(artistNames.size());
    for (String artistName : artistNames) {
        try {
            WSResponse wsResponse = artistTopTagsClient.getTopTags(new Artist(artistName));
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                ArtistTopTagsParser attParser = new ArtistTopTagsParserImpl(stringUtil.getInputStream());
                removeTagsWithLowTagCount(attParser.getTopTags());
                artistTopTagsDao.createTopTags(attParser.getArtist(), attParser.getTopTags());
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching top tags for " + artistName + " failed.", e);
        }
        addFinishedOperation();
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ArtistTopTagsParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTagsParser) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArtistTopTagsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTagsParserImpl) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Aggregations

ArtistTopTagsParser (com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTagsParser)2 ArtistTopTagsParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTagsParserImpl)2 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 Before (org.junit.Before)1