Search in sources :

Example 1 with UserRecommendedArtists

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

the class JdbcUserRecommendedArtistsDaoTest method loadFunctionDependency.

@Before
public void loadFunctionDependency() throws ApplicationException {
    PostgreSQLUtil.loadFunction(dao, UPDATE_USER_RECOMMENDED_ARTISTS);
    joanRec = new UserRecommendedArtists(joan, new UserRecommendedArtistsParserImpl(new ResourceUtil(JOAN_FILE).getInputStream()).getArtists());
    rjRec = new UserRecommendedArtists(rj, new UserRecommendedArtistsParserImpl(new ResourceUtil(RJ_FILE).getInputStream()).getArtists());
    String body = new WSResponse(new ResourceUtil(FTPAREA_FILE).getContent()).getResponseBody();
    ftpareaRec = new UserRecommendedArtists(ftparea, new UserRecommendedArtistsParserImpl(new StringUtil(body).getInputStream()).getArtists());
    createArtistMetaData();
}
Also used : UserRecommendedArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) UserRecommendedArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) Before(org.junit.Before)

Example 2 with UserRecommendedArtists

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

the class JdbcUserRecommendedArtistsDaoTest method createArtistMetaData.

private void createArtistMetaData() {
    Set<Artist> artists = new HashSet<>();
    for (UserRecommendedArtists ura : Arrays.asList(joanRec, rjRec, ftpareaRec)) {
        for (RecommendedArtist rec : ura.getArtists()) {
            artists.add(rec.getArtist());
        }
    }
    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.directory cascade");
    UnittestLibraryUtil.submitFile(additionDao, files);
    artistInfoDao.createArtistInfo(artistInfos);
}
Also used : RecommendedArtist(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist) Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) UserRecommendedArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists) ArrayList(java.util.ArrayList) RecommendedArtist(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist) 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 3 with UserRecommendedArtists

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

the class JdbcUserRecommendedArtistsDao method createUserRecommendedArtists.

@Override
public void createUserRecommendedArtists(List<UserRecommendedArtists> userRecommendedArtists) {
    if (userRecommendedArtists.size() > 0) {
        clearImportTable();
        for (UserRecommendedArtists uta : userRecommendedArtists) {
            batchInsert(uta.getArtists(), uta.getUser());
        }
        updateUserTopArtists();
    }
}
Also used : UserRecommendedArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists)

Example 4 with UserRecommendedArtists

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

UserRecommendedArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists)4 UserRecommendedArtistsParserImpl (com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParserImpl)2 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)2 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)2 ArrayList (java.util.ArrayList)2 RecommendedArtist (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist)1 File (com.github.hakko.musiccabinet.domain.model.library.File)1 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)1 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)1 ArtistInfo (com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 UserRecommendedArtistsParser (com.github.hakko.musiccabinet.parser.lastfm.UserRecommendedArtistsParser)1 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)1 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1