From 8231a440894baf59b822d354d6afd3f68f6dc8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 17 Dec 2016 14:11:47 +0100 Subject: [PATCH] Controllers migration. --- .../player/controller/LyricsController.java | 14 ++-- .../player/controller/MoreController.java | 54 ++++++-------- .../player/controller/UploadController.java | 73 ++++++++++--------- .../src/main/resources/libresonic-servlet.xml | 20 ----- 4 files changed, 71 insertions(+), 90 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/LyricsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/LyricsController.java index 838dcae0..2a3c5698 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/LyricsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/LyricsController.java @@ -19,6 +19,9 @@ */ 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.ModelAndView; @@ -32,16 +35,17 @@ import java.util.HashMap; * * @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 { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("artist", request.getParameter("artist")); map.put("song", request.getParameter("song")); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("lyrics","model",map); } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/MoreController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/MoreController.java index 5b7a3c99..cae21dff 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/MoreController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/MoreController.java @@ -19,18 +19,6 @@ */ 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.Player; 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.SettingsService; 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. * * @author Sindre Mehus */ -public class MoreController extends ParameterizableViewController { +@Controller +@RequestMapping("/more") +public class MoreController { + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; + @Autowired private PlayerService playerService; + @Autowired private MediaFileService mediaFileService; + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); User user = securityService.getCurrentUser(request); @@ -72,7 +80,7 @@ public class MoreController extends ParameterizableViewController { } Player player = playerService.getPlayer(request, response); - ModelAndView result = super.handleRequestInternal(request, response); + ModelAndView result = new ModelAndView(); result.addObject("model", map); map.put("user", user); map.put("uploadDirectory", uploadDirectory); @@ -84,20 +92,4 @@ public class MoreController extends ParameterizableViewController { map.put("jamstashUrl", jamstashUrl); 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; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/UploadController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/UploadController.java index 19dc60bd..921d9076 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/UploadController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/UploadController.java @@ -19,20 +19,33 @@ */ package org.libresonic.player.controller; -import org.libresonic.player.*; -import org.libresonic.player.domain.*; -import org.libresonic.player.upload.*; -import org.libresonic.player.service.*; -import org.libresonic.player.util.*; -import org.apache.commons.fileupload.*; -import org.apache.commons.fileupload.servlet.*; -import org.apache.commons.io.*; -import org.apache.tools.zip.*; -import org.springframework.web.servlet.*; -import org.springframework.web.servlet.mvc.*; - -import javax.servlet.http.*; -import java.io.*; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.FileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.commons.io.IOUtils; +import org.apache.tools.zip.ZipEntry; +import org.apache.tools.zip.ZipFile; +import org.libresonic.player.Logger; +import org.libresonic.player.domain.TransferStatus; +import org.libresonic.player.domain.User; +import org.libresonic.player.service.PlayerService; +import org.libresonic.player.service.SecurityService; +import org.libresonic.player.service.SettingsService; +import org.libresonic.player.service.StatusService; +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.*; /** @@ -40,22 +53,28 @@ import java.util.*; * * @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); + @Autowired private SecurityService securityService; + @Autowired private PlayerService playerService; + @Autowired private StatusService statusService; + @Autowired private SettingsService settingsService; public static final String UPLOAD_STATUS = "uploadStatus"; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); - List uploadedFiles = new ArrayList(); - List unzippedFiles = new ArrayList(); + Map map = new HashMap<>(); + List uploadedFiles = new ArrayList<>(); + List unzippedFiles = new ArrayList<>(); TransferStatus status = null; try { @@ -139,9 +158,7 @@ public class UploadController extends ParameterizableViewController { map.put("uploadedFiles", uploadedFiles); map.put("unzippedFiles", unzippedFiles); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("upload","model",map); } private void unzip(File file, List 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. diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 089916bf..16194673 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,23 +15,6 @@ - - - - - - - - - - - - - - - - - @@ -222,9 +205,6 @@ - lyricsController - moreController - uploadController multiController setMusicFileInfoController shareManagementController