List of usage examples for com.liferay.portal.kernel.service ServiceContext getLiferayPortletResponse
@JSON(include = false)
public LiferayPortletResponse getLiferayPortletResponse()
From source file:com.liferay.contacts.web.internal.notifications.ContactsCenterUserNotificationHandler.java
License:Open Source License
@Override protected String getBody(UserNotificationEvent userNotificationEvent, ServiceContext serviceContext) throws Exception { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(userNotificationEvent.getPayload()); long socialRequestId = jsonObject.getLong("classPK"); SocialRequest socialRequest = _socialRequestLocalService.fetchSocialRequest(socialRequestId); if (socialRequest == null) { _userNotificationEventLocalService .deleteUserNotificationEvent(userNotificationEvent.getUserNotificationEventId()); return null; }/*from w ww . j av a 2 s .c om*/ String creatorUserName = getUserNameLink(socialRequest.getUserId(), serviceContext); ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(serviceContext.getLocale()); String title = StringPool.BLANK; if (socialRequest.getType() == SocialRelationConstants.TYPE_BI_CONNECTION) { title = ResourceBundleUtil.getString(resourceBundle, serviceContext.getLocale(), "request-social-networking-summary-add-connection", new Object[] { creatorUserName }); } else { title = ResourceBundleUtil.getString(resourceBundle, serviceContext.getLocale(), "x-sends-you-a-social-relationship-request", new Object[] { creatorUserName }); } if ((socialRequest.getStatus() != SocialRequestConstants.STATUS_PENDING) || (socialRequest.getModifiedDate() > userNotificationEvent.getTimestamp())) { return StringUtil.replace(_BODY, new String[] { "[$BODY$]", "[$TITLE$]" }, new String[] { StringPool.BLANK, title }); } LiferayPortletResponse liferayPortletResponse = serviceContext.getLiferayPortletResponse(); PortletURL confirmURL = liferayPortletResponse.createActionURL(ContactsPortletKeys.CONTACTS_CENTER); confirmURL.setParameter(ActionRequest.ACTION_NAME, "updateSocialRequest"); confirmURL.setParameter("redirect", serviceContext.getLayoutFullURL()); confirmURL.setParameter("socialRequestId", String.valueOf(socialRequestId)); confirmURL.setParameter("status", String.valueOf(SocialRequestConstants.STATUS_CONFIRM)); confirmURL.setParameter("userNotificationEventId", String.valueOf(userNotificationEvent.getUserNotificationEventId())); confirmURL.setWindowState(WindowState.NORMAL); PortletURL ignoreURL = liferayPortletResponse.createActionURL(ContactsPortletKeys.CONTACTS_CENTER); ignoreURL.setParameter(ActionRequest.ACTION_NAME, "updateSocialRequest"); ignoreURL.setParameter("redirect", serviceContext.getLayoutFullURL()); ignoreURL.setParameter("socialRequestId", String.valueOf(socialRequestId)); ignoreURL.setParameter("status", String.valueOf(SocialRequestConstants.STATUS_IGNORE)); ignoreURL.setParameter("userNotificationEventId", String.valueOf(userNotificationEvent.getUserNotificationEventId())); ignoreURL.setWindowState(WindowState.NORMAL); return StringUtil.replace(getBodyTemplate(), new String[] { "[$CONFIRM$]", "[$CONFIRM_URL$]", "[$IGNORE$]", "[$IGNORE_URL$]", "[$TITLE$]" }, new String[] { serviceContext.translate("confirm"), confirmURL.toString(), serviceContext.translate("ignore"), ignoreURL.toString(), title }); }
From source file:com.liferay.invitation.invite.members.web.internal.notifications.InviteMembersUserNotificationHandler.java
License:Open Source License
@Override protected String getBody(UserNotificationEvent userNotificationEvent, ServiceContext serviceContext) throws Exception { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(userNotificationEvent.getPayload()); long memberRequestId = jsonObject.getLong("classPK"); MemberRequest memberRequest = _memberRequestLocalService.fetchMemberRequest(memberRequestId); if (memberRequest.getStatus() != MembershipRequestConstants.STATUS_PENDING) { return StringPool.BLANK; }/*from www. jav a 2 s . co m*/ Group group = null; if (memberRequest != null) { group = _groupLocalService.fetchGroup(memberRequest.getGroupId()); } if ((group == null) || (memberRequest == null)) { _userNotificationEventLocalService .deleteUserNotificationEvent(userNotificationEvent.getUserNotificationEventId()); return null; } ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(serviceContext.getLocale()); String title = ResourceBundleUtil.getString(resourceBundle, "x-invited-you-to-join-x", getUserNameLink(memberRequest.getUserId(), serviceContext), getSiteDescriptiveName(memberRequest.getGroupId(), serviceContext)); LiferayPortletResponse liferayPortletResponse = serviceContext.getLiferayPortletResponse(); PortletURL confirmURL = liferayPortletResponse.createActionURL(InviteMembersPortletKeys.INVITE_MEMBERS); confirmURL.setParameter(ActionRequest.ACTION_NAME, "updateMemberRequest"); confirmURL.setParameter("memberRequestId", String.valueOf(memberRequestId)); confirmURL.setParameter("status", String.valueOf(MembershipRequestConstants.STATUS_APPROVED)); confirmURL.setParameter("userNotificationEventId", String.valueOf(userNotificationEvent.getUserNotificationEventId())); confirmURL.setWindowState(WindowState.NORMAL); PortletURL ignoreURL = liferayPortletResponse.createActionURL(InviteMembersPortletKeys.INVITE_MEMBERS); ignoreURL.setParameter(ActionRequest.ACTION_NAME, "updateMemberRequest"); ignoreURL.setParameter("memberRequestId", String.valueOf(memberRequestId)); ignoreURL.setParameter("status", String.valueOf(MembershipRequestConstants.STATUS_DENIED)); ignoreURL.setParameter("userNotificationEventId", String.valueOf(userNotificationEvent.getUserNotificationEventId())); ignoreURL.setWindowState(WindowState.NORMAL); return StringUtil.replace(getBodyTemplate(), new String[] { "[$CONFIRM$]", "[$CONFIRM_URL$]", "[$IGNORE$]", "[$IGNORE_URL$]", "[$TITLE$]" }, new String[] { serviceContext.translate("confirm"), confirmURL.toString(), serviceContext.translate("ignore"), ignoreURL.toString(), title }); }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected void notifySubscribers(long userId, JournalArticle article, String action, ServiceContext serviceContext) throws PortalException { String portletId = PortletProviderUtil.getPortletId(JournalArticle.class.getName(), PortletProvider.Action.EDIT); String articleURL = PortalUtil.getControlPanelFullURL(article.getGroupId(), portletId, null); if (!article.isApproved() || Validator.isNull(articleURL)) { return;/*from ww w.ja va 2 s .c o m*/ } JournalGroupServiceConfiguration journalGroupServiceConfiguration = getJournalGroupServiceConfiguration( article.getGroupId()); String articleTitle = article.getTitle(serviceContext.getLanguageId()); articleURL = buildArticleURL(articleURL, article.getGroupId(), article.getFolderId(), article.getArticleId()); if (action.equals("add") && journalGroupServiceConfiguration.emailArticleAddedEnabled()) { } else if (action.equals("move_to") && journalGroupServiceConfiguration.emailArticleMovedToFolderEnabled()) { } else if (action.equals("move_from") && journalGroupServiceConfiguration.emailArticleMovedFromFolderEnabled()) { } else if (action.equals("update") && journalGroupServiceConfiguration.emailArticleUpdatedEnabled()) { } else { return; } String fromName = journalGroupServiceConfiguration.emailFromName(); String fromAddress = journalGroupServiceConfiguration.emailFromAddress(); Map<Locale, String> localizedSubjectMap = null; Map<Locale, String> localizedBodyMap = null; int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY; if (action.equals("add")) { localizedSubjectMap = LocalizationUtil .getMap(journalGroupServiceConfiguration.emailArticleAddedSubject()); localizedBodyMap = LocalizationUtil.getMap(journalGroupServiceConfiguration.emailArticleAddedBody()); } else if (action.equals("move_to")) { localizedSubjectMap = LocalizationUtil .getMap(journalGroupServiceConfiguration.emailArticleMovedToFolderSubject()); localizedBodyMap = LocalizationUtil .getMap(journalGroupServiceConfiguration.emailArticleMovedToFolderBody()); notificationType = JournalArticleConstants.NOTIFICATION_TYPE_MOVE_ENTRY_TO_FOLDER; } else if (action.equals("move_from")) { localizedSubjectMap = LocalizationUtil .getMap(journalGroupServiceConfiguration.emailArticleMovedFromFolderSubject()); localizedBodyMap = LocalizationUtil .getMap(journalGroupServiceConfiguration.emailArticleMovedFromFolderBody()); notificationType = JournalArticleConstants.NOTIFICATION_TYPE_MOVE_ENTRY_FROM_FOLDER; } else if (action.equals("update")) { localizedSubjectMap = LocalizationUtil .getMap(journalGroupServiceConfiguration.emailArticleUpdatedSubject()); localizedBodyMap = LocalizationUtil.getMap(journalGroupServiceConfiguration.emailArticleUpdatedBody()); notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY; } String articleContent = StringPool.BLANK; String articleDiffs = StringPool.BLANK; JournalArticle previousApprovedArticle = getPreviousApprovedArticle(article); try { PortletRequestModel portletRequestModel = new PortletRequestModel( serviceContext.getLiferayPortletRequest(), serviceContext.getLiferayPortletResponse()); JournalArticleDisplay articleDisplay = getArticleDisplay(article, null, Constants.VIEW, LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault()), 1, portletRequestModel, serviceContext.getThemeDisplay()); articleContent = articleDisplay.getContent(); articleDiffs = JournalUtil.diffHtml(article.getGroupId(), article.getArticleId(), previousApprovedArticle.getVersion(), article.getVersion(), LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault()), portletRequestModel, serviceContext.getThemeDisplay()); } catch (Exception e) { } SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender( JournalPermission.RESOURCE_NAME); subscriptionSender.setClassName(article.getModelClassName()); subscriptionSender.setClassPK(article.getId()); subscriptionSender.setCompanyId(article.getCompanyId()); subscriptionSender.setContextAttribute("[$ARTICLE_CONTENT$]", articleContent, false); subscriptionSender.setContextAttribute("[$ARTICLE_DIFFS$]", DiffHtmlUtil.replaceStyles(articleDiffs), false); JournalFolder folder = article.getFolder(); subscriptionSender.setContextAttributes("[$ARTICLE_ID$]", article.getArticleId(), "[$ARTICLE_TITLE$]", articleTitle, "[$ARTICLE_URL$]", articleURL, "[$ARTICLE_VERSION$]", article.getVersion(), "[$FOLDER_NAME$]", folder.getName()); subscriptionSender.setContextCreatorUserPrefix("ARTICLE"); subscriptionSender.setCreatorUserId(article.getUserId()); subscriptionSender.setCurrentUserId(userId); subscriptionSender.setEntryTitle(articleTitle); subscriptionSender.setEntryURL(articleURL); subscriptionSender.setFrom(fromAddress, fromName); subscriptionSender.setHtmlFormat(true); subscriptionSender.setLocalizedBodyMap(localizedBodyMap); subscriptionSender.setLocalizedSubjectMap(localizedSubjectMap); subscriptionSender.setMailId("journal_article", article.getId()); subscriptionSender.setNotificationType(notificationType); subscriptionSender.setPortletId(portletId); subscriptionSender.setReplyToAddress(fromAddress); subscriptionSender.setScopeGroupId(article.getGroupId()); subscriptionSender.setServiceContext(serviceContext); subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), article.getGroupId()); if (folder != null) { subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), folder.getFolderId()); for (Long ancestorFolderId : folder.getAncestorFolderIds()) { subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), ancestorFolderId); } } DDMStructure ddmStructure = ddmStructureLocalService.getStructure(article.getGroupId(), classNameLocalService.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true); subscriptionSender.addPersistedSubscribers(DDMStructure.class.getName(), ddmStructure.getStructureId()); subscriptionSender.addPersistedSubscribers(JournalArticle.class.getName(), article.getResourcePrimKey()); subscriptionSender.flushNotificationsAsync(); }
From source file:com.liferay.microblogs.web.internal.util.MicroblogsWebUtil.java
License:Open Source License
protected static String replaceHashtags(String content, ServiceContext serviceContext) throws PortalException { String escapedContent = HtmlUtil.escape(content); ThemeDisplay themeDisplay = serviceContext.getThemeDisplay(); Matcher matcher = _hashtagPattern.matcher(content); while (matcher.find()) { String result = matcher.group(); StringBuilder sb = new StringBuilder(6); sb.append("<span class=\"hashtag\">#</span>"); sb.append("<a class=\"hashtag-link\" href=\""); PortletURL portletURL = null;/*from w w w . j a va 2 s. c om*/ Group group = GroupLocalServiceUtil.getUserGroup(themeDisplay.getCompanyId(), themeDisplay.getUserId()); long portletPlid = PortalUtil.getPlidFromPortletId(group.getGroupId(), true, MicroblogsPortletKeys.MICROBLOGS); if (portletPlid != 0) { portletURL = PortletURLFactoryUtil.create(serviceContext.getLiferayPortletRequest(), MicroblogsPortletKeys.MICROBLOGS, portletPlid, PortletRequest.RENDER_PHASE); try { portletURL.setWindowState(LiferayWindowState.NORMAL); } catch (WindowStateException wse) { } } else { LiferayPortletResponse liferayPortletResponse = serviceContext.getLiferayPortletResponse(); portletURL = liferayPortletResponse.createRenderURL(MicroblogsPortletKeys.MICROBLOGS); try { portletURL.setWindowState(WindowState.MAXIMIZED); } catch (WindowStateException wse) { } } portletURL.setParameter("mvcPath", "/microblogs/view.jsp"); String assetTagName = result.substring(1); portletURL.setParameter("tabs1", assetTagName); portletURL.setParameter("assetTagName", assetTagName); sb.append(portletURL); sb.append("\">"); sb.append(assetTagName); sb.append("</a>"); String tagLink = sb.toString(); escapedContent = StringUtil.replace(escapedContent, result, tagLink); } return escapedContent; }
From source file:com.liferay.social.activity.customizer.interpreter.CustomWikiActivityInterpreter.java
License:Open Source License
@Override protected String addNoSuchEntryRedirect(String url, String className, long classPK, ServiceContext serviceContext) throws Exception { LiferayPortletResponse liferayPortletResponse = serviceContext.getLiferayPortletResponse(); if (liferayPortletResponse == null) { return null; }//from w ww. ja v a 2 s . com Group group = _groupLocalService.fetchFriendlyURLGroup(serviceContext.getCompanyId(), "/guest"); long plid = _layoutLocalService.getDefaultPlid(group.getGroupId(), true); WikiPage page = _wikiPageLocalService.getPage(classPK); PortletURL portletURL = liferayPortletResponse.createLiferayPortletURL(plid, WikiPortletKeys.WIKI, PortletRequest.RENDER_PHASE); portletURL.setParameter("mvcRenderCommandName", "/wiki/view"); portletURL.setParameter("nodeId", String.valueOf(page.getNodeId())); portletURL.setParameter("title", page.getTitle()); portletURL.setWindowState(WindowState.MAXIMIZED); String viewEntryURL = portletURL.toString(); if (Validator.isNotNull(viewEntryURL)) { return viewEntryURL; } return _http.setParameter(url, "noSuchEntryRedirect", viewEntryURL); }