Begin of migration of deprecated controllers style.

master
Rémi Cocula 8 years ago
parent f6541632bb
commit d422fc4086
  1. 37
      libresonic-main/src/main/java/org/libresonic/player/controller/AdvancedSettingsController.java
  2. 32
      libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java
  3. 15
      libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml

@ -19,24 +19,33 @@
*/ */
package org.libresonic.player.controller; package org.libresonic.player.controller;
import org.apache.commons.lang.StringUtils;
import org.libresonic.player.command.AdvancedSettingsCommand; import org.libresonic.player.command.AdvancedSettingsCommand;
import org.libresonic.player.service.SettingsService; import org.libresonic.player.service.SettingsService;
import org.springframework.web.servlet.mvc.SimpleFormController; import org.springframework.beans.factory.annotation.Autowired;
import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import javax.servlet.http.HttpServletRequest; 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. * Controller for the page used to administrate advanced settings.
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class AdvancedSettingsController extends SimpleFormController { @Controller
@RequestMapping("/advancedSettings")
public class AdvancedSettingsController {
@Autowired
private SettingsService settingsService; private SettingsService settingsService;
@Override // TODO replace with @GetMapping in Spring 4
protected Object formBackingObject(HttpServletRequest request) throws Exception { @RequestMapping(method = RequestMethod.GET)
protected String formBackingObject(Model model) throws Exception {
AdvancedSettingsCommand command = new AdvancedSettingsCommand(); AdvancedSettingsCommand command = new AdvancedSettingsCommand();
command.setDownloadLimit(String.valueOf(settingsService.getDownloadBitrateLimit())); command.setDownloadLimit(String.valueOf(settingsService.getDownloadBitrateLimit()));
command.setUploadLimit(String.valueOf(settingsService.getUploadBitrateLimit())); command.setUploadLimit(String.valueOf(settingsService.getUploadBitrateLimit()));
@ -53,12 +62,12 @@ public class AdvancedSettingsController extends SimpleFormController {
command.setSmtpUser(settingsService.getSmtpUser()); command.setSmtpUser(settingsService.getSmtpUser());
command.setSmtpFrom(settingsService.getSmtpFrom()); command.setSmtpFrom(settingsService.getSmtpFrom());
return command; model.addAttribute("command", command);
return "advancedSettings";
} }
@Override @RequestMapping(method = RequestMethod.POST)
protected void doSubmitAction(Object comm) throws Exception { protected String doSubmitAction(@ModelAttribute AdvancedSettingsCommand command,Model model) throws Exception {
AdvancedSettingsCommand command = (AdvancedSettingsCommand) comm;
command.setToast(true); command.setToast(true);
command.setReloadNeeded(false); command.setReloadNeeded(false);
@ -90,10 +99,8 @@ public class AdvancedSettingsController extends SimpleFormController {
settingsService.setSmtpPassword(command.getSmtpPassword()); settingsService.setSmtpPassword(command.getSmtpPassword());
} }
settingsService.save(); model.addAttribute("command", command);
return "advancedSettings";
} }
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
} }

@ -19,6 +19,12 @@
*/ */
package org.libresonic.player.controller; 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.springframework.web.servlet.mvc.SimpleFormController;
import org.libresonic.player.service.SettingsService; import org.libresonic.player.service.SettingsService;
import org.libresonic.player.service.PodcastService; import org.libresonic.player.service.PodcastService;
@ -31,23 +37,30 @@ import javax.servlet.http.HttpServletRequest;
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class PodcastSettingsController extends SimpleFormController { @Controller
@RequestMapping("/podcastSettings")
public class PodcastSettingsController {
@Autowired
private SettingsService settingsService; private SettingsService settingsService;
@Autowired
private PodcastService podcastService; 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(); PodcastSettingsCommand command = new PodcastSettingsCommand();
command.setInterval(String.valueOf(settingsService.getPodcastUpdateInterval())); command.setInterval(String.valueOf(settingsService.getPodcastUpdateInterval()));
command.setEpisodeRetentionCount(String.valueOf(settingsService.getPodcastEpisodeRetentionCount())); command.setEpisodeRetentionCount(String.valueOf(settingsService.getPodcastEpisodeRetentionCount()));
command.setEpisodeDownloadCount(String.valueOf(settingsService.getPodcastEpisodeDownloadCount())); command.setEpisodeDownloadCount(String.valueOf(settingsService.getPodcastEpisodeDownloadCount()));
command.setFolder(settingsService.getPodcastFolder()); command.setFolder(settingsService.getPodcastFolder());
return command;
model.addAttribute("command",command);
return "podcastSettings";
} }
protected void doSubmitAction(Object comm) throws Exception { @RequestMapping(method = RequestMethod.POST)
PodcastSettingsCommand command = (PodcastSettingsCommand) comm; protected String doSubmitAction(@ModelAttribute PodcastSettingsCommand command, Model model) throws Exception {
command.setToast(true); command.setToast(true);
settingsService.setPodcastUpdateInterval(Integer.parseInt(command.getInterval())); settingsService.setPodcastUpdateInterval(Integer.parseInt(command.getInterval()));
@ -57,13 +70,8 @@ public class PodcastSettingsController extends SimpleFormController {
settingsService.save(); settingsService.save();
podcastService.schedule(); podcastService.schedule();
model.addAttribute("command",command);
return "podcastSettings";
} }
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
public void setPodcastService(PodcastService podcastService) {
this.podcastService = podcastService;
}
} }

@ -225,25 +225,12 @@
<property name="viewName" value="internetRadioSettings"/> <property name="viewName" value="internetRadioSettings"/>
<property name="settingsService" ref="settingsService"/> <property name="settingsService" ref="settingsService"/>
</bean> </bean>
<bean id="podcastSettingsController" class="org.libresonic.player.controller.PodcastSettingsController">
<property name="commandClass" value="org.libresonic.player.command.PodcastSettingsCommand"/>
<property name="successView" value="podcastSettings"/>
<property name="formView" value="podcastSettings"/>
<property name="settingsService" ref="settingsService"/>
<property name="podcastService" ref="podcastService"/>
</bean>
<bean id="generalSettingsController" class="org.libresonic.player.controller.GeneralSettingsController"> <bean id="generalSettingsController" class="org.libresonic.player.controller.GeneralSettingsController">
<property name="commandClass" value="org.libresonic.player.command.GeneralSettingsCommand"/> <property name="commandClass" value="org.libresonic.player.command.GeneralSettingsCommand"/>
<property name="successView" value="generalSettings"/> <property name="successView" value="generalSettings"/>
<property name="formView" value="generalSettings"/> <property name="formView" value="generalSettings"/>
<property name="settingsService" ref="settingsService"/> <property name="settingsService" ref="settingsService"/>
</bean> </bean>
<bean id="advancedSettingsController" class="org.libresonic.player.controller.AdvancedSettingsController">
<property name="commandClass" value="org.libresonic.player.command.AdvancedSettingsCommand"/>
<property name="successView" value="advancedSettings"/>
<property name="formView" value="advancedSettings"/>
<property name="settingsService" ref="settingsService"/>
</bean>
<bean id="personalSettingsController" class="org.libresonic.player.controller.PersonalSettingsController"> <bean id="personalSettingsController" class="org.libresonic.player.controller.PersonalSettingsController">
<property name="commandClass" value="org.libresonic.player.command.PersonalSettingsCommand"/> <property name="commandClass" value="org.libresonic.player.command.PersonalSettingsCommand"/>
<property name="successView" value="personalSettings"/> <property name="successView" value="personalSettings"/>
@ -467,9 +454,7 @@
<prop key="/networkSettings.view">networkSettingsController</prop> <prop key="/networkSettings.view">networkSettingsController</prop>
<prop key="/transcodingSettings.view">transcodingSettingsController</prop> <prop key="/transcodingSettings.view">transcodingSettingsController</prop>
<prop key="/internetRadioSettings.view">internetRadioSettingsController</prop> <prop key="/internetRadioSettings.view">internetRadioSettingsController</prop>
<prop key="/podcastSettings.view">podcastSettingsController</prop>
<prop key="/generalSettings.view">generalSettingsController</prop> <prop key="/generalSettings.view">generalSettingsController</prop>
<prop key="/advancedSettings.view">advancedSettingsController</prop>
<prop key="/personalSettings.view">personalSettingsController</prop> <prop key="/personalSettings.view">personalSettingsController</prop>
<prop key="/avatarUpload.view">avatarUploadController</prop> <prop key="/avatarUpload.view">avatarUploadController</prop>
<prop key="/userSettings.view">userSettingsController</prop> <prop key="/userSettings.view">userSettingsController</prop>

Loading…
Cancel
Save