use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.
the class ArtistInfoClientTest method validateParameters.
@Test
public void validateParameters() throws ApplicationException {
final String method = ArtistInfoClient.METHOD;
final String artistName = "madonna";
final String lang = Locale.FRANCE.getLanguage();
new ArtistInfoClient() {
@Override
protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
Assert.assertEquals(Calltype.ARTIST_GET_INFO, wi.getCallType());
Assert.assertTrue(artistName.equals(wi.getArtist().getName()));
assertHasParameter(params, PARAM_METHOD, method);
assertHasParameter(params, PARAM_ARTIST, artistName);
assertHasParameter(params, PARAM_LANG, lang);
return null;
}
@Override
protected WebserviceHistoryService getHistoryService() {
return Mockito.mock(WebserviceHistoryService.class);
}
}.getArtistInfo(new Artist(artistName), lang);
}
use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.
the class ArtistTopTagsClientTest method validateParameters.
@Test
public void validateParameters() throws ApplicationException {
final String method = ArtistTopTagsClient.METHOD;
final String artistName = "madonna";
new ArtistTopTagsClient() {
@Override
protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
Assert.assertEquals(Calltype.ARTIST_GET_TOP_TAGS, wi.getCallType());
Assert.assertTrue(artistName.equals(wi.getArtist().getName()));
assertHasParameter(params, PARAM_METHOD, method);
assertHasParameter(params, PARAM_ARTIST, artistName);
return null;
}
@Override
protected WebserviceHistoryService getHistoryService() {
return Mockito.mock(WebserviceHistoryService.class);
}
}.getTopTags(new Artist(artistName));
}
use of com.github.hakko.musiccabinet.domain.model.music.Artist 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.domain.model.music.Artist 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.domain.model.music.Artist in project musiccabinet by hakko.
the class ArtistQueryClient method get.
public String get(String artistName) throws ApplicationException {
WebserviceInvocation invocation = new WebserviceInvocation(MB_ARTIST_QUERY, new Artist(artistName));
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair(QUERY, ARTIST + escape(artistName)));
params.add(new BasicNameValuePair(LIMIT, ONE));
return executeWSRequest(invocation, PATH, params);
}
Aggregations