Package org.localify.data
Class SpotifyServiceUtils
java.lang.Object
org.localify.data.SpotifyServiceUtils
A utility class for the Spotify service.
This class contains methods that are shared across different parts of the Spotify service.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA holder for Spotify credentials. -
Constructor Summary
ConstructorsConstructorDescriptionSpotifyServiceUtils(GenreRepository genreRepository, ArtistGenreRepository artistGenreRepository, SongRepository songRepository, ArtistSongRepository artistSongRepository, UserRepository userRepository, ArtistChangeRepository artistChangeRepository) Constructs a new SpotifyServiceUtils. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddArtistGenres(Artist artist, String[] genres) Adds genres to an artist.createSpotifyArtist(se.michaelthelin.spotify.model_objects.specification.Artist artist) Creates a new artist from a Spotify artist object.findOrCreateSong(se.michaelthelin.spotify.model_objects.specification.Track track) Finds or creates a song from a Spotify track.getIsrc(se.michaelthelin.spotify.model_objects.specification.Track track) Gets the ISRC for a track.static StringgetLargestImage(se.michaelthelin.spotify.model_objects.specification.Image[] images) Gets the URL of the largest image from an array of images.getOrAddLocalifyArtistbySpotifyArtist(se.michaelthelin.spotify.model_objects.specification.Artist artist) Gets or adds a Localify artist from a Spotify artist object.getOrCreateGenreByName(String name) Gets or creates a genre by name.voidrefreshUserCreds(User ur) Refreshes a user's Spotify credentials.voidsaveArtistGenres(Artist artist, List<Genre> genres, DataSource dataSource) Saves the genres for an artist.voidSaves the songs for an artist.voidupdateSimilarArtists(Artist artist) Updates the similar artists for a given artist.voidupdateSong(Song song, se.michaelthelin.spotify.model_objects.specification.Track track) Updates a song with data from a Spotify track.
-
Constructor Details
-
SpotifyServiceUtils
public SpotifyServiceUtils(GenreRepository genreRepository, ArtistGenreRepository artistGenreRepository, SongRepository songRepository, ArtistSongRepository artistSongRepository, UserRepository userRepository, ArtistChangeRepository artistChangeRepository) Constructs a new SpotifyServiceUtils.- Parameters:
genreRepository- The genre repository.artistGenreRepository- The artist-genre repository.songRepository- The song repository.artistSongRepository- The artist-song repository.userRepository- The user repository.artistChangeRepository- The artist change repository.
-
-
Method Details
-
refreshUserCreds
Refreshes a user's Spotify credentials.- Parameters:
ur- The user to refresh credentials for.
-
addArtistGenres
Adds genres to an artist.- Parameters:
artist- The artist.genres- The genres to add.
-
createSpotifyArtist
@Transactional(propagation=REQUIRES_NEW) public Artist createSpotifyArtist(se.michaelthelin.spotify.model_objects.specification.Artist artist) Creates a new artist from a Spotify artist object.- Parameters:
artist- The Spotify artist object.- Returns:
- The created artist.
-
getOrAddLocalifyArtistbySpotifyArtist
@Transactional public Artist getOrAddLocalifyArtistbySpotifyArtist(se.michaelthelin.spotify.model_objects.specification.Artist artist) Gets or adds a Localify artist from a Spotify artist object.- Parameters:
artist- The Spotify artist object.- Returns:
- The Localify artist.
-
updateSimilarArtists
Updates the similar artists for a given artist.- Parameters:
artist- The artist to update.
-
getIsrc
Gets the ISRC for a track.- Parameters:
track- The track.- Returns:
- The ISRC.
-
updateSong
Updates a song with data from a Spotify track.- Parameters:
song- The song to update.track- The Spotify track.
-
findOrCreateSong
@Transactional(propagation=REQUIRES_NEW) public Song findOrCreateSong(se.michaelthelin.spotify.model_objects.specification.Track track) Finds or creates a song from a Spotify track.- Parameters:
track- The Spotify track.- Returns:
- The found or created song.
-
saveArtistGenres
@Transactional(propagation=REQUIRES_NEW) public void saveArtistGenres(Artist artist, List<Genre> genres, DataSource dataSource) Saves the genres for an artist.- Parameters:
artist- The artist.genres- The list of genres.dataSource- The data source.
-
saveSongs
Saves the songs for an artist.- Parameters:
artist- The artist.songs- The list of songs.
-
getOrCreateGenreByName
Gets or creates a genre by name.- Parameters:
name- The name of the genre.- Returns:
- The genre.
-
getLargestImage
public static String getLargestImage(se.michaelthelin.spotify.model_objects.specification.Image[] images) Gets the URL of the largest image from an array of images.- Parameters:
images- The array of images.- Returns:
- The URL of the largest image.
-