/** * given some url arguments (ar123, al456, etc...) queries for the tracks that belong to these * items * * @throws java.io.IOException * @throws java.sql.SQLException * @throws com.pugh.sockso.web.BadRequestException */ protected void tracks() throws IOException, SQLException, BadRequestException { final Request req = getRequest(); final List<Track> tracks = Track.getTracksFromPlayArgs(getDatabase(), req.getPlayParams(true)); showTracks(tracks); }
/** * saves a playlist to the database for the current user. outputs a single integer which is the * playlist ID if all goes well, otherwise you'll get a description of the problem. * * @throws IOException */ protected void savePlaylist() throws IOException, SQLException, BadRequestException { final Request req = getRequest(); final User user = getUser(); final Locale locale = getLocale(); final String name = req.getUrlParam(2).trim(); final String[] args = req.getPlayParams(2); String result = locale.getString("www.json.error.unknown"); // make sure data is ok first if (name.equals("")) result = locale.getString("www.json.error.noName"); else if (args.length == 0) result = locale.getString("www.json.error.noArguments"); else if (user == null) result = locale.getString("www.json.error.notLoggedIn"); else { final Database db = getDatabase(); final List<Track> vTracks = Track.getTracksFromPlayArgs(db, args); final Track[] tracks = new Track[vTracks.size()]; for (int i = 0; i < vTracks.size(); i++) tracks[i] = vTracks.get(i); result = Integer.toString(cm.savePlaylist(name, tracks, user)); } final TString tpl = new TString(); tpl.setResult(result); getResponse().showJson(tpl.makeRenderer()); }