use of com.github.hakko.musiccabinet.domain.model.library.LastFmGroup in project musiccabinet by hakko.
the class GroupWeeklyArtistChartClientTest method validateParameters.
@Test
public void validateParameters() throws ApplicationException {
final String method = GroupWeeklyArtistChartClient.METHOD;
final String lastFmGroup = "Brainwashed";
new GroupWeeklyArtistChartClient() {
@Override
protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
Assert.assertEquals(Calltype.GROUP_WEEKLY_ARTIST_CHART, wi.getCallType());
Assert.assertEquals(lastFmGroup, wi.getGroup().getName());
assertHasParameter(params, PARAM_METHOD, method);
assertHasParameter(params, PARAM_GROUP, lastFmGroup);
return null;
}
@Override
protected WebserviceHistoryService getHistoryService() {
return Mockito.mock(WebserviceHistoryService.class);
}
}.getWeeklyArtistChart(new LastFmGroup(lastFmGroup));
}
use of com.github.hakko.musiccabinet.domain.model.library.LastFmGroup 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.domain.model.library.LastFmGroup in project musiccabinet by hakko.
the class JdbcLastFmDao method setLastFmGroups.
@Override
public void setLastFmGroups(List<LastFmGroup> lastFmGroups) {
jdbcTemplate.update("truncate music.lastfmgroup_import");
String sql = "insert into music.lastfmgroup_import (group_name) values (?)";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.setBatchSize(1000);
batchUpdate.declareParameter(new SqlParameter("group_name", Types.VARCHAR));
for (LastFmGroup group : lastFmGroups) {
batchUpdate.update(new Object[] { group.getName() });
}
batchUpdate.flush();
jdbcTemplate.execute("select music.update_lastfmgroup()");
}
use of com.github.hakko.musiccabinet.domain.model.library.LastFmGroup in project musiccabinet by hakko.
the class GroupWeeklyArtistChartServiceTest method canInvokeService.
@Test
public void canInvokeService() throws ApplicationException {
GroupWeeklyArtistChart artistChart = service.getWeeklyArtistChart(new LastFmGroup("group name"));
Assert.assertNotNull(artistChart);
Assert.assertEquals(0, artistChart.getArtistPlayCounts().size());
}
use of com.github.hakko.musiccabinet.domain.model.library.LastFmGroup in project musiccabinet by hakko.
the class JdbcWebserviceHistoryDaoTest method importGroupRelatedDataNotPossibleTwice.
@Test
public void importGroupRelatedDataNotPossibleTwice() {
Calltype GROUP_ARTISTS = Calltype.GROUP_WEEKLY_ARTIST_CHART;
LastFmGroup group = new LastFmGroup("Brainwashed");
WebserviceInvocation groupArtists = new WebserviceInvocation(GROUP_ARTISTS, group);
deleteWebserviceInvocations();
assertTrue(dao.isWebserviceInvocationAllowed(groupArtists));
dao.logWebserviceInvocation(groupArtists);
assertFalse(dao.isWebserviceInvocationAllowed(groupArtists));
}
Aggregations