use of com.github.hakko.musiccabinet.domain.model.music.ArtistInfo in project musiccabinet by hakko.
the class ArtistInfoService method updateSearchIndex.
@Override
protected void updateSearchIndex() throws ApplicationException {
Set<String> artistNames = webserviceHistoryService.getArtistNamesScheduledForUpdate(ARTIST_GET_INFO);
List<ArtistInfo> artistInfos = new ArrayList<>(artistNames.size());
setTotalOperations(artistNames.size());
for (String artistName : artistNames) {
try {
WSResponse wsResponse = artistInfoClient.getArtistInfo(new Artist(artistName), lastFmSettingsService.getLang());
if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
ArtistInfoParser aiParser = new ArtistInfoParserImpl(stringUtil.getInputStream());
if (aiParser.getArtistInfo() != null) {
artistInfos.add(aiParser.getArtistInfo());
} else {
LOG.warn("Artist info response for " + artistName + " not parsed correctly. Response was " + wsResponse.getResponseBody());
}
if (artistInfos.size() == BATCH_SIZE) {
artistInfoDao.createArtistInfo(artistInfos);
artistInfos.clear();
}
}
} catch (ApplicationException e) {
LOG.warn("Fetching artist info for " + artistName + " failed.", e);
}
addFinishedOperation();
}
artistInfoDao.createArtistInfo(artistInfos);
}
use of com.github.hakko.musiccabinet.domain.model.music.ArtistInfo in project musiccabinet by hakko.
the class JdbcArtistInfoDaoTest method unknownArtistInfoReturnsNull.
@Test
public void unknownArtistInfoReturnsNull() throws ApplicationException {
int unknownId = -1;
ArtistInfo artistInfo = dao.getArtistInfo(unknownId);
assertNull(artistInfo);
}
use of com.github.hakko.musiccabinet.domain.model.music.ArtistInfo in project musiccabinet by hakko.
the class JdbcArtistRecommendationDaoTest method createTestData.
@Before
public void createTestData() throws ApplicationException {
PostgreSQLUtil.truncateTables(artistRecommendationDao);
List<ArtistRelation> artistRelations = new ArrayList<>();
for (Artist targetArtist : asList(madonna, cyndi, celine, kylie)) {
artistRelations.add(new ArtistRelation(targetArtist, 0.33f));
}
artistRelationDao.createArtistRelations(cher, artistRelations);
tagDao.createTags(asList("disco"));
tagDao.createTopArtists(Arrays.asList(new TagTopArtists("disco", Arrays.asList(cher, madonna, cyndi, celine, kylie))));
Track track1, track2, track3;
artistTopTracksDao.createTopTracks(madonna, Arrays.asList(track1 = new Track(madonna, "Like A Prayer"), track2 = new Track(madonna, "Hung Up"), new Track(madonna, "Frozen")));
artistTopTracksDao.createTopTracks(cyndi, Arrays.asList(track3 = new Track(cyndi, "Time After Time"), new Track(cyndi, "Girls Just Wanna Have Fun")));
artistTopTracksDao.createTopTracks(celine, Arrays.asList(new Track(celine, "My Heart Will Go On")));
artistTopTracksDao.createTopTracks(kylie, Arrays.asList(new Track(kylie, "Love At First Sight")));
List<File> files = new ArrayList<>();
for (Track track : Arrays.asList(track1, track2, track3)) {
files.add(getFile(track));
}
UnittestLibraryUtil.submitFile(additionDao, files);
playlistGeneratorService.updateSearchIndex();
cherId = musicDao.getArtistId(cher);
List<ArtistInfo> artistInfos = new ArrayList<>();
for (Artist artist : Arrays.asList(madonna, cyndi, celine, kylie)) {
artistInfos.add(new ArtistInfo(artist, "/image/for/" + artist.getName()));
}
artistInfoDao.createArtistInfo(artistInfos);
}
use of com.github.hakko.musiccabinet.domain.model.music.ArtistInfo in project musiccabinet by hakko.
the class JdbcUserTopArtistsDaoTest method createArtistMetaData.
private void createArtistMetaData() {
Set<Artist> artists = new HashSet<>();
for (UserTopArtists uta : Arrays.asList(arnOverall, arn6month, sys3month)) {
for (Artist artist : uta.getArtists()) {
artists.add(artist);
}
}
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.file cascade");
UnittestLibraryUtil.submitFile(additionDao, files);
artistInfoDao.createArtistInfo(artistInfos);
}
use of com.github.hakko.musiccabinet.domain.model.music.ArtistInfo in project musiccabinet by hakko.
the class JdbcArtistInfoDaoTest method createAndValidateUpdatedArtistInfos.
@Test
public void createAndValidateUpdatedArtistInfos() throws ApplicationException {
deleteArtistInfos();
String newBio = "Abba was a pop group.";
String newContent = "Abba was a pop group. They sold many records.";
dao.createArtistInfo(Arrays.asList(aiAbba, aiTina));
aiAbba.setBioSummary(newBio);
aiAbba.setBioContent(newContent);
dao.createArtistInfo(Arrays.asList(aiAbba, aiCher));
ArtistInfo dbAbba = dao.getArtistInfo(aiAbba.getArtist());
Assert.assertEquals(newBio, dbAbba.getBioSummary());
Assert.assertEquals(newContent, dbAbba.getBioContent());
}
Aggregations