Controller migration

master
Rémi Cocula 8 years ago
parent 376f98d670
commit f76470537f
  1. 20
      libresonic-main/src/main/java/org/libresonic/player/controller/DBController.java
  2. 52
      libresonic-main/src/main/java/org/libresonic/player/controller/ExternalPlayerController.java
  3. 13
      libresonic-main/src/main/resources/libresonic-servlet.xml

@ -19,12 +19,15 @@
*/ */
package org.libresonic.player.controller; package org.libresonic.player.controller;
import org.libresonic.player.dao.DaoHelper;
import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.commons.lang.exception.ExceptionUtils;
import org.libresonic.player.dao.DaoHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ColumnMapRowMapper; import org.springframework.jdbc.core.ColumnMapRowMapper;
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.ModelAndView;
import org.springframework.web.servlet.mvc.ParameterizableViewController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -37,10 +40,14 @@ import java.util.Map;
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class DBController extends ParameterizableViewController { @Controller
@RequestMapping("/db")
public class DBController {
@Autowired
private DaoHelper daoHelper; private DaoHelper daoHelper;
@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<String, Object>();
@ -56,12 +63,7 @@ public class DBController extends ParameterizableViewController {
} }
} }
ModelAndView result = super.handleRequestInternal(request, response); return new ModelAndView("db","model",map);
result.addObject("model", map);
return result;
} }
public void setDaoHelper(DaoHelper daoHelper) {
this.daoHelper = daoHelper;
}
} }

@ -19,19 +19,6 @@
*/ */
package org.libresonic.player.controller; package org.libresonic.player.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
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.MediaFile; import org.libresonic.player.domain.MediaFile;
import org.libresonic.player.domain.MusicFolder; import org.libresonic.player.domain.MusicFolder;
import org.libresonic.player.domain.Player; import org.libresonic.player.domain.Player;
@ -40,20 +27,36 @@ import org.libresonic.player.service.MediaFileService;
import org.libresonic.player.service.PlayerService; import org.libresonic.player.service.PlayerService;
import org.libresonic.player.service.SettingsService; import org.libresonic.player.service.SettingsService;
import org.libresonic.player.service.ShareService; import org.libresonic.player.service.ShareService;
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.IOException;
import java.util.*;
/** /**
* Controller for the page used to play shared music (Twitter, Facebook etc). * Controller for the page used to play shared music (Twitter, Facebook etc).
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class ExternalPlayerController extends ParameterizableViewController { @Controller
@RequestMapping("/share/**")
public class ExternalPlayerController {
@Autowired
private SettingsService settingsService; private SettingsService settingsService;
@Autowired
private PlayerService playerService; private PlayerService playerService;
@Autowired
private ShareService shareService; private ShareService shareService;
@Autowired
private MediaFileService mediaFileService; private MediaFileService mediaFileService;
@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<String, Object>();
@ -84,9 +87,7 @@ public class ExternalPlayerController extends ParameterizableViewController {
map.put("redirectUrl", settingsService.getUrlRedirectUrl()); map.put("redirectUrl", settingsService.getUrlRedirectUrl());
map.put("player", player.getId()); map.put("player", player.getId());
ModelAndView result = super.handleRequestInternal(request, response); return new ModelAndView("externalPlayer", "model", map);
result.addObject("model", map);
return result;
} }
private List<MediaFile> getSongs(Share share, String username) throws IOException { private List<MediaFile> getSongs(Share share, String username) throws IOException {
@ -108,19 +109,4 @@ public class ExternalPlayerController extends ParameterizableViewController {
return result; return result;
} }
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
public void setPlayerService(PlayerService playerService) {
this.playerService = playerService;
}
public void setShareService(ShareService shareService) {
this.shareService = shareService;
}
public void setMediaFileService(MediaFileService mediaFileService) {
this.mediaFileService = mediaFileService;
}
} }

@ -17,13 +17,6 @@
org.libresonic.player.validator, org.libresonic.player.validator,
org.libresonic.player.security"/> org.libresonic.player.security"/>
<bean id="externalPlayerController" class="org.libresonic.player.controller.ExternalPlayerController">
<property name="viewName" value="externalPlayer"/>
<property name="mediaFileService" ref="mediaFileService"/>
<property name="settingsService" ref="settingsService"/>
<property name="playerService" ref="playerService"/>
<property name="shareService" ref="shareService"/>
</bean>
<bean id="wapController" class="org.libresonic.player.controller.WapController"> <bean id="wapController" class="org.libresonic.player.controller.WapController">
<property name="settingsService" ref="settingsService"/> <property name="settingsService" ref="settingsService"/>
<property name="playerService" ref="playerService"/> <property name="playerService" ref="playerService"/>
@ -65,21 +58,15 @@
<property name="userSettingsController" ref="userSettingsController"/> <property name="userSettingsController" ref="userSettingsController"/>
<property name="leftController" ref="leftController"/> <property name="leftController" ref="leftController"/>
</bean> </bean>
<bean id="dbController" class="org.libresonic.player.controller.DBController">
<property name="viewName" value="db"/>
<property name="daoHelper" ref="daoHelper"/>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="alwaysUseFullPath" value="true"/> <property name="alwaysUseFullPath" value="true"/>
<property name="mappings"> <property name="mappings">
<props> <props>
<prop key="/db.view">dbController</prop>
<prop key="/podcast/**">podcastController</prop> <prop key="/podcast/**">podcastController</prop>
<prop key="/wap/download.view">downloadController</prop> <prop key="/wap/download.view">downloadController</prop>
<prop key="/wap/**">wapController</prop> <prop key="/wap/**">wapController</prop>
<prop key="/rest/**">restController</prop> <prop key="/rest/**">restController</prop>
<prop key="/share/**">externalPlayerController</prop>
</props> </props>
</property> </property>
</bean> </bean>

Loading…
Cancel
Save