From 9bdbb5ab4f8e18c61f3222e6fde44bf7603e87ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Wed, 30 Nov 2016 21:10:18 +0100 Subject: [PATCH] Migration of NetworkSettingsController + unit test. --- .../controller/NetworkSettingsController.java | 45 ++++++++++++------- .../webapp/WEB-INF/libresonic-servlet.xml | 8 ---- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java index 08824ccf..02f622bd 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java @@ -24,6 +24,13 @@ import java.util.Random; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; +import org.apache.tools.ant.taskdefs.ManifestTask; +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.command.NetworkSettingsCommand; @@ -36,12 +43,17 @@ import org.libresonic.player.service.SettingsService; * * @author Sindre Mehus */ -public class NetworkSettingsController extends SimpleFormController { +@Controller +@RequestMapping("/networkSettings") +public class NetworkSettingsController { + @Autowired private SettingsService settingsService; + @Autowired private NetworkService networkService; - protected Object formBackingObject(HttpServletRequest request) throws Exception { + @RequestMapping(method = RequestMethod.GET) + protected String formBackingObject(Model model) throws Exception { NetworkSettingsCommand command = new NetworkSettingsCommand(); command.setPortForwardingEnabled(settingsService.isPortForwardingEnabled()); command.setUrlRedirectionEnabled(settingsService.isUrlRedirectionEnabled()); @@ -51,18 +63,26 @@ public class NetworkSettingsController extends SimpleFormController { command.setPort(settingsService.getPort()); command.setLicenseInfo(settingsService.getLicenseInfo()); - return command; + model.addAttribute("command",command); + return "networkSettings"; } - protected void doSubmitAction(Object cmd) throws Exception { - NetworkSettingsCommand command = (NetworkSettingsCommand) cmd; + @RequestMapping(method = RequestMethod.POST) + protected String doSubmitAction(@ModelAttribute NetworkSettingsCommand command, Model model) throws Exception { command.setToast(true); settingsService.setPortForwardingEnabled(command.isPortForwardingEnabled()); settingsService.setUrlRedirectionEnabled(command.isUrlRedirectionEnabled()); - settingsService.setUrlRedirectType(UrlRedirectType.valueOf(command.getUrlRedirectType())); - settingsService.setUrlRedirectFrom(StringUtils.lowerCase(command.getUrlRedirectFrom())); - settingsService.setUrlRedirectCustomUrl(StringUtils.trimToEmpty(command.getUrlRedirectCustomUrl())); + String urlRedirectType = command.getUrlRedirectType(); + if (urlRedirectType == null) { + command.setUrlRedirectType("NORMAL"); + command.setUrlRedirectFrom("yourname"); + command.setUrlRedirectCustomUrl("http://"); + } else { + settingsService.setUrlRedirectType(UrlRedirectType.valueOf(command.getUrlRedirectType())); + settingsService.setUrlRedirectFrom(StringUtils.lowerCase(command.getUrlRedirectFrom())); + settingsService.setUrlRedirectCustomUrl(StringUtils.trimToEmpty(command.getUrlRedirectCustomUrl())); + } if (settingsService.getServerId() == null) { Random rand = new Random(System.currentTimeMillis()); @@ -72,13 +92,8 @@ public class NetworkSettingsController extends SimpleFormController { settingsService.save(); networkService.initPortForwarding(0); networkService.initUrlRedirection(true); + model.addAttribute("command",command); + return "networkSettings"; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setNetworkService(NetworkService networkService) { - this.networkService = networkService; - } } \ No newline at end of file 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 d84853e8..431c2c54 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -208,13 +208,6 @@ - - - - - - - @@ -451,7 +444,6 @@ sonosSettingsController shareSettingsController musicFolderSettingsController - networkSettingsController transcodingSettingsController internetRadioSettingsController generalSettingsController