Search in sources :

Example 11 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project liferay-ide by liferay.

the class EditorPortlet method updateGadget.

@Override
public void updateGadget(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
    long groupId = themeDisplay.getScopeGroupId();
    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
    if (cmd.equals(Constants.ADD)) {
        GadgetPermission.check(permissionChecker, groupId, ActionKeys.PUBLISH_GADGET);
        Gadget gadget = doAddGadget(actionRequest, actionResponse);
        String publishGadgetRedirect = ParamUtil.getString(actionRequest, "publishGadgetRedirect");
        boolean unpublishPermission = GadgetPermission.contains(permissionChecker, groupId, gadget.getGadgetId(), ActionKeys.DELETE);
        publishGadgetRedirect = HttpUtil.addParameter(publishGadgetRedirect, "unpublishPermission", unpublishPermission);
        publishGadgetRedirect = HttpUtil.addParameter(publishGadgetRedirect, "gadgetId", gadget.getGadgetId());
        actionResponse.sendRedirect(publishGadgetRedirect);
    } else {
        long gadgetId = ParamUtil.getLong(actionRequest, "gadgetId");
        GadgetPermission.check(permissionChecker, groupId, gadgetId, ActionKeys.UPDATE);
        doUpdateGadget(actionRequest, actionResponse);
    }
}
Also used : Gadget(com.liferay.opensocial.model.Gadget) PermissionChecker(com.liferay.portal.security.permission.PermissionChecker) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 12 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project liferay-ide by liferay.

the class EditorPortlet method serveGetFolderChildren.

protected void serveGetFolderChildren(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
    long repositoryId = ParamUtil.getLong(resourceRequest, "repositoryId");
    long folderId = ParamUtil.getLong(resourceRequest, "folderId");
    List<Folder> folders = DLAppServiceUtil.getFolders(repositoryId, folderId);
    folders = ListUtil.sort(folders, new RepositoryModelNameComparator(true));
    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
    for (Folder folder : folders) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        jsonObject.put("entryId", folder.getFolderId());
        jsonObject.put("label", folder.getName());
        jsonObject.put("leaf", false);
        jsonObject.put("type", "editor");
        jsonArray.put(jsonObject);
    }
    boolean getFileEntries = ParamUtil.getBoolean(resourceRequest, "getFileEntries");
    if (getFileEntries) {
        PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
        List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(repositoryId, folderId);
        fileEntries = ListUtil.sort(fileEntries, new RepositoryModelNameComparator(true));
        for (FileEntry fileEntry : fileEntries) {
            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
            jsonObject.put("entryId", fileEntry.getFileEntryId());
            String portalURL = PortalUtil.getPortalURL(themeDisplay);
            String fileEntryURL = ShindigUtil.getFileEntryURL(portalURL, fileEntry.getFileEntryId());
            jsonObject.put("fileEntryURL", fileEntryURL);
            long gadgetId = 0;
            try {
                Gadget gadget = GadgetLocalServiceUtil.getGadget(themeDisplay.getCompanyId(), fileEntryURL);
                gadgetId = gadget.getGadgetId();
            } catch (Exception e) {
            }
            jsonObject.put("gadgetId", gadgetId);
            jsonObject.put("label", fileEntry.getTitle());
            jsonObject.put("leaf", true);
            JSONObject jsonPermissions = JSONFactoryUtil.createJSONObject();
            if (gadgetId > 0) {
                boolean unpublishPermission = GadgetPermission.contains(permissionChecker, themeDisplay.getScopeGroupId(), gadgetId, ActionKeys.DELETE);
                jsonPermissions.put("unpublishPermission", unpublishPermission);
            }
            jsonObject.put("permissions", jsonPermissions);
            jsonObject.put("type", "editor");
            jsonArray.put(jsonObject);
        }
    }
    writeJSON(resourceRequest, resourceResponse, jsonArray);
}
Also used : Gadget(com.liferay.opensocial.model.Gadget) JSONArray(com.liferay.portal.kernel.json.JSONArray) Folder(com.liferay.portal.kernel.repository.model.Folder) IOException(java.io.IOException) PortletException(javax.portlet.PortletException) RepositoryModelNameComparator(com.liferay.portlet.documentlibrary.util.comparator.RepositoryModelNameComparator) JSONObject(com.liferay.portal.kernel.json.JSONObject) PermissionChecker(com.liferay.portal.security.permission.PermissionChecker) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 13 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project liferay-ide by liferay.

the class BaseGadgetPortlet method doRender.

protected void doRender(RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {
    checkExpando(renderRequest, renderResponse);
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletDisplay.getId());
    Gadget gadget = getGadget(renderRequest);
    if (gadget == null) {
        return;
    }
    GadgetSpec gadgetSpec = ShindigUtil.getGadgetSpec(gadget.getUrl());
    overrideConfiguration(gadgetSpec, portlet, portletDisplay);
    renderRequest.setAttribute(WebKeys.GADGET, gadget);
    String view = getView(renderRequest, gadgetSpec);
    renderRequest.setAttribute(WebKeys.VIEW, view);
}
Also used : GadgetSpec(org.apache.shindig.gadgets.spec.GadgetSpec) Gadget(com.liferay.opensocial.model.Gadget) Portlet(com.liferay.portal.model.Portlet) MVCPortlet(com.liferay.util.bridges.mvc.MVCPortlet) PortletDisplay(com.liferay.portal.theme.PortletDisplay) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 14 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project liferay-ide by liferay.

the class GadgetPortlet method getGadget.

@Override
protected Gadget getGadget(RenderRequest renderRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletConfig portletConfig = getPortletConfig();
    return ShindigUtil.getGadget(portletConfig.getPortletName(), themeDisplay.getCompanyId());
}
Also used : PortletConfig(javax.portlet.PortletConfig) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 15 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project liferay-ide by liferay.

the class EditDiscussionAction method updateMessage.

protected MBMessage updateMessage(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    String className = ParamUtil.getString(actionRequest, "className");
    long classPK = ParamUtil.getLong(actionRequest, "classPK");
    String permissionClassName = ParamUtil.getString(actionRequest, "permissionClassName");
    long permissionClassPK = ParamUtil.getLong(actionRequest, "permissionClassPK");
    long permissionOwnerId = ParamUtil.getLong(actionRequest, "permissionOwnerId");
    long messageId = ParamUtil.getLong(actionRequest, "messageId");
    long threadId = ParamUtil.getLong(actionRequest, "threadId");
    long parentMessageId = ParamUtil.getLong(actionRequest, "parentMessageId");
    String subject = ParamUtil.getString(actionRequest, "subject");
    String body = ParamUtil.getString(actionRequest, "body");
    ServiceContext serviceContext = ServiceContextFactory.getInstance(MBMessage.class.getName(), actionRequest);
    MBMessage message = null;
    if (messageId <= 0) {
        // Add message
        User user = null;
        if (themeDisplay.isSignedIn()) {
            user = themeDisplay.getUser();
        } else {
            String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");
            user = UserLocalServiceUtil.fetchUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);
            if ((user == null) || (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE)) {
                return null;
            }
        }
        String name = PrincipalThreadLocal.getName();
        PrincipalThreadLocal.setName(user.getUserId());
        try {
            message = MBMessageServiceUtil.addDiscussionMessage(serviceContext.getScopeGroupId(), className, classPK, permissionClassName, permissionClassPK, permissionOwnerId, threadId, parentMessageId, subject, body, serviceContext);
        } finally {
            PrincipalThreadLocal.setName(name);
        }
    } else {
        // Update message
        message = MBMessageServiceUtil.updateDiscussionMessage(className, classPK, permissionClassName, permissionClassPK, permissionOwnerId, messageId, subject, body, serviceContext);
    }
    // Subscription
    boolean subscribe = ParamUtil.getBoolean(actionRequest, "subscribe");
    if (subscribe) {
        SubscriptionLocalServiceUtil.addSubscription(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), className, classPK);
    }
    return message;
}
Also used : User(com.liferay.portal.model.User) MBMessage(com.liferay.portlet.messageboards.model.MBMessage) ServiceContext(com.liferay.portal.service.ServiceContext) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Aggregations

ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)63 PermissionChecker (com.liferay.portal.security.permission.PermissionChecker)10 ServiceContext (com.liferay.portal.service.ServiceContext)7 JSONObject (com.liferay.portal.kernel.json.JSONObject)6 PortletURL (javax.portlet.PortletURL)6 PortalException (com.liferay.portal.kernel.exception.PortalException)5 User (com.liferay.portal.model.User)5 Gadget (com.liferay.opensocial.model.Gadget)4 SystemException (com.liferay.portal.kernel.exception.SystemException)4 UploadPortletRequest (com.liferay.portal.kernel.upload.UploadPortletRequest)4 PortletConfig (javax.portlet.PortletConfig)4 KBArticle (com.liferay.knowledgebase.model.KBArticle)3 KBFolder (com.liferay.knowledgebase.model.KBFolder)3 Role (com.liferay.portal.model.Role)3 HashMap (java.util.HashMap)3 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)2 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)2 Folder (com.liferay.portal.kernel.repository.model.Folder)2 Layout (com.liferay.portal.model.Layout)2 SocialActivity (com.liferay.portlet.social.model.SocialActivity)2