From 010815a57813489e13728ce9f8a76191d6dff32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Fri, 16 Dec 2016 00:02:02 +0100 Subject: [PATCH] Controllers migration. --- .../player/controller/HelpController.java | 28 +++++++-------- .../controller/ImportPlaylistController.java | 22 ++++++------ .../player/controller/PlaylistController.java | 34 ++++++++---------- .../controller/PlaylistsController.java | 19 +++++----- .../player/controller/StatusController.java | 35 +++++++++---------- .../src/main/resources/libresonic-servlet.xml | 32 ----------------- 6 files changed, 64 insertions(+), 106 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/HelpController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/HelpController.java index 24f0c27a..d46dabb7 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/HelpController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/HelpController.java @@ -25,6 +25,10 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.ParameterizableViewController; @@ -38,15 +42,20 @@ import org.libresonic.player.service.VersionService; * * @author Sindre Mehus */ -public class HelpController extends ParameterizableViewController { +@Controller +@RequestMapping("/help") +public class HelpController { + @Autowired private VersionService versionService; + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); if (versionService.isNewFinalVersionAvailable()) { map.put("newVersionAvailable", true); @@ -75,20 +84,9 @@ public class HelpController extends ParameterizableViewController { map.put("logEntries", Logger.getLatestLogEntries()); map.put("logFile", Logger.getLogFile()); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("help","model",map); } - public void setVersionService(VersionService versionService) { - this.versionService = versionService; - } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ImportPlaylistController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ImportPlaylistController.java index 3f44959a..b379e081 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ImportPlaylistController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ImportPlaylistController.java @@ -32,6 +32,10 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.ParameterizableViewController; @@ -42,14 +46,18 @@ import org.libresonic.player.service.SecurityService; /** * @author Sindre Mehus */ -public class ImportPlaylistController extends ParameterizableViewController { +@Controller +@RequestMapping("/importPlaylist") +public class ImportPlaylistController { private static final long MAX_PLAYLIST_SIZE_MB = 5L; + @Autowired private SecurityService securityService; + @Autowired private PlaylistService playlistService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -79,16 +87,8 @@ public class ImportPlaylistController extends ParameterizableViewController { map.put("error", e.getMessage()); } - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("importPlaylist","model",map); } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java index 138ba550..aa950fd3 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java @@ -27,7 +27,11 @@ import org.libresonic.player.service.PlayerService; import org.libresonic.player.service.PlaylistService; import org.libresonic.player.service.SecurityService; import org.libresonic.player.service.SettingsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.ParameterizableViewController; import org.springframework.web.servlet.view.RedirectView; @@ -42,16 +46,22 @@ import java.util.Map; * * @author Sindre Mehus */ -public class PlaylistController extends ParameterizableViewController { +@Controller +@RequestMapping("/playlist") +public class PlaylistController { + @Autowired private SecurityService securityService; + @Autowired private PlaylistService playlistService; + @Autowired private SettingsService settingsService; + @Autowired private PlayerService playerService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); User user = securityService.getCurrentUser(request); @@ -60,7 +70,7 @@ public class PlaylistController extends ParameterizableViewController { Player player = playerService.getPlayer(request, response); Playlist playlist = playlistService.getPlaylist(id); if (playlist == null) { - return new ModelAndView(new RedirectView("notFound.view")); + return new ModelAndView(new RedirectView("notFound")); } map.put("playlist", playlist); @@ -69,24 +79,10 @@ public class PlaylistController extends ParameterizableViewController { map.put("editAllowed", username.equals(playlist.getUsername()) || securityService.isAdmin(username)); map.put("partyMode", userSettings.isPartyModeEnabled()); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("playList","model",map); } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistsController.java index 3afbb1f1..daa19cfb 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistsController.java @@ -25,7 +25,10 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.ParameterizableViewController; import org.springframework.web.servlet.view.RedirectView; @@ -44,29 +47,25 @@ import org.libresonic.player.service.SettingsService; * * @author Sindre Mehus */ +@Controller +@RequestMapping("/playlists") public class PlaylistsController extends ParameterizableViewController { + @Autowired private SecurityService securityService; + @Autowired private PlaylistService playlistService; @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); User user = securityService.getCurrentUser(request); List playlists = playlistService.getReadablePlaylistsForUser(user.getUsername()); map.put("playlists", playlists); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("playlists","model",map); } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/StatusController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/StatusController.java index 5cf59354..a0eff1c9 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/StatusController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/StatusController.java @@ -24,37 +24,39 @@ import org.libresonic.player.domain.TransferStatus; import org.libresonic.player.service.StatusService; import org.libresonic.player.util.FileUtil; import org.libresonic.player.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.ParameterizableViewController; import org.springframework.web.servlet.support.RequestContextUtils; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; /** * Controller for the status page. * * @author Sindre Mehus */ -public class StatusController extends ParameterizableViewController { +@Controller +@RequestMapping("/status") +public class StatusController { + @Autowired private StatusService statusService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); List streamStatuses = statusService.getAllStreamStatuses(); List downloadStatuses = statusService.getAllDownloadStatuses(); List uploadStatuses = statusService.getAllUploadStatuses(); Locale locale = RequestContextUtils.getLocale(request); - List transferStatuses = new ArrayList(); + List transferStatuses = new ArrayList<>(); for (int i = 0; i < streamStatuses.size(); i++) { long minutesAgo = streamStatuses.get(i).getMillisSinceLastUpdate() / 1000L / 60L; @@ -73,16 +75,11 @@ public class StatusController extends ParameterizableViewController { map.put("chartWidth", StatusChartController.IMAGE_WIDTH); map.put("chartHeight", StatusChartController.IMAGE_HEIGHT); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("status","model",map); } - public void setStatusService(StatusService statusService) { - this.statusService = statusService; - } - public static class TransferStatusHolder { + private static class TransferStatusHolder { private TransferStatus transferStatus; private boolean isStream; private boolean isDownload; @@ -90,8 +87,8 @@ public class StatusController extends ParameterizableViewController { private int index; private Locale locale; - public TransferStatusHolder(TransferStatus transferStatus, boolean isStream, boolean isDownload, boolean isUpload, - int index, Locale locale) { + TransferStatusHolder(TransferStatus transferStatus, boolean isStream, boolean isDownload, boolean isUpload, + int index, Locale locale) { this.transferStatus = transferStatus; this.isStream = isStream; this.isDownload = isDownload; diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index cb12d7ad..089916bf 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,33 +15,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -249,14 +222,9 @@ - playlistController - playlistsController - helpController lyricsController - statusController moreController uploadController - importPlaylistController multiController setMusicFileInfoController shareManagementController