Search in sources :

Example 6 with Tag

use of com.github.hakko.musiccabinet.domain.model.music.Tag in project musiccabinet by hakko.

the class JdbcTagDaoTest method retrievesCorrectedAvailableTags.

@Test
public void retrievesCorrectedAvailableTags() {
    deleteTags();
    for (int i = 0; i < 5; i++) {
        artistTopTagsDao.createTopTags(new Artist("artist" + i), Arrays.asList(new Tag("sludge", (short) 100), new Tag("drone", (short) 90), new Tag("e-l-e-c-t-r-o", (short) 50), new Tag("disco", (short) 10)));
    }
    Map<String, String> tagCorrections = new HashMap<>();
    tagCorrections.put("e-l-e-c-t-r-o", "electro");
    dao.createTagCorrections(tagCorrections);
    dao.setTopTags(Arrays.asList("sludge"));
    List<TagOccurrence> tags = dao.getAvailableTags();
    Assert.assertEquals(3, tags.size());
    Assert.assertEquals("drone", tags.get(0).getTag());
    Assert.assertEquals("e-l-e-c-t-r-o", tags.get(1).getTag());
    Assert.assertEquals("electro", tags.get(1).getCorrectedTag());
    Assert.assertEquals("sludge", tags.get(2).getTag());
    Assert.assertFalse(tags.get(0).isUse());
    Assert.assertFalse(tags.get(1).isUse());
    Assert.assertTrue(tags.get(2).isUse());
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) HashMap(java.util.HashMap) TagOccurrence(com.github.hakko.musiccabinet.domain.model.aggr.TagOccurrence) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) Test(org.junit.Test)

Example 7 with Tag

use of com.github.hakko.musiccabinet.domain.model.music.Tag in project musiccabinet by hakko.

the class JdbcWebserviceHistoryDaoTest method tagHistoryAllowanceIsBasedOnId.

@Test
public void tagHistoryAllowanceIsBasedOnId() {
    tagDao.createTags(Arrays.asList("disco", "sludge"));
    Tag tag1 = tagDao.getTags().get(0);
    Tag tag2 = tagDao.getTags().get(1);
    Calltype TOP_ARTISTS = Calltype.TAG_GET_TOP_ARTISTS;
    WebserviceInvocation topArtists1 = new WebserviceInvocation(TOP_ARTISTS, tag1);
    WebserviceInvocation topArtists2 = new WebserviceInvocation(TOP_ARTISTS, tag2);
    deleteWebserviceInvocations();
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists2));
    dao.logWebserviceInvocation(topArtists2);
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
    dao.logWebserviceInvocation(topArtists2);
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
    dao.logWebserviceInvocation(topArtists1);
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists1));
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
}
Also used : Calltype(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) Test(org.junit.Test)

Example 8 with Tag

use of com.github.hakko.musiccabinet.domain.model.music.Tag 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);
}
Also used : TagTopArtistsParser(com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParser) TagTopArtistsParserImpl(com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParserImpl) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArrayList(java.util.ArrayList) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) TagTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists)

Example 9 with Tag

use of com.github.hakko.musiccabinet.domain.model.music.Tag in project musiccabinet by hakko.

the class TagTopArtistsClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = TagTopArtistsClient.METHOD;
    final Tag tag = new Tag(0, "sludge");
    new TagTopArtistsClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.TAG_GET_TOP_ARTISTS, wi.getCallType());
            Assert.assertEquals(tag, wi.getTag());
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_TAG, tag.getName());
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getTopArtists(tag);
}
Also used : NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) Test(org.junit.Test)

Example 10 with Tag

use of com.github.hakko.musiccabinet.domain.model.music.Tag in project musiccabinet by hakko.

the class ArtistTopTagsHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    if (TAG_TOP_TAGS.equals(qName)) {
        artistName = attributes.getValue(TAG_ARTIST);
        sourceArtist = new Artist(artistName);
    } else if (TAG_NAME.equals(qName)) {
        currentTag = new Tag();
        state = NAME;
        characterData = new StringBuilder();
    } else if (TAG_COUNT.equals(qName)) {
        state = COUNT;
        characterData = new StringBuilder();
    } else {
        state = null;
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag)

Aggregations

Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)15 Test (org.junit.Test)11 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)4 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)3 TagTopArtists (com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists)2 Calltype (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype)2 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)2 ArrayList (java.util.ArrayList)2 TagOccurrence (com.github.hakko.musiccabinet.domain.model.aggr.TagOccurrence)1 TagTopArtistsParser (com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParser)1 TagTopArtistsParserImpl (com.github.hakko.musiccabinet.parser.lastfm.TagTopArtistsParserImpl)1 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)1 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 HashMap (java.util.HashMap)1 NameValuePair (org.apache.http.NameValuePair)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1 BatchSqlUpdate (org.springframework.jdbc.object.BatchSqlUpdate)1