Migration of MusicFolderSettingsController + unit test.

master
Rémi Cocula 8 years ago
parent 9bdbb5ab4f
commit f5a380eada
  1. 78
      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; package org.libresonic.player.controller;
import org.libresonic.player.command.MusicFolderSettingsCommand; import org.libresonic.player.command.MusicFolderSettingsCommand;
import org.libresonic.player.command.NetworkSettingsCommand;
import org.libresonic.player.dao.AlbumDao; import org.libresonic.player.dao.AlbumDao;
import org.libresonic.player.dao.ArtistDao; import org.libresonic.player.dao.ArtistDao;
import org.libresonic.player.dao.MediaFileDao; 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.MediaScannerService;
import org.libresonic.player.service.SettingsService; 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.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController; import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView; import org.springframework.web.servlet.view.RedirectView;
@ -40,22 +48,33 @@ import java.util.List;
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class MusicFolderSettingsController extends SimpleFormController { @Controller
@RequestMapping("/musicFolderSettings")
public class MusicFolderSettingsController {
@Autowired
private SettingsService settingsService; private SettingsService settingsService;
@Autowired
private MediaScannerService mediaScannerService; private MediaScannerService mediaScannerService;
@Autowired
private ArtistDao artistDao; private ArtistDao artistDao;
@Autowired
private AlbumDao albumDao; private AlbumDao albumDao;
@Autowired
private MediaFileDao mediaFileDao; 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(); MusicFolderSettingsCommand command = new MusicFolderSettingsCommand();
if (request.getParameter("scanNow") != null) { if (scanNow != null) {
settingsService.clearMusicFolderCache(); settingsService.clearMusicFolderCache();
mediaScannerService.scanLibrary(); mediaScannerService.scanLibrary();
} }
if (request.getParameter("expunge") != null) { if (expunge != null) {
expunge(); expunge();
} }
@ -66,8 +85,10 @@ public class MusicFolderSettingsController extends SimpleFormController {
command.setScanning(mediaScannerService.isScanning()); command.setScanning(mediaScannerService.isScanning());
command.setMusicFolders(wrap(settingsService.getAllMusicFolders(true, true))); command.setMusicFolders(wrap(settingsService.getAllMusicFolders(true, true)));
command.setNewMusicFolder(new MusicFolderSettingsCommand.MusicFolderInfo()); command.setNewMusicFolder(new MusicFolderSettingsCommand.MusicFolderInfo());
command.setReload(request.getParameter("reload") != null || request.getParameter("scanNow") != null); command.setReload(reload != null || scanNow != null);
return command;
model.addAttribute("command",command);
return "musicFolderSettings";
} }
private void expunge() { private void expunge() {
@ -84,17 +105,18 @@ public class MusicFolderSettingsController extends SimpleFormController {
return result; return result;
} }
@Override @RequestMapping(method = RequestMethod.POST)
protected ModelAndView onSubmit(Object comm) throws Exception { protected String onSubmit(@ModelAttribute MusicFolderSettingsCommand command, Model model) throws Exception {
MusicFolderSettingsCommand command = (MusicFolderSettingsCommand) comm;
if (command.getMusicFolders() != null) {
for (MusicFolderSettingsCommand.MusicFolderInfo musicFolderInfo : command.getMusicFolders()) { for (MusicFolderSettingsCommand.MusicFolderInfo musicFolderInfo : command.getMusicFolders()) {
if (musicFolderInfo.isDelete()) { if (musicFolderInfo.isDelete()) {
settingsService.deleteMusicFolder(musicFolderInfo.getId()); settingsService.deleteMusicFolder(musicFolderInfo.getId());
} else { } else {
MusicFolder musicFolder = musicFolderInfo.toMusicFolder(); MusicFolder musicFolder = musicFolderInfo.toMusicFolder();
if (musicFolder != null) { if (musicFolder != null) {
settingsService.updateMusicFolder(musicFolder); settingsService.updateMusicFolder(musicFolder);
}
} }
} }
} }
@ -111,26 +133,8 @@ public class MusicFolderSettingsController extends SimpleFormController {
settingsService.save(); settingsService.save();
mediaScannerService.schedule(); mediaScannerService.schedule();
return new ModelAndView(new RedirectView(getSuccessView() + ".view?reload")); model.addAttribute("command",command);
} return "redirect:musicFolderSettings.view";
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
public void setMediaScannerService(MediaScannerService mediaScannerService) {
this.mediaScannerService = mediaScannerService;
} }
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"> <c:forEach items="${command.musicFolders}" var="folder" varStatus="loopStatus">
<tr> <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}].name" size="20"/></td>
<td><form:input path="musicFolders[${loopStatus.count-1}].path" size="40"/></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> <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="mediaFileService" ref="mediaFileService"/>
<property name="settingsService" ref="settingsService"/> <property name="settingsService" ref="settingsService"/>
</bean> </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"> <bean id="transcodingSettingsController" class="org.libresonic.player.controller.TranscodingSettingsController">
<property name="viewName" value="transcodingSettings"/> <property name="viewName" value="transcodingSettings"/>
<property name="transcodingService" ref="transcodingService"/> <property name="transcodingService" ref="transcodingService"/>
@ -443,7 +433,6 @@
<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>
<prop key="/musicFolderSettings.view">musicFolderSettingsController</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="/generalSettings.view">generalSettingsController</prop>

Loading…
Cancel
Save