From d422fc4086e6035add14cd896998010fd0e214b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Wed, 30 Nov 2016 00:18:50 +0100 Subject: [PATCH] Begin of migration of deprecated controllers style. --- .../AdvancedSettingsController.java | 37 +++++++++++-------- .../controller/PodcastSettingsController.java | 32 ++++++++++------ .../webapp/WEB-INF/libresonic-servlet.xml | 15 -------- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/AdvancedSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/AdvancedSettingsController.java index 3622bedc..6cbc2392 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/AdvancedSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/AdvancedSettingsController.java @@ -19,24 +19,33 @@ */ package org.libresonic.player.controller; +import org.apache.commons.lang.StringUtils; import org.libresonic.player.command.AdvancedSettingsCommand; import org.libresonic.player.service.SettingsService; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.apache.commons.lang.StringUtils; - -import javax.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; /** * Controller for the page used to administrate advanced settings. * * @author Sindre Mehus */ -public class AdvancedSettingsController extends SimpleFormController { +@Controller +@RequestMapping("/advancedSettings") +public class AdvancedSettingsController { + @Autowired private SettingsService settingsService; - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { + // TODO replace with @GetMapping in Spring 4 + @RequestMapping(method = RequestMethod.GET) + protected String formBackingObject(Model model) throws Exception { AdvancedSettingsCommand command = new AdvancedSettingsCommand(); command.setDownloadLimit(String.valueOf(settingsService.getDownloadBitrateLimit())); command.setUploadLimit(String.valueOf(settingsService.getUploadBitrateLimit())); @@ -53,12 +62,12 @@ public class AdvancedSettingsController extends SimpleFormController { command.setSmtpUser(settingsService.getSmtpUser()); command.setSmtpFrom(settingsService.getSmtpFrom()); - return command; + model.addAttribute("command", command); + return "advancedSettings"; } - @Override - protected void doSubmitAction(Object comm) throws Exception { - AdvancedSettingsCommand command = (AdvancedSettingsCommand) comm; + @RequestMapping(method = RequestMethod.POST) + protected String doSubmitAction(@ModelAttribute AdvancedSettingsCommand command,Model model) throws Exception { command.setToast(true); command.setReloadNeeded(false); @@ -90,10 +99,8 @@ public class AdvancedSettingsController extends SimpleFormController { settingsService.setSmtpPassword(command.getSmtpPassword()); } - settingsService.save(); + model.addAttribute("command", command); + return "advancedSettings"; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java index 3608b2f2..4a1133de 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java @@ -19,6 +19,12 @@ */ package org.libresonic.player.controller; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.mvc.SimpleFormController; import org.libresonic.player.service.SettingsService; import org.libresonic.player.service.PodcastService; @@ -31,23 +37,30 @@ import javax.servlet.http.HttpServletRequest; * * @author Sindre Mehus */ -public class PodcastSettingsController extends SimpleFormController { +@Controller +@RequestMapping("/podcastSettings") +public class PodcastSettingsController { + @Autowired private SettingsService settingsService; + @Autowired private PodcastService podcastService; - protected Object formBackingObject(HttpServletRequest request) throws Exception { + @RequestMapping(method = RequestMethod.GET) + protected String formBackingObject(Model model) throws Exception { PodcastSettingsCommand command = new PodcastSettingsCommand(); command.setInterval(String.valueOf(settingsService.getPodcastUpdateInterval())); command.setEpisodeRetentionCount(String.valueOf(settingsService.getPodcastEpisodeRetentionCount())); command.setEpisodeDownloadCount(String.valueOf(settingsService.getPodcastEpisodeDownloadCount())); command.setFolder(settingsService.getPodcastFolder()); - return command; + + model.addAttribute("command",command); + return "podcastSettings"; } - protected void doSubmitAction(Object comm) throws Exception { - PodcastSettingsCommand command = (PodcastSettingsCommand) comm; + @RequestMapping(method = RequestMethod.POST) + protected String doSubmitAction(@ModelAttribute PodcastSettingsCommand command, Model model) throws Exception { command.setToast(true); settingsService.setPodcastUpdateInterval(Integer.parseInt(command.getInterval())); @@ -57,13 +70,8 @@ public class PodcastSettingsController extends SimpleFormController { settingsService.save(); podcastService.schedule(); + model.addAttribute("command",command); + return "podcastSettings"; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setPodcastService(PodcastService podcastService) { - this.podcastService = podcastService; - } } diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml index 3a1ca182..d84853e8 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -225,25 +225,12 @@ - - - - - - - - - - - - - @@ -467,9 +454,7 @@ networkSettingsController transcodingSettingsController internetRadioSettingsController - podcastSettingsController generalSettingsController - advancedSettingsController personalSettingsController avatarUploadController userSettingsController