Search in sources :

Example 6 with UploadPortletRequest

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

the class BaseKBPortlet method addTempAttachment.

public void addTempAttachment(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    long resourcePrimKey = ParamUtil.getLong(actionRequest, "resourcePrimKey");
    String sourceFileName = uploadPortletRequest.getFileName("file");
    InputStream inputStream = null;
    try {
        inputStream = uploadPortletRequest.getFileAsStream("file");
        String mimeType = uploadPortletRequest.getContentType("file");
        KBArticleServiceUtil.addTempAttachment(themeDisplay.getScopeGroupId(), resourcePrimKey, sourceFileName, KnowledgeBaseConstants.TEMP_FOLDER_NAME, inputStream, mimeType);
    } finally {
        StreamUtil.cleanUp(inputStream);
    }
}
Also used : InputStream(java.io.InputStream) UploadPortletRequest(com.liferay.portal.kernel.upload.UploadPortletRequest) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 7 with UploadPortletRequest

use of com.liferay.portal.kernel.upload.UploadPortletRequest in project sw360portal by sw360.

the class UserPortlet method getUsersFromRequest.

private List<UserCSV> getUsersFromRequest(PortletRequest request, String fileUploadFormId) throws IOException, TException {
    final UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
    final InputStream stream = uploadPortletRequest.getFileAsStream(fileUploadFormId);
    Reader reader = new InputStreamReader(stream);
    CSVFormat format = CommonUtils.sw360CsvFormat;
    CSVParser parser = new CSVParser(reader, format);
    List<CSVRecord> records;
    records = parser.getRecords();
    if (records.size() > 0) {
        // Remove header
        records.remove(0);
    }
    return getUsersFromCSV(records);
}
Also used : CSVParser(org.apache.commons.csv.CSVParser) CSVFormat(org.apache.commons.csv.CSVFormat) CSVRecord(org.apache.commons.csv.CSVRecord) UploadPortletRequest(com.liferay.portal.kernel.upload.UploadPortletRequest)

Example 8 with UploadPortletRequest

use of com.liferay.portal.kernel.upload.UploadPortletRequest in project sw360portal by sw360.

the class AttachmentPortletUtils method uploadAttachmentPartFromRequest.

private boolean uploadAttachmentPartFromRequest(PortletRequest request, String fileUploadName) throws IOException, TException {
    final UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
    final InputStream stream = uploadPortletRequest.getFileAsStream(fileUploadName);
    final ResumableUpload resumableUpload = ResumableUpload.from(uploadPortletRequest);
    AttachmentContent attachment = null;
    if (resumableUpload.isValid()) {
        final AttachmentStreamConnector attachmentStreamConnector = getConnector();
        attachment = getAttachmentContent(resumableUpload, stream);
        if (attachment != null) {
            try {
                attachmentStreamConnector.uploadAttachmentPart(attachment, resumableUpload.getChunkNumber(), stream);
            } catch (TException e) {
                log.error("Error saving attachment part", e);
                return false;
            }
        }
    }
    return attachment != null;
}
Also used : TException(org.apache.thrift.TException) AttachmentStreamConnector(org.eclipse.sw360.datahandler.couchdb.AttachmentStreamConnector) InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) UploadPortletRequest(com.liferay.portal.kernel.upload.UploadPortletRequest)

Example 9 with UploadPortletRequest

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

the class JukeboxPortlet method addArtist.

public void addArtist(ActionRequest request, ActionResponse response) throws Exception {
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
    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.addArtist(name, bio, inputStream, serviceContext);
        SessionMessages.add(request, "artistAdded");
        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 10 with UploadPortletRequest

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