From f76470537fdd0cb7087ecbe1cb95e1e694f340af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 24 Dec 2016 19:45:44 +0100 Subject: [PATCH] Controller migration --- .../player/controller/DBController.java | 20 +++---- .../controller/ExternalPlayerController.java | 52 +++++++------------ .../src/main/resources/libresonic-servlet.xml | 13 ----- 3 files changed, 30 insertions(+), 55 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/DBController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/DBController.java index 594221f8..ae508e5c 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/DBController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/DBController.java @@ -19,12 +19,15 @@ */ package org.libresonic.player.controller; -import org.libresonic.player.dao.DaoHelper; import org.apache.commons.lang.exception.ExceptionUtils; +import org.libresonic.player.dao.DaoHelper; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.ColumnMapRowMapper; +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 javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -37,10 +40,14 @@ import java.util.Map; * * @author Sindre Mehus */ -public class DBController extends ParameterizableViewController { +@Controller +@RequestMapping("/db") +public class DBController { + @Autowired private DaoHelper daoHelper; + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -56,12 +63,7 @@ public class DBController extends ParameterizableViewController { } } - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("db","model",map); } - public void setDaoHelper(DaoHelper daoHelper) { - this.daoHelper = daoHelper; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ExternalPlayerController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ExternalPlayerController.java index a58dbe5d..71389a95 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ExternalPlayerController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ExternalPlayerController.java @@ -19,19 +19,6 @@ */ package org.libresonic.player.controller; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.ParameterizableViewController; - import org.libresonic.player.domain.MediaFile; import org.libresonic.player.domain.MusicFolder; import org.libresonic.player.domain.Player; @@ -40,20 +27,36 @@ import org.libresonic.player.service.MediaFileService; import org.libresonic.player.service.PlayerService; import org.libresonic.player.service.SettingsService; import org.libresonic.player.service.ShareService; +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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.*; /** * Controller for the page used to play shared music (Twitter, Facebook etc). * * @author Sindre Mehus */ -public class ExternalPlayerController extends ParameterizableViewController { +@Controller +@RequestMapping("/share/**") +public class ExternalPlayerController { + @Autowired private SettingsService settingsService; + @Autowired private PlayerService playerService; + @Autowired private ShareService shareService; + @Autowired private MediaFileService mediaFileService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -84,9 +87,7 @@ public class ExternalPlayerController extends ParameterizableViewController { map.put("redirectUrl", settingsService.getUrlRedirectUrl()); map.put("player", player.getId()); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("externalPlayer", "model", map); } private List getSongs(Share share, String username) throws IOException { @@ -108,19 +109,4 @@ public class ExternalPlayerController extends ParameterizableViewController { return result; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setShareService(ShareService shareService) { - this.shareService = shareService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } } \ No newline at end of file diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index c74f7cd0..1de4c524 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -17,13 +17,6 @@ org.libresonic.player.validator, org.libresonic.player.security"/> - - - - - - - @@ -65,21 +58,15 @@ - - - - - dbController podcastController downloadController wapController restController - externalPlayerController