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);
}
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));
}
}
}
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));
}
}
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();
}
Aggregations