Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.87 KB | None | 0 0
  1. void packetHandler(String message) throws ParseException {
  2.         /**<h1>PacketHandler</h1>
  3.          * recebe a mensagem e redireciona os dados para o devido método segundo o comando recebido
  4.          * @param info Mensagem já dividida nas suas partes constituintes
  5.          * @param action Comando a executar
  6.          *
  7.          */
  8.         String[] info = message.split("; ");
  9.         String action = this.getValue(info[0]);
  10.         switch (action) {
  11.             case "signup_request":
  12.                 this.signUp(info);
  13.                 break;
  14.             case "login_request":
  15.                 this.login(info);
  16.                 break;
  17.             case "logout_request":
  18.                 this.logout(info);
  19.                 break;
  20.             case "search_request":
  21.                 this.search(info);
  22.                 break;
  23.             case "add_song_request":
  24.                 this.addSong(info);
  25.                 break;
  26.             case "add_artist_request":
  27.                 this.addArtist(info);
  28.                 break;
  29.             case "add_album_request":
  30.                 this.addAlbum(info);
  31.                 break;
  32.             case "add_song_review_request":
  33.                 this.addSongReview(info);
  34.                 break;
  35.             case "song_review_request":
  36.                 this.songReviewRequest(info);
  37.                 break;
  38.             case "album_review_request":
  39.                 this.albumReviewRequest(info);
  40.                 break;
  41.             case "add_album_review_request":
  42.                 this.addAlbumReview(info);
  43.                 break;
  44.             case "perks_request":
  45.                 this.getPerks(info);
  46.                 break;
  47.             case "rmv_song_request":
  48.                 this.removeSong(info);
  49.                 break;
  50.             case "rmv_artist_request":
  51.                 this.removeArtist(info);
  52.                 break;
  53.             case "rmv_album_request":
  54.                 this.removeAlbum(info);
  55.                 break;
  56.             case "song_request":
  57.                 this.songRequest(info);
  58.                 break;
  59.             case "artist_request":
  60.                 this.artistRequest(info);
  61.                 break;
  62.             case "user_request":
  63.                 this.userRequest(info);
  64.                 break;
  65.             case "album_request":
  66.                 this.albumRequest(info);
  67.                 break;
  68.             case "genre_request":
  69.                 this.genreRequest(info);
  70.                 break;
  71.             case "band_request":
  72.                 this.bandRequest(info);
  73.                 break;
  74.             case "playlist_request":
  75.                 this.playlistRequest(info);
  76.                 break;
  77.             case "change_perks_request":
  78.                 this.changePerks(info);
  79.                 break;
  80.             case "add_notification_request":
  81.                 this.addNotifications(info);
  82.                 break;
  83.             case "get_notifications_request":
  84.                 this.getNotifications(info);
  85.                 break;
  86.             case "edit_song_request":
  87.                 this.editSong(info);
  88.                 break;
  89.             case "edit_artist_request":
  90.                 this.editArtist(info);
  91.                 break;
  92.             case "edit_album_request":
  93.                 this.editAlbum(info);
  94.                 break;
  95.             case "add_band_request":
  96.                 this.addBand(info);
  97.                 break;
  98.             case "add_band_album_request":
  99.                 this.addBand_album(info);
  100.                 break;
  101.             case "add_artist_band_request":
  102.                 this.addArtist_band(info);
  103.                 break;
  104.             case "add_playlist_request":
  105.                 this.addPlaylist(info);
  106.                 break;
  107.             case "add_song_playlist_request":
  108.                 this.addSongPlaylist(info);
  109.                 break;
  110.             case "edit_playlist_request":
  111.                 break;
  112.             case "add_job_request":
  113.                 this.addJob(info);
  114.                 break;
  115.             case "add_genre_request":
  116.                 this.addGenre(info);
  117.                 break;
  118.             case "add_label_request":
  119.                 this.addLabel(info);
  120.                 break;
  121.             case "songs_by_album_request":
  122.                 this.songByAlbum(info);
  123.                 break;
  124.             case "songs_by_artist_request":
  125.                 this.songByArtist(info);
  126.                 break;
  127.             case "songs_by_band_request":
  128.                 this.songByBand(info);
  129.                 break;
  130.             case "songs_by_genre_request":
  131.                 this.songByGenre(info);
  132.                 break;
  133.             case "songs_by_label_request":
  134.                 this.songByLabel(info);
  135.                 break;
  136.             case "songs_by_playlist_request":
  137.                 this.songByPlaylist(info);
  138.                 break;
  139.             case "album_by_artist_request":
  140.                 this.albumByArtist(info);
  141.                 break;
  142.             case "artist_by_song_request":
  143.                 this.artistBySong(info);
  144.                 break;
  145.             case "artist_by_album_request":
  146.                 this.artistByAlbum(info);
  147.                 break;
  148.             case "artist_by_band_request":
  149.                 this.artistByBand(info);
  150.                 break;
  151.             case "album_by_band_request":
  152.                 this.albumByBand(info);
  153.                 break;
  154.             case "genre_by_album_request":
  155.                 this.genreByAlbum(info);
  156.                 break;
  157.             case "label_by_album_request":
  158.                 this.labelByAlbum(info);
  159.                 break;
  160.             case "artist_edit_request":
  161.                 this.artistEdit(info);
  162.                 break;
  163.             case "search_all_songs_request":
  164.                 this.searchAllSongs(info);
  165.                 break;
  166.             case "search_all_artists_request":
  167.                 this.searchAllArtists(info);
  168.                 break;
  169.             case "search_all_albums_request":
  170.                 this.searchAllAlbums(info);
  171.                 break;
  172.             case "search_all_bands_request":
  173.                 this.searchAllBands(info);
  174.                 break;
  175.             default:
  176.                 break;
  177.         }
  178.     }
  179.  
  180. private void searchAllAlbums(String[] info){
  181.         String id = this.getValue(info[1]);
  182.         String query = "SELECT id, name FROM Album";
  183.         ArrayList<String> albums = new ArrayList<>();
  184.         String name;
  185.         String album_id="";
  186.         String answer="";
  187.         try (PreparedStatement stmt = connection.prepareStatement(query)){
  188.             ResultSet result = stmt.executeQuery();
  189.             while(result.next()) {
  190.                 name = result.getString("name");
  191.                 album_id = result.getString("id");
  192.                 albums.add(album_id);
  193.                 albums.add(name);
  194.             }
  195.             answer = this.concatAlbums(albums);
  196.         }catch (SQLException e){
  197.             System.out.println(e);
  198.             sendPacket(String.format("type | search_all_albums_answer; id | %s; status | not_added"));
  199.         }
  200.         sendPacket(String.format("type | search_all_albums_answer; id | %s%s",id, answer));
  201.     }
  202.  
  203.     private void searchAllArtists(String[] info){
  204.         String id = this.getValue(info[1]);
  205.         String query = "SELECT id, name FROM Artist";
  206.         ArrayList<String> artists = new ArrayList<>();
  207.         String name;
  208.         String artist_id="";
  209.         String answer="";
  210.         try (PreparedStatement stmt = connection.prepareStatement(query)){
  211.             ResultSet result = stmt.executeQuery();
  212.             while(result.next()) {
  213.                 name = result.getString("name");
  214.                 artist_id = result.getString("id");
  215.                 artists.add(artist_id);
  216.                 artists.add(name);
  217.             }
  218.             answer = this.concatArtists(artists);
  219.         }catch (SQLException e){
  220.             System.out.println(e);
  221.             sendPacket(String.format("type | search_all_artists_answer; id | %s; status | not_added"));
  222.         }
  223.         sendPacket(String.format("type | search_all_artists_answer; id | %s%s",id, answer));
  224.     }
  225.  
  226.     private void searchAllSongs(String[] info){
  227.         String id = this.getValue(info[1]);
  228.         String query = "SELECT id, name FROM Song";
  229.         ArrayList<String> songs = new ArrayList<>();
  230.         String name;
  231.         String song_id="";
  232.         String answer="";
  233.         try (PreparedStatement stmt = connection.prepareStatement(query)){
  234.             ResultSet result = stmt.executeQuery();
  235.             while(result.next()) {
  236.                 name = result.getString("name");
  237.                 song_id = result.getString("id");
  238.                 songs.add(song_id);
  239.                 songs.add(name);
  240.             }
  241.             answer = this.concatSongs(songs);
  242.         }catch (SQLException e){
  243.             System.out.println(e);
  244.             sendPacket(String.format("type | search_all_songs_answer; id | %s; status | not_added"));
  245.         }
  246.         sendPacket(String.format("type | search_all_songs_answer; id | %s%s",id, answer));
  247.     }
  248.  
  249.     private void searchAllBands(String[] info){
  250.         String id = this.getValue(info[1]);
  251.         String query = "SELECT name FROM Band";
  252.         ArrayList<String> bands = new ArrayList<>();
  253.         String name;
  254.         String answer="";
  255.         try (PreparedStatement stmt = connection.prepareStatement(query)){
  256.             ResultSet result = stmt.executeQuery();
  257.             while(result.next()) {
  258.                 name = result.getString("name");
  259.                 bands.add(name);
  260.             }
  261.             answer = this.concatBands(bands);
  262.         }catch (SQLException e){
  263.             System.out.println(e);
  264.             sendPacket(String.format("type | search_all_bands_answer; id | %s; status | not_added"));
  265.         }
  266.         sendPacket(String.format("type | search_all_bands_answer; id | %s%s",id, answer));
  267.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement