Controllers migration.

master
Rémi Cocula 8 years ago
parent 878d250930
commit 010815a578
  1. 28
      libresonic-main/src/main/java/org/libresonic/player/controller/HelpController.java
  2. 22
      libresonic-main/src/main/java/org/libresonic/player/controller/ImportPlaylistController.java
  3. 34
      libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java
  4. 19
      libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistsController.java
  5. 35
      libresonic-main/src/main/java/org/libresonic/player/controller/StatusController.java
  6. 32
      libresonic-main/src/main/resources/libresonic-servlet.xml

@ -25,6 +25,10 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ParameterizableViewController;
@ -38,15 +42,20 @@ import org.libresonic.player.service.VersionService;
*
* @author Sindre Mehus
*/
public class HelpController extends ParameterizableViewController {
@Controller
@RequestMapping("/help")
public class HelpController {
@Autowired
private VersionService versionService;
@Autowired
private SettingsService settingsService;
@Autowired
private SecurityService securityService;
@Override
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
if (versionService.isNewFinalVersionAvailable()) {
map.put("newVersionAvailable", true);
@ -75,20 +84,9 @@ public class HelpController extends ParameterizableViewController {
map.put("logEntries", Logger.getLatestLogEntries());
map.put("logFile", Logger.getLogFile());
ModelAndView result = super.handleRequestInternal(request, response);
result.addObject("model", map);
return result;
return new ModelAndView("help","model",map);
}
public void setVersionService(VersionService versionService) {
this.versionService = versionService;
}
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
}

@ -32,6 +32,10 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ParameterizableViewController;
@ -42,14 +46,18 @@ import org.libresonic.player.service.SecurityService;
/**
* @author Sindre Mehus
*/
public class ImportPlaylistController extends ParameterizableViewController {
@Controller
@RequestMapping("/importPlaylist")
public class ImportPlaylistController {
private static final long MAX_PLAYLIST_SIZE_MB = 5L;
@Autowired
private SecurityService securityService;
@Autowired
private PlaylistService playlistService;
@Override
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
@ -79,16 +87,8 @@ public class ImportPlaylistController extends ParameterizableViewController {
map.put("error", e.getMessage());
}
ModelAndView result = super.handleRequestInternal(request, response);
result.addObject("model", map);
return result;
return new ModelAndView("importPlaylist","model",map);
}
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
public void setPlaylistService(PlaylistService playlistService) {
this.playlistService = playlistService;
}
}

@ -27,7 +27,11 @@ import org.libresonic.player.service.PlayerService;
import org.libresonic.player.service.PlaylistService;
import org.libresonic.player.service.SecurityService;
import org.libresonic.player.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ParameterizableViewController;
import org.springframework.web.servlet.view.RedirectView;
@ -42,16 +46,22 @@ import java.util.Map;
*
* @author Sindre Mehus
*/
public class PlaylistController extends ParameterizableViewController {
@Controller
@RequestMapping("/playlist")
public class PlaylistController {
@Autowired
private SecurityService securityService;
@Autowired
private PlaylistService playlistService;
@Autowired
private SettingsService settingsService;
@Autowired
private PlayerService playerService;
@Override
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
User user = securityService.getCurrentUser(request);
@ -60,7 +70,7 @@ public class PlaylistController extends ParameterizableViewController {
Player player = playerService.getPlayer(request, response);
Playlist playlist = playlistService.getPlaylist(id);
if (playlist == null) {
return new ModelAndView(new RedirectView("notFound.view"));
return new ModelAndView(new RedirectView("notFound"));
}
map.put("playlist", playlist);
@ -69,24 +79,10 @@ public class PlaylistController extends ParameterizableViewController {
map.put("editAllowed", username.equals(playlist.getUsername()) || securityService.isAdmin(username));
map.put("partyMode", userSettings.isPartyModeEnabled());
ModelAndView result = super.handleRequestInternal(request, response);
result.addObject("model", map);
return result;
return new ModelAndView("playList","model",map);
}
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
public void setPlaylistService(PlaylistService playlistService) {
this.playlistService = playlistService;
}
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
public void setPlayerService(PlayerService playerService) {
this.playerService = playerService;
}
}

@ -25,7 +25,10 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ParameterizableViewController;
import org.springframework.web.servlet.view.RedirectView;
@ -44,29 +47,25 @@ import org.libresonic.player.service.SettingsService;
*
* @author Sindre Mehus
*/
@Controller
@RequestMapping("/playlists")
public class PlaylistsController extends ParameterizableViewController {
@Autowired
private SecurityService securityService;
@Autowired
private PlaylistService playlistService;
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
User user = securityService.getCurrentUser(request);
List<Playlist> playlists = playlistService.getReadablePlaylistsForUser(user.getUsername());
map.put("playlists", playlists);
ModelAndView result = super.handleRequestInternal(request, response);
result.addObject("model", map);
return result;
return new ModelAndView("playlists","model",map);
}
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
public void setPlaylistService(PlaylistService playlistService) {
this.playlistService = playlistService;
}
}

@ -24,37 +24,39 @@ import org.libresonic.player.domain.TransferStatus;
import org.libresonic.player.service.StatusService;
import org.libresonic.player.util.FileUtil;
import org.libresonic.player.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ParameterizableViewController;
import org.springframework.web.servlet.support.RequestContextUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.*;
/**
* Controller for the status page.
*
* @author Sindre Mehus
*/
public class StatusController extends ParameterizableViewController {
@Controller
@RequestMapping("/status")
public class StatusController {
@Autowired
private StatusService statusService;
@Override
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
List<TransferStatus> streamStatuses = statusService.getAllStreamStatuses();
List<TransferStatus> downloadStatuses = statusService.getAllDownloadStatuses();
List<TransferStatus> uploadStatuses = statusService.getAllUploadStatuses();
Locale locale = RequestContextUtils.getLocale(request);
List<TransferStatusHolder> transferStatuses = new ArrayList<TransferStatusHolder>();
List<TransferStatusHolder> transferStatuses = new ArrayList<>();
for (int i = 0; i < streamStatuses.size(); i++) {
long minutesAgo = streamStatuses.get(i).getMillisSinceLastUpdate() / 1000L / 60L;
@ -73,16 +75,11 @@ public class StatusController extends ParameterizableViewController {
map.put("chartWidth", StatusChartController.IMAGE_WIDTH);
map.put("chartHeight", StatusChartController.IMAGE_HEIGHT);
ModelAndView result = super.handleRequestInternal(request, response);
result.addObject("model", map);
return result;
return new ModelAndView("status","model",map);
}
public void setStatusService(StatusService statusService) {
this.statusService = statusService;
}
public static class TransferStatusHolder {
private static class TransferStatusHolder {
private TransferStatus transferStatus;
private boolean isStream;
private boolean isDownload;
@ -90,8 +87,8 @@ public class StatusController extends ParameterizableViewController {
private int index;
private Locale locale;
public TransferStatusHolder(TransferStatus transferStatus, boolean isStream, boolean isDownload, boolean isUpload,
int index, Locale locale) {
TransferStatusHolder(TransferStatus transferStatus, boolean isStream, boolean isDownload, boolean isUpload,
int index, Locale locale) {
this.transferStatus = transferStatus;
this.isStream = isStream;
this.isDownload = isDownload;

@ -15,33 +15,6 @@
<mvc:annotation-driven />
<context:component-scan base-package="org.libresonic.player.controller, org.libresonic.player.validator"/>
<bean id="statusController" class="org.libresonic.player.controller.StatusController">
<property name="viewName" value="status"/>
<property name="statusService" ref="statusService"/>
</bean>
<bean id="playlistController" class="org.libresonic.player.controller.PlaylistController">
<property name="viewName" value="playlist"/>
<property name="securityService" ref="securityService"/>
<property name="playlistService" ref="playlistService"/>
<property name="settingsService" ref="settingsService"/>
<property name="playerService" ref="playerService"/>
</bean>
<bean id="playlistsController" class="org.libresonic.player.controller.PlaylistsController">
<property name="viewName" value="playlists"/>
<property name="securityService" ref="securityService"/>
<property name="playlistService" ref="playlistService"/>
</bean>
<bean id="importPlaylistController" class="org.libresonic.player.controller.ImportPlaylistController">
<property name="viewName" value="importPlaylist"/>
<property name="securityService" ref="securityService"/>
<property name="playlistService" ref="playlistService"/>
</bean>
<bean id="helpController" class="org.libresonic.player.controller.HelpController">
<property name="viewName" value="help"/>
<property name="versionService" ref="versionService"/>
<property name="settingsService" ref="settingsService"/>
<property name="securityService" ref="securityService"/>
</bean>
<bean id="moreController" class="org.libresonic.player.controller.MoreController">
<property name="viewName" value="more"/>
<property name="settingsService" ref="settingsService"/>
@ -249,14 +222,9 @@
<property name="alwaysUseFullPath" value="true"/>
<property name="mappings">
<props>
<prop key="/playlist.view">playlistController</prop>
<prop key="/playlists.view">playlistsController</prop>
<prop key="/help.view">helpController</prop>
<prop key="/lyrics.view">lyricsController</prop>
<prop key="/status.view">statusController</prop>
<prop key="/more.view">moreController</prop>
<prop key="/upload.view">uploadController</prop>
<prop key="/importPlaylist.view">importPlaylistController</prop>
<prop key="/exportPlaylist.view">multiController</prop>
<prop key="/setMusicFileInfo.view">setMusicFileInfoController</prop>
<prop key="/createShare.view">shareManagementController</prop>

Loading…
Cancel
Save