use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class AlbumLocalServiceImpl method moveAlbumToTrash.
@Indexable(type = IndexableType.REINDEX)
@Override
public Album moveAlbumToTrash(long userId, long albumId) throws PortalException, SystemException {
ServiceContext serviceContext = new ServiceContext();
// Folder
User user = userPersistence.findByPrimaryKey(userId);
Date now = new Date();
Album album = albumPersistence.findByPrimaryKey(albumId);
int oldStatus = album.getStatus();
album.setModifiedDate(serviceContext.getModifiedDate(now));
album.setStatus(WorkflowConstants.STATUS_IN_TRASH);
album.setStatusByUserId(user.getUserId());
album.setStatusByUserName(user.getFullName());
album.setStatusDate(serviceContext.getModifiedDate(now));
albumPersistence.update(album);
// Asset
assetEntryLocalService.updateVisible(Album.class.getName(), album.getAlbumId(), false);
// Trash
TrashEntry trashEntry = trashEntryLocalService.addTrashEntry(userId, album.getGroupId(), Album.class.getName(), album.getAlbumId(), album.getUuid(), null, oldStatus, null, null);
// Folders and entries
List<Song> songs = songLocalService.getSongsByAlbumId(album.getAlbumId());
moveDependentsToTrash(songs, trashEntry.getEntryId());
return album;
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class AlbumLocalServiceImpl method restoreAlbumFromTrash.
@Indexable(type = IndexableType.REINDEX)
@Override
public Album restoreAlbumFromTrash(long userId, long albumId) throws PortalException, SystemException {
ServiceContext serviceContext = new ServiceContext();
// Folder
User user = userPersistence.findByPrimaryKey(userId);
Date now = new Date();
Album album = albumPersistence.findByPrimaryKey(albumId);
TrashEntry trashEntry = trashEntryLocalService.getEntry(Album.class.getName(), albumId);
album.setModifiedDate(serviceContext.getModifiedDate(now));
album.setStatus(trashEntry.getStatus());
album.setStatusByUserId(user.getUserId());
album.setStatusByUserName(user.getFullName());
album.setStatusDate(serviceContext.getModifiedDate(now));
albumPersistence.update(album);
assetEntryLocalService.updateVisible(Album.class.getName(), album.getAlbumId(), true);
// Songs
List<Song> songs = songLocalService.getSongsByAlbumId(album.getGroupId(), album.getAlbumId(), WorkflowConstants.STATUS_IN_TRASH);
restoreDependentsFromTrash(songs, trashEntry.getEntryId());
// Trash
trashEntryLocalService.deleteEntry(trashEntry.getEntryId());
return album;
}
use of com.liferay.portal.service.ServiceContext 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.service.ServiceContext 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.service.ServiceContext 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