Search in sources :

Example 21 with ServiceContext

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

the class JukeboxPortlet method deleteAlbum.

public void deleteAlbum(ActionRequest request, ActionResponse response) throws Exception {
    long albumId = ParamUtil.getLong(request, "albumId");
    boolean moveToTrash = ParamUtil.getBoolean(request, "moveToTrash");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(Album.class.getName(), request);
    try {
        if (moveToTrash) {
            Album album = AlbumServiceUtil.moveAlbumToTrash(albumId);
            Map<String, String[]> data = new HashMap<String, String[]>();
            data.put("deleteEntryClassName", new String[] { Album.class.getName() });
            data.put("deleteEntryTitle", new String[] { album.getName() });
            data.put("restoreEntryIds", new String[] { String.valueOf(albumId) });
            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 {
            AlbumServiceUtil.deleteAlbum(albumId, serviceContext);
            SessionMessages.add(request, "albumDeleted");
        }
        sendRedirect(request, response);
    } catch (Exception e) {
        SessionErrors.add(request, e.getClass().getName());
        response.setRenderParameter("jspPage", "/html/error.jsp");
    }
}
Also used : HashMap(java.util.HashMap) ServiceContext(com.liferay.portal.service.ServiceContext) Album(org.liferay.jukebox.model.Album) 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 22 with ServiceContext

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

the class BaseKBPortlet method updateKBComment.

public void updateKBComment(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    if (!themeDisplay.isSignedIn()) {
        return;
    }
    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
    long kbCommentId = ParamUtil.getLong(actionRequest, "kbCommentId");
    long classNameId = ParamUtil.getLong(actionRequest, "classNameId");
    long classPK = ParamUtil.getLong(actionRequest, "classPK");
    String content = ParamUtil.getString(actionRequest, "content");
    int status = ParamUtil.getInteger(actionRequest, "status", KBCommentConstants.STATUS_ANY);
    ServiceContext serviceContext = ServiceContextFactory.getInstance(KBComment.class.getName(), actionRequest);
    if (cmd.equals(Constants.ADD)) {
        KBCommentLocalServiceUtil.addKBComment(themeDisplay.getUserId(), classNameId, classPK, content, serviceContext);
    } else if (cmd.equals(Constants.UPDATE)) {
        if (status == KBCommentConstants.STATUS_ANY) {
            KBComment kbComment = KBCommentServiceUtil.getKBComment(kbCommentId);
            status = kbComment.getStatus();
        }
        KBCommentServiceUtil.updateKBComment(kbCommentId, classNameId, classPK, content, status, serviceContext);
    }
    SessionMessages.add(actionRequest, "suggestionSaved");
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) ServiceContext(com.liferay.portal.service.ServiceContext) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 23 with ServiceContext

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

the class BaseKBPortlet method updateKBCommentStatus.

public void updateKBCommentStatus(ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException, SystemException {
    long kbCommentId = ParamUtil.getLong(actionRequest, "kbCommentId");
    int status = ParamUtil.getInteger(actionRequest, "kbCommentStatus");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(KBComment.class.getName(), actionRequest);
    KBCommentServiceUtil.updateStatus(kbCommentId, status, serviceContext);
    SessionMessages.add(actionRequest, "suggestionStatusUpdated");
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) ServiceContext(com.liferay.portal.service.ServiceContext)

Example 24 with ServiceContext

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

the class KBArticleAttachmentsUtil method getFolderId.

public static long getFolderId(long groupId, long userId, long resourcePrimKey) throws PortalException, SystemException {
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    Repository repository = PortletFileRepositoryUtil.addPortletRepository(groupId, PortletKeys.KNOWLEDGE_BASE_ARTICLE, serviceContext);
    Folder folder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(resourcePrimKey), serviceContext);
    return folder.getFolderId();
}
Also used : Repository(com.liferay.portal.model.Repository) ServiceContext(com.liferay.portal.service.ServiceContext) Folder(com.liferay.portal.kernel.repository.model.Folder)

Example 25 with ServiceContext

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

the class AlbumStagedModelDataHandler method doImportStagedModel.

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Album album) throws Exception {
    long userId = portletDataContext.getUserId(album.getUserUuid());
    ServiceContext serviceContext = portletDataContext.createServiceContext(album);
    String artistPath = ExportImportPathUtil.getModelPath(portletDataContext, Artist.class.getName(), album.getArtistId());
    Artist artist = (Artist) portletDataContext.getZipEntryAsObject(artistPath);
    if (artist != null) {
        StagedModelDataHandlerUtil.importReferenceStagedModel(portletDataContext, album, Artist.class, album.getArtistId());
    }
    Map<Long, Long> artistIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Artist.class);
    long artistId = MapUtil.getLong(artistIds, album.getArtistId(), album.getArtistId());
    Album importedAlbum = null;
    if (portletDataContext.isDataStrategyMirror()) {
        Album existingAlbum = AlbumLocalServiceUtil.fetchAlbumByUuidAndGroupId(album.getUuid(), portletDataContext.getScopeGroupId());
        if (existingAlbum == null) {
            serviceContext.setUuid(album.getUuid());
            importedAlbum = AlbumLocalServiceUtil.addAlbum(userId, artistId, album.getName(), album.getYear(), null, serviceContext);
        } else {
            importedAlbum = AlbumLocalServiceUtil.updateAlbum(userId, existingAlbum.getAlbumId(), artistId, album.getName(), album.getYear(), null, serviceContext);
        }
    } else {
        importedAlbum = AlbumLocalServiceUtil.addAlbum(userId, artistId, album.getName(), album.getYear(), null, serviceContext);
    }
    Element albumElement = portletDataContext.getImportDataStagedModelElement(album);
    List<Element> attachmentElements = portletDataContext.getReferenceDataElements(albumElement, 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;
            }
            importedAlbum = AlbumLocalServiceUtil.updateAlbum(userId, importedAlbum.getAlbumId(), importedAlbum.getArtistId(), importedAlbum.getName(), importedAlbum.getYear(), inputStream, serviceContext);
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
    portletDataContext.importClassedModel(album, importedAlbum);
}
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) Album(org.liferay.jukebox.model.Album) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) Map(java.util.Map)

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