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();
}
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);
}
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();
}
}
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);
}
Aggregations