@RequestMapping(method = RequestMethod.GET, value = "/artist/{artistName}/listeners")
  public String viewArtistListeners(
      @PathVariable("artistName") String artistName, Model map, HttpSession session) {
    artistName = UtilImpl.rewriteParams(artistName);
    Integer pageSize = 6;
    Integer fanNumberOfArtist;
    Integer fanPageNumberOfArtist;
    Integer artistID;

    Artist artist = serviceFactory.getArtistService().getArtistByName(artistName);
    artistID = artist.getArtistid();
    List<ArtistFans> artistFans =
        serviceFactory.getArtistService().getArtistFans(artist, 0, pageSize.intValue());

    fanNumberOfArtist = serviceFactory.getArtistService().getFanNumberOfAnArtist(artistID);

    if ((fanNumberOfArtist % pageSize) == 0) {
      fanPageNumberOfArtist = (fanNumberOfArtist / pageSize);
    } else {
      fanPageNumberOfArtist = (fanNumberOfArtist / pageSize) + 1;
    }

    map.addAttribute("fanPageNumberOfArtist", fanPageNumberOfArtist);
    map.addAttribute("artistId", artistID);
    map.addAttribute("artistFans", artistFans);
    return "artist/artist_listeners";
  }
  @RequestMapping(method = RequestMethod.GET, value = "/artist/{artistName}/albums")
  public String viewArtistAlbums(
      @PathVariable("artistName") String artistName, Model map, HttpSession session) {
    artistName = UtilImpl.rewriteParams(artistName);
    Integer artistID;
    Integer pageSize = 4;
    Integer albumNumberOfArtist;
    Integer albumPageNumberOfArtist;

    Artist artist = serviceFactory.getArtistService().getArtistByName(artistName);
    artistID = artist.getArtistid();
    albumNumberOfArtist = serviceFactory.getAlbumService().getAlbumNumberOfArtist(artistID);
    List<Album> albums =
        serviceFactory.getAlbumService().getAlbumsByArtist(artist, 0, pageSize.intValue());

    if ((albumNumberOfArtist % pageSize) == 0) {
      albumPageNumberOfArtist = (albumNumberOfArtist / pageSize);
    } else {
      albumPageNumberOfArtist = (albumNumberOfArtist / pageSize) + 1;
    }

    map.addAttribute("albums", albums);
    map.addAttribute("artistId", artistID);
    map.addAttribute("albumPageNumberOfArtist", albumPageNumberOfArtist);
    return "artist/artist_albums";
  }
  @RequestMapping(method = RequestMethod.GET, value = "/artist/{artistName}/songs")
  public String viewArtistSongs(
      @PathVariable("artistName") String artistName, Model map, HttpSession session) {
    artistName = UtilImpl.rewriteParams(artistName);
    Integer artistId;
    Integer songNumberOfArtist;
    Integer songPageNumberOfArtist;
    Artist artist = serviceFactory.getArtistService().getArtistByName(artistName);
    artistId = artist.getArtistid();
    songNumberOfArtist = serviceFactory.getSongService().getSongNumberOfArtist(artistId);
    // List songs = serviceFactory.getListenHistoryService().getMostListenedSongsByArtist(artist, 0,
    // 10);
    // List<SongStats> songs = serviceFactory.getSongService().getTopSongsByArtist(artist, 0, 10);

    List<SongStats> songs = serviceFactory.getSongService().getSongsOfArtistByPage(artist, 1);

    songPageNumberOfArtist = (songNumberOfArtist / 10) + 1;
    map.addAttribute("songs", songs);
    map.addAttribute("artistId", artistId);
    map.addAttribute("songPageNumberOfArtist", songPageNumberOfArtist);
    return "artist/artist_popular_songs";
  }
  @RequestMapping(method = RequestMethod.GET, value = "/artist/{artistName}/similiars")
  public String viewArtistSimiliars(
      @PathVariable("artistName") String artistName, Model map, HttpSession session) {
    artistName = UtilImpl.rewriteParams(artistName);
    Integer artistID;
    Integer similiarArtistPageNumberOfArtist;
    Integer similiarArtistNumberOfArtist;
    Integer pageSize = 5;

    Artist artist = serviceFactory.getArtistService().getArtistByName(artistName);
    List<ArtistSimiliar> similiars =
        serviceFactory.getArtistService().getSimiliarArtists(artist, 0, pageSize.intValue());

    for (ArtistSimiliar similiar : similiars) {
      serviceFactory.getArtistService().saveArtistBioAndPicture(similiar.getSimiliarArtistid());
    }

    String biography = artist.getBiography();
    if (biography != null && artist.getBiography().length() > 50) {
      biography = biography.substring(0, 50);
    }

    artistID = artist.getArtistid();
    similiarArtistNumberOfArtist =
        serviceFactory.getArtistService().getSimiliarArtistNumberOfAnArtist(artistID);

    if ((similiarArtistNumberOfArtist % pageSize) == 0) {
      similiarArtistPageNumberOfArtist = (similiarArtistNumberOfArtist / pageSize);
    } else {
      similiarArtistPageNumberOfArtist = (similiarArtistNumberOfArtist / pageSize) + 1;
    }

    map.addAttribute("similiars", similiars);
    map.addAttribute("artistId", artistID);
    map.addAttribute("similiarArtistPageNumberOfArtist", similiarArtistPageNumberOfArtist);
    return "artist/artist_similiar_artists";
  }