Controllers migration.

master
Rémi Cocula 8 years ago
parent 010815a578
commit 8231a44089
  1. 14
      libresonic-main/src/main/java/org/libresonic/player/controller/LyricsController.java
  2. 54
      libresonic-main/src/main/java/org/libresonic/player/controller/MoreController.java
  3. 73
      libresonic-main/src/main/java/org/libresonic/player/controller/UploadController.java
  4. 20
      libresonic-main/src/main/resources/libresonic-servlet.xml

@ -19,6 +19,9 @@
*/ */
package org.libresonic.player.controller; package org.libresonic.player.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.ParameterizableViewController; import org.springframework.web.servlet.mvc.ParameterizableViewController;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
@ -32,16 +35,17 @@ import java.util.HashMap;
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class LyricsController extends ParameterizableViewController { @Controller
@RequestMapping("/lyrics")
public class LyricsController {
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<>();
map.put("artist", request.getParameter("artist")); map.put("artist", request.getParameter("artist"));
map.put("song", request.getParameter("song")); map.put("song", request.getParameter("song"));
ModelAndView result = super.handleRequestInternal(request, response); return new ModelAndView("lyrics","model",map);
result.addObject("model", map);
return result;
} }
} }

@ -19,18 +19,6 @@
*/ */
package org.libresonic.player.controller; package org.libresonic.player.controller;
import java.io.File;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ParameterizableViewController;
import org.libresonic.player.domain.MusicFolder; import org.libresonic.player.domain.MusicFolder;
import org.libresonic.player.domain.Player; import org.libresonic.player.domain.Player;
import org.libresonic.player.domain.User; import org.libresonic.player.domain.User;
@ -39,21 +27,41 @@ import org.libresonic.player.service.PlayerService;
import org.libresonic.player.service.SecurityService; import org.libresonic.player.service.SecurityService;
import org.libresonic.player.service.SettingsService; import org.libresonic.player.service.SettingsService;
import org.libresonic.player.util.StringUtil; 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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* Controller for the "more" page. * Controller for the "more" page.
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class MoreController extends ParameterizableViewController { @Controller
@RequestMapping("/more")
public class MoreController {
@Autowired
private SettingsService settingsService; private SettingsService settingsService;
@Autowired
private SecurityService securityService; private SecurityService securityService;
@Autowired
private PlayerService playerService; private PlayerService playerService;
@Autowired
private MediaFileService mediaFileService; private MediaFileService mediaFileService;
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { 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); User user = securityService.getCurrentUser(request);
@ -72,7 +80,7 @@ public class MoreController extends ParameterizableViewController {
} }
Player player = playerService.getPlayer(request, response); Player player = playerService.getPlayer(request, response);
ModelAndView result = super.handleRequestInternal(request, response); ModelAndView result = new ModelAndView();
result.addObject("model", map); result.addObject("model", map);
map.put("user", user); map.put("user", user);
map.put("uploadDirectory", uploadDirectory); map.put("uploadDirectory", uploadDirectory);
@ -84,20 +92,4 @@ public class MoreController extends ParameterizableViewController {
map.put("jamstashUrl", jamstashUrl); map.put("jamstashUrl", jamstashUrl);
return result; return result;
} }
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
public void setPlayerService(PlayerService playerService) {
this.playerService = playerService;
}
public void setMediaFileService(MediaFileService mediaFileService) {
this.mediaFileService = mediaFileService;
}
} }

@ -19,20 +19,33 @@
*/ */
package org.libresonic.player.controller; package org.libresonic.player.controller;
import org.libresonic.player.*; import org.apache.commons.fileupload.FileItem;
import org.libresonic.player.domain.*; import org.apache.commons.fileupload.FileItemFactory;
import org.libresonic.player.upload.*; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.libresonic.player.service.*; import org.apache.commons.io.IOUtils;
import org.libresonic.player.util.*; import org.apache.tools.zip.ZipEntry;
import org.apache.commons.fileupload.*; import org.apache.tools.zip.ZipFile;
import org.apache.commons.fileupload.servlet.*; import org.libresonic.player.Logger;
import org.apache.commons.io.*; import org.libresonic.player.domain.TransferStatus;
import org.apache.tools.zip.*; import org.libresonic.player.domain.User;
import org.springframework.web.servlet.*; import org.libresonic.player.service.PlayerService;
import org.springframework.web.servlet.mvc.*; import org.libresonic.player.service.SecurityService;
import org.libresonic.player.service.SettingsService;
import javax.servlet.http.*; import org.libresonic.player.service.StatusService;
import java.io.*; import org.libresonic.player.upload.MonitoredDiskFileItemFactory;
import org.libresonic.player.upload.UploadListener;
import org.libresonic.player.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*; import java.util.*;
/** /**
@ -40,22 +53,28 @@ import java.util.*;
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class UploadController extends ParameterizableViewController { @org.springframework.stereotype.Controller
@RequestMapping("/upload")
public class UploadController {
private static final Logger LOG = Logger.getLogger(UploadController.class); private static final Logger LOG = Logger.getLogger(UploadController.class);
@Autowired
private SecurityService securityService; private SecurityService securityService;
@Autowired
private PlayerService playerService; private PlayerService playerService;
@Autowired
private StatusService statusService; private StatusService statusService;
@Autowired
private SettingsService settingsService; private SettingsService settingsService;
public static final String UPLOAD_STATUS = "uploadStatus"; public static final String UPLOAD_STATUS = "uploadStatus";
@Override @RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<>();
List<File> uploadedFiles = new ArrayList<File>(); List<File> uploadedFiles = new ArrayList<>();
List<File> unzippedFiles = new ArrayList<File>(); List<File> unzippedFiles = new ArrayList<>();
TransferStatus status = null; TransferStatus status = null;
try { try {
@ -139,9 +158,7 @@ public class UploadController extends ParameterizableViewController {
map.put("uploadedFiles", uploadedFiles); map.put("uploadedFiles", uploadedFiles);
map.put("unzippedFiles", unzippedFiles); map.put("unzippedFiles", unzippedFiles);
ModelAndView result = super.handleRequestInternal(request, response); return new ModelAndView("upload","model",map);
result.addObject("model", map);
return result;
} }
private void unzip(File file, List<File> unzippedFiles) throws Exception { private void unzip(File file, List<File> unzippedFiles) throws Exception {
@ -196,21 +213,9 @@ public class UploadController extends ParameterizableViewController {
} }
} }
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
public void setPlayerService(PlayerService playerService) {
this.playerService = playerService;
}
public void setStatusService(StatusService statusService) {
this.statusService = statusService;
}
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
/** /**
* Receives callbacks as the file upload progresses. * Receives callbacks as the file upload progresses.

@ -15,23 +15,6 @@
<mvc:annotation-driven /> <mvc:annotation-driven />
<context:component-scan base-package="org.libresonic.player.controller, org.libresonic.player.validator"/> <context:component-scan base-package="org.libresonic.player.controller, org.libresonic.player.validator"/>
<bean id="moreController" class="org.libresonic.player.controller.MoreController">
<property name="viewName" value="more"/>
<property name="settingsService" ref="settingsService"/>
<property name="securityService" ref="securityService"/>
<property name="mediaFileService" ref="mediaFileService"/>
<property name="playerService" ref="playerService"/>
</bean>
<bean id="uploadController" class="org.libresonic.player.controller.UploadController">
<property name="viewName" value="upload"/>
<property name="securityService" ref="securityService"/>
<property name="statusService" ref="statusService"/>
<property name="playerService" ref="playerService"/>
<property name="settingsService" ref="settingsService"/>
</bean>
<bean id="lyricsController" class="org.libresonic.player.controller.LyricsController">
<property name="viewName" value="lyrics"/>
</bean>
<bean id="allmusicController" class="org.libresonic.player.controller.AllmusicController"> <bean id="allmusicController" class="org.libresonic.player.controller.AllmusicController">
<property name="viewName" value="allmusic"/> <property name="viewName" value="allmusic"/>
</bean> </bean>
@ -222,9 +205,6 @@
<property name="alwaysUseFullPath" value="true"/> <property name="alwaysUseFullPath" value="true"/>
<property name="mappings"> <property name="mappings">
<props> <props>
<prop key="/lyrics.view">lyricsController</prop>
<prop key="/more.view">moreController</prop>
<prop key="/upload.view">uploadController</prop>
<prop key="/exportPlaylist.view">multiController</prop> <prop key="/exportPlaylist.view">multiController</prop>
<prop key="/setMusicFileInfo.view">setMusicFileInfoController</prop> <prop key="/setMusicFileInfo.view">setMusicFileInfoController</prop>
<prop key="/createShare.view">shareManagementController</prop> <prop key="/createShare.view">shareManagementController</prop>

Loading…
Cancel
Save