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);
}
}
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);
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
Aggregations