Search in sources :

Example 1 with MBArtist

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

the class ArtistQueryParserTest method emptyResourceFileCorrectlyParsed.

@Test
public void emptyResourceFileCorrectlyParsed() throws ApplicationException {
    ArtistQueryParser parser = new ArtistQueryParserImpl(new ResourceUtil(ARTIST_QUERY_EMPTY_FILE).getInputStream());
    MBArtist artist = parser.getArtist();
    assertNull(artist);
}
Also used : MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) Test(org.junit.Test)

Example 2 with MBArtist

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

the class ArtistQueryParserTest method resourceFileCorrectlyParsed.

@Test
public void resourceFileCorrectlyParsed() throws ApplicationException {
    ArtistQueryParser parser = new ArtistQueryParserImpl(new ResourceUtil(ARTIST_QUERY_FILE).getInputStream());
    MBArtist artist = parser.getArtist();
    assertEquals(MBID, artist.getMbid());
    assertEquals(NAME, artist.getName());
    assertEquals(COUNTRY_CODE, artist.getCountryCode());
    assertEquals(START_YEAR, artist.getStartYear());
    assertEquals(ACTIVE, artist.isActive());
}
Also used : MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) Test(org.junit.Test)

Example 3 with MBArtist

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

the class ArtistQueryParserTest method dateGetsStoredAsYearOnly.

@Test
public void dateGetsStoredAsYearOnly() throws ApplicationException {
    ArtistQueryParser parser = new ArtistQueryParserImpl(new ResourceUtil(ARTIST_QUERY_DATE_FILE).getInputStream());
    MBArtist artist = parser.getArtist();
    assertEquals(YEAR_PART, artist.getStartYear());
}
Also used : MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) Test(org.junit.Test)

Example 4 with MBArtist

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

the class MusicBrainzService method updateArtistIds.

protected void updateArtistIds() {
    List<Artist> missingArtists = artistDao.getMissingArtists();
    List<MBArtist> mbArtists = new ArrayList<>();
    mbids = missingArtists.size();
    for (Artist artist : artistDao.getMissingArtists()) {
        try {
            StringUtil response = new StringUtil(artistQueryClient.get(artist.getName()));
            ArtistQueryParser parser = new ArtistQueryParserImpl(response.getInputStream());
            if (parser.getArtist() != null) {
                mbArtists.add(parser.getArtist());
                if (mbArtists.size() > 100) {
                    artistDao.createArtists(mbArtists);
                    mbArtists.clear();
                }
            }
            ++mbid;
        } catch (ApplicationException e) {
            LOG.warn("Couldn't read mbid for " + artist.getName(), e);
        }
    }
    artistDao.createArtists(mbArtists);
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArrayList(java.util.ArrayList) ArtistQueryParser(com.github.hakko.musiccabinet.parser.musicbrainz.ArtistQueryParser) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ArtistQueryParserImpl(com.github.hakko.musiccabinet.parser.musicbrainz.ArtistQueryParserImpl)

Example 5 with MBArtist

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

the class MusicBrainzService method updateArtistDiscographies.

protected void updateArtistDiscographies() {
    List<MBArtist> outdatedArtists = artistDao.getOutdatedArtists();
    List<MBRelease> mbReleases = new ArrayList<>();
    ReleaseParser parser;
    discographies = outdatedArtists.size();
    for (MBArtist artist : outdatedArtists) {
        try {
            int offset = 0;
            do {
                StringUtil response = new StringUtil(releaseClient.get(artist.getName(), artist.getMbid(), offset));
                parser = new ReleaseParserImpl(response.getInputStream());
                for (MBRelease album : parser.getReleases()) {
                    album.setArtistId(artist.getId());
                }
                mbReleases.addAll(parser.getReleases());
                offset += 100;
            } while (offset < parser.getTotalReleases());
            ++discography;
            if (mbReleases.size() > 1000) {
                albumDao.createAlbums(mbReleases);
                mbReleases.clear();
            }
        } catch (ApplicationException e) {
            LOG.warn("Couldn't read discography for " + artist.getName(), e);
        }
    }
    albumDao.createAlbums(mbReleases);
}
Also used : MBArtist(com.github.hakko.musiccabinet.domain.model.music.MBArtist) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) ArrayList(java.util.ArrayList) ReleaseParser(com.github.hakko.musiccabinet.parser.musicbrainz.ReleaseParser) StringUtil(com.github.hakko.musiccabinet.util.StringUtil) ReleaseParserImpl(com.github.hakko.musiccabinet.parser.musicbrainz.ReleaseParserImpl) MBRelease(com.github.hakko.musiccabinet.domain.model.music.MBRelease)

Aggregations

MBArtist (com.github.hakko.musiccabinet.domain.model.music.MBArtist)8 Test (org.junit.Test)4 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)3 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)2 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)2 ArrayList (java.util.ArrayList)2 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)1 MBRelease (com.github.hakko.musiccabinet.domain.model.music.MBRelease)1 ArtistQueryParser (com.github.hakko.musiccabinet.parser.musicbrainz.ArtistQueryParser)1 ArtistQueryParserImpl (com.github.hakko.musiccabinet.parser.musicbrainz.ArtistQueryParserImpl)1 ReleaseParser (com.github.hakko.musiccabinet.parser.musicbrainz.ReleaseParser)1 ReleaseParserImpl (com.github.hakko.musiccabinet.parser.musicbrainz.ReleaseParserImpl)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1 BatchSqlUpdate (org.springframework.jdbc.object.BatchSqlUpdate)1