Migration of PlayerSettingsController + unit test.
This commit is contained in:
+20
-18
@@ -25,6 +25,12 @@ import java.util.List;
|
|||||||
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.PlayerSettingsCommand;
|
import org.libresonic.player.command.PlayerSettingsCommand;
|
||||||
@@ -42,14 +48,19 @@ import org.libresonic.player.service.TranscodingService;
|
|||||||
*
|
*
|
||||||
* @author Sindre Mehus
|
* @author Sindre Mehus
|
||||||
*/
|
*/
|
||||||
public class PlayerSettingsController extends SimpleFormController {
|
@Controller
|
||||||
|
@RequestMapping("/playerSettings")
|
||||||
|
public class PlayerSettingsController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
private PlayerService playerService;
|
private PlayerService playerService;
|
||||||
|
@Autowired
|
||||||
private SecurityService securityService;
|
private SecurityService securityService;
|
||||||
|
@Autowired
|
||||||
private TranscodingService transcodingService;
|
private TranscodingService transcodingService;
|
||||||
|
|
||||||
@Override
|
@RequestMapping(method = RequestMethod.GET)
|
||||||
protected Object formBackingObject(HttpServletRequest request) throws Exception {
|
protected Object formBackingObject(HttpServletRequest request, Model model) throws Exception {
|
||||||
|
|
||||||
handleRequestParameters(request);
|
handleRequestParameters(request);
|
||||||
List<Player> players = getPlayers(request);
|
List<Player> players = getPlayers(request);
|
||||||
@@ -91,12 +102,12 @@ public class PlayerSettingsController extends SimpleFormController {
|
|||||||
command.setPlayers(players.toArray(new Player[players.size()]));
|
command.setPlayers(players.toArray(new Player[players.size()]));
|
||||||
command.setAdmin(user.isAdminRole());
|
command.setAdmin(user.isAdminRole());
|
||||||
|
|
||||||
return command;
|
model.addAttribute("command",command);
|
||||||
|
return "playerSettings";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@RequestMapping(method = RequestMethod.POST)
|
||||||
protected void doSubmitAction(Object comm) throws Exception {
|
protected String doSubmitAction(@ModelAttribute PlayerSettingsCommand command, Model model) throws Exception {
|
||||||
PlayerSettingsCommand command = (PlayerSettingsCommand) comm;
|
|
||||||
Player player = playerService.getPlayerById(command.getPlayerId());
|
Player player = playerService.getPlayerById(command.getPlayerId());
|
||||||
|
|
||||||
player.setAutoControlEnabled(command.isAutoControlEnabled());
|
player.setAutoControlEnabled(command.isAutoControlEnabled());
|
||||||
@@ -110,6 +121,8 @@ public class PlayerSettingsController extends SimpleFormController {
|
|||||||
transcodingService.setTranscodingsForPlayer(player, command.getActiveTranscodingIds());
|
transcodingService.setTranscodingsForPlayer(player, command.getActiveTranscodingIds());
|
||||||
|
|
||||||
command.setReloadNeeded(true);
|
command.setReloadNeeded(true);
|
||||||
|
model.addAttribute("command",command);
|
||||||
|
return "redirect:playerSettings.view";
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Player> getPlayers(HttpServletRequest request) {
|
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">
|
<bean id="settingsController" class="org.libresonic.player.controller.SettingsController">
|
||||||
<property name="securityService" ref="securityService"/>
|
<property name="securityService" ref="securityService"/>
|
||||||
</bean>
|
</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">
|
<bean id="dlnaSettingsController" class="org.libresonic.player.controller.DLNASettingsController">
|
||||||
<property name="viewName" value="dlnaSettings"/>
|
<property name="viewName" value="dlnaSettings"/>
|
||||||
<property name="upnpService" ref="upnpService"/>
|
<property name="upnpService" ref="upnpService"/>
|
||||||
@@ -423,7 +415,6 @@
|
|||||||
<prop key="/starred.view">starredController</prop>
|
<prop key="/starred.view">starredController</prop>
|
||||||
<prop key="/search.view">searchController</prop>
|
<prop key="/search.view">searchController</prop>
|
||||||
<prop key="/settings.view">settingsController</prop>
|
<prop key="/settings.view">settingsController</prop>
|
||||||
<prop key="/playerSettings.view">playerSettingsController</prop>
|
|
||||||
<prop key="/dlnaSettings.view">dlnaSettingsController</prop>
|
<prop key="/dlnaSettings.view">dlnaSettingsController</prop>
|
||||||
<prop key="/sonosSettings.view">sonosSettingsController</prop>
|
<prop key="/sonosSettings.view">sonosSettingsController</prop>
|
||||||
<prop key="/shareSettings.view">shareSettingsController</prop>
|
<prop key="/shareSettings.view">shareSettingsController</prop>
|
||||||
|
|||||||
Reference in New Issue
Block a user