use of com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParserImpl in project musiccabinet by hakko.
the class UserTopArtistsService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
List<LastFmUser> users = lastFmSettingsService.getLastFmUsers();
setTotalOperations(users.size() * Period.values().length);
List<UserTopArtists> userTopArtists = new ArrayList<>();
for (LastFmUser user : users) {
for (Period period : Period.values()) {
try {
WSResponse wsResponse = userTopArtistsClient.getUserTopArtists(user, period);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
UserTopArtistsParser parser = new UserTopArtistsParserImpl(stringUtil.getInputStream());
userTopArtists.add(new UserTopArtists(user, period, parser.getArtists()));
}
} catch (ApplicationException e) {
LOG.warn("Fetching top artist for " + user.getLastFmUsername() + ", " + period.getDescription() + " failed.", e);
}
addFinishedOperation();
}
}
userTopArtistsDao.createUserTopArtists(userTopArtists);
}
use of com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParserImpl in project musiccabinet by hakko.
the class UserTopArtistsServiceTest method createArtistInfosAndLocalFiles.
private void createArtistInfosAndLocalFiles() throws ApplicationException {
Map<Artist, ArtistInfo> artistInfos = new HashMap<>();
List<File> files = new ArrayList<>();
for (Period period : Period.values()) {
String fileName = format(TOP_ARTISTS_FILE, period.getDescription());
for (Artist artist : new UserTopArtistsParserImpl(new ResourceUtil(fileName, UTF8).getInputStream()).getArtists()) {
artistInfos.put(artist, new ArtistInfo(artist));
files.add(UnittestLibraryUtil.getFile(artist.getName(), "A", "T"));
}
}
artistInfoDao.createArtistInfo(new ArrayList<ArtistInfo>(artistInfos.values()));
submitFile(additionDao, files);
}
use of com.github.hakko.musiccabinet.parser.lastfm.UserTopArtistsParserImpl in project musiccabinet by hakko.
the class JdbcUserTopArtistsDaoTest method loadFunctionDependency.
@Before
public void loadFunctionDependency() throws ApplicationException {
PostgreSQLUtil.loadFunction(dao, UPDATE_USER_TOP_ARTISTS);
arnOverall = new UserTopArtists(arn, Period.OVERALL, new UserTopArtistsParserImpl(new ResourceUtil(ARN_OVERALL_FILE).getInputStream()).getArtists());
arn6month = new UserTopArtists(arn, Period.SIX_MONTHS, new UserTopArtistsParserImpl(new ResourceUtil(ARN_6MONTH_FILE).getInputStream()).getArtists());
sys3month = new UserTopArtists(sys, Period.THREE_MONTHS, new UserTopArtistsParserImpl(new ResourceUtil(SYS_3MONTH_FILE).getInputStream()).getArtists());
createArtistMetaData();
}
Aggregations