use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class MusicBrainzService method updateArtistIds.
protected void updateArtistIds() {
List<Artist> missingArtists = artistDao.getMissingArtists();
List<MBArtist> mbArtists = new ArrayList<>();
mbids = missingArtists.size();
for (Artist artist : artistDao.getMissingArtists()) {
try {
StringUtil response = new StringUtil(artistQueryClient.get(artist.getName()));
ArtistQueryParser parser = new ArtistQueryParserImpl(response.getInputStream());
if (parser.getArtist() != null) {
mbArtists.add(parser.getArtist());
if (mbArtists.size() > 100) {
artistDao.createArtists(mbArtists);
mbArtists.clear();
}
}
++mbid;
} catch (ApplicationException e) {
LOG.warn("Couldn't read mbid for " + artist.getName(), e);
}
}
artistDao.createArtists(mbArtists);
}
use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class UserRecommendedArtistsParserTest method resourceFile2CorrectlyParsed.
@Test
public void resourceFile2CorrectlyParsed() throws ApplicationException {
WSResponse wsResponse = new WSResponse(new ResourceUtil(USER_RECOMMENDED_ARTISTS_FILE2).getContent());
UserRecommendedArtistsParser parser = new UserRecommendedArtistsParserImpl(new StringUtil(wsResponse.getResponseBody()).getInputStream());
List<RecommendedArtist> artists = parser.getArtists();
for (int i = 0; i < EXPECTED_ARTISTS2.size(); i++) {
assertEquals(EXPECTED_ARTISTS2.get(i), artists.get(i));
}
}
use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class LastFmService method identifyLastFmUser.
public LastFmUser identifyLastFmUser(String token) throws ApplicationException {
LOG.debug("identifyLastFmUser(" + token + ")");
WSResponse wsResponse = authSessionClient.getAuthSession(token);
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
AuthSessionParser authSessionParser = new AuthSessionParserImpl(stringUtil.getInputStream());
return authSessionParser.getLastFmUser();
} else {
LOG.debug("wsResponse: " + wsResponse.getResponseBody());
throw new ApplicationException("Could not get session key for user! (code " + wsResponse.getErrorCode() + ", " + wsResponse.getErrorMessage() + ")");
}
}
use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class MusicBrainzService method updateArtistDiscographies.
protected void updateArtistDiscographies() {
List<MBArtist> outdatedArtists = artistDao.getOutdatedArtists();
List<MBRelease> mbReleases = new ArrayList<>();
ReleaseParser parser;
discographies = outdatedArtists.size();
for (MBArtist artist : outdatedArtists) {
try {
int offset = 0;
do {
StringUtil response = new StringUtil(releaseClient.get(artist.getName(), artist.getMbid(), offset));
parser = new ReleaseParserImpl(response.getInputStream());
for (MBRelease album : parser.getReleases()) {
album.setArtistId(artist.getId());
}
mbReleases.addAll(parser.getReleases());
offset += 100;
} while (offset < parser.getTotalReleases());
++discography;
if (mbReleases.size() > 1000) {
albumDao.createAlbums(mbReleases);
mbReleases.clear();
}
} catch (ApplicationException e) {
LOG.warn("Couldn't read discography for " + artist.getName(), e);
}
}
albumDao.createAlbums(mbReleases);
}
use of com.github.hakko.musiccabinet.util.StringUtil in project musiccabinet by hakko.
the class ArtistInfoService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_INFO);
List<ArtistInfo> artistInfos = new ArrayList<>(artistNames.size());
setTotalOperations(artistNames.size());
for (String artistName : artistNames) {
try {
WSResponse wsResponse = artistInfoClient.getArtistInfo(new Artist(artistName), lastFmSettingsService.getLang());
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
ArtistInfoParser aiParser = new ArtistInfoParserImpl(stringUtil.getInputStream());
if (aiParser.getArtistInfo() != null) {
artistInfos.add(aiParser.getArtistInfo());
} else {
LOG.warn("Artist info response for " + artistName + " not parsed correctly. Response was " + wsResponse.getResponseBody());
}
if (artistInfos.size() == BATCH_SIZE) {
artistInfoDao.createArtistInfo(artistInfos);
artistInfos.clear();
}
}
} catch (ApplicationException e) {
LOG.warn("Fetching artist info for " + artistName + " failed.", e);
}
addFinishedOperation();
}
artistInfoDao.createArtistInfo(artistInfos);
}
Aggregations