Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void packetHandler(String message) throws ParseException {
- /**<h1>PacketHandler</h1>
- * recebe a mensagem e redireciona os dados para o devido método segundo o comando recebido
- * @param info Mensagem já dividida nas suas partes constituintes
- * @param action Comando a executar
- *
- */
- String[] info = message.split("; ");
- String action = this.getValue(info[0]);
- switch (action) {
- case "signup_request":
- this.signUp(info);
- break;
- case "login_request":
- this.login(info);
- break;
- case "logout_request":
- this.logout(info);
- break;
- case "search_request":
- this.search(info);
- break;
- case "add_song_request":
- this.addSong(info);
- break;
- case "add_artist_request":
- this.addArtist(info);
- break;
- case "add_album_request":
- this.addAlbum(info);
- break;
- case "add_song_review_request":
- this.addSongReview(info);
- break;
- case "song_review_request":
- this.songReviewRequest(info);
- break;
- case "album_review_request":
- this.albumReviewRequest(info);
- break;
- case "add_album_review_request":
- this.addAlbumReview(info);
- break;
- case "perks_request":
- this.getPerks(info);
- break;
- case "rmv_song_request":
- this.removeSong(info);
- break;
- case "rmv_artist_request":
- this.removeArtist(info);
- break;
- case "rmv_album_request":
- this.removeAlbum(info);
- break;
- case "song_request":
- this.songRequest(info);
- break;
- case "artist_request":
- this.artistRequest(info);
- break;
- case "user_request":
- this.userRequest(info);
- break;
- case "album_request":
- this.albumRequest(info);
- break;
- case "genre_request":
- this.genreRequest(info);
- break;
- case "band_request":
- this.bandRequest(info);
- break;
- case "playlist_request":
- this.playlistRequest(info);
- break;
- case "change_perks_request":
- this.changePerks(info);
- break;
- case "add_notification_request":
- this.addNotifications(info);
- break;
- case "get_notifications_request":
- this.getNotifications(info);
- break;
- case "edit_song_request":
- this.editSong(info);
- break;
- case "edit_artist_request":
- this.editArtist(info);
- break;
- case "edit_album_request":
- this.editAlbum(info);
- break;
- case "add_band_request":
- this.addBand(info);
- break;
- case "add_band_album_request":
- this.addBand_album(info);
- break;
- case "add_artist_band_request":
- this.addArtist_band(info);
- break;
- case "add_playlist_request":
- this.addPlaylist(info);
- break;
- case "add_song_playlist_request":
- this.addSongPlaylist(info);
- break;
- case "edit_playlist_request":
- break;
- case "add_job_request":
- this.addJob(info);
- break;
- case "add_genre_request":
- this.addGenre(info);
- break;
- case "add_label_request":
- this.addLabel(info);
- break;
- case "songs_by_album_request":
- this.songByAlbum(info);
- break;
- case "songs_by_artist_request":
- this.songByArtist(info);
- break;
- case "songs_by_band_request":
- this.songByBand(info);
- break;
- case "songs_by_genre_request":
- this.songByGenre(info);
- break;
- case "songs_by_label_request":
- this.songByLabel(info);
- break;
- case "songs_by_playlist_request":
- this.songByPlaylist(info);
- break;
- case "album_by_artist_request":
- this.albumByArtist(info);
- break;
- case "artist_by_song_request":
- this.artistBySong(info);
- break;
- case "artist_by_album_request":
- this.artistByAlbum(info);
- break;
- case "artist_by_band_request":
- this.artistByBand(info);
- break;
- case "album_by_band_request":
- this.albumByBand(info);
- break;
- case "genre_by_album_request":
- this.genreByAlbum(info);
- break;
- case "label_by_album_request":
- this.labelByAlbum(info);
- break;
- case "artist_edit_request":
- this.artistEdit(info);
- break;
- case "search_all_songs_request":
- this.searchAllSongs(info);
- break;
- case "search_all_artists_request":
- this.searchAllArtists(info);
- break;
- case "search_all_albums_request":
- this.searchAllAlbums(info);
- break;
- case "search_all_bands_request":
- this.searchAllBands(info);
- break;
- default:
- break;
- }
- }
- private void searchAllAlbums(String[] info){
- String id = this.getValue(info[1]);
- String query = "SELECT id, name FROM Album";
- ArrayList<String> albums = new ArrayList<>();
- String name;
- String album_id="";
- String answer="";
- try (PreparedStatement stmt = connection.prepareStatement(query)){
- ResultSet result = stmt.executeQuery();
- while(result.next()) {
- name = result.getString("name");
- album_id = result.getString("id");
- albums.add(album_id);
- albums.add(name);
- }
- answer = this.concatAlbums(albums);
- }catch (SQLException e){
- System.out.println(e);
- sendPacket(String.format("type | search_all_albums_answer; id | %s; status | not_added"));
- }
- sendPacket(String.format("type | search_all_albums_answer; id | %s%s",id, answer));
- }
- private void searchAllArtists(String[] info){
- String id = this.getValue(info[1]);
- String query = "SELECT id, name FROM Artist";
- ArrayList<String> artists = new ArrayList<>();
- String name;
- String artist_id="";
- String answer="";
- try (PreparedStatement stmt = connection.prepareStatement(query)){
- ResultSet result = stmt.executeQuery();
- while(result.next()) {
- name = result.getString("name");
- artist_id = result.getString("id");
- artists.add(artist_id);
- artists.add(name);
- }
- answer = this.concatArtists(artists);
- }catch (SQLException e){
- System.out.println(e);
- sendPacket(String.format("type | search_all_artists_answer; id | %s; status | not_added"));
- }
- sendPacket(String.format("type | search_all_artists_answer; id | %s%s",id, answer));
- }
- private void searchAllSongs(String[] info){
- String id = this.getValue(info[1]);
- String query = "SELECT id, name FROM Song";
- ArrayList<String> songs = new ArrayList<>();
- String name;
- String song_id="";
- String answer="";
- try (PreparedStatement stmt = connection.prepareStatement(query)){
- ResultSet result = stmt.executeQuery();
- while(result.next()) {
- name = result.getString("name");
- song_id = result.getString("id");
- songs.add(song_id);
- songs.add(name);
- }
- answer = this.concatSongs(songs);
- }catch (SQLException e){
- System.out.println(e);
- sendPacket(String.format("type | search_all_songs_answer; id | %s; status | not_added"));
- }
- sendPacket(String.format("type | search_all_songs_answer; id | %s%s",id, answer));
- }
- private void searchAllBands(String[] info){
- String id = this.getValue(info[1]);
- String query = "SELECT name FROM Band";
- ArrayList<String> bands = new ArrayList<>();
- String name;
- String answer="";
- try (PreparedStatement stmt = connection.prepareStatement(query)){
- ResultSet result = stmt.executeQuery();
- while(result.next()) {
- name = result.getString("name");
- bands.add(name);
- }
- answer = this.concatBands(bands);
- }catch (SQLException e){
- System.out.println(e);
- sendPacket(String.format("type | search_all_bands_answer; id | %s; status | not_added"));
- }
- sendPacket(String.format("type | search_all_bands_answer; id | %s%s",id, answer));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement