Пример #1
0
  @Override
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    User user = securityService.getCurrentUser(request);
    UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
    Player player = playerService.getPlayer(request, response);

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("user", user);
    map.put("player", player);
    map.put("players", playerService.getPlayersForUserAndClientId(user.getUsername(), null));
    map.put("visibility", userSettings.getPlaylistVisibility());
    map.put("partyMode", userSettings.isPartyModeEnabled());
    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
  }
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();

    //	String id = request.getParameter("id");
    //  MediaFile mediaFile = mediaFileService.getMediaFile(path);

    int listOffset = DEFAULT_LIST_OFFSET;
    int listSize = DEFAULT_LIST_SIZE;
    String listType = DEFAULT_LIST_TYPE;

    User user = securityService.getCurrentUser(request);
    String username = user.getUsername();
    UserSettings userSettings = settingsService.getUserSettings(username);
    int userGroupId = securityService.getCurrentUserGroupId(request);

    if (request.getParameter("listOffset") != null) {
      listOffset =
          Math.max(
              0, Math.min(Integer.parseInt(request.getParameter("listOffset")), MAX_LIST_OFFSET));
    }

    if (request.getParameter("listSize") != null) {
      listSize =
          Math.max(0, Math.min(Integer.parseInt(request.getParameter("listSize")), MAX_LIST_SIZE));
    }

    if (request.getParameter("listType") != null) {
      listType = String.valueOf(request.getParameter("listType"));
    }
    List<MediaFile> songs;
    if ("topplayed".equals(listType)) {
      songs = mediaFileDao.getTopPlayedCountForUser(listOffset, listSize, username);
    } else if ("otheruser".equals(listType)) {
      songs = mediaFileDao.getLastPlayedCountForAllUser(listOffset, listSize, userGroupId);
    } else if ("overall".equals(listType)) {
      songs = mediaFileDao.getTopPlayedCountForAllUser(listOffset, listSize, userGroupId);
    } else if ("lastplayed".equals(listType)) {
      songs = mediaFileDao.getLastPlayedCountForUser(listOffset, listSize, username);
    } else {
      songs = mediaFileDao.getLastPlayedCountForAllUser(0, 1, userGroupId);
    }

    mediaFileService.populateStarredDate(songs, username);
    map.put("user", user);
    map.put("songs", songs);

    map.put("partyModeEnabled", userSettings.isPartyModeEnabled());
    map.put("player", playerService.getPlayer(request, response));

    map.put("listOffset", listOffset);
    map.put("listSize", listSize);
    map.put("listType", listType);

    //  map.put("starred", mediaFileService.getMediaFileStarredDate(dir.getId(), username) != null);

    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
  }
Пример #3
0
  @Override
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();

    Player player = playerService.getPlayer(request, response);
    List<MediaFile> mediaFiles = getMediaFiles(request);

    if (mediaFiles.isEmpty()) {
      return new ModelAndView(new RedirectView("notFound.view"));
    }

    MediaFile dir = mediaFiles.get(0);
    if (dir.isFile()) {
      dir = mediaFileService.getParentOf(dir);
    }

    // Redirect if root directory.
    if (mediaFileService.isRoot(dir)) {
      return new ModelAndView(new RedirectView("home.view?"));
    }

    List<MediaFile> children =
        mediaFiles.size() == 1
            ? mediaFileService.getChildrenOf(dir, true, true, true)
            : getMultiFolderChildren(mediaFiles);
    String username = securityService.getCurrentUsername(request);
    UserSettings userSettings = settingsService.getUserSettings(username);

    mediaFileService.populateStarredDate(dir, username);
    mediaFileService.populateStarredDate(children, username);

    map.put("dir", dir);
    map.put("ancestors", getAncestors(dir));
    map.put("children", children);
    map.put("artist", guessArtist(children));
    map.put("album", guessAlbum(children));
    map.put("player", player);
    map.put("sieblingCoverArtScheme", CoverArtScheme.SMALL);
    map.put("user", securityService.getCurrentUser(request));
    map.put("visibility", userSettings.getMainVisibility());
    map.put("showAlbumYear", settingsService.isSortAlbumsByYear());
    map.put("updateNowPlaying", request.getParameter("updateNowPlaying") != null);
    map.put("partyMode", userSettings.isPartyModeEnabled());
    map.put("brand", settingsService.getBrand());

    try {
      MediaFile parent = mediaFileService.getParentOf(dir);
      map.put("parent", parent);
      map.put("navigateUpAllowed", !mediaFileService.isRoot(parent));
    } catch (SecurityException x) {
      // Happens if Podcast directory is outside music folder.
    }

    Integer userRating = ratingService.getRatingForUser(username, dir);
    Double averageRating = ratingService.getAverageRating(dir);

    if (userRating == null) {
      userRating = 0;
    }

    if (averageRating == null) {
      averageRating = 0.0D;
    }

    map.put("userRating", 10 * userRating);
    map.put("averageRating", Math.round(10.0D * averageRating));
    map.put("starred", mediaFileService.getMediaFileStarredDate(dir.getId(), username) != null);

    CoverArtScheme scheme = player.getCoverArtScheme();
    if (scheme != CoverArtScheme.OFF) {
      List<MediaFile> coverArts = getCoverArts(dir, children);
      map.put("coverArts", coverArts);
      setSieblingAlbums(dir, map);
    }

    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
  }