Class SpotifyServiceUtils

java.lang.Object
org.localify.data.SpotifyServiceUtils

@Service @Transactional public class SpotifyServiceUtils extends Object
A utility class for the Spotify service. This class contains methods that are shared across different parts of the Spotify service.
  • 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

      public void refreshUserCreds(User ur)
      Refreshes a user's Spotify credentials.
      Parameters:
      ur - The user to refresh credentials for.
    • addArtistGenres

      @Transactional public void addArtistGenres(Artist artist, String[] genres)
      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

      @Transactional(propagation=REQUIRES_NEW) public void updateSimilarArtists(Artist artist)
      Updates the similar artists for a given artist.
      Parameters:
      artist - The artist to update.
    • getIsrc

      public String getIsrc(se.michaelthelin.spotify.model_objects.specification.Track track)
      Gets the ISRC for a track.
      Parameters:
      track - The track.
      Returns:
      The ISRC.
    • updateSong

      public void updateSong(Song song, se.michaelthelin.spotify.model_objects.specification.Track track)
      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

      @Transactional(propagation=REQUIRES_NEW) public void saveSongs(Artist artist, List<Song> songs)
      Saves the songs for an artist.
      Parameters:
      artist - The artist.
      songs - The list of songs.
    • getOrCreateGenreByName

      public Genre getOrCreateGenreByName(String name)
      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.