From 2767d06731d1d41629e8b94123be2b630f83085a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 18 Dec 2016 01:14:33 +0100 Subject: [PATCH] Controllers migration. --- .../controller/ChangeCoverArtController.java | 19 ++++--- .../controller/SetRatingController.java | 2 + .../player/controller/StarredController.java | 52 +++++++------------ .../src/main/resources/libresonic-servlet.xml | 9 ---- 4 files changed, 29 insertions(+), 53 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java index fed59892..6a021d17 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java @@ -19,21 +19,19 @@ */ package org.libresonic.player.controller; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import org.libresonic.player.domain.MediaFile; +import org.libresonic.player.service.MediaFileService; 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.libresonic.player.domain.MediaFile; -import org.libresonic.player.service.MediaFileService; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; /** * Controller for changing cover art. @@ -47,6 +45,7 @@ public class ChangeCoverArtController { @Autowired private MediaFileService mediaFileService; + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); @@ -61,7 +60,7 @@ public class ChangeCoverArtController { album = dir.getAlbumName(); } - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("id", id); map.put("artist", artist); map.put("album", album); diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java index 091e23ad..9ac974cc 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java @@ -27,6 +27,7 @@ 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.view.RedirectView; @@ -49,6 +50,7 @@ public class SetRatingController { private MediaFileService mediaFileService; + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception { int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); Integer rating = ServletRequestUtils.getIntParameter(request, "rating"); diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/StarredController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/StarredController.java index 20818b97..147cd3b5 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/StarredController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/StarredController.java @@ -20,21 +20,19 @@ package org.libresonic.player.controller; import org.libresonic.player.dao.MediaFileDao; -import org.libresonic.player.domain.CoverArtScheme; -import org.libresonic.player.domain.MediaFile; -import org.libresonic.player.domain.MusicFolder; -import org.libresonic.player.domain.User; -import org.libresonic.player.domain.UserSettings; +import org.libresonic.player.domain.*; import org.libresonic.player.service.MediaFileService; import org.libresonic.player.service.PlayerService; 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.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.ParameterizableViewController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -45,17 +43,24 @@ import java.util.Map; * * @author Sindre Mehus */ -public class StarredController extends ParameterizableViewController { +@Controller +@RequestMapping("/starred") +public class StarredController { + @Autowired private PlayerService playerService; + @Autowired private MediaFileDao mediaFileDao; + @Autowired private SecurityService securityService; + @Autowired private SettingsService settingsService; + @Autowired private MediaFileService mediaFileService; - @Override + @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); String username = user.getUsername(); @@ -69,8 +74,8 @@ public class StarredController extends ParameterizableViewController { mediaFileService.populateStarredDate(albums, username); mediaFileService.populateStarredDate(files, username); - List songs = new ArrayList(); - List videos = new ArrayList(); + List songs = new ArrayList<>(); + List videos = new ArrayList<>(); for (MediaFile file : files) { (file.isVideo() ? videos : songs).add(file); } @@ -83,28 +88,7 @@ public class StarredController extends ParameterizableViewController { map.put("albums", albums); map.put("songs", songs); map.put("videos", videos); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; + return new ModelAndView("starred","model",map); } - public void setMediaFileDao(MediaFileDao mediaFileDao) { - this.mediaFileDao = mediaFileDao; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 7d3c42bf..ab2adc2d 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,14 +15,6 @@ - - - - - - - - @@ -174,7 +166,6 @@ multiController multiController videoPlayerController - starredController dlnaSettingsController sonosSettingsController shareSettingsController