Search in sources :

Example 26 with ServiceContext

use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.

the class ArtistStagedModelDataHandler method doImportStagedModel.

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Artist artist) throws Exception {
    long userId = portletDataContext.getUserId(artist.getUserUuid());
    ServiceContext serviceContext = portletDataContext.createServiceContext(artist);
    Artist importedArtist = null;
    if (portletDataContext.isDataStrategyMirror()) {
        Artist existingArtist = ArtistLocalServiceUtil.fetchArtistByUuidAndGroupId(artist.getUuid(), portletDataContext.getScopeGroupId());
        if (existingArtist == null) {
            serviceContext.setUuid(artist.getUuid());
            importedArtist = ArtistLocalServiceUtil.addArtist(userId, artist.getName(), artist.getBio(), null, serviceContext);
        } else {
            importedArtist = ArtistLocalServiceUtil.updateArtist(userId, existingArtist.getArtistId(), artist.getName(), artist.getBio(), null, serviceContext);
        }
    } else {
        importedArtist = ArtistLocalServiceUtil.addArtist(userId, artist.getName(), artist.getBio(), null, serviceContext);
    }
    Element artistElement = portletDataContext.getImportDataStagedModelElement(artist);
    List<Element> attachmentElements = portletDataContext.getReferenceDataElements(artistElement, FileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);
    for (Element attachmentElement : attachmentElements) {
        String path = attachmentElement.attributeValue("path");
        FileEntry fileEntry = (FileEntry) portletDataContext.getZipEntryAsObject(path);
        InputStream inputStream = null;
        try {
            String binPath = attachmentElement.attributeValue("bin-path");
            if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) {
                try {
                    inputStream = _getContentStream(fileEntry);
                } catch (NoSuchFileException nsfe) {
                }
            } else {
                inputStream = portletDataContext.getZipEntryAsInputStream(binPath);
            }
            if (inputStream == null) {
                if (_log.isWarnEnabled()) {
                    _log.warn("Unable to import attachment for file entry " + fileEntry.getFileEntryId());
                }
                continue;
            }
            importedArtist = ArtistLocalServiceUtil.updateArtist(userId, importedArtist.getArtistId(), importedArtist.getName(), importedArtist.getBio(), inputStream, serviceContext);
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
    portletDataContext.importClassedModel(artist, importedArtist);
}
Also used : Artist(org.liferay.jukebox.model.Artist) ServiceContext(com.liferay.portal.service.ServiceContext) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream) InputStream(java.io.InputStream) Element(com.liferay.portal.kernel.xml.Element) NoSuchFileException(com.liferay.portlet.documentlibrary.NoSuchFileException) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Example 27 with ServiceContext

use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.

the class JukeboxPortlet method deleteSong.

public void deleteSong(ActionRequest request, ActionResponse response) throws Exception {
    long songId = ParamUtil.getLong(request, "songId");
    boolean moveToTrash = ParamUtil.getBoolean(request, "moveToTrash");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(Song.class.getName(), request);
    try {
        if (moveToTrash) {
            Song song = SongServiceUtil.moveSongToTrash(songId);
            Map<String, String[]> data = new HashMap<String, String[]>();
            data.put("deleteEntryClassName", new String[] { Song.class.getName() });
            data.put("deleteEntryTitle", new String[] { TrashUtil.getOriginalTitle(song.getName()) });
            data.put("restoreEntryIds", new String[] { String.valueOf(songId) });
            SessionMessages.add(request, PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_DELETE_SUCCESS_DATA, data);
            SessionMessages.add(request, PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE);
        } else {
            SongServiceUtil.deleteSong(songId, serviceContext);
            SessionMessages.add(request, "songDeleted");
        }
        sendRedirect(request, response);
    } catch (Exception e) {
        SessionErrors.add(request, e.getClass().getName());
        response.setRenderParameter("jspPage", "/html/error.jsp");
    }
}
Also used : Song(org.liferay.jukebox.model.Song) HashMap(java.util.HashMap) ServiceContext(com.liferay.portal.service.ServiceContext) 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 28 with ServiceContext

use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.

the class JukeboxPortlet method deleteArtist.

public void deleteArtist(ActionRequest request, ActionResponse response) throws Exception {
    long artistId = ParamUtil.getLong(request, "artistId");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(Artist.class.getName(), request);
    try {
        ArtistServiceUtil.deleteArtist(artistId, serviceContext);
        SessionMessages.add(request, "artistDeleted");
        sendRedirect(request, response);
    } catch (Exception e) {
        SessionErrors.add(request, e.getClass().getName());
        response.setRenderParameter("jspPage", "/html/error.jsp");
    }
}
Also used : Artist(org.liferay.jukebox.model.Artist) ServiceContext(com.liferay.portal.service.ServiceContext) 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 29 with ServiceContext

use of com.liferay.portal.service.ServiceContext 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 30 with ServiceContext

use of com.liferay.portal.service.ServiceContext 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

ServiceContext (com.liferay.portal.service.ServiceContext)57 User (com.liferay.portal.model.User)11 PrincipalException (com.liferay.portal.security.auth.PrincipalException)11 InputStream (java.io.InputStream)11 AlbumNameException (org.liferay.jukebox.AlbumNameException)9 ArtistNameException (org.liferay.jukebox.ArtistNameException)9 DuplicatedSongException (org.liferay.jukebox.DuplicatedSongException)9 SongNameException (org.liferay.jukebox.SongNameException)9 UploadPortletRequest (com.liferay.portal.kernel.upload.UploadPortletRequest)8 Song (org.liferay.jukebox.model.Song)8 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)7 Date (java.util.Date)7 SystemException (com.liferay.portal.kernel.exception.SystemException)6 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)6 PortalException (com.liferay.portal.kernel.exception.PortalException)5 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 Artist (org.liferay.jukebox.model.Artist)5 Gadget (com.liferay.opensocial.model.Gadget)4 Folder (com.liferay.portal.kernel.repository.model.Folder)4 Element (com.liferay.portal.kernel.xml.Element)4