use of com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists 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);
}
use of com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists in project musiccabinet by hakko.
the class JdbcTagDao method createTopArtists.
@Override
public void createTopArtists(List<TagTopArtists> tagTopArtists) {
if (tagTopArtists.size() > 0) {
clearImportTable();
for (TagTopArtists tta : tagTopArtists) {
batchInsert(tta.getTagName(), tta.getArtists());
}
updateUserTopArtists();
}
}
use of com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists 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());
}
use of com.github.hakko.musiccabinet.domain.model.aggr.TagTopArtists 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);
}
Aggregations