Search in sources :

Example 1 with UploadPortletRequest

use of com.liferay.portal.kernel.upload.UploadPortletRequest in project liferay-ide by liferay.

the class AdminPortlet method importFile.

public void importFile(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    InputStream inputStream = null;
    try {
        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
        UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
        long parentKBFolderId = ParamUtil.getLong(uploadPortletRequest, "parentKBFolderId", KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);
        String fileName = uploadPortletRequest.getFileName("file");
        if (Validator.isNull(fileName)) {
            throw new KBArticleImportException("File name is null");
        }
        boolean prioritizeByNumericalPrefix = ParamUtil.getBoolean(uploadPortletRequest, "prioritizeByNumericalPrefix");
        inputStream = uploadPortletRequest.getFileAsStream("file");
        ServiceContext serviceContext = ServiceContextFactory.getInstance(AdminPortlet.class.getName(), actionRequest);
        serviceContext.setGuestPermissions(new String[] { ActionKeys.VIEW });
        int kbArticleCount = KBArticleServiceUtil.addKBArticlesMarkdown(themeDisplay.getScopeGroupId(), parentKBFolderId, fileName, prioritizeByNumericalPrefix, inputStream, serviceContext);
        SessionMessages.add(actionRequest, "importedKBArticlesCount", kbArticleCount);
    } catch (KBArticleImportException kbaie) {
        SessionErrors.add(actionRequest, kbaie.getClass(), kbaie);
    } finally {
        StreamUtil.cleanUp(inputStream);
    }
}
Also used : InputStream(java.io.InputStream) ServiceContext(com.liferay.portal.service.ServiceContext) KBArticleImportException(com.liferay.knowledgebase.KBArticleImportException) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay) UploadPortletRequest(com.liferay.portal.kernel.upload.UploadPortletRequest)

Example 2 with UploadPortletRequest

use of com.liferay.portal.kernel.upload.UploadPortletRequest in project liferay-ide by liferay.

the class EditRecordAction method updateRecord.

protected DDLRecord updateRecord(ActionRequest actionRequest) throws Exception {
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
    ServiceContext serviceContext = ServiceContextFactory.getInstance(DDLRecord.class.getName(), uploadPortletRequest);
    long recordId = ParamUtil.getLong(serviceContext, "recordId");
    long recordSetId = ParamUtil.getLong(serviceContext, "recordSetId");
    return DDLUtil.updateRecord(recordId, recordSetId, true, serviceContext);
}
Also used : ServiceContext(com.liferay.portal.service.ServiceContext) UploadPortletRequest(com.liferay.portal.kernel.upload.UploadPortletRequest) DDLRecord(com.liferay.portlet.dynamicdatalists.model.DDLRecord)

Example 3 with UploadPortletRequest

use of com.liferay.portal.kernel.upload.UploadPortletRequest in project liferay-ide by liferay.

the class JukeboxPortlet method updateArtist.

public void updateArtist(ActionRequest request, ActionResponse response) throws Exception {
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
    long artistId = ParamUtil.getLong(uploadPortletRequest, "artistId");
    String name = ParamUtil.getString(uploadPortletRequest, "name");
    String bio = ParamUtil.getString(uploadPortletRequest, "bio");
    InputStream inputStream = uploadPortletRequest.getFileAsStream("file");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(Artist.class.getName(), uploadPortletRequest);
    try {
        ArtistServiceUtil.updateArtist(artistId, name, bio, inputStream, serviceContext);
        SessionMessages.add(request, "artistUpdated");
        String redirect = ParamUtil.getString(uploadPortletRequest, "redirect");
        response.sendRedirect(redirect);
    } catch (Exception e) {
        SessionErrors.add(request, e.getClass().getName());
        if (e instanceof ArtistNameException || e instanceof PrincipalException) {
            response.setRenderParameter("jspPage", "/html/artists/edit_artist.jsp");
        } else {
            response.setRenderParameter("jspPage", "/html/error.jsp");
        }
    }
}
Also used : Artist(org.liferay.jukebox.model.Artist) ArtistNameException(org.liferay.jukebox.ArtistNameException) 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 4 with UploadPortletRequest

use of com.liferay.portal.kernel.upload.UploadPortletRequest 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 5 with UploadPortletRequest

use of com.liferay.portal.kernel.upload.UploadPortletRequest in project liferay-ide by liferay.

the class JukeboxPortlet method updateAlbum.

public void updateAlbum(ActionRequest request, ActionResponse response) throws Exception {
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
    long albumId = ParamUtil.getLong(uploadPortletRequest, "albumId");
    long artistId = ParamUtil.getLong(uploadPortletRequest, "artistId");
    String name = ParamUtil.getString(uploadPortletRequest, "name");
    int year = ParamUtil.getInteger(uploadPortletRequest, "year");
    InputStream inputStream = uploadPortletRequest.getFileAsStream("file");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(Album.class.getName(), uploadPortletRequest);
    try {
        AlbumServiceUtil.updateAlbum(albumId, artistId, name, year, inputStream, serviceContext);
        SessionMessages.add(request, "albumUpdated");
        String redirect = ParamUtil.getString(uploadPortletRequest, "redirect");
        response.sendRedirect(redirect);
    } catch (Exception e) {
        SessionErrors.add(request, e.getClass().getName());
        if (e instanceof AlbumNameException || e instanceof PrincipalException) {
            response.setRenderParameter("jspPage", "/html/albums/edit_album.jsp");
        } else {
            response.setRenderParameter("jspPage", "/html/error.jsp");
        }
    }
}
Also used : InputStream(java.io.InputStream) ServiceContext(com.liferay.portal.service.ServiceContext) PrincipalException(com.liferay.portal.security.auth.PrincipalException) Album(org.liferay.jukebox.model.Album) UploadPortletRequest(com.liferay.portal.kernel.upload.UploadPortletRequest) AlbumNameException(org.liferay.jukebox.AlbumNameException) 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)15 InputStream (java.io.InputStream)9 ServiceContext (com.liferay.portal.service.ServiceContext)8 PrincipalException (com.liferay.portal.security.auth.PrincipalException)6 AlbumNameException (org.liferay.jukebox.AlbumNameException)6 ArtistNameException (org.liferay.jukebox.ArtistNameException)6 DuplicatedSongException (org.liferay.jukebox.DuplicatedSongException)6 SongNameException (org.liferay.jukebox.SongNameException)6 File (java.io.File)4 PortalException (com.liferay.portal.kernel.exception.PortalException)3 JSONArray (com.liferay.portal.kernel.json.JSONArray)3 JSONException (com.liferay.portal.kernel.json.JSONException)3 JSONObject (com.liferay.portal.kernel.json.JSONObject)3 Role (com.liferay.portal.kernel.model.Role)3 User (com.liferay.portal.kernel.model.User)3 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)3 BufferedReader (java.io.BufferedReader)3 FileReader (java.io.FileReader)3 IOException (java.io.IOException)3 Album (org.liferay.jukebox.model.Album)2