use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class AlbumInfoService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
List<Album> albums = albumInfoDao.getAlbumsWithoutInfo();
List<AlbumInfo> albumInfos = new ArrayList<>();
setTotalOperations(albums.size());
for (Album album : albums) {
try {
WSResponse wsResponse = albumInfoClient.getAlbumInfo(album);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
AlbumInfoParser aiParser = new AlbumInfoParserImpl(stringUtil.getInputStream());
albumInfos.add(aiParser.getAlbumInfo());
if (albumInfos.size() == BATCH_SIZE) {
albumInfoDao.createAlbumInfo(albumInfos);
albumInfos.clear();
}
}
} catch (ApplicationException e) {
LOG.warn("Fetching album info for " + album.getName() + " failed.", e);
}
addFinishedOperation();
}
albumInfoDao.createAlbumInfo(albumInfos);
}
use of com.github.hakko.musiccabinet.util.StringUtil 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();
}
}
use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class GroupWeeklyArtistChartService method updateSearchIndex.
@Override
public void updateSearchIndex() throws ApplicationException {
List<GroupWeeklyArtistChart> artistCharts = new ArrayList<>();
List<LastFmGroup> groups = lastFmDao.getLastFmGroups();
setTotalOperations(groups.size());
for (LastFmGroup group : groups) {
try {
WSResponse wsResponse = client.getWeeklyArtistChart(group);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
GroupWeeklyArtistChartParser parser = new GroupWeeklyArtistChartParserImpl(stringUtil.getInputStream());
artistCharts.add(new GroupWeeklyArtistChart(group.getName(), parser.getArtistPlayCount()));
}
} catch (ApplicationException e) {
LOG.warn("Fetching weekly artist chart for " + group.getName() + " failed.", e);
}
addFinishedOperation();
}
dao.createArtistCharts(artistCharts);
}
use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class ScrobbledTracksService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
short page = 0, totalPages = 0;
do {
WSResponse wsResponse = client.getLibraryTracks(page, lastFmSettingsService.getLastFmUsername());
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
ScrobbledTracksParser parser = new ScrobbledTracksParserImpl(stringUtil.getInputStream());
totalPages = parser.getTotalPages();
trackPlayCountDao.createTrackPlayCounts(parser.getTrackPlayCounts());
setTotalOperations(totalPages);
addFinishedOperation();
}
} while (++page < totalPages);
}
use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class TagTopArtistsService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
List<TagTopArtists> topArtists = new ArrayList<>();
List<Tag> tags = tagDao.getTagsWithoutTopArtists();
setTotalOperations(tags.size());
for (Tag tag : tags) {
try {
WSResponse wsResponse = tagTopArtistsClient.getTopArtists(tag);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
TagTopArtistsParser parser = new TagTopArtistsParserImpl(stringUtil.getInputStream());
topArtists.add(new TagTopArtists(tag.getName(), parser.getArtists()));
}
} catch (ApplicationException e) {
LOG.warn("Fetching top artist for " + tag.getName() + " failed.", e);
}
addFinishedOperation();
}
tagDao.createTopArtists(topArtists);
}
Aggregations