Migration of PlayerSettingsController + unit test.

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

@ -25,6 +25,12 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
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.libresonic.player.command.PlayerSettingsCommand;
@ -42,14 +48,19 @@ import org.libresonic.player.service.TranscodingService;
*
* @author Sindre Mehus
*/
public class PlayerSettingsController extends SimpleFormController {
@Controller
@RequestMapping("/playerSettings")
public class PlayerSettingsController {
@Autowired
private PlayerService playerService;
@Autowired
private SecurityService securityService;
@Autowired
private TranscodingService transcodingService;
@Override
protected Object formBackingObject(HttpServletRequest request) throws Exception {
@RequestMapping(method = RequestMethod.GET)
protected Object formBackingObject(HttpServletRequest request, Model model) throws Exception {
handleRequestParameters(request);
List<Player> players = getPlayers(request);
@ -91,12 +102,12 @@ public class PlayerSettingsController extends SimpleFormController {
command.setPlayers(players.toArray(new Player[players.size()]));
command.setAdmin(user.isAdminRole());
return command;
model.addAttribute("command",command);
return "playerSettings";
}
@Override
protected void doSubmitAction(Object comm) throws Exception {
PlayerSettingsCommand command = (PlayerSettingsCommand) comm;
@RequestMapping(method = RequestMethod.POST)
protected String doSubmitAction(@ModelAttribute PlayerSettingsCommand command, Model model) throws Exception {
Player player = playerService.getPlayerById(command.getPlayerId());
player.setAutoControlEnabled(command.isAutoControlEnabled());
@ -110,6 +121,8 @@ public class PlayerSettingsController extends SimpleFormController {
transcodingService.setTranscodingsForPlayer(player, command.getActiveTranscodingIds());
command.setReloadNeeded(true);
model.addAttribute("command",command);
return "redirect:playerSettings.view";
}
private List<Player> getPlayers(HttpServletRequest request) {
@ -135,15 +148,4 @@ public class PlayerSettingsController extends SimpleFormController {
}
}
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
public void setPlayerService(PlayerService playerService) {
this.playerService = playerService;
}
public void setTranscodingService(TranscodingService transcodingService) {
this.transcodingService = transcodingService;
}
}

@ -173,14 +173,6 @@
<bean id="settingsController" class="org.libresonic.player.controller.SettingsController">
<property name="securityService" ref="securityService"/>
</bean>
<bean id="playerSettingsController" class="org.libresonic.player.controller.PlayerSettingsController">
<property name="commandClass" value="org.libresonic.player.command.PlayerSettingsCommand"/>
<property name="successView" value="playerSettings"/>
<property name="formView" value="playerSettings"/>
<property name="playerService" ref="playerService"/>
<property name="securityService" ref="securityService"/>
<property name="transcodingService" ref="transcodingService"/>
</bean>
<bean id="dlnaSettingsController" class="org.libresonic.player.controller.DLNASettingsController">
<property name="viewName" value="dlnaSettings"/>
<property name="upnpService" ref="upnpService"/>
@ -423,7 +415,6 @@
<prop key="/starred.view">starredController</prop>
<prop key="/search.view">searchController</prop>
<prop key="/settings.view">settingsController</prop>
<prop key="/playerSettings.view">playerSettingsController</prop>
<prop key="/dlnaSettings.view">dlnaSettingsController</prop>
<prop key="/sonosSettings.view">sonosSettingsController</prop>
<prop key="/shareSettings.view">shareSettingsController</prop>

Loading…
Cancel
Save