Handle player id as an Integer instead of String

master
snw35 7 years ago
parent b3f432a545
commit 6a44c5c815
  1. 6
      airsonic-main/src/main/java/org/airsonic/player/ajax/NowPlayingInfo.java
  2. 10
      airsonic-main/src/main/java/org/airsonic/player/ajax/PlayQueueService.java
  3. 6
      airsonic-main/src/main/java/org/airsonic/player/ajax/PlaylistService.java
  4. 8
      airsonic-main/src/main/java/org/airsonic/player/command/PlayerSettingsCommand.java
  5. 2
      airsonic-main/src/main/java/org/airsonic/player/controller/DownloadController.java
  6. 9
      airsonic-main/src/main/java/org/airsonic/player/controller/LeftController.java
  7. 42
      airsonic-main/src/main/java/org/airsonic/player/controller/PlayerSettingsController.java
  8. 2
      airsonic-main/src/main/java/org/airsonic/player/controller/ShareManagementController.java
  9. 3
      airsonic-main/src/main/java/org/airsonic/player/controller/StatusChartController.java
  10. 4
      airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java
  11. 2
      airsonic-main/src/main/java/org/airsonic/player/controller/VideoPlayerController.java
  12. 19
      airsonic-main/src/main/java/org/airsonic/player/dao/PlayerDao.java
  13. 4
      airsonic-main/src/main/java/org/airsonic/player/dao/TranscodingDao.java
  14. 6
      airsonic-main/src/main/java/org/airsonic/player/domain/Player.java
  15. 4
      airsonic-main/src/main/java/org/airsonic/player/domain/Transcoding.java
  16. 2
      airsonic-main/src/main/java/org/airsonic/player/service/JukeboxJavaService.java
  17. 32
      airsonic-main/src/main/java/org/airsonic/player/service/PlayerService.java
  18. 10
      airsonic-main/src/main/java/org/airsonic/player/service/StatusService.java
  19. 8
      airsonic-main/src/main/java/org/airsonic/player/service/TranscodingService.java
  20. 20
      airsonic-main/src/test/java/org/airsonic/player/dao/PlayerDaoTestCase.java
  21. 2
      airsonic-main/src/test/java/org/airsonic/player/service/StatusServiceTestCase.java

@ -26,7 +26,7 @@ package org.airsonic.player.ajax;
*/ */
public class NowPlayingInfo { public class NowPlayingInfo {
private final String playerId; private final Integer playerId;
private final String username; private final String username;
private final String artist; private final String artist;
private final String title; private final String title;
@ -38,7 +38,7 @@ public class NowPlayingInfo {
private final String avatarUrl; private final String avatarUrl;
private final int minutesAgo; private final int minutesAgo;
public NowPlayingInfo(String playerId, String user, String artist, String title, String tooltip, String streamUrl, String albumUrl, public NowPlayingInfo(Integer playerId, String user, String artist, String title, String tooltip, String streamUrl, String albumUrl,
String lyricsUrl, String coverArtUrl, String avatarUrl, int minutesAgo) { String lyricsUrl, String coverArtUrl, String avatarUrl, int minutesAgo) {
this.playerId = playerId; this.playerId = playerId;
this.username = user; this.username = user;
@ -53,7 +53,7 @@ public class NowPlayingInfo {
this.minutesAgo = minutesAgo; this.minutesAgo = minutesAgo;
} }
public String getPlayerId() { public Integer getPlayerId() {
return playerId; return playerId;
} }

@ -149,7 +149,7 @@ public class PlayQueueService {
return convert(request, player, false); return convert(request, player, false);
} }
public void savePlayQueue(int currentSongIndex, long positionMillis) { public void savePlayQueue(int currentSongIndex, long positionMillis) throws Exception {
HttpServletRequest request = WebContextFactory.get().getHttpServletRequest(); HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
HttpServletResponse response = WebContextFactory.get().getHttpServletResponse(); HttpServletResponse response = WebContextFactory.get().getHttpServletResponse();
@ -710,11 +710,11 @@ public class PlayQueueService {
return mediaFile.getBitRate() + " Kbps"; return mediaFile.getBitRate() + " Kbps";
} }
private Player getCurrentPlayer(HttpServletRequest request, HttpServletResponse response) { private Player getCurrentPlayer(HttpServletRequest request, HttpServletResponse response) throws Exception {
return playerService.getPlayer(request, response); return playerService.getPlayer(request, response);
} }
private Player resolvePlayer() { private Player resolvePlayer() throws Exception {
return getCurrentPlayer(resolveHttpServletRequest(), resolveHttpServletResponse()); return getCurrentPlayer(resolveHttpServletRequest(), resolveHttpServletResponse());
} }
@ -732,7 +732,7 @@ public class PlayQueueService {
// Methods dedicated to jukebox // Methods dedicated to jukebox
// //
public void setGain(float gain) { public void setGain(float gain) throws Exception {
HttpServletRequest request = WebContextFactory.get().getHttpServletRequest(); HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
HttpServletResponse response = WebContextFactory.get().getHttpServletResponse(); HttpServletResponse response = WebContextFactory.get().getHttpServletResponse();
Player player = getCurrentPlayer(request, response); Player player = getCurrentPlayer(request, response);
@ -741,7 +741,7 @@ public class PlayQueueService {
} }
} }
public void setJukeboxPosition(int positionInSeconds) { public void setJukeboxPosition(int positionInSeconds) throws Exception {
Player player = resolvePlayer(); Player player = resolvePlayer();
jukeboxService.setPosition(player,positionInSeconds); jukeboxService.setPosition(player,positionInSeconds);
} }

@ -112,7 +112,7 @@ public class PlaylistService {
return getReadablePlaylists(); return getReadablePlaylists();
} }
public int createPlaylistForPlayQueue() { public int createPlaylistForPlayQueue() throws Exception {
HttpServletRequest request = WebContextFactory.get().getHttpServletRequest(); HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
HttpServletResponse response = WebContextFactory.get().getHttpServletResponse(); HttpServletResponse response = WebContextFactory.get().getHttpServletResponse();
Player player = playerService.getPlayer(request, response); Player player = playerService.getPlayer(request, response);
@ -167,7 +167,7 @@ public class PlaylistService {
} }
playlistService.setFilesInPlaylist(playlistId, files); playlistService.setFilesInPlaylist(playlistId, files);
} }
private List<PlaylistInfo.Entry> createEntries(List<MediaFile> files) { private List<PlaylistInfo.Entry> createEntries(List<MediaFile> files) {
List<PlaylistInfo.Entry> result = new ArrayList<PlaylistInfo.Entry>(); List<PlaylistInfo.Entry> result = new ArrayList<PlaylistInfo.Entry>();
for (MediaFile file : files) { for (MediaFile file : files) {
@ -270,4 +270,4 @@ public class PlaylistService {
public void setLocaleResolver(LocaleResolver localeResolver) { public void setLocaleResolver(LocaleResolver localeResolver) {
this.localeResolver = localeResolver; this.localeResolver = localeResolver;
} }
} }

@ -34,7 +34,7 @@ import java.util.List;
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class PlayerSettingsCommand { public class PlayerSettingsCommand {
private String playerId; private Integer playerId;
private String name; private String name;
private String description; private String description;
private String type; private String type;
@ -55,11 +55,11 @@ public class PlayerSettingsCommand {
private String javaJukeboxMixer; private String javaJukeboxMixer;
private String[] javaJukeboxMixers; private String[] javaJukeboxMixers;
public String getPlayerId() { public Integer getPlayerId() {
return playerId; return playerId;
} }
public void setPlayerId(String playerId) { public void setPlayerId(Integer playerId) {
this.playerId = playerId; this.playerId = playerId;
} }
@ -247,4 +247,4 @@ public class PlayerSettingsCommand {
return isActive; return isActive;
} }
} }
} }

@ -99,7 +99,7 @@ public class DownloadController implements LastModified {
MediaFile mediaFile = getMediaFile(request); MediaFile mediaFile = getMediaFile(request);
Integer playlistId = ServletRequestUtils.getIntParameter(request, "playlist"); Integer playlistId = ServletRequestUtils.getIntParameter(request, "playlist");
String playerId = request.getParameter("player"); Integer playerId = ServletRequestUtils.getIntParameter(request, "player");
int[] indexes = request.getParameter("i") == null ? null : ServletRequestUtils.getIntParameters(request, "i"); int[] indexes = request.getParameter("i") == null ? null : ServletRequestUtils.getIntParameters(request, "i");
if (mediaFile != null) { if (mediaFile != null) {

@ -68,7 +68,7 @@ public class LeftController {
* Note: This class intentionally does not implement org.springframework.web.servlet.mvc.LastModified * Note: This class intentionally does not implement org.springframework.web.servlet.mvc.LastModified
* as we don't need browser-side caching of left.jsp. This method is only used by RESTController. * as we don't need browser-side caching of left.jsp. This method is only used by RESTController.
*/ */
long getLastModified(HttpServletRequest request) { long getLastModified(HttpServletRequest request) throws Exception {
saveSelectedMusicFolder(request); saveSelectedMusicFolder(request);
if (mediaScannerService.isScanning()) { if (mediaScannerService.isScanning()) {
@ -157,12 +157,11 @@ public class LeftController {
return new ModelAndView("left","model",map); return new ModelAndView("left","model",map);
} }
private boolean saveSelectedMusicFolder(HttpServletRequest request) { private boolean saveSelectedMusicFolder(HttpServletRequest request) throws Exception {
if (request.getParameter("musicFolderId") == null) { Integer musicFolderId = ServletRequestUtils.getIntParameter(request, "musicFolderId");
if (musicFolderId == null) {
return false; return false;
} }
int musicFolderId = Integer.parseInt(request.getParameter("musicFolderId"));
// Note: UserSettings.setChanged() is intentionally not called. This would break browser caching // Note: UserSettings.setChanged() is intentionally not called. This would break browser caching
// of the left frame. // of the left frame.
UserSettings settings = settingsService.getUserSettings(securityService.getCurrentUsername(request)); UserSettings settings = settingsService.getUserSettings(securityService.getCurrentUsername(request));

@ -29,6 +29,7 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
@ -70,7 +71,7 @@ public class PlayerSettingsController {
User user = securityService.getCurrentUser(request); User user = securityService.getCurrentUser(request);
PlayerSettingsCommand command = new PlayerSettingsCommand(); PlayerSettingsCommand command = new PlayerSettingsCommand();
Player player = null; Player player = null;
String playerId = request.getParameter("id"); Integer playerId = ServletRequestUtils.getIntParameter(request, "id");
if (playerId != null) { if (playerId != null) {
player = playerService.getPlayerById(playerId); player = playerService.getPlayerById(playerId);
} else if (!players.isEmpty()) { } else if (!players.isEmpty()) {
@ -113,21 +114,24 @@ public class PlayerSettingsController {
@RequestMapping(method = RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
protected String doSubmitAction(@ModelAttribute("command") PlayerSettingsCommand command, RedirectAttributes redirectAttributes) throws Exception { protected String doSubmitAction(@ModelAttribute("command") PlayerSettingsCommand command, RedirectAttributes redirectAttributes) throws Exception {
Player player = playerService.getPlayerById(command.getPlayerId()); Player player = playerService.getPlayerById(command.getPlayerId());
if (player != null) {
player.setAutoControlEnabled(command.isAutoControlEnabled()); player.setAutoControlEnabled(command.isAutoControlEnabled());
player.setM3uBomEnabled(command.isM3uBomEnabled()); player.setM3uBomEnabled(command.isM3uBomEnabled());
player.setDynamicIp(command.isDynamicIp()); player.setDynamicIp(command.isDynamicIp());
player.setName(StringUtils.trimToNull(command.getName())); player.setName(StringUtils.trimToNull(command.getName()));
player.setTranscodeScheme(TranscodeScheme.valueOf(command.getTranscodeSchemeName())); player.setTranscodeScheme(TranscodeScheme.valueOf(command.getTranscodeSchemeName()));
player.setTechnology(PlayerTechnology.valueOf(command.getTechnologyName())); player.setTechnology(PlayerTechnology.valueOf(command.getTechnologyName()));
player.setJavaJukeboxMixer(command.getJavaJukeboxMixer()); player.setJavaJukeboxMixer(command.getJavaJukeboxMixer());
playerService.updatePlayer(player); playerService.updatePlayer(player);
transcodingService.setTranscodingsForPlayer(player, command.getActiveTranscodingIds()); transcodingService.setTranscodingsForPlayer(player, command.getActiveTranscodingIds());
redirectAttributes.addFlashAttribute("settings_reload", true); redirectAttributes.addFlashAttribute("settings_reload", true);
redirectAttributes.addFlashAttribute("settings_toast", true); redirectAttributes.addFlashAttribute("settings_toast", true);
return "redirect:playerSettings.view"; return "redirect:playerSettings.view";
} else {
return "redirect:notFound";
}
} }
private List<Player> getPlayers(HttpServletRequest request) { private List<Player> getPlayers(HttpServletRequest request) {
@ -145,11 +149,11 @@ public class PlayerSettingsController {
return authorizedPlayers; return authorizedPlayers;
} }
private void handleRequestParameters(HttpServletRequest request) { private void handleRequestParameters(HttpServletRequest request) throws Exception {
if (request.getParameter("delete") != null) { if (request.getParameter("delete") != null) {
playerService.removePlayerById(request.getParameter("delete")); playerService.removePlayerById(ServletRequestUtils.getIntParameter(request, "delete"));
} else if (request.getParameter("clone") != null) { } else if (request.getParameter("clone") != null) {
playerService.clonePlayer(request.getParameter("clone")); playerService.clonePlayer(ServletRequestUtils.getIntParameter(request, "clone"));
} }
} }

@ -94,7 +94,7 @@ public class ShareManagementController {
private List<MediaFile> getMediaFiles(HttpServletRequest request) throws Exception { private List<MediaFile> getMediaFiles(HttpServletRequest request) throws Exception {
Integer id = ServletRequestUtils.getIntParameter(request, "id"); Integer id = ServletRequestUtils.getIntParameter(request, "id");
String playerId = request.getParameter("player"); Integer playerId = ServletRequestUtils.getIntParameter(request, "player");
Integer playlistId = ServletRequestUtils.getIntParameter(request, "playlist"); Integer playlistId = ServletRequestUtils.getIntParameter(request, "playlist");
List<MediaFile> result = new ArrayList<>(); List<MediaFile> result = new ArrayList<>();

@ -32,6 +32,7 @@ import org.jfree.data.Range;
import org.jfree.data.time.*; import org.jfree.data.time.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
@ -62,7 +63,7 @@ public class StatusChartController extends AbstractChartController {
@RequestMapping(method = RequestMethod.GET) @RequestMapping(method = RequestMethod.GET)
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
String type = request.getParameter("type"); String type = request.getParameter("type");
int index = Integer.parseInt(request.getParameter("index")); int index = ServletRequestUtils.getIntParameter(request, "index");
List<TransferStatus> statuses = Collections.emptyList(); List<TransferStatus> statuses = Collections.emptyList();
if ("stream".equals(type)) { if ("stream".equals(type)) {

@ -1225,7 +1225,7 @@ public class SubsonicRESTController {
if (minutesAgo < 60) { if (minutesAgo < 60) {
NowPlayingEntry entry = new NowPlayingEntry(); NowPlayingEntry entry = new NowPlayingEntry();
entry.setUsername(username); entry.setUsername(username);
entry.setPlayerId(Integer.parseInt(player.getId())); entry.setPlayerId(player.getId());
entry.setPlayerName(player.getName()); entry.setPlayerName(player.getName());
entry.setMinutesAgo((int) minutesAgo); entry.setMinutesAgo((int) minutesAgo);
result.getEntry().add(createJaxbChild(entry, player, mediaFile, username)); result.getEntry().add(createJaxbChild(entry, player, mediaFile, username));
@ -2399,7 +2399,7 @@ public class SubsonicRESTController {
} }
// Return the player ID. // Return the player ID.
return !players.isEmpty() ? players.get(0).getId() : null; return !players.isEmpty() ? String.valueOf(players.get(0).getId()) : null;
} }
private Locale getUserLocale(HttpServletRequest request) { private Locale getUserLocale(HttpServletRequest request) {

@ -69,7 +69,7 @@ public class VideoPlayerController {
mediaFileService.populateStarredDate(file, user.getUsername()); mediaFileService.populateStarredDate(file, user.getUsername());
Integer duration = file.getDurationSeconds(); Integer duration = file.getDurationSeconds();
String playerId = playerService.getPlayer(request, response).getId(); Integer playerId = playerService.getPlayer(request, response).getId();
String url = NetworkService.getBaseUrl(request); String url = NetworkService.getBaseUrl(request);
String streamUrl = url + "stream?id=" + file.getId() + "&player=" + playerId + "&format=mp4"; String streamUrl = url + "stream?id=" + file.getId() + "&player=" + playerId + "&format=mp4";
String coverArtUrl = url + "coverArt.view?id=" + file.getId(); String coverArtUrl = url + "coverArt.view?id=" + file.getId();

@ -20,7 +20,6 @@
package org.airsonic.player.dao; package org.airsonic.player.dao;
import org.airsonic.player.domain.*; import org.airsonic.player.domain.*;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
@ -45,7 +44,7 @@ public class PlayerDao extends AbstractDao {
private static final String QUERY_COLUMNS = "id, " + INSERT_COLUMNS; private static final String QUERY_COLUMNS = "id, " + INSERT_COLUMNS;
private PlayerRowMapper rowMapper = new PlayerRowMapper(); private PlayerRowMapper rowMapper = new PlayerRowMapper();
private Map<String, PlayQueue> playlists = Collections.synchronizedMap(new HashMap<String, PlayQueue>()); private Map<Integer, PlayQueue> playlists = Collections.synchronizedMap(new HashMap<Integer, PlayQueue>());
/** /**
* Returns all players. * Returns all players.
@ -81,13 +80,9 @@ public class PlayerDao extends AbstractDao {
* @param id The unique player ID. * @param id The unique player ID.
* @return The player with the given ID, or <code>null</code> if no such player exists. * @return The player with the given ID, or <code>null</code> if no such player exists.
*/ */
public Player getPlayerById(String id) { public Player getPlayerById(int id) {
if (StringUtils.isBlank(id)) { String sql = "select " + QUERY_COLUMNS + " from player where id=?";
return null; return queryOne(sql, rowMapper, id);
} else {
String sql = "select " + QUERY_COLUMNS + " from player where id=?";
return queryOne(sql, rowMapper, id);
}
} }
/** /**
@ -102,7 +97,7 @@ public class PlayerDao extends AbstractDao {
existingMax = 0; existingMax = 0;
} }
int id = existingMax + 1; int id = existingMax + 1;
player.setId(String.valueOf(id)); player.setId(id);
String sql = "insert into player (" + QUERY_COLUMNS + ") values (" + questionMarks(QUERY_COLUMNS) + ")"; String sql = "insert into player (" + QUERY_COLUMNS + ") values (" + questionMarks(QUERY_COLUMNS) + ")";
update(sql, player.getId(), player.getName(), player.getType(), player.getUsername(), update(sql, player.getId(), player.getName(), player.getType(), player.getUsername(),
player.getIpAddress(), player.isAutoControlEnabled(), player.isM3uBomEnabled(), player.getIpAddress(), player.isAutoControlEnabled(), player.isM3uBomEnabled(),
@ -119,7 +114,7 @@ public class PlayerDao extends AbstractDao {
* *
* @param id The player ID. * @param id The player ID.
*/ */
public void deletePlayer(String id) { public void deletePlayer(Integer id) {
String sql = "delete from player where id=?"; String sql = "delete from player where id=?";
update(sql, id); update(sql, id);
playlists.remove(id); playlists.remove(id);
@ -181,7 +176,7 @@ public class PlayerDao extends AbstractDao {
public Player mapRow(ResultSet rs, int rowNum) throws SQLException { public Player mapRow(ResultSet rs, int rowNum) throws SQLException {
Player player = new Player(); Player player = new Player();
int col = 1; int col = 1;
player.setId(rs.getString(col++)); player.setId(rs.getInt(col++));
player.setName(rs.getString(col++)); player.setName(rs.getString(col++));
player.setType(rs.getString(col++)); player.setType(rs.getString(col++));
player.setUsername(rs.getString(col++)); player.setUsername(rs.getString(col++));

@ -59,7 +59,7 @@ public class TranscodingDao extends AbstractDao {
* @param playerId The player ID. * @param playerId The player ID.
* @return All active transcodings for the player. * @return All active transcodings for the player.
*/ */
public List<Transcoding> getTranscodingsForPlayer(String playerId) { public List<Transcoding> getTranscodingsForPlayer(Integer playerId) {
String sql = "select " + QUERY_COLUMNS + " from transcoding2, player_transcoding2 " + String sql = "select " + QUERY_COLUMNS + " from transcoding2, player_transcoding2 " +
"where player_transcoding2.player_id = ? " + "where player_transcoding2.player_id = ? " +
"and player_transcoding2.transcoding_id = transcoding2.id"; "and player_transcoding2.transcoding_id = transcoding2.id";
@ -72,7 +72,7 @@ public class TranscodingDao extends AbstractDao {
* @param playerId The player ID. * @param playerId The player ID.
* @param transcodingIds ID's of the active transcodings. * @param transcodingIds ID's of the active transcodings.
*/ */
public void setTranscodingsForPlayer(String playerId, int[] transcodingIds) { public void setTranscodingsForPlayer(Integer playerId, int[] transcodingIds) {
update("delete from player_transcoding2 where player_id = ?", playerId); update("delete from player_transcoding2 where player_id = ?", playerId);
String sql = "insert into player_transcoding2(player_id, transcoding_id) values (?, ?)"; String sql = "insert into player_transcoding2(player_id, transcoding_id) values (?, ?)";
for (int transcodingId : transcodingIds) { for (int transcodingId : transcodingIds) {

@ -31,7 +31,7 @@ import java.util.Date;
*/ */
public class Player { public class Player {
private String id; private Integer id;
private String name; private String name;
private PlayerTechnology technology = PlayerTechnology.WEB; private PlayerTechnology technology = PlayerTechnology.WEB;
private String clientId; private String clientId;
@ -51,7 +51,7 @@ public class Player {
* *
* @return The player ID. * @return The player ID.
*/ */
public String getId() { public Integer getId() {
return id; return id;
} }
@ -60,7 +60,7 @@ public class Player {
* *
* @param id The player ID. * @param id The player ID.
*/ */
public void setId(String id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }

@ -74,7 +74,7 @@ public class Transcoding {
return id; return id;
} }
public void setId(int id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }
@ -219,4 +219,4 @@ public class Transcoding {
public int hashCode() { public int hashCode() {
return (id != null ? id.hashCode() : 0); return (id != null ? id.hashCode() : 0);
} }
} }

@ -39,7 +39,7 @@ public class JukeboxJavaService {
private TransferStatus status; private TransferStatus status;
private Map<String, com.github.biconou.AudioPlayer.api.Player> activeAudioPlayers = new Hashtable<>(); private Map<Integer, com.github.biconou.AudioPlayer.api.Player> activeAudioPlayers = new Hashtable<>();
private Map<String, List<com.github.biconou.AudioPlayer.api.Player>> activeAudioPlayersPerMixer = new Hashtable<>(); private Map<String, List<com.github.biconou.AudioPlayer.api.Player>> activeAudioPlayersPerMixer = new Hashtable<>();
private final static String DEFAULT_MIXER_ENTRY_KEY = "_default"; private final static String DEFAULT_MIXER_ENTRY_KEY = "_default";

@ -30,6 +30,7 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.ServletRequestUtils;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
@ -70,7 +71,7 @@ public class PlayerService {
/** /**
* Equivalent to <code>getPlayer(request, response, true)</code> . * Equivalent to <code>getPlayer(request, response, true)</code> .
*/ */
public Player getPlayer(HttpServletRequest request, HttpServletResponse response) { public Player getPlayer(HttpServletRequest request, HttpServletResponse response) throws Exception {
return getPlayer(request, response, true, false); return getPlayer(request, response, true, false);
} }
@ -85,14 +86,14 @@ public class PlayerService {
* @return The player associated with the given HTTP request. * @return The player associated with the given HTTP request.
*/ */
public synchronized Player getPlayer(HttpServletRequest request, HttpServletResponse response, public synchronized Player getPlayer(HttpServletRequest request, HttpServletResponse response,
boolean remoteControlEnabled, boolean isStreamRequest) { boolean remoteControlEnabled, boolean isStreamRequest) throws Exception {
// Find by 'player' request parameter. // Find by 'player' request parameter.
Player player = getPlayerById(request.getParameter("player")); Player player = getPlayerById(ServletRequestUtils.getIntParameter(request, "player"));
// Find in session context. // Find in session context.
if (player == null && remoteControlEnabled) { if (player == null && remoteControlEnabled) {
String playerId = (String) request.getSession().getAttribute("player"); Integer playerId = (Integer) request.getSession().getAttribute("player");
if (playerId != null) { if (playerId != null) {
player = getPlayerById(playerId); player = getPlayerById(playerId);
} }
@ -148,7 +149,7 @@ public class PlayerService {
// Set cookie in response. // Set cookie in response.
if (response != null) { if (response != null) {
String cookieName = COOKIE_NAME + "-" + StringUtil.utf8HexEncode(username); String cookieName = COOKIE_NAME + "-" + StringUtil.utf8HexEncode(username);
Cookie cookie = new Cookie(cookieName, player.getId()); Cookie cookie = new Cookie(cookieName, String.valueOf(player.getId()));
cookie.setMaxAge(COOKIE_EXPIRY); cookie.setMaxAge(COOKIE_EXPIRY);
String path = request.getContextPath(); String path = request.getContextPath();
if (StringUtils.isEmpty(path)) { if (StringUtils.isEmpty(path)) {
@ -181,8 +182,8 @@ public class PlayerService {
* @param id The unique player ID. * @param id The unique player ID.
* @return The player with the given ID, or <code>null</code> if no such player exists. * @return The player with the given ID, or <code>null</code> if no such player exists.
*/ */
public Player getPlayerById(String id) { public Player getPlayerById(Integer id) {
if (StringUtils.isBlank(id)) { if (id == null) {
return null; return null;
} else { } else {
return playerDao.getPlayerById(id); return playerDao.getPlayerById(id);
@ -234,7 +235,7 @@ public class PlayerService {
* @param username The name of the current user. * @param username The name of the current user.
* @return The player ID embedded in the cookie, or <code>null</code> if cookie is not present. * @return The player ID embedded in the cookie, or <code>null</code> if cookie is not present.
*/ */
private String getPlayerIdFromCookie(HttpServletRequest request, String username) { private Integer getPlayerIdFromCookie(HttpServletRequest request, String username) {
Cookie[] cookies = request.getCookies(); Cookie[] cookies = request.getCookies();
if (cookies == null) { if (cookies == null) {
return null; return null;
@ -242,7 +243,11 @@ public class PlayerService {
String cookieName = COOKIE_NAME + "-" + StringUtil.utf8HexEncode(username); String cookieName = COOKIE_NAME + "-" + StringUtil.utf8HexEncode(username);
for (Cookie cookie : cookies) { for (Cookie cookie : cookies) {
if (cookieName.equals(cookie.getName())) { if (cookieName.equals(cookie.getName())) {
return StringUtils.trimToNull(cookie.getValue()); try {
return Integer.valueOf(cookie.getValue());
} catch (NumberFormatException e) {
return null;
}
} }
} }
return null; return null;
@ -274,7 +279,7 @@ public class PlayerService {
* *
* @param id The unique player ID. * @param id The unique player ID.
*/ */
public synchronized void removePlayerById(String id) { public synchronized void removePlayerById(int id) {
playerDao.deletePlayer(id); playerDao.deletePlayer(id);
} }
@ -284,7 +289,7 @@ public class PlayerService {
* @param playerId The ID of the player to clone. * @param playerId The ID of the player to clone.
* @return The cloned player. * @return The cloned player.
*/ */
public Player clonePlayer(String playerId) { public Player clonePlayer(int playerId) {
Player player = getPlayerById(playerId); Player player = getPlayerById(playerId);
if (player.getName() != null) { if (player.getName() != null) {
player.setName(player.getName() + " (copy)"); player.setName(player.getName() + " (copy)");
@ -309,8 +314,9 @@ public class PlayerService {
defaultActiveTranscodings.add(transcoding); defaultActiveTranscodings.add(transcoding);
} }
} }
if (player != null) {
transcodingService.setTranscodingsForPlayer(player, defaultActiveTranscodings); transcodingService.setTranscodingsForPlayer(player, defaultActiveTranscodings);
}
} }
/** /**

@ -49,7 +49,7 @@ public class StatusService {
private final List<PlayStatus> remotePlays = new ArrayList<PlayStatus>(); private final List<PlayStatus> remotePlays = new ArrayList<PlayStatus>();
// Maps from player ID to latest inactive stream status. // Maps from player ID to latest inactive stream status.
private final Map<String, TransferStatus> inactiveStreamStatuses = new LinkedHashMap<String, TransferStatus>(); private final Map<Integer, TransferStatus> inactiveStreamStatuses = new LinkedHashMap<Integer, TransferStatus>();
public synchronized TransferStatus createStreamStatus(Player player) { public synchronized TransferStatus createStreamStatus(Player player) {
// Reuse existing status, if possible. // Reuse existing status, if possible.
@ -74,12 +74,12 @@ public class StatusService {
List<TransferStatus> result = new ArrayList<TransferStatus>(streamStatuses); List<TransferStatus> result = new ArrayList<TransferStatus>(streamStatuses);
// Add inactive status for those players that have no active status. // Add inactive status for those players that have no active status.
Set<String> activePlayers = new HashSet<String>(); Set<Integer> activePlayers = new HashSet<Integer>();
for (TransferStatus status : streamStatuses) { for (TransferStatus status : streamStatuses) {
activePlayers.add(status.getPlayer().getId()); activePlayers.add(status.getPlayer().getId());
} }
for (Map.Entry<String, TransferStatus> entry : inactiveStreamStatuses.entrySet()) { for (Map.Entry<Integer, TransferStatus> entry : inactiveStreamStatuses.entrySet()) {
if (!activePlayers.contains(entry.getKey())) { if (!activePlayers.contains(entry.getKey())) {
result.add(entry.getValue()); result.add(entry.getValue());
} }
@ -142,7 +142,7 @@ public class StatusService {
} }
public synchronized List<PlayStatus> getPlayStatuses() { public synchronized List<PlayStatus> getPlayStatuses() {
Map<String, PlayStatus> result = new LinkedHashMap<String, PlayStatus>(); Map<Integer, PlayStatus> result = new LinkedHashMap<Integer, PlayStatus>();
for (PlayStatus remotePlay : remotePlays) { for (PlayStatus remotePlay : remotePlays) {
if (!remotePlay.isExpired()) { if (!remotePlay.isExpired()) {
result.put(remotePlay.getPlayer().getId(), remotePlay); result.put(remotePlay.getPlayer().getId(), remotePlay);
@ -179,4 +179,4 @@ public class StatusService {
public void setMediaFileService(MediaFileService mediaFileService) { public void setMediaFileService(MediaFileService mediaFileService) {
this.mediaFileService = mediaFileService; this.mediaFileService = mediaFileService;
} }
} }

@ -118,9 +118,11 @@ public class TranscodingService {
// Activate this transcoding for all players? // Activate this transcoding for all players?
if (transcoding.isDefaultActive()) { if (transcoding.isDefaultActive()) {
for (Player player : playerService.getAllPlayers()) { for (Player player : playerService.getAllPlayers()) {
List<Transcoding> transcodings = getTranscodingsForPlayer(player); if (player != null) {
transcodings.add(transcoding); List<Transcoding> transcodings = getTranscodingsForPlayer(player);
setTranscodingsForPlayer(player, transcodings); transcodings.add(transcoding);
setTranscodingsForPlayer(player, transcodings);
}
} }
} }
} }

@ -65,25 +65,25 @@ public class PlayerDaoTestCase extends DaoTestCaseBean2 {
Player player = new Player(); Player player = new Player();
playerDao.createPlayer(player); playerDao.createPlayer(player);
assertEquals("Wrong ID", "1", player.getId()); assertEquals("Wrong ID", (Integer)1, player.getId());
assertEquals("Wrong number of players.", 1, playerDao.getAllPlayers().size()); assertEquals("Wrong number of players.", 1, playerDao.getAllPlayers().size());
playerDao.createPlayer(player); playerDao.createPlayer(player);
assertEquals("Wrong ID", "2", player.getId()); assertEquals("Wrong ID", (Integer)2, player.getId());
assertEquals("Wrong number of players.", 2, playerDao.getAllPlayers().size()); assertEquals("Wrong number of players.", 2, playerDao.getAllPlayers().size());
playerDao.createPlayer(player); playerDao.createPlayer(player);
assertEquals("Wrong ID", "3", player.getId()); assertEquals("Wrong ID", (Integer)3, player.getId());
assertEquals("Wrong number of players.", 3, playerDao.getAllPlayers().size()); assertEquals("Wrong number of players.", 3, playerDao.getAllPlayers().size());
playerDao.deletePlayer("3"); playerDao.deletePlayer(3);
playerDao.createPlayer(player); playerDao.createPlayer(player);
assertEquals("Wrong ID", "3", player.getId()); assertEquals("Wrong ID", (Integer)3, player.getId());
assertEquals("Wrong number of players.", 3, playerDao.getAllPlayers().size()); assertEquals("Wrong number of players.", 3, playerDao.getAllPlayers().size());
playerDao.deletePlayer("2"); playerDao.deletePlayer(2);
playerDao.createPlayer(player); playerDao.createPlayer(player);
assertEquals("Wrong ID", "4", player.getId()); assertEquals("Wrong ID", (Integer)4, player.getId());
assertEquals("Wrong number of players.", 3, playerDao.getAllPlayers().size()); assertEquals("Wrong number of players.", 3, playerDao.getAllPlayers().size());
} }
@ -153,10 +153,10 @@ public class PlayerDaoTestCase extends DaoTestCaseBean2 {
playerDao.createPlayer(new Player()); playerDao.createPlayer(new Player());
assertEquals("Wrong number of players.", 2, playerDao.getAllPlayers().size()); assertEquals("Wrong number of players.", 2, playerDao.getAllPlayers().size());
playerDao.deletePlayer("1"); playerDao.deletePlayer(1);
assertEquals("Wrong number of players.", 1, playerDao.getAllPlayers().size()); assertEquals("Wrong number of players.", 1, playerDao.getAllPlayers().size());
playerDao.deletePlayer("2"); playerDao.deletePlayer(2);
assertEquals("Wrong number of players.", 0, playerDao.getAllPlayers().size()); assertEquals("Wrong number of players.", 0, playerDao.getAllPlayers().size());
} }
@ -173,4 +173,4 @@ public class PlayerDaoTestCase extends DaoTestCaseBean2 {
assertEquals("Wrong last seen.", expected.getLastSeen(), actual.getLastSeen()); assertEquals("Wrong last seen.", expected.getLastSeen(), actual.getLastSeen());
assertEquals("Wrong transcode scheme.", expected.getTranscodeScheme(), actual.getTranscodeScheme()); assertEquals("Wrong transcode scheme.", expected.getTranscodeScheme(), actual.getTranscodeScheme());
} }
} }

@ -40,7 +40,7 @@ public class StatusServiceTestCase extends TestCase {
super.setUp(); super.setUp();
service = new StatusService(); service = new StatusService();
player1 = new Player(); player1 = new Player();
player1.setId("1"); player1.setId(1);
} }
public void testSimpleAddRemove() { public void testSimpleAddRemove() {

Loading…
Cancel
Save