Search in sources :

Example 1 with LastFmGroup

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));
}
Also used : NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) LastFmGroup(com.github.hakko.musiccabinet.domain.model.library.LastFmGroup) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 2 with 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);
}
Also used : LastFmGroup(com.github.hakko.musiccabinet.domain.model.library.LastFmGroup) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArrayList(java.util.ArrayList) GroupWeeklyArtistChart(com.github.hakko.musiccabinet.domain.model.aggr.GroupWeeklyArtistChart) GroupWeeklyArtistChartParser(com.github.hakko.musiccabinet.parser.lastfm.GroupWeeklyArtistChartParser) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) GroupWeeklyArtistChartParserImpl(com.github.hakko.musiccabinet.parser.lastfm.GroupWeeklyArtistChartParserImpl)

Example 3 with LastFmGroup

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()");
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) LastFmGroup(com.github.hakko.musiccabinet.domain.model.library.LastFmGroup) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 4 with 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());
}
Also used : LastFmGroup(com.github.hakko.musiccabinet.domain.model.library.LastFmGroup) GroupWeeklyArtistChart(com.github.hakko.musiccabinet.domain.model.aggr.GroupWeeklyArtistChart) Test(org.junit.Test)

Example 5 with LastFmGroup

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));
}
Also used : LastFmGroup(com.github.hakko.musiccabinet.domain.model.library.LastFmGroup) Calltype(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Aggregations

LastFmGroup (com.github.hakko.musiccabinet.domain.model.library.LastFmGroup)6 Test (org.junit.Test)4 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)3 GroupWeeklyArtistChart (com.github.hakko.musiccabinet.domain.model.aggr.GroupWeeklyArtistChart)2 Calltype (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype)2 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)2 GroupWeeklyArtistChartParser (com.github.hakko.musiccabinet.parser.lastfm.GroupWeeklyArtistChartParser)1 GroupWeeklyArtistChartParserImpl (com.github.hakko.musiccabinet.parser.lastfm.GroupWeeklyArtistChartParserImpl)1 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 ArrayList (java.util.ArrayList)1 NameValuePair (org.apache.http.NameValuePair)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1 BatchSqlUpdate (org.springframework.jdbc.object.BatchSqlUpdate)1