@ -1,47 +1,36 @@
/ *
/ *
This file is part of Libre sonic.
This file is part of Air sonic.
Libre sonic is free software : you can redistribute it and / or modify
Air sonic is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
( at your option ) any later version .
Libre sonic is distributed in the hope that it will be useful ,
Air sonic is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with Libre sonic. If not , see < http : //www.gnu.org/licenses/>.
along with Air sonic. If not , see < http : //www.gnu.org/licenses/>.
Copyright 2016 ( C ) Libre sonic Authors
Copyright 2016 ( C ) Air sonic Authors
Based upon Subsonic , Copyright 2009 ( C ) Sindre Mehus
Based upon Subsonic , Copyright 2009 ( C ) Sindre Mehus
* /
* /
package org.libresonic.player.controller ;
package org.airsonic.player.controller ;
import org.airsonic.player.ajax.LyricsInfo ;
import org.airsonic.player.ajax.LyricsService ;
import org.airsonic.player.ajax.PlayQueueService ;
import org.airsonic.player.command.UserSettingsCommand ;
import org.airsonic.player.dao.* ;
import org.airsonic.player.domain.* ;
import org.airsonic.player.service.* ;
import org.airsonic.player.util.Pair ;
import org.airsonic.player.util.StringUtil ;
import org.airsonic.player.util.Util ;
import org.apache.commons.lang.StringUtils ;
import org.apache.commons.lang.StringUtils ;
import org.apache.http.HttpStatus ;
import org.apache.http.HttpStatus ;
import org.libresonic.player.ajax.LyricsInfo ;
import org.libresonic.player.ajax.LyricsService ;
import org.libresonic.player.ajax.PlayQueueService ;
import org.libresonic.player.command.UserSettingsCommand ;
import org.libresonic.player.dao.* ;
import org.libresonic.player.domain.* ;
import org.libresonic.player.domain.Artist ;
import org.libresonic.player.domain.Bookmark ;
import org.libresonic.player.domain.Genre ;
import org.libresonic.player.domain.MusicFolder ;
import org.libresonic.player.domain.PlayQueue ;
import org.libresonic.player.domain.Playlist ;
import org.libresonic.player.domain.PodcastChannel ;
import org.libresonic.player.domain.PodcastEpisode ;
import org.libresonic.player.domain.SearchResult ;
import org.libresonic.player.domain.Share ;
import org.libresonic.player.domain.User ;
import org.libresonic.player.service.* ;
import org.libresonic.player.util.Pair ;
import org.libresonic.player.util.StringUtil ;
import org.libresonic.player.util.Util ;
import org.slf4j.Logger ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -62,7 +51,7 @@ import javax.servlet.http.HttpServletResponse;
import java.util.* ;
import java.util.* ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.concurrent.ConcurrentHashMap ;
import static org.libre sonic.player.security.RESTRequestParameterProcessingFilter.decrypt ;
import static org.air sonic.player.security.RESTRequestParameterProcessingFilter.decrypt ;
import static org.springframework.web.bind.ServletRequestUtils.* ;
import static org.springframework.web.bind.ServletRequestUtils.* ;
/ * *
/ * *
@ -141,7 +130,7 @@ public class RESTController {
@Autowired
@Autowired
private MediaScannerService mediaScannerService ;
private MediaScannerService mediaScannerService ;
private final Map < BookmarkKey , Bookmark > bookmarkCache = new ConcurrentHashMap < BookmarkKey , Bookmark > ( ) ;
private final Map < BookmarkKey , org . airsonic . player . domain . Bookmark > bookmarkCache = new ConcurrentHashMap < BookmarkKey , org . airsonic . player . domain . Bookmark > ( ) ;
private final JAXBWriter jaxbWriter = new JAXBWriter ( ) ;
private final JAXBWriter jaxbWriter = new JAXBWriter ( ) ;
private static final String NOT_YET_IMPLEMENTED = "Not yet implemented" ;
private static final String NOT_YET_IMPLEMENTED = "Not yet implemented" ;
@ -154,7 +143,7 @@ public class RESTController {
private void refreshBookmarkCache ( ) {
private void refreshBookmarkCache ( ) {
bookmarkCache . clear ( ) ;
bookmarkCache . clear ( ) ;
for ( Bookmark bookmark : bookmarkDao . getBookmarks ( ) ) {
for ( org . airsonic . player . domain . Bookmark bookmark : bookmarkDao . getBookmarks ( ) ) {
bookmarkCache . put ( BookmarkKey . forBookmark ( bookmark ) , bookmark ) ;
bookmarkCache . put ( BookmarkKey . forBookmark ( bookmark ) , bookmark ) ;
}
}
}
}
@ -179,7 +168,7 @@ public class RESTController {
License license = new License ( ) ;
License license = new License ( ) ;
license . setEmail ( "libre sonic@github.com" ) ;
license . setEmail ( "air sonic@github.com" ) ;
license . setValid ( true ) ;
license . setValid ( true ) ;
Date neverExpireDate = new Date ( Long . MAX_VALUE ) ;
Date neverExpireDate = new Date ( Long . MAX_VALUE ) ;
license . setLicenseExpires ( jaxbWriter . convertDate ( neverExpireDate ) ) ;
license . setLicenseExpires ( jaxbWriter . convertDate ( neverExpireDate ) ) ;
@ -197,7 +186,7 @@ public class RESTController {
MusicFolders musicFolders = new MusicFolders ( ) ;
MusicFolders musicFolders = new MusicFolders ( ) ;
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
for ( MusicFolder musicFolder : settingsService . getMusicFoldersForUser ( username ) ) {
for ( org . airsonic . player . domain . MusicFolder musicFolder : settingsService . getMusicFoldersForUser ( username ) ) {
org . subsonic . restapi . MusicFolder mf = new org . subsonic . restapi . MusicFolder ( ) ;
org . subsonic . restapi . MusicFolder mf = new org . subsonic . restapi . MusicFolder ( ) ;
mf . setId ( musicFolder . getId ( ) ) ;
mf . setId ( musicFolder . getId ( ) ) ;
mf . setName ( musicFolder . getName ( ) ) ;
mf . setName ( musicFolder . getName ( ) ) ;
@ -226,10 +215,10 @@ public class RESTController {
indexes . setLastModified ( lastModified ) ;
indexes . setLastModified ( lastModified ) ;
indexes . setIgnoredArticles ( settingsService . getIgnoredArticles ( ) ) ;
indexes . setIgnoredArticles ( settingsService . getIgnoredArticles ( ) ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
if ( musicFolderId ! = null ) {
if ( musicFolderId ! = null ) {
for ( MusicFolder musicFolder : musicFolders ) {
for ( org . airsonic . player . domain . MusicFolder musicFolder : musicFolders ) {
if ( musicFolderId . equals ( musicFolder . getId ( ) ) ) {
if ( musicFolderId . equals ( musicFolder . getId ( ) ) ) {
musicFolders = Collections . singletonList ( musicFolder ) ;
musicFolders = Collections . singletonList ( musicFolder ) ;
break ;
break ;
@ -283,7 +272,7 @@ public class RESTController {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
org . subsonic . restapi . Genres genres = new org . subsonic . restapi . Genres ( ) ;
org . subsonic . restapi . Genres genres = new org . subsonic . restapi . Genres ( ) ;
for ( Genre genre : mediaFileDao . getGenres ( false ) ) {
for ( org . airsonic . player . domain . Genre genre : mediaFileDao . getGenres ( false ) ) {
org . subsonic . restapi . Genre g = new org . subsonic . restapi . Genre ( ) ;
org . subsonic . restapi . Genre g = new org . subsonic . restapi . Genre ( ) ;
genres . getGenre ( ) . add ( g ) ;
genres . getGenre ( ) . add ( g ) ;
g . setContent ( genre . getName ( ) ) ;
g . setContent ( genre . getName ( ) ) ;
@ -308,7 +297,7 @@ public class RESTController {
int count = getIntParameter ( request , "count" , 10 ) ;
int count = getIntParameter ( request , "count" , 10 ) ;
count = Math . max ( 0 , Math . min ( count , 500 ) ) ;
count = Math . max ( 0 , Math . min ( count , 500 ) ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
for ( MediaFile mediaFile : mediaFileDao . getSongsByGenre ( genre , offset , count , musicFolders ) ) {
for ( MediaFile mediaFile : mediaFileDao . getSongsByGenre ( genre , offset , count , musicFolders ) ) {
songs . getSong ( ) . add ( createJaxbChild ( player , mediaFile , username ) ) ;
songs . getSong ( ) . add ( createJaxbChild ( player , mediaFile , username ) ) ;
@ -325,9 +314,9 @@ public class RESTController {
ArtistsID3 result = new ArtistsID3 ( ) ;
ArtistsID3 result = new ArtistsID3 ( ) ;
result . setIgnoredArticles ( settingsService . getIgnoredArticles ( ) ) ;
result . setIgnoredArticles ( settingsService . getIgnoredArticles ( ) ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < Artist > artists = artistDao . getAlphabetialArtists ( 0 , Integer . MAX_VALUE , musicFolders ) ;
List < org . airsonic . player . domain . Artist > artists = artistDao . getAlphabetialArtists ( 0 , Integer . MAX_VALUE , musicFolders ) ;
SortedMap < MusicIndex , List < MusicIndex . SortableArtistWithArtist > > indexedArtists = musicIndexService . getIndexedArtists ( artists ) ;
SortedMap < MusicIndex , List < MusicIndex . SortableArtistWithArtist > > indexedArtists = musicIndexService . getIndexedArtists ( artists ) ;
for ( Map . Entry < MusicIndex , List < MusicIndex . SortableArtistWithArtist > > entry : indexedArtists . entrySet ( ) ) {
for ( Map . Entry < MusicIndex , List < MusicIndex . SortableArtistWithArtist > > entry : indexedArtists . entrySet ( ) ) {
IndexID3 index = new IndexID3 ( ) ;
IndexID3 index = new IndexID3 ( ) ;
@ -358,7 +347,7 @@ public class RESTController {
error ( request , response , ErrorCode . NOT_FOUND , "Media file not found." ) ;
error ( request , response , ErrorCode . NOT_FOUND , "Media file not found." ) ;
return ;
return ;
}
}
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < MediaFile > similarSongs = lastFmService . getSimilarSongs ( mediaFile , count , musicFolders ) ;
List < MediaFile > similarSongs = lastFmService . getSimilarSongs ( mediaFile , count , musicFolders ) ;
Player player = playerService . getPlayer ( request , response ) ;
Player player = playerService . getPlayer ( request , response ) ;
for ( MediaFile similarSong : similarSongs ) {
for ( MediaFile similarSong : similarSongs ) {
@ -380,13 +369,13 @@ public class RESTController {
SimilarSongs2 result = new SimilarSongs2 ( ) ;
SimilarSongs2 result = new SimilarSongs2 ( ) ;
Artist artist = artistDao . getArtist ( id ) ;
org . airsonic . player . domain . Artist artist = artistDao . getArtist ( id ) ;
if ( artist = = null ) {
if ( artist = = null ) {
error ( request , response , ErrorCode . NOT_FOUND , "Artist not found." ) ;
error ( request , response , ErrorCode . NOT_FOUND , "Artist not found." ) ;
return ;
return ;
}
}
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < MediaFile > similarSongs = lastFmService . getSimilarSongs ( artist , count , musicFolders ) ;
List < MediaFile > similarSongs = lastFmService . getSimilarSongs ( artist , count , musicFolders ) ;
Player player = playerService . getPlayer ( request , response ) ;
Player player = playerService . getPlayer ( request , response ) ;
for ( MediaFile similarSong : similarSongs ) {
for ( MediaFile similarSong : similarSongs ) {
@ -408,7 +397,7 @@ public class RESTController {
TopSongs result = new TopSongs ( ) ;
TopSongs result = new TopSongs ( ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < MediaFile > topSongs = lastFmService . getTopSongs ( artist , count , musicFolders ) ;
List < MediaFile > topSongs = lastFmService . getTopSongs ( artist , count , musicFolders ) ;
Player player = playerService . getPlayer ( request , response ) ;
Player player = playerService . getPlayer ( request , response ) ;
for ( MediaFile topSong : topSongs ) {
for ( MediaFile topSong : topSongs ) {
@ -436,7 +425,7 @@ public class RESTController {
error ( request , response , ErrorCode . NOT_FOUND , "Media file not found." ) ;
error ( request , response , ErrorCode . NOT_FOUND , "Media file not found." ) ;
return ;
return ;
}
}
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < MediaFile > similarArtists = lastFmService . getSimilarArtists ( mediaFile , count , includeNotPresent , musicFolders ) ;
List < MediaFile > similarArtists = lastFmService . getSimilarArtists ( mediaFile , count , includeNotPresent , musicFolders ) ;
for ( MediaFile similarArtist : similarArtists ) {
for ( MediaFile similarArtist : similarArtists ) {
result . getSimilarArtist ( ) . add ( createJaxbArtist ( similarArtist , username ) ) ;
result . getSimilarArtist ( ) . add ( createJaxbArtist ( similarArtist , username ) ) ;
@ -467,15 +456,15 @@ public class RESTController {
ArtistInfo2 result = new ArtistInfo2 ( ) ;
ArtistInfo2 result = new ArtistInfo2 ( ) ;
Artist artist = artistDao . getArtist ( id ) ;
org . airsonic . player . domain . Artist artist = artistDao . getArtist ( id ) ;
if ( artist = = null ) {
if ( artist = = null ) {
error ( request , response , ErrorCode . NOT_FOUND , "Artist not found." ) ;
error ( request , response , ErrorCode . NOT_FOUND , "Artist not found." ) ;
return ;
return ;
}
}
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < Artist > similarArtists = lastFmService . getSimilarArtists ( artist , count , includeNotPresent , musicFolders ) ;
List < org . airsonic . player . domain . Artist > similarArtists = lastFmService . getSimilarArtists ( artist , count , includeNotPresent , musicFolders ) ;
for ( Artist similarArtist : similarArtists ) {
for ( org . airsonic . player . domain . Artist similarArtist : similarArtists ) {
result . getSimilarArtist ( ) . add ( createJaxbArtist ( new ArtistID3 ( ) , similarArtist , username ) ) ;
result . getSimilarArtist ( ) . add ( createJaxbArtist ( new ArtistID3 ( ) , similarArtist , username ) ) ;
}
}
ArtistBio artistBio = lastFmService . getArtistBio ( artist ) ;
ArtistBio artistBio = lastFmService . getArtistBio ( artist ) ;
@ -493,7 +482,7 @@ public class RESTController {
jaxbWriter . writeResponse ( request , response , res ) ;
jaxbWriter . writeResponse ( request , response , res ) ;
}
}
private < T extends ArtistID3 > T createJaxbArtist ( T jaxbArtist , Artist artist , String username ) {
private < T extends ArtistID3 > T createJaxbArtist ( T jaxbArtist , org . airsonic . player . domain . Artist artist , String username ) {
jaxbArtist . setId ( String . valueOf ( artist . getId ( ) ) ) ;
jaxbArtist . setId ( String . valueOf ( artist . getId ( ) ) ) ;
jaxbArtist . setName ( artist . getName ( ) ) ;
jaxbArtist . setName ( artist . getName ( ) ) ;
jaxbArtist . setStarred ( jaxbWriter . convertDate ( mediaFileDao . getMediaFileStarredDate ( artist . getId ( ) , username ) ) ) ;
jaxbArtist . setStarred ( jaxbWriter . convertDate ( mediaFileDao . getMediaFileStarredDate ( artist . getId ( ) , username ) ) ) ;
@ -519,13 +508,13 @@ public class RESTController {
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
int id = getRequiredIntParameter ( request , "id" ) ;
int id = getRequiredIntParameter ( request , "id" ) ;
Artist artist = artistDao . getArtist ( id ) ;
org . airsonic . player . domain . Artist artist = artistDao . getArtist ( id ) ;
if ( artist = = null ) {
if ( artist = = null ) {
error ( request , response , ErrorCode . NOT_FOUND , "Artist not found." ) ;
error ( request , response , ErrorCode . NOT_FOUND , "Artist not found." ) ;
return ;
return ;
}
}
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
ArtistWithAlbumsID3 result = createJaxbArtist ( new ArtistWithAlbumsID3 ( ) , artist , username ) ;
ArtistWithAlbumsID3 result = createJaxbArtist ( new ArtistWithAlbumsID3 ( ) , artist , username ) ;
for ( Album album : albumDao . getAlbumsForArtist ( artist . getName ( ) , musicFolders ) ) {
for ( Album album : albumDao . getAlbumsForArtist ( artist . getName ( ) , musicFolders ) ) {
result . getAlbum ( ) . add ( createJaxbAlbum ( new AlbumID3 ( ) , album , username ) ) ;
result . getAlbum ( ) . add ( createJaxbAlbum ( new AlbumID3 ( ) , album , username ) ) ;
@ -541,7 +530,7 @@ public class RESTController {
jaxbAlbum . setName ( album . getName ( ) ) ;
jaxbAlbum . setName ( album . getName ( ) ) ;
if ( album . getArtist ( ) ! = null ) {
if ( album . getArtist ( ) ! = null ) {
jaxbAlbum . setArtist ( album . getArtist ( ) ) ;
jaxbAlbum . setArtist ( album . getArtist ( ) ) ;
Artist artist = artistDao . getArtist ( album . getArtist ( ) ) ;
org . airsonic . player . domain . Artist artist = artistDao . getArtist ( album . getArtist ( ) ) ;
if ( artist ! = null ) {
if ( artist ! = null ) {
jaxbAlbum . setArtistId ( String . valueOf ( artist . getId ( ) ) ) ;
jaxbAlbum . setArtistId ( String . valueOf ( artist . getId ( ) ) ) ;
}
}
@ -558,7 +547,7 @@ public class RESTController {
return jaxbAlbum ;
return jaxbAlbum ;
}
}
private < T extends org . subsonic . restapi . Playlist > T createJaxbPlaylist ( T jaxbPlaylist , Playlist playlist ) {
private < T extends org . subsonic . restapi . Playlist > T createJaxbPlaylist ( T jaxbPlaylist , org . airsonic . player . domain . Playlist playlist ) {
jaxbPlaylist . setId ( String . valueOf ( playlist . getId ( ) ) ) ;
jaxbPlaylist . setId ( String . valueOf ( playlist . getId ( ) ) ) ;
jaxbPlaylist . setName ( playlist . getName ( ) ) ;
jaxbPlaylist . setName ( playlist . getName ( ) ) ;
jaxbPlaylist . setComment ( playlist . getComment ( ) ) ;
jaxbPlaylist . setComment ( playlist . getComment ( ) ) ;
@ -695,9 +684,9 @@ public class RESTController {
criteria . setQuery ( query . toString ( ) . trim ( ) ) ;
criteria . setQuery ( query . toString ( ) . trim ( ) ) ;
criteria . setCount ( getIntParameter ( request , "count" , 20 ) ) ;
criteria . setCount ( getIntParameter ( request , "count" , 20 ) ) ;
criteria . setOffset ( getIntParameter ( request , "offset" , 0 ) ) ;
criteria . setOffset ( getIntParameter ( request , "offset" , 0 ) ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
SearchResult result = searchService . search ( criteria , musicFolders , SearchService . IndexType . SONG ) ;
org . airsonic . player . domain . SearchResult result = searchService . search ( criteria , musicFolders , SearchService . IndexType . SONG ) ;
org . subsonic . restapi . SearchResult searchResult = new org . subsonic . restapi . SearchResult ( ) ;
org . subsonic . restapi . SearchResult searchResult = new org . subsonic . restapi . SearchResult ( ) ;
searchResult . setOffset ( result . getOffset ( ) ) ;
searchResult . setOffset ( result . getOffset ( ) ) ;
searchResult . setTotalHits ( result . getTotalHits ( ) ) ;
searchResult . setTotalHits ( result . getTotalHits ( ) ) ;
@ -716,7 +705,7 @@ public class RESTController {
Player player = playerService . getPlayer ( request , response ) ;
Player player = playerService . getPlayer ( request , response ) ;
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
SearchResult2 searchResult = new SearchResult2 ( ) ;
SearchResult2 searchResult = new SearchResult2 ( ) ;
@ -725,21 +714,21 @@ public class RESTController {
criteria . setQuery ( StringUtils . trimToEmpty ( query ) ) ;
criteria . setQuery ( StringUtils . trimToEmpty ( query ) ) ;
criteria . setCount ( getIntParameter ( request , "artistCount" , 20 ) ) ;
criteria . setCount ( getIntParameter ( request , "artistCount" , 20 ) ) ;
criteria . setOffset ( getIntParameter ( request , "artistOffset" , 0 ) ) ;
criteria . setOffset ( getIntParameter ( request , "artistOffset" , 0 ) ) ;
SearchResult artists = searchService . search ( criteria , musicFolders , SearchService . IndexType . ARTIST ) ;
org . airsonic . player . domain . SearchResult artists = searchService . search ( criteria , musicFolders , SearchService . IndexType . ARTIST ) ;
for ( MediaFile mediaFile : artists . getMediaFiles ( ) ) {
for ( MediaFile mediaFile : artists . getMediaFiles ( ) ) {
searchResult . getArtist ( ) . add ( createJaxbArtist ( mediaFile , username ) ) ;
searchResult . getArtist ( ) . add ( createJaxbArtist ( mediaFile , username ) ) ;
}
}
criteria . setCount ( getIntParameter ( request , "albumCount" , 20 ) ) ;
criteria . setCount ( getIntParameter ( request , "albumCount" , 20 ) ) ;
criteria . setOffset ( getIntParameter ( request , "albumOffset" , 0 ) ) ;
criteria . setOffset ( getIntParameter ( request , "albumOffset" , 0 ) ) ;
SearchResult albums = searchService . search ( criteria , musicFolders , SearchService . IndexType . ALBUM ) ;
org . airsonic . player . domain . SearchResult albums = searchService . search ( criteria , musicFolders , SearchService . IndexType . ALBUM ) ;
for ( MediaFile mediaFile : albums . getMediaFiles ( ) ) {
for ( MediaFile mediaFile : albums . getMediaFiles ( ) ) {
searchResult . getAlbum ( ) . add ( createJaxbChild ( player , mediaFile , username ) ) ;
searchResult . getAlbum ( ) . add ( createJaxbChild ( player , mediaFile , username ) ) ;
}
}
criteria . setCount ( getIntParameter ( request , "songCount" , 20 ) ) ;
criteria . setCount ( getIntParameter ( request , "songCount" , 20 ) ) ;
criteria . setOffset ( getIntParameter ( request , "songOffset" , 0 ) ) ;
criteria . setOffset ( getIntParameter ( request , "songOffset" , 0 ) ) ;
SearchResult songs = searchService . search ( criteria , musicFolders , SearchService . IndexType . SONG ) ;
org . airsonic . player . domain . SearchResult songs = searchService . search ( criteria , musicFolders , SearchService . IndexType . SONG ) ;
for ( MediaFile mediaFile : songs . getMediaFiles ( ) ) {
for ( MediaFile mediaFile : songs . getMediaFiles ( ) ) {
searchResult . getSong ( ) . add ( createJaxbChild ( player , mediaFile , username ) ) ;
searchResult . getSong ( ) . add ( createJaxbChild ( player , mediaFile , username ) ) ;
}
}
@ -755,7 +744,7 @@ public class RESTController {
Player player = playerService . getPlayer ( request , response ) ;
Player player = playerService . getPlayer ( request , response ) ;
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
SearchResult3 searchResult = new SearchResult3 ( ) ;
SearchResult3 searchResult = new SearchResult3 ( ) ;
@ -764,8 +753,8 @@ public class RESTController {
criteria . setQuery ( StringUtils . trimToEmpty ( query ) ) ;
criteria . setQuery ( StringUtils . trimToEmpty ( query ) ) ;
criteria . setCount ( getIntParameter ( request , "artistCount" , 20 ) ) ;
criteria . setCount ( getIntParameter ( request , "artistCount" , 20 ) ) ;
criteria . setOffset ( getIntParameter ( request , "artistOffset" , 0 ) ) ;
criteria . setOffset ( getIntParameter ( request , "artistOffset" , 0 ) ) ;
SearchResult result = searchService . search ( criteria , musicFolders , SearchService . IndexType . ARTIST_ID3 ) ;
org . airsonic . player . domain . SearchResult result = searchService . search ( criteria , musicFolders , SearchService . IndexType . ARTIST_ID3 ) ;
for ( Artist artist : result . getArtists ( ) ) {
for ( org . airsonic . player . domain . Artist artist : result . getArtists ( ) ) {
searchResult . getArtist ( ) . add ( createJaxbArtist ( new ArtistID3 ( ) , artist , username ) ) ;
searchResult . getArtist ( ) . add ( createJaxbArtist ( new ArtistID3 ( ) , artist , username ) ) ;
}
}
@ -792,7 +781,7 @@ public class RESTController {
public void getPlaylists ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void getPlaylists ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
String authenticatedUsername = user . getUsername ( ) ;
String authenticatedUsername = user . getUsername ( ) ;
String requestedUsername = request . getParameter ( "username" ) ;
String requestedUsername = request . getParameter ( "username" ) ;
@ -805,7 +794,7 @@ public class RESTController {
Playlists result = new Playlists ( ) ;
Playlists result = new Playlists ( ) ;
for ( Playlist playlist : playlistService . getReadablePlaylistsForUser ( requestedUsername ) ) {
for ( org . airsonic . player . domain . Playlist playlist : playlistService . getReadablePlaylistsForUser ( requestedUsername ) ) {
result . getPlaylist ( ) . add ( createJaxbPlaylist ( new org . subsonic . restapi . Playlist ( ) , playlist ) ) ;
result . getPlaylist ( ) . add ( createJaxbPlaylist ( new org . subsonic . restapi . Playlist ( ) , playlist ) ) ;
}
}
@ -822,7 +811,7 @@ public class RESTController {
int id = getRequiredIntParameter ( request , "id" ) ;
int id = getRequiredIntParameter ( request , "id" ) ;
Playlist playlist = playlistService . getPlaylist ( id ) ;
org . airsonic . player . domain . Playlist playlist = playlistService . getPlaylist ( id ) ;
if ( playlist = = null ) {
if ( playlist = = null ) {
error ( request , response , ErrorCode . NOT_FOUND , "Playlist not found: " + id ) ;
error ( request , response , ErrorCode . NOT_FOUND , "Playlist not found: " + id ) ;
return ;
return ;
@ -847,7 +836,7 @@ public class RESTController {
public void jukeboxControl ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void jukeboxControl ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request , true ) ;
request = wrapRequest ( request , true ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isJukeboxRole ( ) ) {
if ( ! user . isJukeboxRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to use jukebox." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to use jukebox." ) ;
return ;
return ;
@ -891,11 +880,11 @@ public class RESTController {
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
Player jukeboxPlayer = jukeboxService . getPlayer ( ) ;
Player jukeboxPlayer = jukeboxService . getPlayer ( ) ;
boolean controlsJukebox = jukeboxPlayer ! = null & & jukeboxPlayer . getId ( ) . equals ( player . getId ( ) ) ;
boolean controlsJukebox = jukeboxPlayer ! = null & & jukeboxPlayer . getId ( ) . equals ( player . getId ( ) ) ;
PlayQueue playQueue = player . getPlayQueue ( ) ;
org . airsonic . player . domain . PlayQueue playQueue = player . getPlayQueue ( ) ;
int currentIndex = controlsJukebox & & ! playQueue . isEmpty ( ) ? playQueue . getIndex ( ) : - 1 ;
int currentIndex = controlsJukebox & & ! playQueue . isEmpty ( ) ? playQueue . getIndex ( ) : - 1 ;
boolean playing = controlsJukebox & & ! playQueue . isEmpty ( ) & & playQueue . getStatus ( ) = = PlayQueue . Status . PLAYING ;
boolean playing = controlsJukebox & & ! playQueue . isEmpty ( ) & & playQueue . getStatus ( ) = = org . airsonic . player . domain . PlayQueue . Status . PLAYING ;
float gain = jukeboxService . getGain ( ) ;
float gain = jukeboxService . getGain ( ) ;
int position = controlsJukebox & & ! playQueue . isEmpty ( ) ? jukeboxService . getPosition ( ) : 0 ;
int position = controlsJukebox & & ! playQueue . isEmpty ( ) ? jukeboxService . getPosition ( ) : 0 ;
@ -934,7 +923,7 @@ public class RESTController {
return ;
return ;
}
}
Playlist playlist ;
org . airsonic . player . domain . Playlist playlist ;
if ( playlistId ! = null ) {
if ( playlistId ! = null ) {
playlist = playlistService . getPlaylist ( playlistId ) ;
playlist = playlistService . getPlaylist ( playlistId ) ;
if ( playlist = = null ) {
if ( playlist = = null ) {
@ -946,7 +935,7 @@ public class RESTController {
return ;
return ;
}
}
} else {
} else {
playlist = new Playlist ( ) ;
playlist = new org . airsonic . player . domain . Playlist ( ) ;
playlist . setName ( name ) ;
playlist . setName ( name ) ;
playlist . setCreated ( new Date ( ) ) ;
playlist . setCreated ( new Date ( ) ) ;
playlist . setChanged ( new Date ( ) ) ;
playlist . setChanged ( new Date ( ) ) ;
@ -973,7 +962,7 @@ public class RESTController {
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
int id = getRequiredIntParameter ( request , "playlistId" ) ;
int id = getRequiredIntParameter ( request , "playlistId" ) ;
Playlist playlist = playlistService . getPlaylist ( id ) ;
org . airsonic . player . domain . Playlist playlist = playlistService . getPlaylist ( id ) ;
if ( playlist = = null ) {
if ( playlist = = null ) {
error ( request , response , ErrorCode . NOT_FOUND , "Playlist not found: " + id ) ;
error ( request , response , ErrorCode . NOT_FOUND , "Playlist not found: " + id ) ;
return ;
return ;
@ -1041,7 +1030,7 @@ public class RESTController {
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
int id = getRequiredIntParameter ( request , "id" ) ;
int id = getRequiredIntParameter ( request , "id" ) ;
Playlist playlist = playlistService . getPlaylist ( id ) ;
org . airsonic . player . domain . Playlist playlist = playlistService . getPlaylist ( id ) ;
if ( playlist = = null ) {
if ( playlist = = null ) {
error ( request , response , ErrorCode . NOT_FOUND , "Playlist not found: " + id ) ;
error ( request , response , ErrorCode . NOT_FOUND , "Playlist not found: " + id ) ;
return ;
return ;
@ -1065,7 +1054,7 @@ public class RESTController {
int offset = getIntParameter ( request , "offset" , 0 ) ;
int offset = getIntParameter ( request , "offset" , 0 ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
size = Math . max ( 0 , Math . min ( size , 500 ) ) ;
size = Math . max ( 0 , Math . min ( size , 500 ) ) ;
String type = getRequiredStringParameter ( request , "type" ) ;
String type = getRequiredStringParameter ( request , "type" ) ;
@ -1116,7 +1105,7 @@ public class RESTController {
String type = getRequiredStringParameter ( request , "type" ) ;
String type = getRequiredStringParameter ( request , "type" ) ;
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
List < Album > albums ;
List < Album > albums ;
if ( "frequent" . equals ( type ) ) {
if ( "frequent" . equals ( type ) ) {
@ -1162,7 +1151,7 @@ public class RESTController {
Integer fromYear = getIntParameter ( request , "fromYear" ) ;
Integer fromYear = getIntParameter ( request , "fromYear" ) ;
Integer toYear = getIntParameter ( request , "toYear" ) ;
Integer toYear = getIntParameter ( request , "toYear" ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
RandomSearchCriteria criteria = new RandomSearchCriteria ( size , genre , fromYear , toYear , musicFolders ) ;
RandomSearchCriteria criteria = new RandomSearchCriteria ( size , genre , fromYear , toYear , musicFolders ) ;
Songs result = new Songs ( ) ;
Songs result = new Songs ( ) ;
@ -1182,7 +1171,7 @@ public class RESTController {
int size = getIntParameter ( request , "size" , Integer . MAX_VALUE ) ;
int size = getIntParameter ( request , "size" , Integer . MAX_VALUE ) ;
int offset = getIntParameter ( request , "offset" , 0 ) ;
int offset = getIntParameter ( request , "offset" , 0 ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
Videos result = new Videos ( ) ;
Videos result = new Videos ( ) ;
for ( MediaFile mediaFile : mediaFileDao . getVideos ( size , offset , musicFolders ) ) {
for ( MediaFile mediaFile : mediaFileDao . getVideos ( size , offset , musicFolders ) ) {
@ -1267,7 +1256,7 @@ public class RESTController {
child . setIsVideo ( mediaFile . isVideo ( ) ) ;
child . setIsVideo ( mediaFile . isVideo ( ) ) ;
child . setPath ( getRelativePath ( mediaFile ) ) ;
child . setPath ( getRelativePath ( mediaFile ) ) ;
Bookmark bookmark = bookmarkCache . get ( new BookmarkKey ( username , mediaFile . getId ( ) ) ) ;
org . airsonic . player . domain . Bookmark bookmark = bookmarkCache . get ( new BookmarkKey ( username , mediaFile . getId ( ) ) ) ;
if ( bookmark ! = null ) {
if ( bookmark ! = null ) {
child . setBookmarkPosition ( bookmark . getPositionMillis ( ) ) ;
child . setBookmarkPosition ( bookmark . getPositionMillis ( ) ) ;
}
}
@ -1279,7 +1268,7 @@ public class RESTController {
}
}
}
}
if ( mediaFile . getArtist ( ) ! = null ) {
if ( mediaFile . getArtist ( ) ! = null ) {
Artist artist = artistDao . getArtist ( mediaFile . getArtist ( ) ) ;
org . airsonic . player . domain . Artist artist = artistDao . getArtist ( mediaFile . getArtist ( ) ) ;
if ( artist ! = null ) {
if ( artist ! = null ) {
child . setArtistId ( String . valueOf ( artist . getId ( ) ) ) ;
child . setArtistId ( String . valueOf ( artist . getId ( ) ) ) ;
}
}
@ -1329,8 +1318,8 @@ public class RESTController {
String filePathLower = filePath . toLowerCase ( ) ;
String filePathLower = filePath . toLowerCase ( ) ;
List < MusicFolder > musicFolders = settingsService . getAllMusicFolders ( false , true ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getAllMusicFolders ( false , true ) ;
for ( MusicFolder musicFolder : musicFolders ) {
for ( org . airsonic . player . domain . MusicFolder musicFolder : musicFolders ) {
String folderPath = musicFolder . getPath ( ) . getPath ( ) ;
String folderPath = musicFolder . getPath ( ) . getPath ( ) ;
folderPath = folderPath . replace ( '\\' , '/' ) ;
folderPath = folderPath . replace ( '\\' , '/' ) ;
String folderPathLower = folderPath . toLowerCase ( ) ;
String folderPathLower = folderPath . toLowerCase ( ) ;
@ -1350,7 +1339,7 @@ public class RESTController {
@RequestMapping ( value = "/download" )
@RequestMapping ( value = "/download" )
public ModelAndView download ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public ModelAndView download ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isDownloadRole ( ) ) {
if ( ! user . isDownloadRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to download files." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to download files." ) ;
return null ;
return null ;
@ -1374,7 +1363,7 @@ public class RESTController {
@RequestMapping ( value = "/stream" )
@RequestMapping ( value = "/stream" )
public ModelAndView stream ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public ModelAndView stream ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isStreamRole ( ) ) {
if ( ! user . isStreamRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to play files." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to play files." ) ;
return null ;
return null ;
@ -1387,7 +1376,7 @@ public class RESTController {
@RequestMapping ( value = "/hls" )
@RequestMapping ( value = "/hls" )
public ModelAndView hls ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public ModelAndView hls ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isStreamRole ( ) ) {
if ( ! user . isStreamRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to play files." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to play files." ) ;
return null ;
return null ;
@ -1478,7 +1467,7 @@ public class RESTController {
}
}
}
}
for ( int artistId : getIntParameters ( request , "artistId" ) ) {
for ( int artistId : getIntParameters ( request , "artistId" ) ) {
Artist artist = artistDao . getArtist ( artistId ) ;
org . airsonic . player . domain . Artist artist = artistDao . getArtist ( artistId ) ;
if ( artist = = null ) {
if ( artist = = null ) {
error ( request , response , ErrorCode . NOT_FOUND , "Artist not found: " + artistId ) ;
error ( request , response , ErrorCode . NOT_FOUND , "Artist not found: " + artistId ) ;
return ;
return ;
@ -1499,7 +1488,7 @@ public class RESTController {
Player player = playerService . getPlayer ( request , response ) ;
Player player = playerService . getPlayer ( request , response ) ;
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
Starred result = new Starred ( ) ;
Starred result = new Starred ( ) ;
for ( MediaFile artist : mediaFileDao . getStarredDirectories ( 0 , Integer . MAX_VALUE , username , musicFolders ) ) {
for ( MediaFile artist : mediaFileDao . getStarredDirectories ( 0 , Integer . MAX_VALUE , username , musicFolders ) ) {
@ -1522,10 +1511,10 @@ public class RESTController {
Player player = playerService . getPlayer ( request , response ) ;
Player player = playerService . getPlayer ( request , response ) ;
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
Integer musicFolderId = getIntParameter ( request , "musicFolderId" ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username , musicFolderId ) ;
Starred2 result = new Starred2 ( ) ;
Starred2 result = new Starred2 ( ) ;
for ( Artist artist : artistDao . getStarredArtists ( 0 , Integer . MAX_VALUE , username , musicFolders ) ) {
for ( org . airsonic . player . domain . Artist artist : artistDao . getStarredArtists ( 0 , Integer . MAX_VALUE , username , musicFolders ) ) {
result . getArtist ( ) . add ( createJaxbArtist ( new ArtistID3 ( ) , artist , username ) ) ;
result . getArtist ( ) . add ( createJaxbArtist ( new ArtistID3 ( ) , artist , username ) ) ;
}
}
for ( Album album : albumDao . getStarredAlbums ( 0 , Integer . MAX_VALUE , username , musicFolders ) ) {
for ( Album album : albumDao . getStarredAlbums ( 0 , Integer . MAX_VALUE , username , musicFolders ) ) {
@ -1549,7 +1538,7 @@ public class RESTController {
Podcasts result = new Podcasts ( ) ;
Podcasts result = new Podcasts ( ) ;
for ( PodcastChannel channel : podcastService . getAllChannels ( ) ) {
for ( org . airsonic . player . domain . PodcastChannel channel : podcastService . getAllChannels ( ) ) {
if ( channelId = = null | | channelId . equals ( channel . getId ( ) ) ) {
if ( channelId = = null | | channelId . equals ( channel . getId ( ) ) ) {
org . subsonic . restapi . PodcastChannel c = new org . subsonic . restapi . PodcastChannel ( ) ;
org . subsonic . restapi . PodcastChannel c = new org . subsonic . restapi . PodcastChannel ( ) ;
@ -1565,8 +1554,8 @@ public class RESTController {
c . setErrorMessage ( channel . getErrorMessage ( ) ) ;
c . setErrorMessage ( channel . getErrorMessage ( ) ) ;
if ( includeEpisodes ) {
if ( includeEpisodes ) {
List < PodcastEpisode > episodes = podcastService . getEpisodes ( channel . getId ( ) ) ;
List < org . airsonic . player . domain . PodcastEpisode > episodes = podcastService . getEpisodes ( channel . getId ( ) ) ;
for ( PodcastEpisode episode : episodes ) {
for ( org . airsonic . player . domain . PodcastEpisode episode : episodes ) {
c . getEpisode ( ) . add ( createJaxbPodcastEpisode ( player , username , episode ) ) ;
c . getEpisode ( ) . add ( createJaxbPodcastEpisode ( player , username , episode ) ) ;
}
}
}
}
@ -1586,7 +1575,7 @@ public class RESTController {
int count = getIntParameter ( request , "count" , 20 ) ;
int count = getIntParameter ( request , "count" , 20 ) ;
NewestPodcasts result = new NewestPodcasts ( ) ;
NewestPodcasts result = new NewestPodcasts ( ) ;
for ( PodcastEpisode episode : podcastService . getNewestEpisodes ( count ) ) {
for ( org . airsonic . player . domain . PodcastEpisode episode : podcastService . getNewestEpisodes ( count ) ) {
result . getEpisode ( ) . add ( createJaxbPodcastEpisode ( player , username , episode ) ) ;
result . getEpisode ( ) . add ( createJaxbPodcastEpisode ( player , username , episode ) ) ;
}
}
@ -1595,7 +1584,7 @@ public class RESTController {
jaxbWriter . writeResponse ( request , response , res ) ;
jaxbWriter . writeResponse ( request , response , res ) ;
}
}
private org . subsonic . restapi . PodcastEpisode createJaxbPodcastEpisode ( Player player , String username , PodcastEpisode episode ) {
private org . subsonic . restapi . PodcastEpisode createJaxbPodcastEpisode ( Player player , String username , org . airsonic . player . domain . PodcastEpisode episode ) {
org . subsonic . restapi . PodcastEpisode e = new org . subsonic . restapi . PodcastEpisode ( ) ;
org . subsonic . restapi . PodcastEpisode e = new org . subsonic . restapi . PodcastEpisode ( ) ;
String path = episode . getPath ( ) ;
String path = episode . getPath ( ) ;
@ -1617,7 +1606,7 @@ public class RESTController {
@RequestMapping ( value = "/refreshPodcasts" )
@RequestMapping ( value = "/refreshPodcasts" )
public void refreshPodcasts ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void refreshPodcasts ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isPodcastRole ( ) ) {
if ( ! user . isPodcastRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to administrate podcasts." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to administrate podcasts." ) ;
return ;
return ;
@ -1629,7 +1618,7 @@ public class RESTController {
@RequestMapping ( value = "/createPodcastChannel" )
@RequestMapping ( value = "/createPodcastChannel" )
public void createPodcastChannel ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void createPodcastChannel ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isPodcastRole ( ) ) {
if ( ! user . isPodcastRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to administrate podcasts." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to administrate podcasts." ) ;
return ;
return ;
@ -1643,7 +1632,7 @@ public class RESTController {
@RequestMapping ( value = "/deletePodcastChannel" )
@RequestMapping ( value = "/deletePodcastChannel" )
public void deletePodcastChannel ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void deletePodcastChannel ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isPodcastRole ( ) ) {
if ( ! user . isPodcastRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to administrate podcasts." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to administrate podcasts." ) ;
return ;
return ;
@ -1657,7 +1646,7 @@ public class RESTController {
@RequestMapping ( value = "/deletePodcastEpisode" )
@RequestMapping ( value = "/deletePodcastEpisode" )
public void deletePodcastEpisode ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void deletePodcastEpisode ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isPodcastRole ( ) ) {
if ( ! user . isPodcastRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to administrate podcasts." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to administrate podcasts." ) ;
return ;
return ;
@ -1671,14 +1660,14 @@ public class RESTController {
@RequestMapping ( value = "/downloadPodcastEpisode" )
@RequestMapping ( value = "/downloadPodcastEpisode" )
public void downloadPodcastEpisode ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void downloadPodcastEpisode ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isPodcastRole ( ) ) {
if ( ! user . isPodcastRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to administrate podcasts." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to administrate podcasts." ) ;
return ;
return ;
}
}
int id = getRequiredIntParameter ( request , "id" ) ;
int id = getRequiredIntParameter ( request , "id" ) ;
PodcastEpisode episode = podcastService . getEpisode ( id , true ) ;
org . airsonic . player . domain . PodcastEpisode episode = podcastService . getEpisode ( id , true ) ;
if ( episode = = null ) {
if ( episode = = null ) {
error ( request , response , ErrorCode . NOT_FOUND , "Podcast episode " + id + " not found." ) ;
error ( request , response , ErrorCode . NOT_FOUND , "Podcast episode " + id + " not found." ) ;
return ;
return ;
@ -1713,7 +1702,7 @@ public class RESTController {
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
Bookmarks result = new Bookmarks ( ) ;
Bookmarks result = new Bookmarks ( ) ;
for ( Bookmark bookmark : bookmarkDao . getBookmarks ( username ) ) {
for ( org . airsonic . player . domain . Bookmark bookmark : bookmarkDao . getBookmarks ( username ) ) {
org . subsonic . restapi . Bookmark b = new org . subsonic . restapi . Bookmark ( ) ;
org . subsonic . restapi . Bookmark b = new org . subsonic . restapi . Bookmark ( ) ;
result . getBookmark ( ) . add ( b ) ;
result . getBookmark ( ) . add ( b ) ;
b . setPosition ( bookmark . getPositionMillis ( ) ) ;
b . setPosition ( bookmark . getPositionMillis ( ) ) ;
@ -1740,7 +1729,7 @@ public class RESTController {
String comment = request . getParameter ( "comment" ) ;
String comment = request . getParameter ( "comment" ) ;
Date now = new Date ( ) ;
Date now = new Date ( ) ;
Bookmark bookmark = new Bookmark ( 0 , mediaFileId , position , username , comment , now , now ) ;
org . airsonic . player . domain . Bookmark bookmark = new org . airsonic . player . domain . Bookmark ( 0 , mediaFileId , position , username , comment , now , now ) ;
bookmarkDao . createOrUpdateBookmark ( bookmark ) ;
bookmarkDao . createOrUpdateBookmark ( bookmark ) ;
refreshBookmarkCache ( ) ;
refreshBookmarkCache ( ) ;
writeEmptyResponse ( request , response ) ;
writeEmptyResponse ( request , response ) ;
@ -1814,11 +1803,11 @@ public class RESTController {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
Player player = playerService . getPlayer ( request , response ) ;
Player player = playerService . getPlayer ( request , response ) ;
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
Shares result = new Shares ( ) ;
Shares result = new Shares ( ) ;
for ( Share share : shareService . getSharesForUser ( user ) ) {
for ( org . airsonic . player . domain . Share share : shareService . getSharesForUser ( user ) ) {
org . subsonic . restapi . Share s = createJaxbShare ( request , share ) ;
org . subsonic . restapi . Share s = createJaxbShare ( request , share ) ;
result . getShare ( ) . add ( s ) ;
result . getShare ( ) . add ( s ) ;
@ -1837,7 +1826,7 @@ public class RESTController {
Player player = playerService . getPlayer ( request , response ) ;
Player player = playerService . getPlayer ( request , response ) ;
String username = securityService . getCurrentUsername ( request ) ;
String username = securityService . getCurrentUsername ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isShareRole ( ) ) {
if ( ! user . isShareRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to share media." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to share media." ) ;
return ;
return ;
@ -1848,7 +1837,7 @@ public class RESTController {
files . add ( mediaFileService . getMediaFile ( id ) ) ;
files . add ( mediaFileService . getMediaFile ( id ) ) ;
}
}
Share share = shareService . createShare ( request , files ) ;
org . airsonic . player . domain . Share share = shareService . createShare ( request , files ) ;
share . setDescription ( request . getParameter ( "description" ) ) ;
share . setDescription ( request . getParameter ( "description" ) ) ;
long expires = getLongParameter ( request , "expires" , 0L ) ;
long expires = getLongParameter ( request , "expires" , 0L ) ;
if ( expires ! = 0 ) {
if ( expires ! = 0 ) {
@ -1860,7 +1849,7 @@ public class RESTController {
org . subsonic . restapi . Share s = createJaxbShare ( request , share ) ;
org . subsonic . restapi . Share s = createJaxbShare ( request , share ) ;
result . getShare ( ) . add ( s ) ;
result . getShare ( ) . add ( s ) ;
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( username ) ;
for ( MediaFile mediaFile : shareService . getSharedFiles ( share . getId ( ) , musicFolders ) ) {
for ( MediaFile mediaFile : shareService . getSharedFiles ( share . getId ( ) , musicFolders ) ) {
s . getEntry ( ) . add ( createJaxbChild ( player , mediaFile , username ) ) ;
s . getEntry ( ) . add ( createJaxbChild ( player , mediaFile , username ) ) ;
@ -1874,10 +1863,10 @@ public class RESTController {
@RequestMapping ( value = "/deleteShare" )
@RequestMapping ( value = "/deleteShare" )
public void deleteShare ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void deleteShare ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
int id = getRequiredIntParameter ( request , "id" ) ;
int id = getRequiredIntParameter ( request , "id" ) ;
Share share = shareService . getShareById ( id ) ;
org . airsonic . player . domain . Share share = shareService . getShareById ( id ) ;
if ( share = = null ) {
if ( share = = null ) {
error ( request , response , ErrorCode . NOT_FOUND , "Shared media not found." ) ;
error ( request , response , ErrorCode . NOT_FOUND , "Shared media not found." ) ;
return ;
return ;
@ -1894,10 +1883,10 @@ public class RESTController {
@RequestMapping ( value = "/updateShare" )
@RequestMapping ( value = "/updateShare" )
public void updateShare ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void updateShare ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
int id = getRequiredIntParameter ( request , "id" ) ;
int id = getRequiredIntParameter ( request , "id" ) ;
Share share = shareService . getShareById ( id ) ;
org . airsonic . player . domain . Share share = shareService . getShareById ( id ) ;
if ( share = = null ) {
if ( share = = null ) {
error ( request , response , ErrorCode . NOT_FOUND , "Shared media not found." ) ;
error ( request , response , ErrorCode . NOT_FOUND , "Shared media not found." ) ;
return ;
return ;
@ -1917,7 +1906,7 @@ public class RESTController {
writeEmptyResponse ( request , response ) ;
writeEmptyResponse ( request , response ) ;
}
}
private org . subsonic . restapi . Share createJaxbShare ( HttpServletRequest request , Share share ) {
private org . subsonic . restapi . Share createJaxbShare ( HttpServletRequest request , org . airsonic . player . domain . Share share ) {
org . subsonic . restapi . Share result = new org . subsonic . restapi . Share ( ) ;
org . subsonic . restapi . Share result = new org . subsonic . restapi . Share ( ) ;
result . setId ( String . valueOf ( share . getId ( ) ) ) ;
result . setId ( String . valueOf ( share . getId ( ) ) ) ;
result . setUrl ( shareService . getShareUrl ( request , share ) ) ;
result . setUrl ( shareService . getShareUrl ( request , share ) ) ;
@ -1983,7 +1972,7 @@ public class RESTController {
String username = getRequiredStringParameter ( request , "username" ) ;
String username = getRequiredStringParameter ( request , "username" ) ;
String password = decrypt ( getRequiredStringParameter ( request , "password" ) ) ;
String password = decrypt ( getRequiredStringParameter ( request , "password" ) ) ;
User authUser = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User authUser = securityService . getCurrentUser ( request ) ;
boolean allowed = authUser . isAdminRole ( )
boolean allowed = authUser . isAdminRole ( )
| | username . equals ( authUser . getUsername ( ) ) & & authUser . isSettingsRole ( ) ;
| | username . equals ( authUser . getUsername ( ) ) & & authUser . isSettingsRole ( ) ;
@ -1993,7 +1982,7 @@ public class RESTController {
return ;
return ;
}
}
User user = securityService . getUserByName ( username ) ;
org . airsonic . player . domain . User user = securityService . getUserByName ( username ) ;
user . setPassword ( password ) ;
user . setPassword ( password ) ;
securityService . updateUser ( user ) ;
securityService . updateUser ( user ) ;
@ -2006,13 +1995,13 @@ public class RESTController {
String username = getRequiredStringParameter ( request , "username" ) ;
String username = getRequiredStringParameter ( request , "username" ) ;
User currentUser = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User currentUser = securityService . getCurrentUser ( request ) ;
if ( ! username . equals ( currentUser . getUsername ( ) ) & & ! currentUser . isAdminRole ( ) ) {
if ( ! username . equals ( currentUser . getUsername ( ) ) & & ! currentUser . isAdminRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , currentUser . getUsername ( ) + " is not authorized to get details for other users." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , currentUser . getUsername ( ) + " is not authorized to get details for other users." ) ;
return ;
return ;
}
}
User requestedUser = securityService . getUserByName ( username ) ;
org . airsonic . player . domain . User requestedUser = securityService . getUserByName ( username ) ;
if ( requestedUser = = null ) {
if ( requestedUser = = null ) {
error ( request , response , ErrorCode . NOT_FOUND , "No such user: " + username ) ;
error ( request , response , ErrorCode . NOT_FOUND , "No such user: " + username ) ;
return ;
return ;
@ -2027,14 +2016,14 @@ public class RESTController {
public void getUsers ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void getUsers ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User currentUser = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User currentUser = securityService . getCurrentUser ( request ) ;
if ( ! currentUser . isAdminRole ( ) ) {
if ( ! currentUser . isAdminRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , currentUser . getUsername ( ) + " is not authorized to get details for other users." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , currentUser . getUsername ( ) + " is not authorized to get details for other users." ) ;
return ;
return ;
}
}
Users result = new Users ( ) ;
Users result = new Users ( ) ;
for ( User user : securityService . getAllUsers ( ) ) {
for ( org . airsonic . player . domain . User user : securityService . getAllUsers ( ) ) {
result . getUser ( ) . add ( createJaxbUser ( user ) ) ;
result . getUser ( ) . add ( createJaxbUser ( user ) ) ;
}
}
@ -2043,7 +2032,7 @@ public class RESTController {
jaxbWriter . writeResponse ( request , response , res ) ;
jaxbWriter . writeResponse ( request , response , res ) ;
}
}
private org . subsonic . restapi . User createJaxbUser ( User user ) {
private org . subsonic . restapi . User createJaxbUser ( org . airsonic . player . domain . User user ) {
UserSettings userSettings = settingsService . getUserSettings ( user . getUsername ( ) ) ;
UserSettings userSettings = settingsService . getUserSettings ( user . getUsername ( ) ) ;
org . subsonic . restapi . User result = new org . subsonic . restapi . User ( ) ;
org . subsonic . restapi . User result = new org . subsonic . restapi . User ( ) ;
@ -2061,7 +2050,7 @@ public class RESTController {
result . setStreamRole ( user . isStreamRole ( ) ) ;
result . setStreamRole ( user . isStreamRole ( ) ) ;
result . setJukeboxRole ( user . isJukeboxRole ( ) ) ;
result . setJukeboxRole ( user . isJukeboxRole ( ) ) ;
result . setShareRole ( user . isShareRole ( ) ) ;
result . setShareRole ( user . isShareRole ( ) ) ;
// currently this role isn't supported by libre sonic
// currently this role isn't supported by air sonic
result . setVideoConversionRole ( false ) ;
result . setVideoConversionRole ( false ) ;
// Useless
// Useless
result . setAvatarLastChanged ( null ) ;
result . setAvatarLastChanged ( null ) ;
@ -2071,8 +2060,8 @@ public class RESTController {
result . setMaxBitRate ( transcodeScheme . getMaxBitRate ( ) ) ;
result . setMaxBitRate ( transcodeScheme . getMaxBitRate ( ) ) ;
}
}
List < MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( user . getUsername ( ) ) ;
List < org . airsonic . player . domain . MusicFolder > musicFolders = settingsService . getMusicFoldersForUser ( user . getUsername ( ) ) ;
for ( MusicFolder musicFolder : musicFolders ) {
for ( org . airsonic . player . domain . MusicFolder musicFolder : musicFolders ) {
result . getFolder ( ) . add ( musicFolder . getId ( ) ) ;
result . getFolder ( ) . add ( musicFolder . getId ( ) ) ;
}
}
return result ;
return result ;
@ -2081,7 +2070,7 @@ public class RESTController {
@RequestMapping ( value = "/createUser" )
@RequestMapping ( value = "/createUser" )
public void createUser ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void createUser ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isAdminRole ( ) ) {
if ( ! user . isAdminRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to create new users." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to create new users." ) ;
return ;
return ;
@ -2106,7 +2095,7 @@ public class RESTController {
int [ ] folderIds = ServletRequestUtils . getIntParameters ( request , "musicFolderId" ) ;
int [ ] folderIds = ServletRequestUtils . getIntParameters ( request , "musicFolderId" ) ;
if ( folderIds . length = = 0 ) {
if ( folderIds . length = = 0 ) {
folderIds = Util . toIntArray ( MusicFolder . toIdList ( settingsService . getAllMusicFolders ( ) ) ) ;
folderIds = Util . toIntArray ( org . airsonic . player . domain . MusicFolder . toIdList ( settingsService . getAllMusicFolders ( ) ) ) ;
}
}
command . setAllowedMusicFolderIds ( folderIds ) ;
command . setAllowedMusicFolderIds ( folderIds ) ;
@ -2117,20 +2106,20 @@ public class RESTController {
@RequestMapping ( value = "/updateUser" )
@RequestMapping ( value = "/updateUser" )
public void updateUser ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void updateUser ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isAdminRole ( ) ) {
if ( ! user . isAdminRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to update users." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to update users." ) ;
return ;
return ;
}
}
String username = getRequiredStringParameter ( request , "username" ) ;
String username = getRequiredStringParameter ( request , "username" ) ;
User u = securityService . getUserByName ( username ) ;
org . airsonic . player . domain . User u = securityService . getUserByName ( username ) ;
UserSettings s = settingsService . getUserSettings ( username ) ;
UserSettings s = settingsService . getUserSettings ( username ) ;
if ( u = = null ) {
if ( u = = null ) {
error ( request , response , ErrorCode . NOT_FOUND , "No such user: " + username ) ;
error ( request , response , ErrorCode . NOT_FOUND , "No such user: " + username ) ;
return ;
return ;
} else if ( User . USERNAME_ADMIN . equals ( username ) ) {
} else if ( org . airsonic . player . domain . User . USERNAME_ADMIN . equals ( username ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , "Not allowed to change admin user" ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , "Not allowed to change admin user" ) ;
return ;
return ;
}
}
@ -2160,7 +2149,7 @@ public class RESTController {
int [ ] folderIds = ServletRequestUtils . getIntParameters ( request , "musicFolderId" ) ;
int [ ] folderIds = ServletRequestUtils . getIntParameters ( request , "musicFolderId" ) ;
if ( folderIds . length = = 0 ) {
if ( folderIds . length = = 0 ) {
folderIds = Util . toIntArray ( MusicFolder . toIdList ( settingsService . getMusicFoldersForUser ( username ) ) ) ;
folderIds = Util . toIntArray ( org . airsonic . player . domain . MusicFolder . toIdList ( settingsService . getMusicFoldersForUser ( username ) ) ) ;
}
}
command . setAllowedMusicFolderIds ( folderIds ) ;
command . setAllowedMusicFolderIds ( folderIds ) ;
@ -2175,14 +2164,14 @@ public class RESTController {
@RequestMapping ( value = "/deleteUser" )
@RequestMapping ( value = "/deleteUser" )
public void deleteUser ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
public void deleteUser ( HttpServletRequest request , HttpServletResponse response ) throws Exception {
request = wrapRequest ( request ) ;
request = wrapRequest ( request ) ;
User user = securityService . getCurrentUser ( request ) ;
org . airsonic . player . domain . User user = securityService . getCurrentUser ( request ) ;
if ( ! user . isAdminRole ( ) ) {
if ( ! user . isAdminRole ( ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to delete users." ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , user . getUsername ( ) + " is not authorized to delete users." ) ;
return ;
return ;
}
}
String username = getRequiredStringParameter ( request , "username" ) ;
String username = getRequiredStringParameter ( request , "username" ) ;
if ( User . USERNAME_ADMIN . equals ( username ) ) {
if ( org . airsonic . player . domain . User . USERNAME_ADMIN . equals ( username ) ) {
error ( request , response , ErrorCode . NOT_AUTHORIZED , "Not allowed to delete admin user" ) ;
error ( request , response , ErrorCode . NOT_AUTHORIZED , "Not allowed to delete admin user" ) ;
return ;
return ;
}
}
@ -2402,8 +2391,8 @@ public class RESTController {
GENERIC ( 0 , "A generic error." ) ,
GENERIC ( 0 , "A generic error." ) ,
MISSING_PARAMETER ( 10 , "Required parameter is missing." ) ,
MISSING_PARAMETER ( 10 , "Required parameter is missing." ) ,
PROTOCOL_MISMATCH_CLIENT_TOO_OLD ( 20 , "Incompatible Libre sonic REST protocol version. Client must upgrade." ) ,
PROTOCOL_MISMATCH_CLIENT_TOO_OLD ( 20 , "Incompatible Air sonic REST protocol version. Client must upgrade." ) ,
PROTOCOL_MISMATCH_SERVER_TOO_OLD ( 30 , "Incompatible Libre sonic REST protocol version. Server must upgrade." ) ,
PROTOCOL_MISMATCH_SERVER_TOO_OLD ( 30 , "Incompatible Air sonic REST protocol version. Server must upgrade." ) ,
NOT_AUTHENTICATED ( 40 , "Wrong username or password." ) ,
NOT_AUTHENTICATED ( 40 , "Wrong username or password." ) ,
NOT_AUTHORIZED ( 50 , "User is not authorized for the given operation." ) ,
NOT_AUTHORIZED ( 50 , "User is not authorized for the given operation." ) ,
NOT_FOUND ( 70 , "Requested data was not found." ) ;
NOT_FOUND ( 70 , "Requested data was not found." ) ;
@ -2430,7 +2419,7 @@ public class RESTController {
super ( username , mediaFileId ) ;
super ( username , mediaFileId ) ;
}
}
static BookmarkKey forBookmark ( Bookmark b ) {
static BookmarkKey forBookmark ( org . airsonic . player . domain . Bookmark b ) {
return new BookmarkKey ( b . getUsername ( ) , b . getMediaFileId ( ) ) ;
return new BookmarkKey ( b . getUsername ( ) , b . getMediaFileId ( ) ) ;
}
}
}
}