Search in sources :

Example 1 with TagInfo

use of com.github.hakko.musiccabinet.domain.model.music.TagInfo in project musiccabinet by hakko.

the class TagInfoParserTest method resourceFileCorrectlyParsed.

@Test
public void resourceFileCorrectlyParsed() throws ApplicationException {
    TagInfoParser parser = new TagInfoParserImpl(new ResourceUtil(TAG_INFO_FILE).getInputStream());
    TagInfo tagInfo = parser.getTagInfo();
    Assert.assertEquals(NAME, tagInfo.getTagName());
    Assert.assertEquals(SUMMARY, tagInfo.getSummary());
    Assert.assertEquals(CONTENT, tagInfo.getContent());
}
Also used : ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) TagInfo(com.github.hakko.musiccabinet.domain.model.music.TagInfo) Test(org.junit.Test)

Example 2 with TagInfo

use of com.github.hakko.musiccabinet.domain.model.music.TagInfo in project musiccabinet by hakko.

the class JdbcTagInfoDao method createTagInfo.

@Override
public void createTagInfo(List<TagInfo> tagInfos) {
    String sql = "insert into music.taginfo_import (tag_name, summary, content) values (?,?,?)";
    BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batchUpdate.setBatchSize(1000);
    batchUpdate.declareParameter(new SqlParameter("tag_name", VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("summary", VARCHAR));
    batchUpdate.declareParameter(new SqlParameter("content", VARCHAR));
    for (TagInfo ti : tagInfos) {
        batchUpdate.update(new Object[] { ti.getTagName(), ti.getSummary(), ti.getContent() });
    }
    batchUpdate.flush();
    jdbcTemplate.execute("select music.update_taginfo()");
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) TagInfo(com.github.hakko.musiccabinet.domain.model.music.TagInfo) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate)

Example 3 with TagInfo

use of com.github.hakko.musiccabinet.domain.model.music.TagInfo in project musiccabinet by hakko.

the class TagInfoService method updateSearchIndex.

@Override
protected void updateSearchIndex() throws ApplicationException {
    List<TagInfo> tagInfos = new ArrayList<>();
    Set<String> tags = getTagsForUpdate();
    setTotalOperations(tags.size());
    for (String tag : tags) {
        WSResponse wsResponse = tagInfoClient.getTagInfo(tag, lastFmSettingsService.getLang());
        if (wsResponse.wasCallAllowed() && wsResponse.wasCallSuccessful()) {
            StringUtil stringUtil = new StringUtil(wsResponse.getResponseBody());
            TagInfoParser tiParser = new TagInfoParserImpl(stringUtil.getInputStream());
            tagInfos.add(tiParser.getTagInfo());
        }
        addFinishedOperation();
    }
    tagInfoDao.createTagInfo(tagInfos);
}
Also used : TagInfoParser(com.github.hakko.musiccabinet.parser.lastfm.TagInfoParser) TagInfo(com.github.hakko.musiccabinet.domain.model.music.TagInfo) ArrayList(java.util.ArrayList) TagInfoParserImpl(com.github.hakko.musiccabinet.parser.lastfm.TagInfoParserImpl) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) StringUtil(com.github.hakko.musiccabinet.util.StringUtil)

Example 4 with TagInfo

use of com.github.hakko.musiccabinet.domain.model.music.TagInfo in project musiccabinet by hakko.

the class TagInfoHandler method endElement.

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    String chars = characterData.toString();
    if (TAG_NAME.equals(qName)) {
        tagInfo = new TagInfo();
        tagInfo.setTagName(chars);
    } else if (TAG_SUMMARY.equals(qName)) {
        tagInfo.setSummary(chars);
    } else if (TAG_CONTENT.equals(qName)) {
        tagInfo.setContent(chars);
    }
}
Also used : TagInfo(com.github.hakko.musiccabinet.domain.model.music.TagInfo)

Aggregations

TagInfo (com.github.hakko.musiccabinet.domain.model.music.TagInfo)4 TagInfoParser (com.github.hakko.musiccabinet.parser.lastfm.TagInfoParser)1 TagInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.TagInfoParserImpl)1 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1 BatchSqlUpdate (org.springframework.jdbc.object.BatchSqlUpdate)1