use of com.github.hakko.musiccabinet.domain.model.music.Tag in project musiccabinet by hakko.
the class JdbcTagDaoTest method retrievesCorrectedAvailableTags.
@Test
public void retrievesCorrectedAvailableTags() {
deleteTags();
for (int i = 0; i < 5; i++) {
artistTopTagsDao.createTopTags(new Artist("artist" + i), Arrays.asList(new Tag("sludge", (short) 100), new Tag("drone", (short) 90), new Tag("e-l-e-c-t-r-o", (short) 50), new Tag("disco", (short) 10)));
}
Map<String, String> tagCorrections = new HashMap<>();
tagCorrections.put("e-l-e-c-t-r-o", "electro");
dao.createTagCorrections(tagCorrections);
dao.setTopTags(Arrays.asList("sludge"));
List<TagOccurrence> tags = dao.getAvailableTags();
Assert.assertEquals(3, tags.size());
Assert.assertEquals("drone", tags.get(0).getTag());
Assert.assertEquals("e-l-e-c-t-r-o", tags.get(1).getTag());
Assert.assertEquals("electro", tags.get(1).getCorrectedTag());
Assert.assertEquals("sludge", tags.get(2).getTag());
Assert.assertFalse(tags.get(0).isUse());
Assert.assertFalse(tags.get(1).isUse());
Assert.assertTrue(tags.get(2).isUse());
}
use of com.github.hakko.musiccabinet.domain.model.music.Tag in project musiccabinet by hakko.
the class JdbcWebserviceHistoryDaoTest method tagHistoryAllowanceIsBasedOnId.
@Test
public void tagHistoryAllowanceIsBasedOnId() {
tagDao.createTags(Arrays.asList("disco", "sludge"));
Tag tag1 = tagDao.getTags().get(0);
Tag tag2 = tagDao.getTags().get(1);
Calltype TOP_ARTISTS = Calltype.TAG_GET_TOP_ARTISTS;
WebserviceInvocation topArtists1 = new WebserviceInvocation(TOP_ARTISTS, tag1);
WebserviceInvocation topArtists2 = new WebserviceInvocation(TOP_ARTISTS, tag2);
deleteWebserviceInvocations();
assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
assertTrue(dao.isWebserviceInvocationAllowed(topArtists2));
dao.logWebserviceInvocation(topArtists2);
assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
dao.logWebserviceInvocation(topArtists2);
assertTrue(dao.isWebserviceInvocationAllowed(topArtists1));
assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
dao.logWebserviceInvocation(topArtists1);
assertFalse(dao.isWebserviceInvocationAllowed(topArtists1));
assertFalse(dao.isWebserviceInvocationAllowed(topArtists2));
}
use of com.github.hakko.musiccabinet.domain.model.music.Tag 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.music.Tag in project musiccabinet by hakko.
the class TagTopArtistsClientTest method validateParameters.
@Test
public void validateParameters() throws ApplicationException {
final String method = TagTopArtistsClient.METHOD;
final Tag tag = new Tag(0, "sludge");
new TagTopArtistsClient() {
@Override
protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
Assert.assertEquals(Calltype.TAG_GET_TOP_ARTISTS, wi.getCallType());
Assert.assertEquals(tag, wi.getTag());
assertHasParameter(params, PARAM_METHOD, method);
assertHasParameter(params, PARAM_TAG, tag.getName());
return null;
}
@Override
protected WebserviceHistoryService getHistoryService() {
return Mockito.mock(WebserviceHistoryService.class);
}
}.getTopArtists(tag);
}
use of com.github.hakko.musiccabinet.domain.model.music.Tag in project musiccabinet by hakko.
the class ArtistTopTagsHandler method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (TAG_TOP_TAGS.equals(qName)) {
artistName = attributes.getValue(TAG_ARTIST);
sourceArtist = new Artist(artistName);
} else if (TAG_NAME.equals(qName)) {
currentTag = new Tag();
state = NAME;
characterData = new StringBuilder();
} else if (TAG_COUNT.equals(qName)) {
state = COUNT;
characterData = new StringBuilder();
} else {
state = null;
}
}
Aggregations