public boolean createOrUpdateSession( int locationId, boolean open, String sessionName, boolean resetVotes) { if (resetVotes) { removeRequests(locationId); } if (sessionName == null) { return data.updateSession(locationId, open); } else { return data.createOrUpdateSession(locationId, sessionName, open); } }
public List<Track> searchForTrack(String query, String orderBy, int page, int locationId) throws SpotifyApiException { SpotifyTrackSearchContainer tracks = searchSpotify(query, page); List<String> spotifyIds = new ArrayList<String>(); for (SpotifyTrack track : tracks.getTracks()) { // Save tracks to db long length = (long) track.getLength() * 1000; data.saveSong(track.getHref(), track.getName(), track.concatArtistNames(), length); // logger.debug("Found - "+track.getName()+" id: "+track.getHref()); spotifyIds.add(track.getHref()); } if (spotifyIds.size() > 0) { return data.getSongs(spotifyIds, locationId, orderBy); } else { // to prevent sql-error when there are no ids. return new ArrayList<Track>(); } }
public RequestResponse requestSong(String spotifyId, String token, int locationId, String code) throws SpotifyApiException, UpdateQRCodeException { if (!data.hasSong(spotifyId)) { // Fetch song info from spotify if neccessary SpotifyLookupContainer song = requestSpotifySong(spotifyId); logger.debug( song.getTrack().getName() + " - Fetched from spotify, length: " + song.getTrack().getLength()); long length = (long) song.getTrack().getLength() * 1000; data.saveSong( spotifyId, song.getTrack().getName(), song.getTrack().concatArtistNames(), length); } int qrValidationCode = qrService.verify(code, locationId); if (!data.getSession(locationId).isOpen()) { // session is not open return new RequestResponse( "Stemming er ikke mulig. Sesjonen er ikke aktiv", false, qrValidationCode); } else if (qrValidationCode == QR_IS_NOT_VALID) { // Code is not valid return new RequestResponse("QR-koden er ikke gyldig", false, qrValidationCode); } else if (qrValidationCode == QR_HAS_UNLIMITED_USES) { // Unlimited votes so check token int userId = verifyToken(token); // throws exception if code is not valid or is null if (data.userCanRequestSong(spotifyId, locationId, userId)) { data.requestSongOneActiveVote(spotifyId, locationId, userId); } else { logger.debug( "User " + userId + " could not vote for song " + spotifyId + " at location " + locationId); return new RequestResponse( "Denne brukeren har allerede stemt opp denne sangen", false, qrValidationCode); } } else if (qrValidationCode == QR_HAS_LIMITED_USES) { // Limited votes, so token not neccessary int userId = authService.verify(token); if (userId == -1) { // Token null or not valid userId = -1337; // The fake spotify user } boolean success = data.requestSongManyActiveVotes( spotifyId, locationId, userId); // No need to update qrcodes and such.//Jo? Have to decrement the uses. if (success) { if (!qrService.codeIsUsed(code)) { logger.debug("Could not update QRcode"); } } else { return new RequestResponse("Kunne ikke oppdatere databasen", false, qrValidationCode); } } return new RequestResponse("Stemmen ble registrert", true, qrValidationCode); }
public List<Track> getPlayedSongs(int from, int num, int locationId) { int to = from + Math.abs(num); return data.getPlayedTracks(locationId, from, to); }
public List<Track> getSongs(int from, int num, String orderBy, long notPlayedIn, int locationId) { int to = from + Math.abs(num); Timestamp notPlayedSince = new Timestamp(System.currentTimeMillis() - notPlayedIn); return data.getSongs(locationId, from, to, orderBy, notPlayedSince); }
public Track getSong(String spotifyId, int locationId) { return data.getSong(spotifyId, locationId); }
public MusicSession getSession(int locationId) { return data.getSession(locationId); }
public List<MusicSession> getSessions() { return data.getSessions(); }
public boolean removeRequests(int locationId) { return data.removeRequests(locationId); }
public Track setSongAsPlaying(String spotifyId, int locationId) { data.setSongAsPlayed(spotifyId, locationId); return data.getSong(spotifyId, locationId); }