Search in sources :

Example 1 with SongNameException

use of org.liferay.jukebox.SongNameException in project liferay-ide by liferay.

the class JukeboxPortlet method updateSong.

public void updateSong(ActionRequest request, ActionResponse response) throws Exception {
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
    long albumId = ParamUtil.getLong(uploadPortletRequest, "albumId");
    long songId = ParamUtil.getLong(uploadPortletRequest, "songId");
    String name = ParamUtil.getString(uploadPortletRequest, "name");
    InputStream songInputStream = uploadPortletRequest.getFileAsStream("songFile");
    String songFileName = uploadPortletRequest.getFileName("songFile");
    InputStream lyricsInputStream = uploadPortletRequest.getFileAsStream("lyricsFile");
    String lyricsFileName = uploadPortletRequest.getFileName("lyricsFile");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(Song.class.getName(), uploadPortletRequest);
    try {
        SongServiceUtil.updateSong(songId, albumId, name, songFileName, songInputStream, lyricsFileName, lyricsInputStream, serviceContext);
        SessionMessages.add(request, "songUpdated");
        String redirect = ParamUtil.getString(uploadPortletRequest, "redirect");
        response.sendRedirect(redirect);
    } catch (Exception e) {
        SessionErrors.add(request, e.getClass().getName());
        if (e instanceof SongNameException || e instanceof PrincipalException) {
            response.setRenderParameter("jspPage", "/html/songs/edit_song.jsp");
        } else {
            response.setRenderParameter("jspPage", "/html/error.jsp");
        }
    }
}
Also used : Song(org.liferay.jukebox.model.Song) SongNameException(org.liferay.jukebox.SongNameException) InputStream(java.io.InputStream) ServiceContext(com.liferay.portal.service.ServiceContext) PrincipalException(com.liferay.portal.security.auth.PrincipalException) UploadPortletRequest(com.liferay.portal.kernel.upload.UploadPortletRequest) SongNameException(org.liferay.jukebox.SongNameException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) DuplicatedSongException(org.liferay.jukebox.DuplicatedSongException) AlbumNameException(org.liferay.jukebox.AlbumNameException) ArtistNameException(org.liferay.jukebox.ArtistNameException)

Example 2 with SongNameException

use of org.liferay.jukebox.SongNameException in project liferay-ide by liferay.

the class JukeboxPortlet method addSong.

public void addSong(ActionRequest request, ActionResponse response) throws Exception {
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
    long albumId = ParamUtil.getLong(uploadPortletRequest, "albumId");
    String name = ParamUtil.getString(uploadPortletRequest, "name");
    InputStream songInputStream = uploadPortletRequest.getFileAsStream("songFile");
    String songFileName = uploadPortletRequest.getFileName("songFile");
    InputStream lyricsInputStream = uploadPortletRequest.getFileAsStream("lyricsFile");
    String lyricsFileName = uploadPortletRequest.getFileName("lyricsFile");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(Song.class.getName(), uploadPortletRequest);
    try {
        SongServiceUtil.addSong(albumId, name, songFileName, songInputStream, lyricsFileName, lyricsInputStream, serviceContext);
        SessionMessages.add(request, "songAdded");
        String redirect = ParamUtil.getString(uploadPortletRequest, "redirect");
        response.sendRedirect(redirect);
    } catch (Exception e) {
        SessionErrors.add(request, e.getClass().getName());
        if (e instanceof SongNameException || e instanceof DuplicatedSongException || e instanceof PrincipalException) {
            response.setRenderParameter("jspPage", "/html/songs/edit_song.jsp");
        } else {
            response.setRenderParameter("jspPage", "/html/error.jsp");
        }
    }
}
Also used : Song(org.liferay.jukebox.model.Song) SongNameException(org.liferay.jukebox.SongNameException) InputStream(java.io.InputStream) ServiceContext(com.liferay.portal.service.ServiceContext) DuplicatedSongException(org.liferay.jukebox.DuplicatedSongException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) UploadPortletRequest(com.liferay.portal.kernel.upload.UploadPortletRequest) SongNameException(org.liferay.jukebox.SongNameException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) DuplicatedSongException(org.liferay.jukebox.DuplicatedSongException) AlbumNameException(org.liferay.jukebox.AlbumNameException) ArtistNameException(org.liferay.jukebox.ArtistNameException)

Aggregations

UploadPortletRequest (com.liferay.portal.kernel.upload.UploadPortletRequest)2 PrincipalException (com.liferay.portal.security.auth.PrincipalException)2 ServiceContext (com.liferay.portal.service.ServiceContext)2 InputStream (java.io.InputStream)2 AlbumNameException (org.liferay.jukebox.AlbumNameException)2 ArtistNameException (org.liferay.jukebox.ArtistNameException)2 DuplicatedSongException (org.liferay.jukebox.DuplicatedSongException)2 SongNameException (org.liferay.jukebox.SongNameException)2 Song (org.liferay.jukebox.model.Song)2