Migration of MusicFolderSettingsController + unit test.

master
Rémi Cocula 8 years ago
parent 9bdbb5ab4f
commit f5a380eada
  1. 62
      libresonic-main/src/main/java/org/libresonic/player/controller/MusicFolderSettingsController.java
  2. 1
      libresonic-main/src/main/webapp/WEB-INF/jsp/musicFolderSettings.jsp
  3. 11
      libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml

@ -20,6 +20,7 @@
package org.libresonic.player.controller;
import org.libresonic.player.command.MusicFolderSettingsCommand;
import org.libresonic.player.command.NetworkSettingsCommand;
import org.libresonic.player.dao.AlbumDao;
import org.libresonic.player.dao.ArtistDao;
import org.libresonic.player.dao.MediaFileDao;
@ -27,6 +28,13 @@ import org.libresonic.player.domain.MusicFolder;
import org.libresonic.player.service.MediaScannerService;
import org.libresonic.player.service.SettingsService;
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.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;
@ -40,22 +48,33 @@ import java.util.List;
*
* @author Sindre Mehus
*/
public class MusicFolderSettingsController extends SimpleFormController {
@Controller
@RequestMapping("/musicFolderSettings")
public class MusicFolderSettingsController {
@Autowired
private SettingsService settingsService;
@Autowired
private MediaScannerService mediaScannerService;
@Autowired
private ArtistDao artistDao;
@Autowired
private AlbumDao albumDao;
@Autowired
private MediaFileDao mediaFileDao;
protected Object formBackingObject(HttpServletRequest request) throws Exception {
@RequestMapping(method = RequestMethod.GET)
protected String formBackingObject(@RequestParam(value = "scanNow",required = false) String scanNow,
@RequestParam(value = "expunge",required = false) String expunge,
@RequestParam(value = "reload",required = false) String reload,
Model model) throws Exception {
MusicFolderSettingsCommand command = new MusicFolderSettingsCommand();
if (request.getParameter("scanNow") != null) {
if (scanNow != null) {
settingsService.clearMusicFolderCache();
mediaScannerService.scanLibrary();
}
if (request.getParameter("expunge") != null) {
if (expunge != null) {
expunge();
}
@ -66,8 +85,10 @@ public class MusicFolderSettingsController extends SimpleFormController {
command.setScanning(mediaScannerService.isScanning());
command.setMusicFolders(wrap(settingsService.getAllMusicFolders(true, true)));
command.setNewMusicFolder(new MusicFolderSettingsCommand.MusicFolderInfo());
command.setReload(request.getParameter("reload") != null || request.getParameter("scanNow") != null);
return command;
command.setReload(reload != null || scanNow != null);
model.addAttribute("command",command);
return "musicFolderSettings";
}
private void expunge() {
@ -84,10 +105,10 @@ public class MusicFolderSettingsController extends SimpleFormController {
return result;
}
@Override
protected ModelAndView onSubmit(Object comm) throws Exception {
MusicFolderSettingsCommand command = (MusicFolderSettingsCommand) comm;
@RequestMapping(method = RequestMethod.POST)
protected String onSubmit(@ModelAttribute MusicFolderSettingsCommand command, Model model) throws Exception {
if (command.getMusicFolders() != null) {
for (MusicFolderSettingsCommand.MusicFolderInfo musicFolderInfo : command.getMusicFolders()) {
if (musicFolderInfo.isDelete()) {
settingsService.deleteMusicFolder(musicFolderInfo.getId());
@ -98,6 +119,7 @@ public class MusicFolderSettingsController extends SimpleFormController {
}
}
}
}
MusicFolder newMusicFolder = command.getNewMusicFolder().toMusicFolder();
if (newMusicFolder != null) {
@ -111,26 +133,8 @@ public class MusicFolderSettingsController extends SimpleFormController {
settingsService.save();
mediaScannerService.schedule();
return new ModelAndView(new RedirectView(getSuccessView() + ".view?reload"));
}
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
public void setMediaScannerService(MediaScannerService mediaScannerService) {
this.mediaScannerService = mediaScannerService;
model.addAttribute("command",command);
return "redirect:musicFolderSettings.view";
}
public void setArtistDao(ArtistDao artistDao) {
this.artistDao = artistDao;
}
public void setAlbumDao(AlbumDao albumDao) {
this.albumDao = albumDao;
}
public void setMediaFileDao(MediaFileDao mediaFileDao) {
this.mediaFileDao = mediaFileDao;
}
}

@ -38,6 +38,7 @@
<c:forEach items="${command.musicFolders}" var="folder" varStatus="loopStatus">
<tr>
<form:hidden path="musicFolders[${loopStatus.count-1}].id"/>
<td><form:input path="musicFolders[${loopStatus.count-1}].name" size="20"/></td>
<td><form:input path="musicFolders[${loopStatus.count-1}].path" size="40"/></td>
<td align="center" style="padding-left:1em"><form:checkbox path="musicFolders[${loopStatus.count-1}].enabled" cssClass="checkbox"/></td>

@ -198,16 +198,6 @@
<property name="mediaFileService" ref="mediaFileService"/>
<property name="settingsService" ref="settingsService"/>
</bean>
<bean id="musicFolderSettingsController" class="org.libresonic.player.controller.MusicFolderSettingsController">
<property name="commandClass" value="org.libresonic.player.command.MusicFolderSettingsCommand"/>
<property name="successView" value="musicFolderSettings"/>
<property name="formView" value="musicFolderSettings"/>
<property name="settingsService" ref="settingsService"/>
<property name="mediaScannerService" ref="mediaScannerService"/>
<property name="artistDao" ref="artistDao"/>
<property name="albumDao" ref="albumDao"/>
<property name="mediaFileDao" ref="mediaFileDao"/>
</bean>
<bean id="transcodingSettingsController" class="org.libresonic.player.controller.TranscodingSettingsController">
<property name="viewName" value="transcodingSettings"/>
<property name="transcodingService" ref="transcodingService"/>
@ -443,7 +433,6 @@
<prop key="/dlnaSettings.view">dlnaSettingsController</prop>
<prop key="/sonosSettings.view">sonosSettingsController</prop>
<prop key="/shareSettings.view">shareSettingsController</prop>
<prop key="/musicFolderSettings.view">musicFolderSettingsController</prop>
<prop key="/transcodingSettings.view">transcodingSettingsController</prop>
<prop key="/internetRadioSettings.view">internetRadioSettingsController</prop>
<prop key="/generalSettings.view">generalSettingsController</prop>

Loading…
Cancel
Save