Search in sources :

Example 16 with StringUtil

use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.

the class ArtistRelationService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_SIMILAR);
    setTotalOperations(artistNames.size());
    for (String artistName : artistNames) {
        try {
            WSResponse wsResponse = artistSimilarityClient.getArtistSimilarity(new Artist(artistName));
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                ArtistSimilarityParser asParser = new ArtistSimilarityParserImpl(stringUtil.getInputStream());
                artistRelationDao.createArtistRelations(asParser.getArtist(), asParser.getArtistRelations());
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching artist relations for " + artistName + " failed.", e);
        }
        addFinishedOperation();
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ArtistSimilarityParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParser) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArtistSimilarityParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistSimilarityParserImpl) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Example 17 with StringUtil

use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.

the class ArtistTopTracksService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_TOP_TRACKS);
    setTotalOperations(artistNames.size());
    for (String artistName : artistNames) {
        try {
            WSResponse wsResponse = artistTopTracksClient.getTopTracks(new Artist(artistName));
            if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
                StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
                ArtistTopTracksParser attParser = new ArtistTopTracksParserImpl(stringUtil.getInputStream());
                artistTopTracksDao.createTopTracks(attParser.getArtist(), attParser.getTopTracks());
            }
        } catch (ApplicationException e) {
            LOG.warn("Fetching top tracks for " + artistName + " failed.", e);
        }
        addFinishedOperation();
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArtistTopTracksParser(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParser) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ArtistTopTracksParserImpl(com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParserImpl)

Example 18 with StringUtil

use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.

the class TagInfoService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    List<TagInfo> tagInfos = new ArrayList<>();
    Set<String> tags = getTagsForUpdate();
    setTotalOperations(tags.size());
    for (String tag : tags) {
        WSResponse wsResponse = tagInfoClient.getTagInfo(tag, lastFmSettingsService.getLang());
        if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
            StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
            TagInfoParser tiParser = new TagInfoParserImpl(stringUtil.getInputStream());
            tagInfos.add(tiParser.getTagInfo());
        }
        addFinishedOperation();
    }
    tagInfoDao.createTagInfo(tagInfos);
}
Also used : TagInfoParser(com.github.hakko.musiccabinet.parser.lastfm.TagInfoParser) TagInfo(com.github.hakko.musiccabinet.domain.model.music.TagInfo) ArrayList(java.util.ArrayList) TagInfoParserImpl(com.github.hakko.musiccabinet.parser.lastfm.TagInfoParserImpl) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Example 19 with StringUtil

use of com.github.hakko.musiccabinet.util.StringUtil 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);
}
Also used : UserRecommendedArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) UserRecommendedArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl) UserRecommendedArtistsParser(com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParser) ArrayList(java.util.ArrayList) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Aggregations

StringUtil (com.github.hakko.musiccabinet.util.StringUtil)19 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)15 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)14 ArrayList (java.util.ArrayList)10 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)5 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)4 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)3 Test (org.junit.Test)3 UserRecommendedArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists)2 MBArtist (com.github.hakko.musiccabinet.domain.model.music.MBArtist)2 ArtistInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl)2 ArtistTopTracksParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistTopTracksParserImpl)2 UserRecommendedArtistsParserImpl (com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl)2 GroupWeeklyArtistChart (com.github.hakko.musiccabinet.domain.model.aggr.GroupWeeklyArtistChart)1 TagTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists)1 UserLovedTracks (com.github.hakko.musiccabinet.domain.model.aggr.UserLovedTracks)1 RecommendedArtist (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist)1 UserStarredTrack (com.github.hakko.musiccabinet.domain.model.aggr.UserStarredTrack)1 UserTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserTopArtists)1 LastFmGroup (com.github.hakko.musiccabinet.domain.model.library.LastFmGroup)1