Search in sources :

Example 11 with Tag

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

the class JdbcTagDaoTest method tagsWithTopArtistsAreNotPickedForUpdate.

@Test
public void tagsWithTopArtistsAreNotPickedForUpdate() {
    deleteTags();
    List<String> tagNames = Arrays.asList("disco", "sludge");
    dao.createTags(tagNames);
    dao.setTopTags(tagNames);
    List<TagTopArtists> topArtists = Arrays.asList(new TagTopArtists("disco", asList(new Artist("Madonna"))));
    dao.createTopArtists(topArtists);
    List<Tag> tags = dao.getTagsWithoutTopArtists();
    Assert.assertEquals(1, tags.size());
    Assert.assertEquals("sludge", tags.get(0).getName());
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) TagTopArtists(com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists) Test(org.junit.Test)

Example 12 with Tag

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

the class JdbcArtistTopTagsDaoTest method storeUpdateAndValidateTopTags.

@Test
public void storeUpdateAndValidateTopTags() throws ApplicationException {
    deleteArtistTopTags();
    dao.createTopTags(cherArtist, cherTopTags);
    dao.createTopTags(rihannaArtist, rihannaTopTags);
    rihannaTopTags = new ArrayList<>();
    rihannaTopTags.add(new Tag("dance", (short) 22));
    rihannaTopTags.add(new Tag("r&b", (short) 8));
    dao.createTopTags(rihannaArtist, rihannaTopTags);
    List<Tag> cherStoredTopTags = dao.getTopTags(cherArtist.getId());
    List<Tag> rihannaStoredTopTags = dao.getTopTags(rihannaArtist.getId());
    assertEquals(100, cherStoredTopTags.size());
    assertEquals(2, rihannaStoredTopTags.size());
    for (int i = 0; i < cherTopTags.size(); i++) {
        assertTrue(cherStoredTopTags.contains(cherTopTags.get(i)));
    }
    for (int i = 0; i < rihannaTopTags.size(); i++) {
        assertTrue(rihannaStoredTopTags.contains(rihannaTopTags.get(i)));
    }
}
Also used : Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) Test(org.junit.Test)

Example 13 with Tag

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

the class JdbcArtistTopTagsDaoTest method returnsMostPopularCloudTagsForArtist.

@Test
public void returnsMostPopularCloudTagsForArtist() throws ApplicationException {
    deleteArtistTopTags();
    dao.createTopTags(cherArtist, cherTopTags);
    int cherId = musicDao.getArtistId(cherArtist);
    Tag tagPop = new Tag("pop", (short) 100), tag80s = new Tag("80s", (short) 52);
    tagDao.setTopTags(Arrays.asList(tagPop.getName(), tag80s.getName()));
    assertEquals(asList(tagPop), dao.getTopTags(cherId, 1));
    assertEquals(asList(tagPop, tag80s), dao.getTopTags(cherId, 3));
}
Also used : Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) Test(org.junit.Test)

Example 14 with Tag

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

the class JdbcWebserviceHistoryDaoTest method importTagRelatedDataNotPossibleTwice.

@Test
public void importTagRelatedDataNotPossibleTwice() {
    tagDao.createTags(Arrays.asList("disco"));
    Tag tag = tagDao.getTags().get(0);
    Calltype TOP_ARTISTS = Calltype.TAG_GET_TOP_ARTISTS;
    WebserviceInvocation topArtists = new WebserviceInvocation(TOP_ARTISTS, tag);
    deleteWebserviceInvocations();
    assertTrue(dao.isWebserviceInvocationAllowed(topArtists));
    dao.logWebserviceInvocation(topArtists);
    assertFalse(dao.isWebserviceInvocationAllowed(topArtists));
}
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 15 with Tag

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

the class JdbcArtistTopTagsDao method batchInsert.

private void batchInsert(Artist artist, List<Tag> tags) {
    int sourceArtistId = jdbcTemplate.queryForInt("select * from music.get_artist_id(?)", artist.getName());
    String sql = "insert into music.artisttoptag_import (artist_id, tag_name, tag_count) values (?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("artist_id", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("tag_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("tag_count", Types.SMALLINT));
    for (Tag tag : tags) {
        batchUpdate.update(new Object[] { sourceArtistId, tag.getName(), tag.getCount() });
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) 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