Migration of PersonalSettingsController + unit test.

master
Rémi Cocula 8 years ago
parent f4636a09ed
commit ba80e99703
  1. 38
      libresonic-main/src/main/java/org/libresonic/player/controller/PersonalSettingsController.java
  2. 8
      libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml

@ -25,6 +25,12 @@ import java.util.Locale;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
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.PersonalSettingsCommand; import org.libresonic.player.command.PersonalSettingsCommand;
@ -41,13 +47,17 @@ import org.libresonic.player.service.SettingsService;
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class PersonalSettingsController extends SimpleFormController { @Controller
@RequestMapping("/personalSettings")
public class PersonalSettingsController {
@Autowired
private SettingsService settingsService; private SettingsService settingsService;
@Autowired
private SecurityService securityService; private SecurityService securityService;
@Override @ModelAttribute
protected Object formBackingObject(HttpServletRequest request) throws Exception { protected void formBackingObject(HttpServletRequest request,Model model) throws Exception {
PersonalSettingsCommand command = new PersonalSettingsCommand(); PersonalSettingsCommand command = new PersonalSettingsCommand();
User user = securityService.getCurrentUser(request); User user = securityService.getCurrentUser(request);
@ -100,12 +110,16 @@ public class PersonalSettingsController extends SimpleFormController {
} }
} }
return command; model.addAttribute("command",command);
} }
@Override @RequestMapping(method = RequestMethod.GET)
protected void doSubmitAction(Object comm) throws Exception { protected String displayForm() throws Exception {
PersonalSettingsCommand command = (PersonalSettingsCommand) comm; return "personalSettings";
}
@RequestMapping(method = RequestMethod.POST)
protected String doSubmitAction(@ModelAttribute("command") PersonalSettingsCommand command,Model model) throws Exception {
int localeIndex = Integer.parseInt(command.getLocaleIndex()); int localeIndex = Integer.parseInt(command.getLocaleIndex());
Locale locale = null; Locale locale = null;
@ -152,6 +166,9 @@ public class PersonalSettingsController extends SimpleFormController {
settingsService.updateUserSettings(settings); settingsService.updateUserSettings(settings);
command.setReloadNeeded(true); command.setReloadNeeded(true);
model.addAttribute("command",command);
return "personalSettings";
} }
private int getAvatarId(UserSettings userSettings) { private int getAvatarId(UserSettings userSettings) {
@ -178,11 +195,4 @@ public class PersonalSettingsController extends SimpleFormController {
return avatarId; return avatarId;
} }
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
} }

@ -191,13 +191,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="personalSettingsController" class="org.libresonic.player.controller.PersonalSettingsController">
<property name="commandClass" value="org.libresonic.player.command.PersonalSettingsCommand"/>
<property name="successView" value="personalSettings"/>
<property name="formView" value="personalSettings"/>
<property name="settingsService" ref="settingsService"/>
<property name="securityService" ref="securityService"/>
</bean>
<bean id="avatarUploadController" class="org.libresonic.player.controller.AvatarUploadController"> <bean id="avatarUploadController" class="org.libresonic.player.controller.AvatarUploadController">
<property name="viewName" value="avatarUploadResult"/> <property name="viewName" value="avatarUploadResult"/>
<property name="settingsService" ref="settingsService"/> <property name="settingsService" ref="settingsService"/>
@ -396,7 +389,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="/personalSettings.view">personalSettingsController</prop>
<prop key="/avatarUpload.view">avatarUploadController</prop> <prop key="/avatarUpload.view">avatarUploadController</prop>
<prop key="/passwordSettings.view">passwordSettingsController</prop> <prop key="/passwordSettings.view">passwordSettingsController</prop>
<prop key="/premiumSettings.view">premiumSettingsController</prop> <prop key="/premiumSettings.view">premiumSettingsController</prop>

Loading…
Cancel
Save