Migration of GeneralSettingsController + unit test.

master
Rémi Cocula 8 years ago
parent f5a380eada
commit 7a76a3ea75
  1. 27
      libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java
  2. 7
      libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml

@ -23,6 +23,12 @@ import java.util.Locale;
import javax.servlet.http.HttpServletRequest; 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.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.command.GeneralSettingsCommand; import org.libresonic.player.command.GeneralSettingsCommand;
@ -34,11 +40,15 @@ import org.libresonic.player.service.SettingsService;
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class GeneralSettingsController extends SimpleFormController { @Controller
@RequestMapping("/generalSettings")
public class GeneralSettingsController {
@Autowired
private SettingsService settingsService; private SettingsService settingsService;
protected Object formBackingObject(HttpServletRequest request) throws Exception { @RequestMapping(method = RequestMethod.GET)
protected String formBackingObject(Model model) throws Exception {
GeneralSettingsCommand command = new GeneralSettingsCommand(); GeneralSettingsCommand command = new GeneralSettingsCommand();
command.setCoverArtFileTypes(settingsService.getCoverArtFileTypes()); command.setCoverArtFileTypes(settingsService.getCoverArtFileTypes());
command.setIgnoredArticles(settingsService.getIgnoredArticles()); command.setIgnoredArticles(settingsService.getIgnoredArticles());
@ -76,12 +86,12 @@ public class GeneralSettingsController extends SimpleFormController {
} }
command.setLocales(localeStrings); command.setLocales(localeStrings);
return command; model.addAttribute("command",command);
return "generalSettings";
} }
protected void doSubmitAction(Object comm) throws Exception { @RequestMapping(method = RequestMethod.POST)
GeneralSettingsCommand command = (GeneralSettingsCommand) comm; protected String doSubmitAction(@ModelAttribute GeneralSettingsCommand command, Model model) throws Exception {
int themeIndex = Integer.parseInt(command.getThemeIndex()); int themeIndex = Integer.parseInt(command.getThemeIndex());
Theme theme = settingsService.getAvailableThemes()[themeIndex]; Theme theme = settingsService.getAvailableThemes()[themeIndex];
@ -112,9 +122,8 @@ public class GeneralSettingsController extends SimpleFormController {
settingsService.setThemeId(theme.getId()); settingsService.setThemeId(theme.getId());
settingsService.setLocale(locale); settingsService.setLocale(locale);
settingsService.save(); settingsService.save();
}
public void setSettingsService(SettingsService settingsService) { return "redirect:generalSettings.view";
this.settingsService = settingsService;
} }
} }

@ -208,12 +208,6 @@
<property name="viewName" value="internetRadioSettings"/> <property name="viewName" value="internetRadioSettings"/>
<property name="settingsService" ref="settingsService"/> <property name="settingsService" ref="settingsService"/>
</bean> </bean>
<bean id="generalSettingsController" class="org.libresonic.player.controller.GeneralSettingsController">
<property name="commandClass" value="org.libresonic.player.command.GeneralSettingsCommand"/>
<property name="successView" value="generalSettings"/>
<property name="formView" value="generalSettings"/>
<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"/>
@ -435,7 +429,6 @@
<prop key="/shareSettings.view">shareSettingsController</prop> <prop key="/shareSettings.view">shareSettingsController</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="/generalSettings.view">generalSettingsController</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