Search in sources :

Example 1 with MBMessage

use of com.liferay.portlet.messageboards.model.MBMessage 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)

Example 2 with MBMessage

use of com.liferay.portlet.messageboards.model.MBMessage in project liferay-ide by liferay.

the class EditDiscussionAction method processAction.

@Override
public void processAction(ActionMapping actionMapping, ActionForm actionForm, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
    try {
        String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));
        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            MBMessage message = updateMessage(actionRequest);
            boolean ajax = ParamUtil.getBoolean(actionRequest, "ajax");
            if (ajax) {
                String randomNamespace = ParamUtil.getString(actionRequest, "randomNamespace");
                JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
                jsonObject.put("messageId", message.getMessageId());
                jsonObject.put("randomNamespace", randomNamespace);
                writeJSON(actionRequest, actionResponse, jsonObject);
                return;
            }
        } else if (cmd.equals(Constants.DELETE)) {
            deleteMessage(actionRequest);
        } else if (cmd.equals(Constants.SUBSCRIBE_TO_COMMENTS)) {
            subscribeToComments(actionRequest, true);
        } else if (cmd.equals(Constants.UNSUBSCRIBE_FROM_COMMENTS)) {
            subscribeToComments(actionRequest, false);
        }
        sendRedirect(actionRequest, actionResponse, redirect);
    } catch (Exception e) {
        if (e instanceof MessageBodyException || e instanceof NoSuchMessageException || e instanceof PrincipalException || e instanceof RequiredMessageException) {
            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
            jsonObject.putException(e);
            writeJSON(actionRequest, actionResponse, jsonObject);
        } else {
            throw e;
        }
    }
}
Also used : RequiredMessageException(com.liferay.portlet.messageboards.RequiredMessageException) MessageBodyException(com.liferay.portlet.messageboards.MessageBodyException) NoSuchMessageException(com.liferay.portlet.messageboards.NoSuchMessageException) MBMessage(com.liferay.portlet.messageboards.model.MBMessage) JSONObject(com.liferay.portal.kernel.json.JSONObject) PrincipalException(com.liferay.portal.security.auth.PrincipalException) NoSuchMessageException(com.liferay.portlet.messageboards.NoSuchMessageException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) MessageBodyException(com.liferay.portlet.messageboards.MessageBodyException) RequiredMessageException(com.liferay.portlet.messageboards.RequiredMessageException)

Example 3 with MBMessage

use of com.liferay.portlet.messageboards.model.MBMessage in project liferay-ide by liferay.

the class SearchResultTest method getSearchResults.

public static List<SearchResult> getSearchResults(Hits hits, Locale locale, PortletURL portletURL) {
    List<SearchResult> searchResults = new ArrayList<SearchResult>();
    for (Document document : hits.getDocs()) {
        String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME));
        long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));
        try {
            String className = entryClassName;
            long classPK = entryClassPK;
            FileEntry fileEntry = null;
            MBMessage mbMessage = null;
            if (entryClassName.equals(DLFileEntry.class.getName()) || entryClassName.equals(MBMessage.class.getName())) {
                classPK = GetterUtil.getLong(document.get(Field.CLASS_PK));
                long classNameId = GetterUtil.getLong(document.get(Field.CLASS_NAME_ID));
                if ((classPK > 0) && (classNameId > 0)) {
                    className = PortalUtil.getClassName(classNameId);
                    if (entryClassName.equals(DLFileEntry.class.getName())) {
                        fileEntry = DLAppLocalServiceUtil.getFileEntry(entryClassPK);
                    } else if (entryClassName.equals(MBMessage.class.getName())) {
                        mbMessage = MBMessageLocalServiceUtil.getMessage(entryClassPK);
                    }
                } else {
                    className = entryClassName;
                    classPK = entryClassPK;
                }
            }
            SearchResult searchResult = new SearchResult(className, classPK);
            int index = searchResults.indexOf(searchResult);
            if (index < 0) {
                searchResults.add(searchResult);
            } else {
                searchResult = searchResults.get(index);
            }
            if (fileEntry != null) {
                Summary summary = getSummary(document, DLFileEntry.class.getName(), fileEntry.getFileEntryId(), locale, portletURL);
                searchResult.addFileEntry(fileEntry, summary);
            }
            if (mbMessage != null) {
                searchResult.addMBMessage(mbMessage);
                searchResult.getMBMessages();
                searchResult.getFileEntryTuples();
            }
            if (entryClassName.equals(JournalArticle.class.getName())) {
                String version = document.get(Field.VERSION);
                searchResult.addVersion(version);
            }
            if ((mbMessage == null) && (fileEntry == null)) {
                Summary summary = getSummary(document, className, classPK, locale, portletURL);
                searchResult.setSummary(summary);
            } else {
                if (searchResult.getSummary() == null) {
                    Summary summary = getSummary(className, classPK, locale, portletURL);
                    searchResult.setSummary(summary);
                }
            }
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn("Search index is stale and contains entry {" + entryClassPK + "}");
            }
        }
    }
    return searchResults;
}
Also used : ArrayList(java.util.ArrayList) SearchResult(com.liferay.portal.kernel.search.SearchResult) Document(com.liferay.portal.kernel.search.Document) MBMessage(com.liferay.portlet.messageboards.model.MBMessage) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) Summary(com.liferay.portal.kernel.search.Summary) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) JournalArticle(com.liferay.portlet.journal.model.JournalArticle)

Aggregations

MBMessage (com.liferay.portlet.messageboards.model.MBMessage)3 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)1 Document (com.liferay.portal.kernel.search.Document)1 SearchResult (com.liferay.portal.kernel.search.SearchResult)1 Summary (com.liferay.portal.kernel.search.Summary)1 User (com.liferay.portal.model.User)1 PrincipalException (com.liferay.portal.security.auth.PrincipalException)1 ServiceContext (com.liferay.portal.service.ServiceContext)1 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)1 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)1 JournalArticle (com.liferay.portlet.journal.model.JournalArticle)1 MessageBodyException (com.liferay.portlet.messageboards.MessageBodyException)1 NoSuchMessageException (com.liferay.portlet.messageboards.NoSuchMessageException)1 RequiredMessageException (com.liferay.portlet.messageboards.RequiredMessageException)1 ArrayList (java.util.ArrayList)1