Java Code Examples for org.springframework.web.bind.ServletRequestUtils#getBooleanParameter()

The following examples show how to use org.springframework.web.bind.ServletRequestUtils#getBooleanParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AvatarController.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
private Avatar getAvatar(HttpServletRequest request) {
    String id = request.getParameter("id");
    boolean forceCustom = ServletRequestUtils.getBooleanParameter(request, "forceCustom", false);

    if (id != null) {
        return settingsService.getSystemAvatar(Integer.parseInt(id));
    }

    String username = request.getParameter("username");
    if (username == null) {
        return null;
    }

    UserSettings userSettings = settingsService.getUserSettings(username);
    if (userSettings.getAvatarScheme() == AvatarScheme.CUSTOM || forceCustom) {
        return settingsService.getCustomAvatar(username);
    }
    if (userSettings.getAvatarScheme() == AvatarScheme.NONE) {
        return null;
    }
    return settingsService.getSystemAvatar(userSettings.getSystemAvatarId());
}
 
Example 2
Source File: StreamController.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
private VideoTranscodingSettings createVideoTranscodingSettings(MediaFile file, HttpServletRequest request) throws ServletRequestBindingException {
    Integer existingWidth = file.getWidth();
    Integer existingHeight = file.getHeight();
    Integer maxBitRate = ServletRequestUtils.getIntParameter(request, "maxBitRate");
    int timeOffset = ServletRequestUtils.getIntParameter(request, "timeOffset", 0);
    int defaultDuration = file.getDurationSeconds() == null ? Integer.MAX_VALUE : file.getDurationSeconds() - timeOffset;
    int duration = ServletRequestUtils.getIntParameter(request, "duration", defaultDuration);
    boolean hls = ServletRequestUtils.getBooleanParameter(request, "hls", false);

    Dimension dim = getRequestedVideoSize(request.getParameter("size"));
    if (dim == null) {
        dim = getSuitableVideoSize(existingWidth, existingHeight, maxBitRate);
    }

    return new VideoTranscodingSettings(dim.width, dim.height, timeOffset, duration, hls);
}
 
Example 3
Source File: StreamController.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
private VideoTranscodingSettings createVideoTranscodingSettings(MediaFile file, HttpServletRequest request)
        throws ServletRequestBindingException {
    Integer existingWidth = file.getWidth();
    Integer existingHeight = file.getHeight();
    Integer maxBitRate = ServletRequestUtils.getIntParameter(request, "maxBitRate");
    int timeOffset = ServletRequestUtils.getIntParameter(request, "timeOffset", 0);
    double defaultDuration = file.getDuration() == null ? Double.MAX_VALUE : file.getDuration() - timeOffset;
    double duration = ServletRequestUtils.getDoubleParameter(request, "duration", defaultDuration);
    boolean hls = ServletRequestUtils.getBooleanParameter(request, "hls", false);

    Dimension dim = getRequestedVideoSize(request.getParameter("size"));
    if (dim == null) {
        dim = getSuitableVideoSize(existingWidth, existingHeight, maxBitRate);
    }

    return new VideoTranscodingSettings(dim.width, dim.height, timeOffset, duration, hls);
}
 
Example 4
Source File: SonosSettingsController.java    From airsonic-advanced with GNU General Public License v3.0 6 votes vote down vote up
@PostMapping
public ModelAndView doPost(HttpServletRequest request) throws Exception {

    boolean sonosEnabled = ServletRequestUtils.getBooleanParameter(request, "sonosEnabled", false);
    String sonosServiceName = StringUtils.trimToNull(request.getParameter("sonosServiceName"));
    if (StringUtils.isBlank(sonosServiceName)) {
        sonosServiceName = "Airsonic";
    }

    settingsService.setSonosLinkMethod(request.getParameter("sonosLinkMethod"));
    settingsService.setSonosEnabled(sonosEnabled);
    settingsService.setSonosServiceName(sonosServiceName);
    settingsService.setSonosCallbackHostAddress(StringUtils.appendIfMissing(StringUtils.trimToNull(request.getParameter("callbackHostAddress")), "/"));
    settingsService.save();

    List<String> returnCodes = sonosService.updateMusicServiceRegistration();

    Map<String, Object> map = getModel(request);

    map.put("returnCodes", returnCodes);

    return new ModelAndView("sonosSettings", "model", map);
}
 
Example 5
Source File: AvatarController.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
private Avatar getAvatar(HttpServletRequest request) {
    String id = request.getParameter("id");
    boolean forceCustom = ServletRequestUtils.getBooleanParameter(request, "forceCustom", false);

    if (id != null) {
        return settingsService.getSystemAvatar(Integer.parseInt(id));
    }

    String username = request.getParameter("username");
    if (username == null) {
        return null;
    }

    UserSettings userSettings = settingsService.getUserSettings(username);
    if (userSettings.getAvatarScheme() == AvatarScheme.CUSTOM || forceCustom) {
        return settingsService.getCustomAvatar(username);
    }
    return settingsService.getSystemAvatar(userSettings.getSystemAvatarId());
}
 
Example 6
Source File: AvatarController.java    From airsonic with GNU General Public License v3.0 6 votes vote down vote up
private Avatar getAvatar(HttpServletRequest request) {
    String id = request.getParameter("id");
    boolean forceCustom = ServletRequestUtils.getBooleanParameter(request, "forceCustom", false);

    if (id != null) {
        return settingsService.getSystemAvatar(Integer.parseInt(id));
    }

    String username = request.getParameter("username");
    if (username == null) {
        return null;
    }

    UserSettings userSettings = settingsService.getUserSettings(username);
    if (userSettings.getAvatarScheme() == AvatarScheme.CUSTOM || forceCustom) {
        return settingsService.getCustomAvatar(username);
    }
    if (userSettings.getAvatarScheme() == AvatarScheme.NONE) {
        return null;
    }
    return settingsService.getSystemAvatar(userSettings.getSystemAvatarId());
}
 
Example 7
Source File: StreamController.java    From airsonic with GNU General Public License v3.0 6 votes vote down vote up
private VideoTranscodingSettings createVideoTranscodingSettings(MediaFile file, HttpServletRequest request)
        throws ServletRequestBindingException {
    Integer existingWidth = file.getWidth();
    Integer existingHeight = file.getHeight();
    Integer maxBitRate = ServletRequestUtils.getIntParameter(request, "maxBitRate");
    int timeOffset = ServletRequestUtils.getIntParameter(request, "timeOffset", 0);
    int defaultDuration = file.getDurationSeconds() == null ? Integer.MAX_VALUE :
            file.getDurationSeconds() - timeOffset;
    int duration = ServletRequestUtils.getIntParameter(request, "duration", defaultDuration);
    boolean hls = ServletRequestUtils.getBooleanParameter(request, "hls", false);

    Dimension dim = getRequestedVideoSize(request.getParameter("size"));
    if (dim == null) {
        dim = getSuitableVideoSize(existingWidth, existingHeight, maxBitRate);
    }

    return new VideoTranscodingSettings(dim.width, dim.height, timeOffset, duration, hls);
}
 
Example 8
Source File: SubsonicRESTController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping("/getArtistInfo2")
public void getArtistInfo2(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);

    int id = getRequiredIntParameter(request, "id");
    int count = getIntParameter(request, "count", 20);
    boolean includeNotPresent = ServletRequestUtils.getBooleanParameter(request, "includeNotPresent", false);

    ArtistInfo2 result = new ArtistInfo2();

    org.airsonic.player.domain.Artist artist = artistDao.getArtist(id);
    if (artist == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Artist not found.");
        return;
    }

    List<org.airsonic.player.domain.MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<org.airsonic.player.domain.Artist> similarArtists = lastFmService.getSimilarArtists(artist, count, includeNotPresent, musicFolders);
    for (org.airsonic.player.domain.Artist similarArtist : similarArtists) {
        result.getSimilarArtist().add(createJaxbArtist(new ArtistID3(), similarArtist, username));
    }
    ArtistBio artistBio = lastFmService.getArtistBio(artist, localeResolver.resolveLocale(request));
    if (artistBio != null) {
        result.setBiography(artistBio.getBiography());
        result.setMusicBrainzId(artistBio.getMusicBrainzId());
        result.setLastFmUrl(artistBio.getLastFmUrl());
        result.setSmallImageUrl(artistBio.getSmallImageUrl());
        result.setMediumImageUrl(artistBio.getMediumImageUrl());
        result.setLargeImageUrl(artistBio.getLargeImageUrl());
    }

    Response res = createResponse();
    res.setArtistInfo2(result);
    jaxbWriter.writeResponse(request, response, res);
}
 
Example 9
Source File: MainController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
private boolean isViewAsList(HttpServletRequest request, UserSettings userSettings) {
    boolean viewAsList = ServletRequestUtils.getBooleanParameter(request, "viewAsList", userSettings.isViewAsList());
    if (viewAsList != userSettings.isViewAsList()) {
        userSettings.setViewAsList(viewAsList);
        userSettings.setChanged(new Date());
        settingsService.updateUserSettings(userSettings);
    }
    return viewAsList;
}
 
Example 10
Source File: RESTController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
public void getArtistInfo2(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);

    int id = getRequiredIntParameter(request, "id");
    int count = getIntParameter(request, "count", 20);
    boolean includeNotPresent = ServletRequestUtils.getBooleanParameter(request, "includeNotPresent", false);

    ArtistInfo2 result = new ArtistInfo2();

    Artist artist = artistDao.getArtist(id);
    if (artist == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Artist not found.");
        return;
    }

    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<Artist> similarArtists = lastFmService.getSimilarArtists(artist, count, includeNotPresent, musicFolders);
    for (Artist similarArtist : similarArtists) {
        result.getSimilarArtist().add(createJaxbArtist(new ArtistID3(), similarArtist, username));
    }
    ArtistBio artistBio = lastFmService.getArtistBio(artist);
    if (artistBio != null) {
        result.setBiography(artistBio.getBiography());
        result.setMusicBrainzId(artistBio.getMusicBrainzId());
        result.setLastFmUrl(artistBio.getLastFmUrl());
        result.setSmallImageUrl(artistBio.getSmallImageUrl());
        result.setMediumImageUrl(artistBio.getMediumImageUrl());
        result.setLargeImageUrl(artistBio.getLargeImageUrl());
    }

    Response res = createResponse();
    res.setArtistInfo2(result);
    jaxbWriter.writeResponse(request, response, res);
}
 
Example 11
Source File: RESTController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
public void getArtistInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);

    int id = getRequiredIntParameter(request, "id");
    int count = getIntParameter(request, "count", 20);
    boolean includeNotPresent = ServletRequestUtils.getBooleanParameter(request, "includeNotPresent", false);

    ArtistInfo result = new ArtistInfo();

    MediaFile mediaFile = mediaFileService.getMediaFile(id);
    if (mediaFile == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Media file not found.");
        return;
    }
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<MediaFile> similarArtists = lastFmService.getSimilarArtists(mediaFile, count, includeNotPresent, musicFolders);
    for (MediaFile similarArtist : similarArtists) {
        result.getSimilarArtist().add(createJaxbArtist(similarArtist, username));
    }
    ArtistBio artistBio = lastFmService.getArtistBio(mediaFile);
    if (artistBio != null) {
        result.setBiography(artistBio.getBiography());
        result.setMusicBrainzId(artistBio.getMusicBrainzId());
        result.setLastFmUrl(artistBio.getLastFmUrl());
        result.setSmallImageUrl(artistBio.getSmallImageUrl());
        result.setMediumImageUrl(artistBio.getMediumImageUrl());
        result.setLargeImageUrl(artistBio.getLargeImageUrl());
    }

    Response res = createResponse();
    res.setArtistInfo(result);
    jaxbWriter.writeResponse(request, response, res);
}
 
Example 12
Source File: DLNASettingsController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
private void handleParameters(HttpServletRequest request) {
    boolean dlnaEnabled = ServletRequestUtils.getBooleanParameter(request, "dlnaEnabled", false);
    String dlnaServerName = StringUtils.trimToNull(request.getParameter("dlnaServerName"));
    if (dlnaServerName == null) {
        dlnaServerName = "Subsonic";
    }

    upnpService.setMediaServerEnabled(false);
    settingsService.setDlnaEnabled(dlnaEnabled);
    settingsService.setDlnaServerName(dlnaServerName);
    settingsService.save();
    upnpService.setMediaServerEnabled(dlnaEnabled);
}
 
Example 13
Source File: DLNASettingsController.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
private void handleParameters(HttpServletRequest request) {
    boolean dlnaEnabled = ServletRequestUtils.getBooleanParameter(request, "dlnaEnabled", false);
    String dlnaServerName = StringUtils.trimToNull(request.getParameter("dlnaServerName"));
    String dlnaBaseLANURL = StringUtils.trimToNull(request.getParameter("dlnaBaseLANURL"));
    if (dlnaServerName == null) {
        dlnaServerName = "Airsonic";
    }

    upnpService.setMediaServerEnabled(false);
    settingsService.setDlnaEnabled(dlnaEnabled);
    settingsService.setDlnaServerName(dlnaServerName);
    settingsService.setDlnaBaseLANURL(dlnaBaseLANURL);
    settingsService.save();
    upnpService.setMediaServerEnabled(dlnaEnabled);
}
 
Example 14
Source File: MainController.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
private boolean isViewAsList(HttpServletRequest request, UserSettings userSettings) {
    boolean viewAsList = ServletRequestUtils.getBooleanParameter(request, "viewAsList", userSettings.isViewAsList());
    if (viewAsList != userSettings.isViewAsList()) {
        userSettings.setViewAsList(viewAsList);
        userSettings.setChanged(new Date());
        settingsService.updateUserSettings(userSettings);
    }
    return viewAsList;
}
 
Example 15
Source File: SonosSettingsController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
private void handleParameters(HttpServletRequest request) {
    boolean sonosEnabled = ServletRequestUtils.getBooleanParameter(request, "sonosEnabled", false);
    String sonosServiceName = StringUtils.trimToNull(request.getParameter("sonosServiceName"));
    if (sonosServiceName == null) {
        sonosServiceName = "Subsonic";
    }

    settingsService.setSonosEnabled(sonosEnabled);
    settingsService.setSonosServiceName(sonosServiceName);
    settingsService.save();

    sonosService.setMusicServiceEnabled(false);
    sonosService.setMusicServiceEnabled(sonosEnabled);
}
 
Example 16
Source File: SubsonicRESTController.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping("/getArtistInfo")
public void getArtistInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);

    int id = getRequiredIntParameter(request, "id");
    int count = getIntParameter(request, "count", 20);
    boolean includeNotPresent = ServletRequestUtils.getBooleanParameter(request, "includeNotPresent", false);

    ArtistInfo result = new ArtistInfo();

    MediaFile mediaFile = mediaFileService.getMediaFile(id);
    if (mediaFile == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Media file not found.");
        return;
    }
    List<org.airsonic.player.domain.MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<MediaFile> similarArtists = lastFmService.getSimilarArtists(mediaFile, count, includeNotPresent, musicFolders);
    for (MediaFile similarArtist : similarArtists) {
        result.getSimilarArtist().add(createJaxbArtist(similarArtist, username));
    }
    ArtistBio artistBio = lastFmService.getArtistBio(mediaFile, localeResolver.resolveLocale(request));
    if (artistBio != null) {
        result.setBiography(artistBio.getBiography());
        result.setMusicBrainzId(artistBio.getMusicBrainzId());
        result.setLastFmUrl(artistBio.getLastFmUrl());
        result.setSmallImageUrl(artistBio.getSmallImageUrl());
        result.setMediumImageUrl(artistBio.getMediumImageUrl());
        result.setLargeImageUrl(artistBio.getLargeImageUrl());
    }

    Response res = createResponse();
    res.setArtistInfo(result);
    jaxbWriter.writeResponse(request, response, res);
}
 
Example 17
Source File: SubsonicRESTController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping("/getArtistInfo")
public void getArtistInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);

    int id = getRequiredIntParameter(request, "id");
    int count = getIntParameter(request, "count", 20);
    boolean includeNotPresent = ServletRequestUtils.getBooleanParameter(request, "includeNotPresent", false);

    ArtistInfo result = new ArtistInfo();

    MediaFile mediaFile = mediaFileService.getMediaFile(id);
    if (mediaFile == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Media file not found.");
        return;
    }
    List<org.airsonic.player.domain.MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<MediaFile> similarArtists = lastFmService.getSimilarArtists(mediaFile, count, includeNotPresent, musicFolders);
    for (MediaFile similarArtist : similarArtists) {
        result.getSimilarArtist().add(createJaxbArtist(similarArtist, username));
    }
    ArtistBio artistBio = lastFmService.getArtistBio(mediaFile, localeResolver.resolveLocale(request));
    if (artistBio != null) {
        result.setBiography(artistBio.getBiography());
        result.setMusicBrainzId(artistBio.getMusicBrainzId());
        result.setLastFmUrl(artistBio.getLastFmUrl());
        result.setSmallImageUrl(artistBio.getSmallImageUrl());
        result.setMediumImageUrl(artistBio.getMediumImageUrl());
        result.setLargeImageUrl(artistBio.getLargeImageUrl());
    }

    Response res = createResponse();
    res.setArtistInfo(result);
    jaxbWriter.writeResponse(request, response, res);
}
 
Example 18
Source File: LeftController.java    From airsonic with GNU General Public License v3.0 4 votes vote down vote up
@GetMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    boolean musicFolderChanged = saveSelectedMusicFolder(request);
    Map<String, Object> map = new HashMap<>();

    MediaLibraryStatistics statistics = indexManager.getStatistics();
    Locale locale = RequestContextUtils.getLocale(request);

    boolean refresh = ServletRequestUtils.getBooleanParameter(request, "refresh", false);
    if (refresh) {
        settingsService.clearMusicFolderCache();
    }

    String username = securityService.getCurrentUsername(request);
    List<MusicFolder> allMusicFolders = settingsService.getMusicFoldersForUser(username);
    MusicFolder selectedMusicFolder = settingsService.getSelectedMusicFolder(username);
    List<MusicFolder> musicFoldersToUse = selectedMusicFolder == null ? allMusicFolders : Collections.singletonList(selectedMusicFolder);
    UserSettings userSettings = settingsService.getUserSettings(username);
    MusicFolderContent musicFolderContent = musicIndexService.getMusicFolderContent(musicFoldersToUse, refresh);

    map.put("player", playerService.getPlayer(request, response));
    map.put("scanning", mediaScannerService.isScanning());
    map.put("musicFolders", allMusicFolders);
    map.put("selectedMusicFolder", selectedMusicFolder);
    map.put("radios", settingsService.getAllInternetRadios());
    map.put("shortcuts", musicIndexService.getShortcuts(musicFoldersToUse));
    map.put("partyMode", userSettings.isPartyModeEnabled());
    map.put("organizeByFolderStructure", settingsService.isOrganizeByFolderStructure());
    map.put("musicFolderChanged", musicFolderChanged);

    if (statistics != null) {
        map.put("statistics", statistics);
        long bytes = statistics.getTotalLengthInBytes();
        long hours = statistics.getTotalDurationInSeconds() / 3600L;
        map.put("hours", hours);
        map.put("bytes", StringUtil.formatBytes(bytes, locale));
    }

    map.put("indexedArtists", musicFolderContent.getIndexedArtists());
    map.put("singleSongs", musicFolderContent.getSingleSongs());
    map.put("indexes", musicFolderContent.getIndexedArtists().keySet());
    map.put("user", securityService.getCurrentUser(request));

    return new ModelAndView("left","model",map);
}
 
Example 19
Source File: LeftController.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    boolean musicFolderChanged = saveSelectedMusicFolder(request);
    Map<String, Object> map = new HashMap<String, Object>();

    MediaLibraryStatistics statistics = mediaScannerService.getStatistics();
    Locale locale = RequestContextUtils.getLocale(request);

    boolean refresh = ServletRequestUtils.getBooleanParameter(request, "refresh", false);
    if (refresh) {
        settingsService.clearMusicFolderCache();
    }

    String username = securityService.getCurrentUsername(request);
    List<MusicFolder> allMusicFolders = settingsService.getMusicFoldersForUser(username);
    MusicFolder selectedMusicFolder = settingsService.getSelectedMusicFolder(username);
    List<MusicFolder> musicFoldersToUse = selectedMusicFolder == null ? allMusicFolders : Arrays.asList(selectedMusicFolder);
    UserSettings userSettings = settingsService.getUserSettings(username);
    MusicFolderContent musicFolderContent = musicIndexService.getMusicFolderContent(musicFoldersToUse, refresh);

    map.put("player", playerService.getPlayer(request, response));
    map.put("scanning", mediaScannerService.isScanning());
    map.put("musicFolders", allMusicFolders);
    map.put("selectedMusicFolder", selectedMusicFolder);
    map.put("radios", settingsService.getAllInternetRadios());
    map.put("shortcuts", musicIndexService.getShortcuts(musicFoldersToUse));
    map.put("partyMode", userSettings.isPartyModeEnabled());
    map.put("organizeByFolderStructure", settingsService.isOrganizeByFolderStructure());
    map.put("musicFolderChanged", musicFolderChanged);

    if (statistics != null) {
        map.put("statistics", statistics);
        long bytes = statistics.getTotalLengthInBytes();
        long hours = statistics.getTotalDurationInSeconds() / 3600L;
        map.put("hours", hours);
        map.put("bytes", StringUtil.formatBytes(bytes, locale));
    }

    map.put("indexedArtists", musicFolderContent.getIndexedArtists());
    map.put("singleSongs", musicFolderContent.getSingleSongs());
    map.put("indexes", musicFolderContent.getIndexedArtists().keySet());
    map.put("user", securityService.getCurrentUser(request));

    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
}
 
Example 20
Source File: LeftController.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
@GetMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    boolean musicFolderChanged = saveSelectedMusicFolder(request);
    Map<String, Object> map = new HashMap<>();

    MediaLibraryStatistics statistics = indexManager.getStatistics();
    Locale locale = RequestContextUtils.getLocale(request);

    boolean refresh = ServletRequestUtils.getBooleanParameter(request, "refresh", false);
    if (refresh) {
        settingsService.clearMusicFolderCache();
    }

    String username = securityService.getCurrentUsername(request);
    List<MusicFolder> allMusicFolders = settingsService.getMusicFoldersForUser(username);
    MusicFolder selectedMusicFolder = settingsService.getSelectedMusicFolder(username);
    List<MusicFolder> musicFoldersToUse = selectedMusicFolder == null ? allMusicFolders : Collections.singletonList(selectedMusicFolder);
    UserSettings userSettings = settingsService.getUserSettings(username);
    MusicFolderContent musicFolderContent = musicIndexService.getMusicFolderContent(musicFoldersToUse, refresh);

    map.put("player", playerService.getPlayer(request, response));
    map.put("scanning", mediaScannerService.isScanning());
    map.put("musicFolders", allMusicFolders);
    map.put("selectedMusicFolder", selectedMusicFolder);
    map.put("radios", settingsService.getAllInternetRadios());
    map.put("shortcuts", musicIndexService.getShortcuts(musicFoldersToUse));
    map.put("partyMode", userSettings.getPartyModeEnabled());
    map.put("organizeByFolderStructure", settingsService.isOrganizeByFolderStructure());
    map.put("musicFolderChanged", musicFolderChanged);

    if (statistics != null) {
        map.put("statistics", statistics);
        long bytes = statistics.getTotalLengthInBytes();
        long hours = (long) (statistics.getTotalDurationInSeconds() / 3600L);
        map.put("hours", hours);
        map.put("bytes", StringUtil.formatBytes(bytes, locale));
    }

    map.put("indexedArtists", musicFolderContent.getIndexedArtists());
    map.put("singleSongs", musicFolderContent.getSingleSongs());
    map.put("indexes", musicFolderContent.getIndexedArtists().keySet());
    map.put("user", securityService.getCurrentUser(request));

    return new ModelAndView("left","model",map);
}