Search in sources :

Example 1 with RecommendedArtist

use of com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist in project musiccabinet by hakko.

the class JdbcUserRecommendedArtistsDaoTest method createArtistMetaData.

private void createArtistMetaData() {
    Set<Artist> artists = new HashSet<>();
    for (UserRecommendedArtists ura : Arrays.asList(joanRec, rjRec, ftpareaRec)) {
        for (RecommendedArtist rec : ura.getArtists()) {
            artists.add(rec.getArtist());
        }
    }
    List<File> files = new ArrayList<>();
    for (Artist artist : artists) {
        files.add(getFile(artist.getName(), null, null));
    }
    List<ArtistInfo> artistInfos = new ArrayList<>();
    for (Artist artist : artists) {
        artistInfos.add(new ArtistInfo(artist, "/url/to/" + artist.getName()));
    }
    additionDao.getJdbcTemplate().execute("truncate library.directory cascade");
    UnittestLibraryUtil.submitFile(additionDao, files);
    artistInfoDao.createArtistInfo(artistInfos);
}
Also used : RecommendedArtist(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist) Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) UserRecommendedArtists(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists) ArrayList(java.util.ArrayList) RecommendedArtist(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist) UnittestLibraryUtil.getFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile) File(com.github.hakko.musiccabinet.domain.model.library.File) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo) HashSet(java.util.HashSet)

Example 2 with RecommendedArtist

use of com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist in project musiccabinet by hakko.

the class UserRecommendedArtistsHandler method endElement.

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (TAG_CONTEXT.equals(qName)) {
        insideContext = false;
    }
    if (TAG_NAME.equals(qName)) {
        String chars = characterData.toString();
        Artist artist = new Artist(chars);
        if (insideContext) {
            if (currentRecommendedArtist.getContextArtist1() == null) {
                currentRecommendedArtist.setContextArtist1(artist);
            } else {
                currentRecommendedArtist.setContextArtist2(artist);
            }
        } else {
            artists.add(currentRecommendedArtist = new RecommendedArtist(artist));
        }
    }
}
Also used : RecommendedArtist(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist) Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) RecommendedArtist(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist)

Example 3 with RecommendedArtist

use of com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist in project musiccabinet by hakko.

the class UserRecommendedArtistsParserTest method resourceFile2CorrectlyParsed.

@Test
public void resourceFile2CorrectlyParsed() throws ApplicationException {
    WSResponse wsResponse = new WSResponse(new ResourceUtil(USER_RECOMMENDED_ARTISTS_FILE2).getContent());
    UserRecommendedArtistsParser parser = new UserRecommendedArtistsParserImpl(new StringUtil(wsResponse.getResponseBody()).getInputStream());
    List<RecommendedArtist> artists = parser.getArtists();
    for (int i = 0; i < EXPECTED_ARTISTS2.size(); i++) {
        assertEquals(EXPECTED_ARTISTS2.get(i), artists.get(i));
    }
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) RecommendedArtist(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) Test(org.junit.Test)

Example 4 with RecommendedArtist

use of com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist in project musiccabinet by hakko.

the class JdbcUserRecommendedArtistsDao method batchInsert.

private void batchInsert(List<RecommendedArtist> artists, LastFmUser user) {
    String sql = "insert into music.userrecommendedartist_import" + " (lastfm_user, artist_name, rank, contextartist1_name, contextartist2_name)" + " values (?,?,?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("lastfm_user", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("rank", Types.INTEGER));
    batchUpdate.declareParameter(new SqlParameter("contextartist1_name", Types.VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("contextartist2_name", Types.VARCHAR));
    for (int i = 0; i < artists.size(); i++) {
        RecommendedArtist rec = artists.get(i);
        batchUpdate.update(new Object[] { user.getLastFmUsername(), rec.getArtist().getName(), i, name(rec.getContextArtist1()), name(rec.getContextArtist2()) });
    }
    batchUpdate.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) RecommendedArtist(com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist)

Aggregations

RecommendedArtist (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists.RecommendedArtist)4 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)2 UserRecommendedArtists (com.github.hakko.musiccabinet.domain.model.aggr.UserRecommendedArtists)1 File (com.github.hakko.musiccabinet.domain.model.library.File)1 ArtistInfo (com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)1 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1 BatchSqlUpdate (org.springframework.jdbc.object.BatchSqlUpdate)1